-Tester improved (used time is displayed)
This commit is contained in:
parent
f890ca3b7d
commit
66dae4501e
|
@ -44,7 +44,7 @@ int main()
|
|||
|
||||
job_queue = job_queue_create();
|
||||
|
||||
tester_t *tester = tester_create(test_output);
|
||||
tester_t *tester = tester_create(test_output, FALSE);
|
||||
|
||||
tester->test_all(tester,tests);
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include <pluto/defs.h>
|
||||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "tester.h"
|
||||
#include "linked_list.h"
|
||||
|
@ -47,6 +48,7 @@ struct private_tester_s {
|
|||
int tests_count;
|
||||
int failed_tests_count;
|
||||
int failed_asserts_count;
|
||||
bool display_succeeded_asserts;
|
||||
pthread_mutex_t mutex;
|
||||
};
|
||||
|
||||
|
@ -70,18 +72,41 @@ static status_t test_all(tester_t *tester,test_t **tests)
|
|||
return SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the difference of to timeval structs in microseconds
|
||||
*
|
||||
* @param end_time end time
|
||||
* @param start_time start time
|
||||
*
|
||||
* @return difference in microseconds
|
||||
*/
|
||||
static long time_difference(struct timeval *end_time, struct timeval *start_time)
|
||||
{
|
||||
long seconds, microseconds;
|
||||
|
||||
seconds = (end_time->tv_sec - start_time->tv_sec);
|
||||
microseconds = (end_time->tv_usec - start_time->tv_usec);
|
||||
return ((seconds * 1000000) + microseconds);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of function run_test
|
||||
*/
|
||||
static void run_test(tester_t *tester, void (*test_function) (tester_t * tester), char * test_name)
|
||||
{
|
||||
struct timeval start_time, end_time;
|
||||
long timediff;
|
||||
private_tester_t *this = (private_tester_t *) tester;
|
||||
this->tests_count++;
|
||||
this->failed_asserts_count = 0;
|
||||
fprintf(this->output,"Start Test '%s'\n", test_name);
|
||||
gettimeofday(&start_time,NULL);
|
||||
test_function(tester);
|
||||
fprintf(this->output,"End Test '%s'\n", test_name);
|
||||
gettimeofday(&end_time,NULL);
|
||||
timediff = time_difference(&end_time, &start_time);
|
||||
|
||||
fprintf(this->output,"End Test '%s' in %ld microseconds\n", test_name,timediff);
|
||||
if (this->failed_asserts_count > 0)
|
||||
{
|
||||
this->failed_tests_count++;
|
||||
|
@ -107,11 +132,22 @@ static void assert_true(tester_t *tester, bool to_be_true,char * assert_name)
|
|||
fprintf(this->output," Assert '%s' failed!\n", assert_name);
|
||||
}else
|
||||
{
|
||||
fprintf(this->output," Assert '%s' succeeded\n", assert_name);
|
||||
if (this->display_succeeded_asserts)
|
||||
{
|
||||
fprintf(this->output," Assert '%s' succeeded\n", assert_name);
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&(this->mutex));
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of function assert_false
|
||||
*/
|
||||
static void assert_false(tester_t *tester, bool to_be_false,char * assert_name)
|
||||
{
|
||||
tester->assert_true(tester,(!to_be_false),assert_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the destroy function
|
||||
*/
|
||||
|
@ -123,7 +159,7 @@ static status_t destroy(tester_t *tester)
|
|||
return SUCCESS;
|
||||
}
|
||||
|
||||
tester_t *tester_create(FILE *output)
|
||||
tester_t *tester_create(FILE *output, bool display_succeeded_asserts)
|
||||
{
|
||||
private_tester_t *this = alloc_thing(private_tester_t, "private_tester_t");
|
||||
|
||||
|
@ -131,7 +167,9 @@ tester_t *tester_create(FILE *output)
|
|||
this->public.test_all = test_all;
|
||||
this->public.run_test = run_test;
|
||||
this->public.assert_true = assert_true;
|
||||
|
||||
this->public.assert_false = assert_false;
|
||||
|
||||
this->display_succeeded_asserts = display_succeeded_asserts;
|
||||
this->failed_tests_count = 0;
|
||||
this->tests_count = 0;
|
||||
this->output = output;
|
||||
|
|
|
@ -58,16 +58,32 @@ struct tester_s {
|
|||
status_t (*test_all) (tester_t *tester,test_t **tests);
|
||||
|
||||
/**
|
||||
* @brief is called in a testcase to check a specific situation
|
||||
* @brief is called in a testcase to check a specific situation for TRUE
|
||||
*
|
||||
* Log-Values to the tester output are protected from multiple access
|
||||
*
|
||||
* @warning this function should only be called in a test_function
|
||||
*
|
||||
* @param this tester object
|
||||
* @param to_be_true assert which has to be true
|
||||
* @param to_be_true assert which has to be TRUE
|
||||
* @param Name of the assertion
|
||||
*/
|
||||
void (*assert_true) (tester_t *tester, bool to_be_true, char *assert_name);
|
||||
|
||||
/**
|
||||
* @brief is called in a testcase to check a specific situation for FALSE
|
||||
*
|
||||
* Log-Values to the tester output are protected from multiple access
|
||||
*
|
||||
* @warning this function should only be called in a test_function
|
||||
*
|
||||
* @param this tester object
|
||||
* @param to_be_false assert which has to be FALSE
|
||||
* @param Name of the assertion
|
||||
*/
|
||||
void (*assert_false) (tester_t *tester, bool to_be_false, char *assert_name);
|
||||
|
||||
|
||||
/**
|
||||
* @brief run a specific test case
|
||||
*
|
||||
|
@ -87,6 +103,15 @@ struct tester_s {
|
|||
status_t (*destroy) (tester_t *tester);
|
||||
};
|
||||
|
||||
tester_t *tester_create(FILE *output);
|
||||
/**
|
||||
* @brief creates a tester object needed to perform tests
|
||||
*
|
||||
* @param output test output is written to this output
|
||||
* @param display_succeeded_asserts has to be TRUE, if all asserts should be displayed,
|
||||
* else otherwise
|
||||
*
|
||||
* @return tester object
|
||||
*/
|
||||
tester_t *tester_create(FILE *output, bool display_succeeded_asserts);
|
||||
|
||||
#endif /*TESTER_H_*/
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include <pluto/constants.h>
|
||||
#include <pluto/defs.h>
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "../tester.h"
|
||||
#include "../job_queue.h"
|
||||
|
@ -98,8 +99,8 @@ void test_job_queue(tester_t *tester)
|
|||
|
||||
test_infos.tester = tester;
|
||||
test_infos.job_queue = job_queue;
|
||||
test_infos.insert_item_count = 50000;
|
||||
test_infos.remove_item_count = 10000;
|
||||
test_infos.insert_item_count = 100000;
|
||||
test_infos.remove_item_count = 20000;
|
||||
|
||||
|
||||
for (i = 0; i < 5;i++)
|
||||
|
|
Loading…
Reference in New Issue