- changed memory allocator functions to own allocator calls

This commit is contained in:
Jan Hutter
2005-11-09 09:11:06 +00:00
parent c1ca1ee042
commit 7953866962
22 changed files with 606 additions and 606 deletions
+27 -27
View File
@@ -1,8 +1,8 @@
/**
* @file event_queue_test.h
*
*
* @brief Tests to test the Event-Queue type event_queue_t
*
*
*/
/*
@@ -19,10 +19,10 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include <stdlib.h>
#include <pthread.h>
#include "event_queue_test.h"
#include "../tester.h"
#include "../event_queue.h"
@@ -43,23 +43,23 @@
/**
* @brief Informations for the involved test-thread used in this test
*
*
*/
typedef struct event_queue_test_s event_queue_test_t;
struct event_queue_test_s{
tester_t *tester;
event_queue_t *event_queue;
/**
* number of different event times to be inserted in the event-queue by each thread
*/
int insert_times_count;
int insert_times_count;
/**
* number of event to insert at one time
*/
int entries_per_time;
int entries_per_time;
};
@@ -70,21 +70,21 @@ static void event_queue_insert_thread(event_queue_test_t * testinfos)
timeval_t time;
job_t * job;
int i,j;
gettimeofday(&current_time,NULL);
for (i = 0; i < testinfos->insert_times_count;i++)
{
for (j = 0; j < testinfos->entries_per_time;j++)
{
int *value = alloc_thing(int, "value");
int *value = allocator_alloc_thing(int, "value");
*value = i;
job = job_create(INCOMING_PACKET,value);
time.tv_usec = 0;
time.tv_sec = current_time.tv_sec + i;
tester->assert_true(tester,(testinfos->event_queue->add_absolute(testinfos->event_queue,job,time) == SUCCESS), "add call check");
}
}
}
}
@@ -96,22 +96,22 @@ void test_event_queue(tester_t *tester)
int i,j, number_of_total_events;
int count;
timeval_t current_time, start_time;
testinfos.tester = tester;
testinfos.event_queue = event_queue;
testinfos.insert_times_count = EVENT_QUEUE_TIMES;
testinfos.entries_per_time = EVENT_QUEUE_ENTRY_PER_TIME;
number_of_total_events = EVENT_QUEUE_ENTRY_PER_TIME * EVENT_QUEUE_TIMES * EVENT_QUEUE_INSERT_THREADS;
gettimeofday(&start_time,NULL);
for (i = 0; i < EVENT_QUEUE_INSERT_THREADS; i++)
{
pthread_create( &threads[i], NULL,(void*(*)(void*)) &event_queue_insert_thread, (void*) &testinfos);
}
/* wait for all threads */
for (i = 0; i < EVENT_QUEUE_INSERT_THREADS; i++)
@@ -120,22 +120,22 @@ void test_event_queue(tester_t *tester)
}
tester->assert_true(tester,(event_queue->get_count(event_queue,&count) == SUCCESS), "get_count call check");
tester->assert_true(tester,(count == number_of_total_events), "event count check");
tester->assert_true(tester,(count == number_of_total_events), "event count check");
for (i = 0; i < EVENT_QUEUE_TIMES;i++)
{
for (j = 0; j < (EVENT_QUEUE_ENTRY_PER_TIME * EVENT_QUEUE_INSERT_THREADS);j++)
{
job_t *job;
tester->assert_true(tester,(event_queue->get(event_queue,&job) == SUCCESS), "get call check");
tester->assert_true(tester,(event_queue->get(event_queue,&job) == SUCCESS), "get call check");
gettimeofday(&current_time,NULL);
tester->assert_true(tester,((current_time.tv_sec - start_time.tv_sec) == i), "value of entry check");
pfree(job->assigned_data);
tester->assert_true(tester,(job->destroy(job) == SUCCESS), "job destroy call check");
tester->assert_true(tester,((current_time.tv_sec - start_time.tv_sec) == i), "value of entry check");
allocator_free(job->assigned_data);
tester->assert_true(tester,(job->destroy(job) == SUCCESS), "job destroy call check");
}
}
tester->assert_true(tester,(event_queue->destroy(event_queue) == SUCCESS), "destroy call check");
}
+27 -27
View File
@@ -1,8 +1,8 @@
/**
* @file job_queue_test.c
*
*
* @brief Tests to test the Job-Queue type job_queue_t
*
*
*/
/*
@@ -20,50 +20,50 @@
* for more details.
*/
#include <stdlib.h>
#include <freeswan.h>
#include <pluto/constants.h>
#include <pluto/defs.h>
#include <pthread.h>
#include <unistd.h>
#include "job_queue_test.h"
#include "../tester.h"
#include "../job_queue.h"
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;
/**
* number of items to be inserted in the job-queue
* number of items to be inserted in the job-queue
*/
int insert_item_count;
int insert_item_count;
/**
* number of items to be removed by each
* receiver thread from the job-queue
* number of items to be removed by each
* receiver thread from the job-queue
*/
int remove_item_count;
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;
int i;
for (i = 0; i < testinfo->insert_item_count; i++)
{
int *value = alloc_thing(int,"int in test_job_queue_sender");
int *value = allocator_alloc_thing(int,"int in test_job_queue_sender");
*value = i;
job_t *job = job_create(INCOMING_PACKET,value);
testinfo->job_queue->add(testinfo->job_queue,job);
@@ -72,7 +72,7 @@ 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)
@@ -82,8 +82,8 @@ static void test_job_queue_receiver(job_queue_test_t * testinfo)
{
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");
pfree(job->assigned_data);
testinfo->tester->assert_true(testinfo->tester,(job->type == INCOMING_PACKET), "job type check");
allocator_free(job->assigned_data);
testinfo->tester->assert_true(testinfo->tester,(job->destroy(job) == SUCCESS), "job destroy call check");
}
}
@@ -105,11 +105,11 @@ void test_job_queue(tester_t *tester)
test_infos.job_queue = job_queue;
test_infos.insert_item_count = 10000;
test_infos.remove_item_count = 50000;
desired_value = test_infos.insert_item_count * sender_count -
desired_value = test_infos.insert_item_count * sender_count -
test_infos.remove_item_count * receiver_count;
for (i = 0; i < receiver_count;i++)
{
pthread_create( &receiver_threads[i], NULL,(void*(*)(void*)) &test_job_queue_receiver, (void*) &test_infos);
@@ -118,8 +118,8 @@ void test_job_queue(tester_t *tester)
{
pthread_create( &sender_threads[i], NULL,(void*(*)(void*)) &test_job_queue_sender, (void*) &test_infos);
}
/* Wait for all threads */
for (i = 0; i < sender_count;i++)
{
@@ -129,10 +129,10 @@ void test_job_queue(tester_t *tester)
{
pthread_join(receiver_threads[i], NULL);
}
/* the job-queue has to have disered_value count entries! */
tester->assert_true(tester,(job_queue->get_count(job_queue,&value) == SUCCESS), "get count call check");
tester->assert_true(tester,(value == desired_value), "get count value check");
tester->assert_true(tester,(value == desired_value), "get count value check");
tester->assert_true(tester,(job_queue->destroy(job_queue) == SUCCESS), "destroy call check");
}
+10 -10
View File
@@ -1,8 +1,8 @@
/**
* @file receiver_test.c
*
*
* @brief Tests to test the Receiver (type receiver_t)
*
*
*/
/*
@@ -19,7 +19,7 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include <string.h>
#include <unistd.h>
@@ -45,7 +45,7 @@
* Destination IP Address
*/
#define DESTINATION_IP "127.0.0.1"
void test_receiver(tester_t *tester)
{
int i;
@@ -54,21 +54,21 @@ void test_receiver(tester_t *tester)
job_t *job;
packet_t *received_packet;
receiver = receiver_create();
for (i = 0; i < NUMBER_OF_PACKETS_TO_SEND; i++)
{
packet = packet_create(AF_INET);
packet->set_destination(packet,DESTINATION_IP,PORT_TO_SEND);
packet->data.ptr = alloc_thing(int, "packet data");
packet->data.ptr = allocator_alloc_thing(int, "packet data");
packet->data.len = ( sizeof(int));
*((int *) (packet->data.ptr)) = i;
global_socket->send(global_socket,packet);
packet->destroy(packet);
}
for (i = 0; i < NUMBER_OF_PACKETS_TO_SEND; i++)
{
global_job_queue->get(global_job_queue,&job);
global_job_queue->get(global_job_queue,&job);
tester->assert_true(tester, (job->type == INCOMING_PACKET), "job type check");
received_packet = (packet_t *) job->assigned_data;
tester->assert_true(tester, (received_packet->data.len == (sizeof(int))), "received data length check");
@@ -76,7 +76,7 @@ void test_receiver(tester_t *tester)
received_packet->destroy(received_packet);
job->destroy(job);
}
}
tester->assert_true(tester, (receiver->destroy(receiver) == SUCCESS), "destroy call check");
}
+8 -8
View File
@@ -1,8 +1,8 @@
/**
* @file sender_test.h
*
*
* @brief Tests to test the Sender (type sender_t)
*
*
*/
/*
@@ -44,7 +44,7 @@
* Destination IP Address
*/
#define DESTINATION_IP "127.0.0.1"
void test_sender(tester_t *tester)
{
int i;
@@ -52,24 +52,24 @@ void test_sender(tester_t *tester)
packet_t *packet;
packet_t *received_packet;
sender = sender_create();
for (i = 0; i < NUMBER_OF_PACKETS_TO_SEND; i++)
{
packet = packet_create(AF_INET);
packet->set_destination(packet,DESTINATION_IP,PORT_TO_SEND);
packet->data.ptr = alloc_thing(int, "packet data");
packet->data.ptr = allocator_alloc_thing(int, "packet data");
packet->data.len = ( sizeof(int));
*((int *) (packet->data.ptr)) = i;
global_send_queue->add(global_send_queue,packet);
}
for (i = 0; i < NUMBER_OF_PACKETS_TO_SEND; i++)
{
global_socket->receive(global_socket,&received_packet);
tester->assert_true(tester, (received_packet->data.len == (sizeof(int))), "received data length check");
tester->assert_true(tester, (i == *((int *)(received_packet->data.ptr))), "received data value check");
received_packet->destroy(received_packet);
}
}
tester->assert_true(tester, (sender->destroy(sender) == SUCCESS), "destroy call check");
}
+10 -10
View File
@@ -1,8 +1,8 @@
/**
* @file thread_pool_test.c
*
*
* @brief Tests to test the Socket (type socket_t)
*
*
*/
/*
@@ -31,31 +31,31 @@
* Description in header file
*/
void test_socket(tester_t *tester)
{
{
int packet_count = 5;
int current;
socket_t *skt = socket_create(4500);
packet_t *pkt = packet_create(AF_INET);
char *test_string = "Testing functionality of socket_t";
pkt->data.ptr = alloc_bytes(strlen(test_string) + 1,"test_string");
pkt->data.ptr = allocator_alloc(strlen(test_string) + 1,"test_string");
memcpy(pkt->data.ptr,test_string,strlen(test_string) + 1);
pkt->data.len = strlen(test_string) + 1;
/* send to previously bound socket */
pkt->set_destination(pkt, "127.0.0.1", 4500);
/* send packet_count packets */
for (current = 0; current < packet_count; current++)
{
if (skt->send(skt, pkt) == FAILED)
if (skt->send(skt, pkt) == FAILED)
{
tester->assert_true(tester, 0, "packet send");
}
}
pkt->destroy(pkt);
/* receive packet_count packets */
for (current = 0; current < packet_count; current++)
{
@@ -63,7 +63,7 @@ void test_socket(tester_t *tester)
tester->assert_false(tester, strcmp(test_string, pkt->data.ptr), "packet exchange");
pkt->destroy(pkt);
}
tester->assert_true(tester, (skt->destroy(skt) == SUCCESS), "socket destroy call check");
}