]>
git.ipfire.org Git - people/ms/strongswan.git/blob - programs/charon/testing/scheduler_test.c
2 * @file scheduler_test.c
4 * @brief Tests for the scheduler_t class.
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
26 #include "scheduler_test.h"
29 #include <threads/scheduler.h>
30 #include <queues/event_queue.h>
31 #include <queues/job_queue.h>
32 #include <queues/jobs/incoming_packet_job.h>
36 * @brief implementation of a scheduler test
38 * This one uses relative time events, which are not that exact.
39 * Test may fail on too slow machines.
41 void test_scheduler(protected_tester_t
*tester
)
44 job_t
*jobs
[job_count
];
46 scheduler_t
*scheduler
= scheduler_create();
49 for (current
= 0; current
< job_count
; current
++)
51 /* misusing for testing only */
52 jobs
[current
] = (job_t
*) incoming_packet_job_create((packet_t
*)(current
+1));
53 charon
->event_queue
->add_relative(charon
->event_queue
, jobs
[current
], (current
+1) * 500);
57 for (current
= 0; current
< job_count
; current
++)
64 /* check if times are correct */
65 for (current
= 0; current
< job_count
; current
++)
69 tester
->assert_true(tester
, (charon
->job_queue
->get_count(charon
->job_queue
) == current
), "job-queue size before event");
70 tester
->assert_true(tester
, (charon
->event_queue
->get_count(charon
->event_queue
) == job_count
- current
), "event-queue size before event");
73 tester
->assert_true(tester
, (charon
->job_queue
->get_count(charon
->job_queue
) == current
+ 1), "job-queue size after event");
74 tester
->assert_true(tester
, (charon
->event_queue
->get_count(charon
->event_queue
) == job_count
- current
- 1), "event-queue size after event");
78 for (current
= 0; current
< job_count
; current
++)
80 jobs
[current
] = charon
->job_queue
->get(charon
->job_queue
);
81 incoming_packet_job_t
*current_job
;
82 current_job
= (incoming_packet_job_t
*) jobs
[current
];
84 packet
= current_job
->get_packet(current_job
);
86 tester
->assert_true(tester
, (((int)packet
) == current
+1), "job order");
87 jobs
[current
]->destroy(jobs
[current
]);
90 /* destruction test */
91 scheduler
->destroy(scheduler
);