2 * @file scheduler_test.c
4 * @brief Tests to test the Scheduler (type scheduler_t)
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"
27 #include "../globals.h"
28 #include "../scheduler.h"
29 #include "../event_queue.h"
30 #include "../job_queue.h"
34 * @brief implementation of a scheduler test
36 * This one uses relative time events, which are not that exact.
37 * Test may fail on too slow machines.
39 void test_scheduler(tester_t
*tester
)
44 job_t
*jobs
[job_count
];
46 scheduler_t
*scheduler
= scheduler_create();
49 for (current
= 0; current
< job_count
; current
++)
51 jobs
[current
] = job_create(INCOMING_PACKET
, (void*)current
);
52 global_event_queue
->add_relative(global_event_queue
, jobs
[current
], (current
+1) * 500);
56 for (current
= 0; current
< job_count
; current
++)
63 /* check if times are correct */
64 for (current
= 0; current
< job_count
; current
++)
67 global_event_queue
->get_count(global_event_queue
, &event_queue_size
);
68 global_job_queue
->get_count(global_job_queue
, &job_queue_size
);
69 tester
->assert_true(tester
, (job_queue_size
== current
), "job-queue size before event");
70 tester
->assert_true(tester
, (event_queue_size
== job_count
- current
), "event-queue size before event");
72 global_event_queue
->get_count(global_event_queue
, &event_queue_size
);
73 global_job_queue
->get_count(global_job_queue
, &job_queue_size
);
74 tester
->assert_true(tester
, (job_queue_size
== current
+ 1), "job-queue size after event");
75 tester
->assert_true(tester
, (event_queue_size
== job_count
- current
- 1), "event-queue size after event");
79 for (current
= 0; current
< job_count
; current
++)
81 global_job_queue
->get(global_job_queue
, &(jobs
[current
]));
82 tester
->assert_true(tester
, ((int)jobs
[current
]->assigned_data
== current
), "job order");
83 jobs
[current
]->destroy(jobs
[current
]);
86 /* destruction test */
87 tester
->assert_true(tester
, (scheduler
->destroy(scheduler
) == SUCCESS
), "destroy call check");