comparison spandsp-0.0.6pre17/tests/schedule_tests.c @ 4:26cd8f1ef0b1

import spandsp-0.0.6pre17
author Peter Meerwald <pmeerw@cosy.sbg.ac.at>
date Fri, 25 Jun 2010 15:50:58 +0200
parents
children
comparison
equal deleted inserted replaced
3:c6c5a16ce2f2 4:26cd8f1ef0b1
1 /*
2 * SpanDSP - a series of DSP components for telephony
3 *
4 * schedule_tests.c
5 *
6 * Written by Steve Underwood <steveu@coppice.org>
7 *
8 * Copyright (C) 2004 Steve Underwood
9 *
10 * All rights reserved.
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2, as
14 * published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 *
25 * $Id: schedule_tests.c,v 1.20 2008/11/30 05:43:37 steveu Exp $
26 */
27
28 /*! \page schedule_tests_page Event scheduler tests
29 \section schedule_tests_page_sec_1 What does it do?
30 ???.
31
32 \section schedule_tests_page_sec_2 How does it work?
33 ???.
34 */
35
36 #if defined(HAVE_CONFIG_H)
37 #include "config.h"
38 #endif
39
40 #include <stdlib.h>
41 #include <stdio.h>
42 #include <string.h>
43
44 #define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
45 #include "spandsp.h"
46
47 uint64_t when1;
48 uint64_t when2;
49
50 static void callback1(span_sched_state_t *s, void *user_data)
51 {
52 int id;
53 uint64_t when;
54
55 when = span_schedule_time(s);
56 printf("1: Callback at %f %" PRId64 "\n", (float) when/1000000.0, when - when1);
57 if ((when - when1))
58 {
59 printf("Callback occured at the wrong time.\n");
60 exit(2);
61 }
62 id = span_schedule_event(s, 500000, callback1, NULL);
63 when1 = when + 500000;
64 when = span_schedule_next(s);
65 printf("1: Event %d, earliest is %" PRId64 "\n", id, when);
66 }
67
68 static void callback2(span_sched_state_t *s, void *user_data)
69 {
70 int id;
71 uint64_t when;
72
73 when = span_schedule_time(s);
74 printf("2: Callback at %f %" PRId64 "\n", (float) when/1000000.0, when - when2);
75 id = span_schedule_event(s, 550000, callback2, NULL);
76 if ((when - when2) != 10000)
77 {
78 printf("Callback occured at the wrong time.\n");
79 exit(2);
80 }
81 when2 = when + 550000;
82 when = span_schedule_next(s);
83 printf("2: Event %d, earliest is %" PRId64 "\n", id, when);
84 }
85
86 int main(int argc, char *argv[])
87 {
88 int i;
89 int id1;
90 int id2;
91 span_sched_state_t sched;
92 uint64_t when;
93
94 span_schedule_init(&sched);
95
96 id1 = span_schedule_event(&sched, 500000, callback1, NULL);
97 id2 = span_schedule_event(&sched, 550000, callback2, NULL);
98 when1 = span_schedule_time(&sched) + 500000;
99 when2 = span_schedule_time(&sched) + 550000;
100 //span_schedule_del(&sched, id);
101
102 for (i = 0; i < 100000000; i += 20000)
103 {
104 span_schedule_update(&sched, 20000);
105 }
106 when = span_schedule_time(&sched);
107 if ((when1 - when) < 0 || (when1 - when) > 500000 || (when2 - when) < 0 || (when2 - when) > 550000)
108 {
109 printf("Callback failed to occur.\n");
110 exit(2);
111 }
112 span_schedule_release(&sched);
113
114 printf("Tests passed.\n");
115 return 0;
116 }
117 /*- End of function --------------------------------------------------------*/
118 /*- End of file ------------------------------------------------------------*/

Repositories maintained by Peter Meerwald, pmeerw@pmeerw.net.