ip_proto.h now requires expert.h.
[metze/wireshark/wip.git] / echld_test.c
1 /* echld-test.c
2  *  basic test framework for echld
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998 Gerald Combs
9  *
10  * Copyright (c) 2013 by Luis Ontanon <luis@ontanon.org>
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25  */
26
27 #include "config.h"
28
29 #ifdef HAVE_FCNTL_H
30 #include <fcntl.h>
31 #endif
32
33 #ifdef HAVE_SYS_TYPES_H
34 # include <sys/types.h>
35 #endif
36
37 #include <sys/time.h>
38 #include <sys/uio.h>
39
40 #ifdef HAVE_UNISTD_H
41 #include <unistd.h>
42 #endif
43
44 #include <signal.h>
45 #include <stdio.h>
46 #include <stdlib.h>
47
48 #include <glib.h>
49 #include <glib/gprintf.h>
50
51 #include "echld/echld.h"
52 #include "echld/echld-util.h"
53
54 #include "epan/epan.h"
55 #include "wsutil/str_util.h"
56
57 int pings = 0;
58 int errors = 0;
59
60 void ping_cb(long usec, void* data _U_) {
61
62         fprintf(stderr, "Ping ping=%d usec=%d\n", pings ,(int)usec );
63
64         if (usec >= 0) {
65                 pings++;
66         } else {
67                 errors++;
68         }
69 }
70
71 int got_param = 0;
72
73 void param_cb(const char* param, const char* value, const char* error, void* data _U_) {
74         if (error) {
75                 fprintf(stderr, "Param Set Error msg=%s\n", error );
76                 got_param = 0;
77                 return;
78         }
79
80         got_param = 1;
81         fprintf(stderr, "Param: param='%s' val='%s'\n", param, value );
82 }
83
84
85 int main(int argc _U_, char** argv _U_) {
86         struct timeval tv;
87         int tot_cycles = 0;
88         int max_cycles = 50;
89         int child = -1;
90         int keep_going = 1;
91
92         tv.tv_sec = 0;
93         tv.tv_usec = 250000;
94
95         echld_set_parent_dbg_level(5);
96
97         echld_initialize(ECHLD_ENCODING_JSON,argv[0],main);
98
99         do {
100                 if ( tot_cycles == 2 ) echld_ping(0,ping_cb,NULL);
101
102                 if ( tot_cycles == 4 ) {
103                         if (pings!=1) {
104                                 fprintf(stderr, "No Dispatcher PONG 0\n");
105                                 break;
106                         }
107                         echld_ping(0,ping_cb,NULL);
108                 }
109
110                 if ( tot_cycles == 6 ) {
111                         if (pings!=2) {
112                                 fprintf(stderr, "No Dispatcher PONG 1\n");
113                                 break;
114                         }
115
116                         echld_set_param(0,"dbg_level","5",param_cb,NULL);
117                 }
118
119                 if ( tot_cycles == 8) {
120                         if (! got_param ) {
121                                 fprintf(stderr, "Set Dispatcher Param Failed\n");
122                                 break;
123                         }
124
125                         echld_get_param(0,"interfaces",param_cb,NULL);
126                 }
127
128                 if ( tot_cycles == 10) {
129                         if (! got_param ) {
130                                 fprintf(stderr, "Set Dispatcher Param Failed\n");
131                                 break;
132                         }
133
134                         child = echld_new(NULL);
135                         
136                         fprintf(stderr, "New chld_id=%d\n",child);
137
138                         if (child <= 0) {
139                                 fprintf(stderr, "No child\n");
140                                 break;
141                         }
142                 }
143
144
145                 if ( tot_cycles == 16 ) echld_ping(child,ping_cb,NULL);
146
147                 if ( tot_cycles == 18 ) {
148                         if (pings!=3) {
149                                 fprintf(stderr, "No Child PONG 0\n");
150                                 break;
151                         }
152                         echld_ping(child,ping_cb,NULL);
153                 }
154
155
156
157                 if ( tot_cycles == 20 ) {
158                         if (pings!=4) {
159                                 fprintf(stderr, "No Child PONG 1\n");
160                                 break;
161                         }
162
163                         echld_set_param(child,"cookie","hello-hello",param_cb,NULL);
164                 }
165
166
167                 if ( tot_cycles == 22 ) {
168                         if (!got_param) {
169                                 fprintf(stderr, "Set Child Param Failed\n");
170                                 break;
171                         }
172
173                         echld_get_param(child,"dbg_level",param_cb,NULL);
174                 }
175
176                 if ( tot_cycles == 24 ) {
177                         if (!got_param) {
178                                 fprintf(stderr, "Get Child Param Failed\n");
179                                 break;
180                         }
181
182                         keep_going = 0;
183                 }
184
185                 tot_cycles++;
186                 echld_wait(&tv);
187         } while( keep_going && (tot_cycles < max_cycles));
188
189         fprintf(stderr, "Done: pings=%d errors=%d tot_cycles=%d\n", pings, errors ,tot_cycles );
190
191         echld_terminate();
192         return 0;
193 }
194
195
196 void main_window_update(void) {}