2005-11-07 08:57:57 +00:00
|
|
|
/**
|
|
|
|
* @file send_queue_test.c
|
2005-11-10 09:35:28 +00:00
|
|
|
*
|
2005-11-29 07:32:33 +00:00
|
|
|
* @brief Tests for the send_queue_t class.
|
2005-11-10 09:35:28 +00:00
|
|
|
*
|
2005-11-07 08:57:57 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2005 Jan Hutter, Martin Willi
|
|
|
|
* Hochschule fuer Technik Rapperswil
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <pthread.h>
|
|
|
|
|
|
|
|
#include "send_queue_test.h"
|
2005-11-11 13:52:11 +00:00
|
|
|
|
2005-11-23 09:22:25 +00:00
|
|
|
#include <queues/send_queue.h>
|
2005-11-07 08:57:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Informations for the involved test-thread used in this test
|
2005-11-10 09:35:28 +00:00
|
|
|
*
|
2005-11-07 08:57:57 +00:00
|
|
|
*/
|
|
|
|
typedef struct send_queue_test_s send_queue_test_t;
|
|
|
|
|
|
|
|
|
|
|
|
struct send_queue_test_s{
|
|
|
|
/**
|
2005-12-07 11:08:54 +00:00
|
|
|
* Associated protected_tester_t object
|
2005-11-07 08:57:57 +00:00
|
|
|
*/
|
2005-12-07 11:08:54 +00:00
|
|
|
protected_tester_t *tester;
|
2005-11-10 09:35:28 +00:00
|
|
|
|
2005-11-07 08:57:57 +00:00
|
|
|
/**
|
|
|
|
* Queue to test
|
|
|
|
*/
|
|
|
|
send_queue_t *send_queue;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* number of items to be inserted in the send-queue by each thread
|
|
|
|
*/
|
2005-11-10 09:35:28 +00:00
|
|
|
int insert_item_count;
|
2005-11-07 08:57:57 +00:00
|
|
|
|
|
|
|
/**
|
2005-11-10 09:35:28 +00:00
|
|
|
* number of items to be removed by each
|
|
|
|
* receiver thread from the send-queue
|
2005-11-07 08:57:57 +00:00
|
|
|
*/
|
2005-11-10 09:35:28 +00:00
|
|
|
int remove_item_count;
|
2005-11-07 08:57:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief sender thread used in the the send_queue test function
|
2005-11-10 09:35:28 +00:00
|
|
|
*
|
2005-11-07 08:57:57 +00:00
|
|
|
* @param testinfo informations for the specific thread.
|
|
|
|
*/
|
|
|
|
static void test_send_queue_sender(send_queue_test_t * testinfo)
|
|
|
|
{
|
2005-11-10 09:35:28 +00:00
|
|
|
int i;
|
2005-11-07 08:57:57 +00:00
|
|
|
for (i = 0; i < testinfo->insert_item_count; i++)
|
|
|
|
{
|
2006-05-30 13:00:18 +00:00
|
|
|
packet_t *packet = packet_create();
|
2005-11-07 08:57:57 +00:00
|
|
|
testinfo->tester->assert_true(testinfo->tester,(packet != NULL), "create packet call check");
|
2005-11-29 07:15:52 +00:00
|
|
|
testinfo->send_queue->add(testinfo->send_queue,packet);
|
2005-11-07 08:57:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief receiver thread used in the the send_queue test function
|
2005-11-10 09:35:28 +00:00
|
|
|
*
|
2005-11-07 08:57:57 +00:00
|
|
|
* @param testinfo informations for the specific thread.
|
|
|
|
*/
|
|
|
|
static void test_send_queue_receiver(send_queue_test_t * testinfo)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < testinfo->remove_item_count; i++)
|
|
|
|
{
|
|
|
|
packet_t *packet;
|
2005-11-29 07:15:52 +00:00
|
|
|
packet = testinfo->send_queue->get(testinfo->send_queue);
|
2005-11-07 08:57:57 +00:00
|
|
|
|
|
|
|
testinfo->tester->assert_true(testinfo->tester,( packet != NULL), "packet not NULL call check");
|
2005-11-10 09:35:28 +00:00
|
|
|
|
2005-11-29 08:08:03 +00:00
|
|
|
packet->destroy(packet);
|
2005-11-07 08:57:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* description is in header file
|
|
|
|
*/
|
2005-12-07 11:08:54 +00:00
|
|
|
void test_send_queue(protected_tester_t *tester)
|
2005-11-07 08:57:57 +00:00
|
|
|
{
|
2005-11-10 08:44:17 +00:00
|
|
|
int desired_value, i;
|
2005-11-07 08:57:57 +00:00
|
|
|
int sender_count = 10;
|
|
|
|
int receiver_count = 2;
|
|
|
|
pthread_t sender_threads[sender_count];
|
|
|
|
pthread_t receiver_threads[receiver_count];
|
|
|
|
send_queue_t *send_queue = send_queue_create();
|
|
|
|
send_queue_test_t test_infos;
|
|
|
|
|
|
|
|
test_infos.tester = tester;
|
|
|
|
test_infos.send_queue = send_queue;
|
|
|
|
test_infos.insert_item_count = 10000;
|
|
|
|
test_infos.remove_item_count = 10000;
|
2005-11-10 09:35:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
desired_value = test_infos.insert_item_count * sender_count -
|
2005-11-07 08:57:57 +00:00
|
|
|
test_infos.remove_item_count * receiver_count;
|
2005-11-10 09:35:28 +00:00
|
|
|
|
2005-11-07 08:57:57 +00:00
|
|
|
for (i = 0; i < receiver_count;i++)
|
|
|
|
{
|
|
|
|
pthread_create( &receiver_threads[i], NULL,(void*(*)(void*)) &test_send_queue_receiver, (void*) &test_infos);
|
|
|
|
}
|
2005-11-10 09:35:28 +00:00
|
|
|
|
2005-11-07 08:57:57 +00:00
|
|
|
for (i = 0; i < sender_count;i++)
|
|
|
|
{
|
|
|
|
pthread_create( &sender_threads[i], NULL,(void*(*)(void*)) &test_send_queue_sender, (void*) &test_infos);
|
|
|
|
}
|
2005-11-10 09:35:28 +00:00
|
|
|
|
|
|
|
|
2005-11-07 08:57:57 +00:00
|
|
|
/* Wait for all threads */
|
|
|
|
for (i = 0; i < sender_count;i++)
|
|
|
|
{
|
|
|
|
pthread_join(sender_threads[i], NULL);
|
|
|
|
}
|
|
|
|
for (i = 0; i < receiver_count;i++)
|
|
|
|
{
|
|
|
|
pthread_join(receiver_threads[i], NULL);
|
|
|
|
}
|
2005-11-10 09:35:28 +00:00
|
|
|
|
|
|
|
|
2005-11-07 08:57:57 +00:00
|
|
|
/* the send-queue has to have diserd_value count entries*/
|
2005-11-10 08:44:17 +00:00
|
|
|
tester->assert_true(tester,(send_queue->get_count(send_queue) == desired_value), "count value check");
|
2005-11-28 20:29:47 +00:00
|
|
|
send_queue->destroy(send_queue);
|
2005-11-07 08:57:57 +00:00
|
|
|
}
|