diff options
author | Martin Willi <martin@strongswan.org> | 2006-04-28 10:51:19 +0000 |
---|---|---|
committer | Martin Willi <martin@strongswan.org> | 2006-04-28 10:51:19 +0000 |
commit | 1029d84d2365ca6e6b2d2a96e5c0a1fad3c127e3 (patch) | |
tree | d7d1152d0651f01f023b4faa09fc51f936f89e60 /src/charon/testing/scheduler_test.c | |
parent | 51c3484a9f70f03b2ea73151428a40e785c0c56c (diff) | |
download | strongswan-1029d84d2365ca6e6b2d2a96e5c0a1fad3c127e3.tar.bz2 strongswan-1029d84d2365ca6e6b2d2a96e5c0a1fad3c127e3.tar.xz |
Diffstat (limited to 'src/charon/testing/scheduler_test.c')
-rw-r--r-- | src/charon/testing/scheduler_test.c | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/src/charon/testing/scheduler_test.c b/src/charon/testing/scheduler_test.c new file mode 100644 index 000000000..de7346d83 --- /dev/null +++ b/src/charon/testing/scheduler_test.c @@ -0,0 +1,92 @@ +/** + * @file scheduler_test.c + * + * @brief Tests for the scheduler_t class. + * + */ + +/* + * 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 <string.h> +#include <unistd.h> + +#include "scheduler_test.h" + +#include <daemon.h> +#include <threads/scheduler.h> +#include <queues/event_queue.h> +#include <queues/job_queue.h> +#include <queues/jobs/incoming_packet_job.h> + + +/** + * @brief implementation of a scheduler test + * + * This one uses relative time events, which are not that exact. + * Test may fail on too slow machines. + */ +void test_scheduler(protected_tester_t *tester) +{ + int job_count = 5; + job_t *jobs[job_count]; + int current; + scheduler_t *scheduler = scheduler_create(); + + /* schedule 5 jobs */ + for (current = 0; current < job_count; current++) + { + /* misusing for testing only */ + jobs[current] = (job_t *) incoming_packet_job_create((packet_t*)(current+1)); + charon->event_queue->add_relative(charon->event_queue, jobs[current], (current+1) * 500); + } + + + for (current = 0; current < job_count; current++) + { + jobs[current] = NULL; + } + + usleep(50 * 1000); + + /* check if times are correct */ + for (current = 0; current < job_count; current++) + { + usleep(400 * 1000); + + tester->assert_true(tester, (charon->job_queue->get_count(charon->job_queue) == current ), "job-queue size before event"); + tester->assert_true(tester, (charon->event_queue->get_count(charon->event_queue) == job_count - current), "event-queue size before event"); + usleep(100 * 1000); + + tester->assert_true(tester, (charon->job_queue->get_count(charon->job_queue) == current + 1), "job-queue size after event"); + tester->assert_true(tester, (charon->event_queue->get_count(charon->event_queue) == job_count - current - 1), "event-queue size after event"); + } + + /* check job order */ + for (current = 0; current < job_count; current++) + { + jobs[current] = charon->job_queue->get(charon->job_queue); + incoming_packet_job_t *current_job; + current_job = (incoming_packet_job_t*) jobs[current]; + packet_t *packet; + packet = current_job->get_packet(current_job); + + tester->assert_true(tester, (((int)packet) == current+1), "job order"); + jobs[current]->destroy(jobs[current]); + } + + /* destruction test */ + scheduler->destroy(scheduler); +} |