/** * Callback to be called when an operation is completed * * @param cls the callback closure from functions generating an operation * @param op the operation that has been finished * @param emsg error message in case the operation has failed; will be NULL if * operation has executed successfully. */ static void op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg) { if (common_operation != op) { GNUNET_break (0); abort_test (); return; } switch (result) { case PEER3_STARTED: case PEERS_2_3_CONNECTED: case PEERS_1_2_CONNECTED: break; default: GNUNET_break (0); abort_test (); return; } if ((NULL != peer1.operation) || (NULL != peer2.operation) || (NULL != peer3.operation)) { GNUNET_break (0); abort_test (); return; } }
/** * Callback to signal successfull startup of the controller process * * @param cls the closure from GNUNET_TESTBED_controller_start() * @param cfg the configuration with which the controller has been started; * NULL if status is not GNUNET_OK * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not, * GNUNET_TESTBED_controller_stop() shouldn't be called in this case */ static void status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *config, int status) { uint64_t event_mask; if (GNUNET_OK != status) { GNUNET_break (0); cp1 = NULL; abort_test (); return; } event_mask = 0; event_mask |= (1L << GNUNET_TESTBED_ET_PEER_START); event_mask |= (1L << GNUNET_TESTBED_ET_PEER_STOP); event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT); event_mask |= (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED); switch (result) { case INIT: controller1 = GNUNET_TESTBED_controller_connect (host, event_mask, &controller_cb, NULL); if (NULL == controller1) { GNUNET_break (0); abort_test (); return; } result = CONTROLLER1_UP; neighbour1 = GNUNET_TESTBED_host_create ("127.0.0.1", NULL, cfg, 0); if (NULL == neighbour1) { GNUNET_break (0); abort_test (); return; } reg_handle = GNUNET_TESTBED_register_host (controller1, neighbour1, ®istration_comp, neighbour1); if (NULL == reg_handle) { GNUNET_break (0); abort_test (); return; } break; default: GNUNET_break (0); abort_test (); return; } }
static void tls_endpoint_estab_handler(const char *cipher, void *arg) { int err; (void)arg; re_fprintf(stderr, "\r[ %u .. %c ]", tlsperf.count, 0x20 + tlsperf.count % 0x60); if (tls_endpoint_established(tlsperf.ep_cli) && tls_endpoint_established(tlsperf.ep_srv)) { if (tlsperf.count >= tlsperf.num) { tlsperf.ts_estab = tmr_jiffies(); re_printf("\nDONE!\n"); re_printf("cipher: %s\n", cipher); print_report(); re_cancel(); } else { stop_test(); err = start_test(); if (err) abort_test(err); } } }
/** * Main run function. * * @param cls NULL * @param args arguments passed to GNUNET_PROGRAM_run * @param cfgfile the path to configuration file * @param cfg the configuration file handle */ static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *config) { cfg = GNUNET_CONFIGURATION_dup (config); host = GNUNET_TESTBED_host_create (NULL, NULL, cfg, 0); if (NULL == host) { GNUNET_break (0); abort_test (); return; } if (NULL == (hc_handle = GNUNET_TESTBED_is_host_habitable (host, config, &host_habitable_cb, NULL))) { GNUNET_TESTBED_host_destroy (host); host = NULL; (void) PRINTF ("%s", "Unable to run the test as this system is not configured " "to use password less SSH logins to localhost.\n" "Skipping test\n"); result = SKIP; return; } abort_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 3), &do_abort, NULL); }
/** * Callback to be called when the requested peer information is available * * @param cls the closure from GNUNET_TESTBED_peer_get_information() * @param op the operation this callback corresponds to * @param pinfo the result; will be NULL if the operation has failed * @param emsg error message if the operation has failed; * NULL if the operation is successfull */ static void pi_cb (void *cls, struct GNUNET_TESTBED_Operation *op, const struct GNUNET_TESTBED_PeerInformation *pinfo, const char *emsg) { long i = (long) cls; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "id callback for %ld\n", i); if (NULL == pinfo || NULL != emsg) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "pi_cb: %s\n", emsg); abort_test (__LINE__); return; } p_id[i] = pinfo->result.id; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " id: %s\n", GNUNET_i2s (p_id[i])); p_ids++; if (p_ids < 2) return; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got all IDs, starting test\n"); test_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &do_test, NULL); }
/** * Functions of this signature are called when a peer has been successfully * created * * @param cls NULL * @param peer the handle for the created peer; NULL on any error during * creation * @param emsg NULL if peer is not NULL; else MAY contain the error description */ static void peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg) { switch (result) { case CONTROLLER1_UP: if ((NULL == peer1.operation) || (NULL == peer) || (NULL != peer1.peer)) { GNUNET_break (0); abort_test (); return; } peer1.peer = peer; GNUNET_TESTBED_operation_done (peer1.operation); result = PEER1_CREATED; peer1.operation = GNUNET_TESTBED_peer_start (NULL, peer, NULL, NULL); break; case CONTROLLER2_UP: if ((NULL == peer2.operation) || (NULL == peer) || (NULL != peer2.peer)) { GNUNET_break (0); abort_test (); return; } peer2.peer = peer; GNUNET_TESTBED_operation_done (peer2.operation); result = PEER2_CREATED; peer2.operation = GNUNET_TESTBED_peer_start (NULL, peer, NULL, NULL); break; case CONTROLLER3_UP: if ((NULL == peer3.operation) || (NULL == peer) || (NULL != peer3.peer)) { GNUNET_break (0); abort_test (); return; } peer3.peer = peer; GNUNET_TESTBED_operation_done (peer3.operation); result = PEER3_CREATED; peer3.operation = GNUNET_TESTBED_peer_start (NULL, peer, NULL, NULL); break; default: GNUNET_break (0); abort_test (); return; } }
static void tls_endpoint_error_handler(int err, void *arg) { (void)arg; re_fprintf(stderr, "TLS Endpoint error (%m) -- ABORT\n", err); abort_test(err); }
static void close_handler(int err, const struct sip_msg *msg, void *arg) { struct test *test = arg; (void)err; (void)msg; (void)arg; abort_test(test, err ? err : ENOMEM); }
/** * Callback which will be called to after a host registration succeeded or failed * * @param cls the host which has been registered * @param emsg the error message; NULL if host registration is successful */ static void registration_comp (void *cls, const char *emsg) { reg_handle = NULL; if (cls == neighbour1) { neighbour2 = GNUNET_TESTBED_host_create ("127.0.0.1", NULL, cfg, 0); if (NULL == neighbour2) { GNUNET_break (0); abort_test (); return; } reg_handle = GNUNET_TESTBED_register_host (controller1, neighbour2, ®istration_comp, neighbour2); if (NULL == reg_handle) { GNUNET_break (0); abort_test (); return; } return; } if (cls != neighbour2) { GNUNET_break (0); abort_test (); return; } peer1.operation = GNUNET_TESTBED_peer_create (controller1, host, cfg, &peer_create_cb, &peer1); if (NULL == peer1.operation) { GNUNET_break (0); abort_test (); return; } }
/** * task for delaying a connect * * @param cls NULL * @param tc the task context */ static void do_delayed_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { delayed_connect_task = NULL; if (NULL != common_operation) { GNUNET_break (0); abort_test (); return; } common_operation = GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peer1.peer, peer2.peer); }
static void conn_handler(const struct sip_msg *msg, void *arg) { struct test *test = arg; int err; (void)arg; err = sipsess_accept(&test->b, test->sock, msg, 200, "OK", "b", "application/sdp", NULL, NULL, NULL, false, offer_handler, answer_handler, estab_handler_b, NULL, NULL, close_handler, test, NULL); if (err) { abort_test(test, err); } }
SCM handle_test_exception (jobject test_name_obj) { jthrowable throwable; jclass object_class; jobject err_msg_obj; char *err_msg, *test_name; const char *utf; SCM result; jboolean is_copy; static jmethodID obj_toString_mid = NULL; throwable = (*env)->ExceptionOccurred (env); (*env)->ExceptionClear (env); if (obj_toString_mid == NULL) obj_toString_mid = (*env)->GetMethodID (env, (*env)->FindClass (env, "java/lang/Object"), "toString", "()Ljava/lang/String;"); err_msg_obj = (*env)->CallObjectMethod (env, throwable, obj_toString_mid); utf = (*env)->GetStringUTFChars (env, err_msg_obj, &is_copy); err_msg = strdup (utf); (*env)->ReleaseStringUTFChars (env, err_msg_obj, utf); utf = (*env)->GetStringUTFChars (env, test_name_obj, &is_copy); test_name = strdup (utf); (*env)->ReleaseStringUTFChars (env, test_name_obj, utf); result = abort_test (gh_str02scm (test_name), err_msg); free (err_msg); free (test_name); return result; }
SCM perform_test (SCM clazz_scm_name) { char *clazz_name, *test_name, *result_name, *msg; const char *utf; jclass clazz; jmethodID mid; jobject test_obj, result_obj, test_name_obj, result_name_obj, msg_obj; jboolean is_copy; SCM scm_test_name, scm_result_name, scm_result_msg; clazz_name = gh_scm2newstr (clazz_scm_name, NULL); clazz = (*env)->FindClass (env, clazz_name); if (clazz == NULL) { SCM clazz_err = gh_str02scm (clazz_name); free (clazz_name); return abort_test (clazz_err, "Unable to find class"); } mid = (*env)->GetMethodID (env, clazz, "<init>", "()V"); test_obj = (*env)->NewObject (env, clazz, mid); if ((*env)->IsInstanceOf (env, test_obj, test_class) == JNI_FALSE) { SCM clazz_err = gh_str02scm (clazz_name); free (clazz_name); return abort_test (clazz_err, "Not an instanceof gnu.test.Test"); } free (clazz_name); /* Call all the Java testing methods */ test_name_obj = (*env)->CallObjectMethod (env, test_obj, test_name_mid); result_obj = (*env)->CallObjectMethod (env, test_obj, test_mid); /* Handle an exception if one occurred */ if ((*env)->ExceptionOccurred (env)) return handle_test_exception (test_name_obj); result_name_obj = (*env)->CallObjectMethod (env, result_obj, result_name_mid); msg_obj = (*env)->CallObjectMethod (env, result_obj, result_msg_mid); /* Grab all the C result messages */ utf = (*env)->GetStringUTFChars (env, test_name_obj, &is_copy); test_name = strdup (utf); (*env)->ReleaseStringUTFChars (env, test_name_obj, utf); utf = (*env)->GetStringUTFChars (env, result_name_obj, &is_copy); result_name = strdup (utf); (*env)->ReleaseStringUTFChars (env, result_name_obj, utf); utf = (*env)->GetStringUTFChars (env, msg_obj, &is_copy); msg = strdup (utf); (*env)->ReleaseStringUTFChars (env, msg_obj, utf); /* Convert the C result messages to Scheme */ scm_test_name = gh_str02scm (test_name); scm_result_name = gh_symbol2scm (result_name); scm_result_msg = gh_str02scm (msg); /* Free up the C result messages */ free (test_name); free (result_name); free (msg); return gh_list (scm_test_name, scm_result_name, scm_result_msg, SCM_UNDEFINED); }
void main() { int e_flag; /* event flag */ int rc; /* function return code */ char buffer[BUFLEN+2]; /* general buffer */ char prompt[BUFLEN+2]; /* prompt buffer */ int prlen; int length; long tstart; /* open com port */ rc = com_open( (int*) &e_flag, 1200); if ( rc != 0) { printf("\nOPEN failed!\n"); printf("error code = %d\n",rc); abort_test(); } /* setup prompt string */ strcpy(prompt, "\r\nEnter string: "); prlen = strlen(prompt); /* prompt and read until "quit" is typed */ buffer[0] = NULCH; while (strcmp(buffer,"quit\r\n") != 0) { /* display the prompt */ e_flag = 0; rc = com_write((char*) prompt, (int*) &prlen); if (rc != 0) { printf("\nerror displaying prompt!\n"); printf("error code = %d\n",rc); abort_test(); } /* loop until output is done */ tstart = time(NULL); while (e_flag == 0) { if ((time(NULL) - tstart) > WR_TIME_LIMIT) { printf("\ntimeout on prompt\n"); printf("event flag not set\n"); exit(); } } /* read a string */ length = BUFLEN-1; e_flag = 0; rc = com_read((char*) buffer, (int*) &length); if (rc != 0) { printf("\nerror reading string!\n"); printf("error code = %d\n",rc); abort_test(); } /* loop until input is done */ tstart = time(NULL); while (e_flag == 0) { if ((time(NULL) - tstart) > RD_TIME_LIMIT) { printf("\ntimeout on input\n"); printf("event flag not set\n"); abort_test(); } } /* display the input string */ e_flag = 0; if (buffer[length-1] == '\n') { buffer[length-1] = NULCH; length--; } strcat(buffer,"\r\n"); length = length + 2; printf("%s",buffer); rc = com_write((char*) buffer, (int*) &length); if (rc != 0) { printf("\nerror displaying string!\n"); printf("error code = %d\n",rc); abort_test(); } /* loop until output is done */ tstart = time(NULL); while (e_flag == 0) { if ((time(NULL) - tstart) > WR_TIME_LIMIT) { printf("\ntimeout on output\n"); printf("event flag not set\n"); abort_test(); } } } /* end of while loop */ /* print final message */ e_flag = 0; length = 29; printf("\nEnd of Com Driver IO Test\n"); rc = com_write((char*) "\r\nEnd of Com Driver IO Test\r\n", (int*) &length); if (rc != 0) { printf("\nWRITE error on final message!\n"); printf("error code = %d\n",rc); abort_test(); } /* loop until output is done */ tstart = time(NULL); while (e_flag == 0) { if ((time(NULL) - tstart) > WR_TIME_LIMIT) { printf("\ntimeout on final message\n"); printf("event flag not set\n"); abort_test(); } } /* close the com port */ rc = com_close(); if ( rc != 0) { printf("\nCLOSE failed!\n"); printf("error code = %d\n",rc); exit(); } printf("Test completed successfully!\n"); }
void main(void) { int e_flag; /* event flag */ int ix; /* loop index */ int rc; /* function return code */ char buffer[BUFLEN]; /* output buffer */ int length; long tstart; /* open com port */ rc = com_open( (int *) &e_flag, 1200); if ( rc != 0) { printf("\nOPEN failed!\n"); printf("error code = %d\n",rc); abort_test(); } /* fill buffer with Xs */ for (ix=0; ix<BUFLEN; ix++) buffer[ix] = 'X'; /* insert test string */ strcpy(buffer,"This is a test of com driver output "); strcat(buffer,"abcdefghijklmnopqrstuvwxyz 0123456789\012\015"); length = strlen(buffer); /* output test string the specified number of times */ for (ix=1; ix<=REPEAT_COUNT; ix++) { e_flag = 0; rc = com_write((char *) buffer, (int *) &length); if (rc != 0) { printf("\nWRITE error!\n"); printf("error code = %d\n",rc); abort_test(); } /* loop until output is done */ tstart = time(NULL); while (e_flag == 0) { if ((time(NULL) - tstart) > TIME_LIMIT) { printf("\nTIMEOUT: event flag not set\n"); abort_test(); } } } /* output final message */ e_flag = 0; length = 31; rc = com_write((char *) "End of Com Driver Output Test\012\015", (int *) &length); if (rc != 0) { printf("\nWRITE error on final message!\n"); printf("error code = %d\n",rc); abort_test(); } /* loop until output is done */ tstart = time(NULL); while (e_flag == 0) { if ((time(NULL) - tstart) > TIME_LIMIT) { printf("\nTIMEOUT: event flag not set\n"); abort_test(); } } /* close the com port */ rc = com_close(); if ( rc != 0) { printf("\nCLOSE failed!\n"); printf("error code = %d\n",rc); exit(); } printf("Test completed successfully!\n"); }
/** * Signature of the event handler function called by the * respective event controller. * * @param cls closure * @param event information about the event */ static void controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) { switch (event->type) { case GNUNET_TESTBED_ET_OPERATION_FINISHED: if ((NULL != event->op_cls) || (NULL != event->details.operation_finished.emsg)) { GNUNET_break (0); abort_test (); return; } switch (result) { case PEERS_STOPPED: if (NULL != event->details.operation_finished.generic) { GNUNET_break (0); abort_test (); return; } if (event->op == peer1.operation) { GNUNET_TESTBED_operation_done (peer1.operation); peer1.operation = NULL; peer1.peer = NULL; } else if (event->op == peer2.operation) { GNUNET_TESTBED_operation_done (peer2.operation); peer2.operation = NULL; peer2.peer = NULL; } else if (event->op == peer3.operation) { GNUNET_TESTBED_operation_done (peer3.operation); peer3.operation = NULL; peer3.peer = NULL; } else { GNUNET_break (0); abort_test (); return; } if ((NULL == peer1.peer) && (NULL == peer2.peer) && (NULL == peer3.peer)) { result = SUCCESS; GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); } break; case PEER1_STARTED: if ((NULL != event->details.operation_finished.generic) || (NULL == common_operation)) { GNUNET_break (0); abort_test (); return; } GNUNET_TESTBED_operation_done (common_operation); common_operation = NULL; result = CONTROLLER2_UP; peer2.operation = GNUNET_TESTBED_peer_create (controller1, neighbour1, cfg, &peer_create_cb, NULL); if (NULL == peer2.operation) { GNUNET_break (0); abort_test (); return; } break; case PEER2_STARTED: if ((NULL != event->details.operation_finished.generic) || (NULL == common_operation)) { GNUNET_break (0); abort_test (); return; } GNUNET_TESTBED_operation_done (common_operation); common_operation = NULL; result = CONTROLLER3_UP; peer3.operation = GNUNET_TESTBED_peer_create (controller1, neighbour2, cfg, &peer_create_cb, NULL); if (NULL == peer3.operation) { GNUNET_break (0); abort_test (); return; } break; default: GNUNET_break (0); abort_test (); return; } break; case GNUNET_TESTBED_ET_PEER_START: switch (result) { case PEER1_CREATED: if (event->details.peer_start.host != host) { GNUNET_break (0); abort_test (); return; } peer1.is_running = GNUNET_YES; GNUNET_TESTBED_operation_done (peer1.operation); peer1.operation = NULL; result = PEER1_STARTED; common_operation = GNUNET_TESTBED_controller_link (NULL, controller1, neighbour1, NULL, GNUNET_YES); break; case PEER2_CREATED: if (event->details.peer_start.host != neighbour1) { GNUNET_break (0); abort_test (); return; } peer2.is_running = GNUNET_YES; GNUNET_TESTBED_operation_done (peer2.operation); peer2.operation = NULL; result = PEER2_STARTED; if (NULL != common_operation) { GNUNET_break (0); abort_test (); return; } common_operation = GNUNET_TESTBED_controller_link (NULL, controller1, neighbour2, NULL, GNUNET_YES); if (NULL == common_operation) { GNUNET_break (0); abort_test (); return; } break; case PEER3_CREATED: if (event->details.peer_start.host != neighbour2) { GNUNET_break (0); abort_test (); return; } peer3.is_running = GNUNET_YES; GNUNET_TESTBED_operation_done (peer3.operation); peer3.operation = NULL; result = PEER3_STARTED; common_operation = GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peer2.peer, peer1.peer); break; default: GNUNET_break (0); abort_test (); return; } break; case GNUNET_TESTBED_ET_PEER_STOP: if (PEERS_CONNECTED_2 != result) { GNUNET_break (0); abort_test (); return; } if (event->details.peer_stop.peer == peer1.peer) { peer1.is_running = GNUNET_NO; GNUNET_TESTBED_operation_done (peer1.operation); } else if (event->details.peer_stop.peer == peer2.peer) { peer2.is_running = GNUNET_NO; GNUNET_TESTBED_operation_done (peer2.operation); } else if (event->details.peer_stop.peer == peer3.peer) { peer3.is_running = GNUNET_NO; GNUNET_TESTBED_operation_done (peer3.operation); } else { GNUNET_break (0); abort_test (); return; } if ((GNUNET_NO == peer1.is_running) && (GNUNET_NO == peer2.is_running) && (GNUNET_NO == peer3.is_running)) { result = PEERS_STOPPED; peer1.operation = GNUNET_TESTBED_peer_destroy (peer1.peer); peer2.operation = GNUNET_TESTBED_peer_destroy (peer2.peer); peer3.operation = GNUNET_TESTBED_peer_destroy (peer3.peer); } break; case GNUNET_TESTBED_ET_CONNECT: if ((NULL != peer1.operation) || (NULL != peer2.operation) || (NULL != peer3.operation) || (NULL == common_operation)) { GNUNET_break (0); abort_test (); return; } switch (result) { case PEER3_STARTED: if ((event->details.peer_connect.peer1 != peer2.peer) || (event->details.peer_connect.peer2 != peer1.peer)) { GNUNET_break (0); abort_test (); return; } GNUNET_TESTBED_operation_done (common_operation); common_operation = NULL; result = PEERS_1_2_CONNECTED; LOG (GNUNET_ERROR_TYPE_DEBUG, "Peers connected\n"); common_operation = GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peer2.peer, peer3.peer); break; case PEERS_1_2_CONNECTED: if ((event->details.peer_connect.peer1 != peer2.peer) || (event->details.peer_connect.peer2 != peer3.peer)) { GNUNET_break (0); abort_test (); return; } GNUNET_TESTBED_operation_done (common_operation); common_operation = NULL; result = PEERS_2_3_CONNECTED; delayed_connect_task = GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (3), &do_delayed_connect, NULL); break; case PEERS_2_3_CONNECTED: if ((event->details.peer_connect.peer1 != peer1.peer) || (event->details.peer_connect.peer2 != peer2.peer)) { GNUNET_break (0); abort_test (); return; } GNUNET_TESTBED_operation_done (common_operation); common_operation = NULL; result = PEERS_CONNECTED_2; LOG (GNUNET_ERROR_TYPE_DEBUG, "Peers connected again\n"); peer1.operation = GNUNET_TESTBED_peer_stop (NULL, peer1.peer, NULL, NULL); peer2.operation = GNUNET_TESTBED_peer_stop (NULL, peer2.peer, NULL, NULL); peer3.operation = GNUNET_TESTBED_peer_stop (NULL, peer3.peer, NULL, NULL); break; default: GNUNET_break (0); abort_test (); return; } break; default: GNUNET_break (0); abort_test (); return; } }