- Tests more documented
This commit is contained in:
parent
5ea7551195
commit
ef23cd28c1
8 changed files with 76 additions and 37 deletions
|
@ -50,12 +50,8 @@ struct private_tester_s {
|
|||
pthread_mutex_t mutex;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Testing of all registered tests
|
||||
*
|
||||
* New tests have to be added in this function
|
||||
/*
|
||||
* Implementation of function test_all
|
||||
*/
|
||||
static status_t test_all(tester_t *tester,test_t **tests)
|
||||
{
|
||||
|
@ -76,8 +72,7 @@ static status_t test_all(tester_t *tester,test_t **tests)
|
|||
|
||||
|
||||
/**
|
||||
* @brief implements the private run_test-Function
|
||||
*
|
||||
* Implementation of function run_test
|
||||
*/
|
||||
static void run_test(tester_t *tester, void (*test_function) (tester_t * tester), char * test_name)
|
||||
{
|
||||
|
@ -94,8 +89,7 @@ static void run_test(tester_t *tester, void (*test_function) (tester_t * tester)
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief implements the private assert_true-Function
|
||||
*
|
||||
* Implementation of function assert_true
|
||||
*/
|
||||
static void assert_true(tester_t *tester, bool to_be_true,char * assert_name)
|
||||
{
|
||||
|
@ -120,7 +114,6 @@ static void assert_true(tester_t *tester, bool to_be_true,char * assert_name)
|
|||
|
||||
/**
|
||||
* Implements the destroy function
|
||||
*
|
||||
*/
|
||||
static status_t destroy(tester_t *tester)
|
||||
{
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
typedef struct test_s test_t;
|
||||
|
||||
/**
|
||||
* @brief A tester object to perform tests
|
||||
* @brief A tester object to perform tests with
|
||||
*/
|
||||
typedef struct tester_s tester_t;
|
||||
|
||||
|
|
|
@ -33,21 +33,33 @@
|
|||
|
||||
typedef struct job_queue_test_s job_queue_test_t;
|
||||
|
||||
/**
|
||||
* @brief Informations for the involved test-thread used in this test
|
||||
*
|
||||
*/
|
||||
struct job_queue_test_s{
|
||||
tester_t *tester;
|
||||
job_queue_t *job_queue;
|
||||
int max_queue_item_count;
|
||||
/**
|
||||
* number of items to be inserted in the job-queue
|
||||
*/
|
||||
int insert_item_count;
|
||||
/**
|
||||
* number of items to be removed by each
|
||||
* receiver thread from the job-queue
|
||||
*/
|
||||
int remove_item_count;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief sender thread used in the the job_queue test function
|
||||
*
|
||||
* @param testinfo informations for the specific thread.
|
||||
*/
|
||||
static void test_job_queue_sender(job_queue_test_t * testinfo)
|
||||
{
|
||||
|
||||
int i;
|
||||
|
||||
for (i = 0; i < testinfo->max_queue_item_count; i++)
|
||||
int i;
|
||||
for (i = 0; i < testinfo->insert_item_count; i++)
|
||||
{
|
||||
int *value = alloc_thing(int,"int");
|
||||
*value = i;
|
||||
|
@ -58,43 +70,52 @@ static void test_job_queue_sender(job_queue_test_t * testinfo)
|
|||
|
||||
/**
|
||||
* @brief receiver thread used in the the job_queue test function
|
||||
*
|
||||
* @param testinfo informations for the specific thread.
|
||||
*/
|
||||
static void test_job_queue_receiver(job_queue_test_t * testinfo)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < testinfo->max_queue_item_count; i++)
|
||||
for (i = 0; i < testinfo->remove_item_count; i++)
|
||||
{
|
||||
job_t *job;
|
||||
testinfo->tester->assert_true(testinfo->tester,(testinfo->job_queue->get(testinfo->job_queue,&job) == SUCCESS), "get job call check");
|
||||
testinfo->tester->assert_true(testinfo->tester,(job->type == INCOMING_PACKET), "job type check");
|
||||
testinfo->tester->assert_true(testinfo->tester,((*((int *) (job->assigned_data))) == i), "job value check");
|
||||
|
||||
testinfo->tester->assert_true(testinfo->tester,(job->type == INCOMING_PACKET), "job type check");
|
||||
pfree(job->assigned_data);
|
||||
testinfo->tester->assert_true(testinfo->tester,(job->destroy(job) == SUCCESS), "job destroy call check");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* description is in header file
|
||||
*/
|
||||
void test_job_queue(tester_t *tester)
|
||||
{
|
||||
int value = 1000;
|
||||
pthread_t sender_thread, receiver_thread;
|
||||
int value, i;
|
||||
pthread_t sender_thread, receiver_threads[5];
|
||||
job_queue_t *job_queue = job_queue_create();
|
||||
job_queue_test_t test_infos;
|
||||
|
||||
test_infos.tester = tester;
|
||||
test_infos.job_queue = job_queue;
|
||||
test_infos.max_queue_item_count = 100000;
|
||||
test_infos.insert_item_count = 50000;
|
||||
test_infos.remove_item_count = 10000;
|
||||
|
||||
pthread_create( &receiver_thread, NULL,(void*(*)(void*)) &test_job_queue_receiver, (void*) &test_infos);
|
||||
|
||||
for (i = 0; i < 5;i++)
|
||||
{
|
||||
pthread_create( &receiver_threads[i], NULL,(void*(*)(void*)) &test_job_queue_receiver, (void*) &test_infos);
|
||||
}
|
||||
pthread_create( &sender_thread, NULL,(void*(*)(void*)) &test_job_queue_sender, (void*) &test_infos);
|
||||
|
||||
pthread_join(sender_thread, NULL);
|
||||
pthread_join(receiver_thread, NULL);
|
||||
|
||||
/* Wait for all threads */
|
||||
pthread_join(sender_thread, NULL);
|
||||
for (i = 0; i < 5;i++)
|
||||
{
|
||||
pthread_join(receiver_threads[i], NULL);
|
||||
}
|
||||
|
||||
/* the job-queue has to be empty now! */
|
||||
tester->assert_true(tester,(job_queue->get_count(job_queue,&value) == SUCCESS), "get count call check");
|
||||
tester->assert_true(tester,(value == 0), "get count value check");
|
||||
tester->assert_true(tester,(job_queue->destroy(job_queue) == SUCCESS), "destroy call check");
|
||||
|
|
|
@ -25,11 +25,17 @@
|
|||
|
||||
/**
|
||||
* @brief Test function used to test the job_queue functionality
|
||||
*
|
||||
* Tests are performed using different threads to test the multi-threaded
|
||||
* features of the job_queue_t.
|
||||
*
|
||||
* @param tester associated tester object
|
||||
*/
|
||||
void test_job_queue(tester_t *tester);
|
||||
|
||||
/**
|
||||
* Test 1 for linked_list_t
|
||||
*/
|
||||
test_t job_queue_test1 = {test_job_queue,"Job-Queue Test1"};
|
||||
|
||||
#endif /*JOB_QUEUE_TEST_H_*/
|
||||
|
|
|
@ -24,13 +24,21 @@
|
|||
#define LINKED_LIST_TEST_H_
|
||||
|
||||
/**
|
||||
* @brief Tes function for the type linked_list_t
|
||||
* @brief Test function for the type linked_list_t
|
||||
*
|
||||
* Performs different kinds of assertions to check the functionality
|
||||
* of the linked_list_t in a Single-Threaded environment.
|
||||
*
|
||||
* @warning To be usable in multi-threaded software
|
||||
* this list has to get protected with locks.
|
||||
*
|
||||
* @param tester tester object
|
||||
*/
|
||||
void test_linked_list(tester_t *tester);
|
||||
|
||||
|
||||
/**
|
||||
* Test for linked_list_t
|
||||
*/
|
||||
test_t linked_list_test = {test_linked_list,"Linked List"};
|
||||
|
||||
#endif /*LINKED_LIST_TEST_H_*/
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
/**
|
||||
* @file tests.h
|
||||
*
|
||||
* @brief Lists all the tests to get performed by the tester
|
||||
* @brief Lists all the tests to be processed by the tester object
|
||||
*
|
||||
* New tests have to be added here
|
||||
* New tests have to be added here!
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -30,7 +30,10 @@
|
|||
#include "thread_pool_test.h"
|
||||
#include "job_queue_test.h"
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief these tests are getting performed by the tester
|
||||
*/
|
||||
test_t *tests[] ={
|
||||
&linked_list_test,
|
||||
&thread_pool_test,
|
||||
|
|
|
@ -24,8 +24,8 @@
|
|||
#include "../tester.h"
|
||||
#include "../thread_pool.h"
|
||||
|
||||
/**
|
||||
* @brief Test function to test the thread pool class
|
||||
/*
|
||||
* Description in header file
|
||||
*/
|
||||
void test_thread_pool(tester_t *tester)
|
||||
{
|
||||
|
|
|
@ -23,8 +23,16 @@
|
|||
#ifndef THREAD_POOL_TEST_H_
|
||||
#define THREAD_POOL_TEST_H_
|
||||
|
||||
/**
|
||||
* @brief Test function for the type thread_pool_t
|
||||
*
|
||||
* @param tester tester object
|
||||
*/
|
||||
void test_thread_pool(tester_t *tester);
|
||||
|
||||
/**
|
||||
* Test for thread_pool_t
|
||||
*/
|
||||
test_t thread_pool_test = {test_thread_pool,"Thread Pool"};
|
||||
|
||||
#endif /*THREAD_POOL_TEST_H_*/
|
||||
|
|
Loading…
Reference in a new issue