Statistics
| Branch: | Tag: | Revision:

sssimulator / EventScheduler / Test / event_scheduler_test.c @ af271552

History | View | Annotate | Download (3.6 KB)

1
/*
2
 * this is sssim: the simple & stupid simulator
3
 *
4
 *  copyright (c) 2015 luca baldesi
5
 *
6
 *  this is free software; see gpl-3.0.txt
7
 */
8

    
9
#include<malloc.h>
10
#include<assert.h>
11

    
12
#include"event_scheduler.h"
13

    
14
void event_scheduler_destroy_test()
15
{
16
        event_scheduler_destroy(NULL);
17
        fprintf(stderr,"%s successfully passed!\n",__func__);
18
}
19

    
20
void event_scheduler_new_test()
21
{
22
        struct event_scheduler * es;
23

    
24
        es = event_scheduler_new(0);
25
        assert(es != NULL);
26
        event_scheduler_destroy(&es);
27
        assert(es == NULL);
28

    
29
        es = event_scheduler_new(1);
30
        assert(es != NULL);
31
        event_scheduler_destroy(&es);
32
        assert(es == NULL);
33

    
34
        fprintf(stderr,"%s successfully passed!\n",__func__);
35
}
36

    
37
void event_scheduler_insert_test()
38
{
39
        struct event_scheduler * es;
40
        struct action_event * ev;
41
        int res;
42

    
43
        es = event_scheduler_new(0);
44
        ev = action_event_new(NULL);
45

    
46
        res = event_scheduler_insert(NULL,NULL,-1);
47
        assert(res < 0);
48

    
49
        res = event_scheduler_insert(NULL,ev,-1);
50
        assert(res < 0);
51

    
52
        res = event_scheduler_insert(NULL,NULL,1);
53
        assert(res < 0);
54

    
55
        res = event_scheduler_insert(NULL,ev,1);
56
        assert(res < 0);
57

    
58
        res = event_scheduler_insert(es,NULL,-1);
59
        assert(res < 0);
60

    
61
        res = event_scheduler_insert(es,ev,-1);
62
        assert(res < 0);
63

    
64
        res = event_scheduler_insert(es,NULL,1);
65
        assert(res < 0);
66

    
67
        res = event_scheduler_insert(es,ev,1);
68
        assert(res == 0);
69

    
70
        event_scheduler_destroy(&es);
71
        action_event_destroy(&ev);
72

    
73
        fprintf(stderr,"%s successfully passed!\n",__func__);
74
}
75

    
76
void event_scheduler_queue_length_test()
77
{
78
        struct event_scheduler * es;
79
        struct action_event * ev;
80
        uint32_t res;
81

    
82
        es = event_scheduler_new(0);
83
        ev = action_event_new(NULL);
84

    
85
        res = event_scheduler_queue_length(NULL);
86
        assert(res == 0);
87

    
88
        res = event_scheduler_queue_length(es);
89
        assert(res == 0);
90

    
91
        event_scheduler_insert(es,ev,0);
92
        res = event_scheduler_queue_length(es);
93
        assert(res == 1);
94

    
95
        event_scheduler_insert(es,ev,0);
96
        res = event_scheduler_queue_length(es);
97
        assert(res == 2);
98

    
99
        event_scheduler_destroy(&es);
100
        action_event_destroy(&ev);
101

    
102
        fprintf(stderr,"%s successfully passed!\n",__func__);
103
}
104

    
105
void event_scheduler_elapsed_time_test()
106
{
107
        struct event_scheduler * es;
108

    
109
        es = event_scheduler_new(0);
110

    
111
        assert(event_scheduler_elapsed_time(NULL) < 0);
112
        assert(event_scheduler_elapsed_time(es) == 0);
113

    
114
        event_scheduler_destroy(&es);
115
        fprintf(stderr,"%s successfully passed!\n",__func__);
116
}
117

    
118
void event_scheduler_pop_test()
119
{
120
        struct event_scheduler * es;
121
        struct action_event * ev, *ev2, *ev3, *ev4;
122

    
123
        es = event_scheduler_new(0);
124
        ev = action_event_new(NULL);
125

    
126
        assert(event_scheduler_pop(NULL) == NULL);
127
        assert(event_scheduler_pop(es) == NULL);
128
        event_scheduler_insert(es,ev,1);
129
        assert(event_scheduler_pop(es) == ev);
130
        assert(event_scheduler_queue_length(es) == 0);
131
        assert(event_scheduler_elapsed_time(es) == 1);
132

    
133
        ev2 = action_event_new(NULL);
134
        ev3 = action_event_new(NULL);
135
        ev4= action_event_new(NULL);
136
        event_scheduler_insert(es,ev4,3);
137
        event_scheduler_insert(es,ev2,1);
138
        event_scheduler_insert(es,ev3,2);
139

    
140
        assert(event_scheduler_pop(es) == ev2);
141
        assert(event_scheduler_elapsed_time(es) == 2);
142
        assert(event_scheduler_pop(es) == ev3);
143
        assert(event_scheduler_elapsed_time(es) == 3);
144
        assert(event_scheduler_pop(es) == ev4);
145
        assert(event_scheduler_elapsed_time(es) == 4);
146

    
147
        event_scheduler_destroy(&es);
148
        action_event_destroy(&ev);
149
        action_event_destroy(&ev2);
150
        action_event_destroy(&ev3);
151
        action_event_destroy(&ev4);
152

    
153
        fprintf(stderr,"%s successfully passed!\n",__func__);
154
}
155

    
156
int main(char ** argc,int argv)
157
{
158
        event_scheduler_destroy_test();
159
        event_scheduler_new_test();
160
        event_scheduler_insert_test();
161
        event_scheduler_queue_length_test();
162
        event_scheduler_elapsed_time_test();
163
        event_scheduler_pop_test();
164
        return 0;
165
}