2013-06-22 20:26:13 +00:00
|
|
|
/* echld-test.c
|
|
|
|
* basic test framework for echld
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
|
|
|
* Copyright (c) 2013 by Luis Ontanon <luis@ontanon.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2013-06-25 00:31:01 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_FCNTL_H
|
|
|
|
#include <fcntl.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
|
|
|
# include <sys/types.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/uio.h>
|
|
|
|
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2013-06-22 20:26:13 +00:00
|
|
|
#include <signal.h>
|
|
|
|
#include <stdio.h>
|
2013-06-25 00:31:01 +00:00
|
|
|
#include <stdlib.h>
|
2013-06-22 20:26:13 +00:00
|
|
|
|
2013-06-25 03:33:02 +00:00
|
|
|
#include <glib.h>
|
|
|
|
#include <glib/gprintf.h>
|
|
|
|
|
|
|
|
#include "echld/echld.h"
|
|
|
|
#include "echld/echld-util.h"
|
|
|
|
|
|
|
|
#include "epan/epan.h"
|
|
|
|
#include "wsutil/str_util.h"
|
2013-06-22 20:26:13 +00:00
|
|
|
|
2013-06-25 00:31:01 +00:00
|
|
|
int pings = 0;
|
|
|
|
int errors = 0;
|
2013-06-22 20:26:13 +00:00
|
|
|
|
2013-06-25 00:31:01 +00:00
|
|
|
void ping_cb(long usec, void* data _U_) {
|
2013-06-27 03:41:48 +00:00
|
|
|
|
|
|
|
fprintf(stderr, "Ping ping=%d usec=%d\n", pings ,(int)usec );
|
|
|
|
|
|
|
|
if (usec >= 0) {
|
2013-06-25 00:31:01 +00:00
|
|
|
pings++;
|
|
|
|
} else {
|
|
|
|
errors++;
|
|
|
|
}
|
|
|
|
}
|
2013-06-22 20:26:13 +00:00
|
|
|
|
2013-06-28 21:10:52 +00:00
|
|
|
int got_param = 0;
|
|
|
|
|
2013-06-27 19:00:01 +00:00
|
|
|
void param_cb(const char* param, const char* value, const char* error, void* data _U_) {
|
|
|
|
if (error) {
|
|
|
|
fprintf(stderr, "Param Set Error msg=%s\n", error );
|
2013-06-28 21:10:52 +00:00
|
|
|
got_param = 0;
|
2013-06-27 19:00:01 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-28 21:10:52 +00:00
|
|
|
got_param = 1;
|
2013-06-27 19:00:01 +00:00
|
|
|
fprintf(stderr, "Param: param='%s' val='%s'\n", param, value );
|
|
|
|
}
|
2013-06-22 20:26:13 +00:00
|
|
|
|
2013-06-27 19:00:01 +00:00
|
|
|
|
|
|
|
int main(int argc _U_, char** argv _U_) {
|
2013-06-25 00:31:01 +00:00
|
|
|
struct timeval tv;
|
|
|
|
int tot_cycles = 0;
|
2013-06-28 21:10:52 +00:00
|
|
|
int max_cycles = 50;
|
|
|
|
int child = -1;
|
|
|
|
int keep_going = 1;
|
|
|
|
|
2013-06-25 00:31:01 +00:00
|
|
|
tv.tv_sec = 0;
|
|
|
|
tv.tv_usec = 250000;
|
2013-06-22 20:26:13 +00:00
|
|
|
|
2013-06-27 03:41:48 +00:00
|
|
|
echld_set_parent_dbg_level(5);
|
2013-06-25 03:33:02 +00:00
|
|
|
|
2013-06-27 19:00:01 +00:00
|
|
|
echld_initialize(ECHLD_ENCODING_JSON,argv[0],main);
|
2013-06-25 00:31:01 +00:00
|
|
|
|
2013-06-27 19:00:01 +00:00
|
|
|
do {
|
2013-06-28 21:10:52 +00:00
|
|
|
if ( tot_cycles == 2 ) echld_ping(0,ping_cb,NULL);
|
|
|
|
|
|
|
|
if ( tot_cycles == 4 ) {
|
|
|
|
if (pings!=1) {
|
|
|
|
fprintf(stderr, "No Dispatcher PONG 0\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
echld_ping(0,ping_cb,NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( tot_cycles == 6 ) {
|
|
|
|
if (pings!=2) {
|
|
|
|
fprintf(stderr, "No Dispatcher PONG 1\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
echld_set_param(0,"dbg_level","5",param_cb,NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( tot_cycles == 8) {
|
|
|
|
if (! got_param ) {
|
|
|
|
fprintf(stderr, "Set Dispatcher Param Failed\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
echld_get_param(0,"interfaces",param_cb,NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( tot_cycles == 10) {
|
|
|
|
if (! got_param ) {
|
|
|
|
fprintf(stderr, "Set Dispatcher Param Failed\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
child = echld_new(NULL);
|
|
|
|
|
|
|
|
fprintf(stderr, "New chld_id=%d\n",child);
|
|
|
|
|
|
|
|
if (child <= 0) {
|
|
|
|
fprintf(stderr, "No child\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ( tot_cycles == 16 ) echld_ping(child,ping_cb,NULL);
|
|
|
|
|
|
|
|
if ( tot_cycles == 18 ) {
|
|
|
|
if (pings!=3) {
|
|
|
|
fprintf(stderr, "No Child PONG 0\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
echld_ping(child,ping_cb,NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( tot_cycles == 20 ) {
|
|
|
|
if (pings!=4) {
|
|
|
|
fprintf(stderr, "No Child PONG 1\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
echld_set_param(child,"cookie","hello-hello",param_cb,NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ( tot_cycles == 22 ) {
|
|
|
|
if (!got_param) {
|
|
|
|
fprintf(stderr, "Set Child Param Failed\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
echld_get_param(child,"dbg_level",param_cb,NULL);
|
|
|
|
}
|
2013-06-27 03:41:48 +00:00
|
|
|
|
2013-06-28 21:10:52 +00:00
|
|
|
if ( tot_cycles == 24 ) {
|
|
|
|
if (!got_param) {
|
|
|
|
fprintf(stderr, "Get Child Param Failed\n");
|
|
|
|
break;
|
|
|
|
}
|
2013-06-25 00:31:01 +00:00
|
|
|
|
2013-06-28 21:10:52 +00:00
|
|
|
keep_going = 0;
|
|
|
|
}
|
2013-06-25 00:31:01 +00:00
|
|
|
|
|
|
|
tot_cycles++;
|
2013-06-25 17:43:52 +00:00
|
|
|
echld_wait(&tv);
|
2013-06-28 21:10:52 +00:00
|
|
|
} while( keep_going && (tot_cycles < max_cycles));
|
2013-06-25 00:31:01 +00:00
|
|
|
|
|
|
|
fprintf(stderr, "Done: pings=%d errors=%d tot_cycles=%d\n", pings, errors ,tot_cycles );
|
|
|
|
|
|
|
|
echld_terminate();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-27 19:00:01 +00:00
|
|
|
void main_window_update(void) {}
|