/** * 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) { switch (result) { case INIT: FAIL_TEST (GNUNET_OK == status); 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); mc = GNUNET_TESTBED_controller_connect (host, event_mask, &controller_cb, NULL); FAIL_TEST (NULL != mc); result = MASTER_STARTED; op = GNUNET_TESTBED_peer_create (mc, host, cfg, peer_create_cb, NULL); FAIL_TEST (NULL != op); break; default: GNUNET_break (0); cp = NULL; do_abort_now (NULL); } }
/** * 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); FAIL_TEST (NULL != host); if (NULL == (hc_handle = GNUNET_TESTBED_is_host_habitable (host, config, &host_habitable_cb, NULL))) { GNUNET_TESTBED_host_destroy (host); GNUNET_CONFIGURATION_destroy (cfg); cfg = NULL; 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" "Marking test as successful\n"); result = SKIP; return; } abort_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5), &do_abort, NULL); }
void delete_large_files() { START_TEST; if(g_unlink(WAV1)){ FAIL_TEST("delete failed"); } assert(!g_unlink(WAV2), "delete failed"); FINISH_TEST; }
/** * Functions of this signature are called when a peer has been successfully * created * * @param cls the closure from GNUNET_TESTBED_peer_create() * @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) { FAIL_TEST (NULL != peer); FAIL_TEST (NULL == emsg); switch (result) { case MASTER_STARTED: result = MASTER_PEER_CREATE_SUCCESS; master_peer = peer; GNUNET_TESTBED_operation_done (op); op = GNUNET_TESTBED_peer_start (NULL, master_peer, NULL, NULL); break; case SLAVE1_LINK_SUCCESS: result = SLAVE1_PEER_CREATE_SUCCESS; slave1_peer = peer; GNUNET_TESTBED_operation_done (op); op = GNUNET_TESTBED_peer_start (NULL, slave1_peer, NULL, NULL); break; case SLAVE2_LINK_SUCCESS: result = SLAVE2_PEER_CREATE_SUCCESS; slave2_peer = peer; GNUNET_TESTBED_operation_done (op); delay_task_id = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1), &delay_task, NULL); break; case SLAVE3_STARTED: result = SLAVE3_PEER_CREATE_SUCCESS; slave3_peer = peer; GNUNET_TESTBED_operation_done (op); op = GNUNET_TESTBED_peer_start (NULL, slave3_peer, NULL, NULL); break; default: FAIL_TEST (0); } FAIL_TEST (NULL != op); }
/** * Task for inserting delay between tests * * @param * @return */ static void delay_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { delay_task_id = NULL; switch (result) { case SLAVE2_PEER_CREATE_SUCCESS: op = GNUNET_TESTBED_peer_stop (NULL, slave1_peer, NULL, NULL); FAIL_TEST (NULL != op); break; case MASTER_SLAVE2_PEERS_CONNECTED: slave3 = GNUNET_TESTBED_host_create_with_id (3, "127.0.0.1", NULL, cfg, 0); rh = GNUNET_TESTBED_register_host (mc, slave3, ®istration_cont, NULL); break; case SLAVE2_SLAVE3_PEERS_CONNECTED: op = GNUNET_TESTBED_peer_stop (NULL, slave2_peer, NULL, NULL); FAIL_TEST (NULL != op); break; default: FAIL_TEST (0); } }
/** * Checks the event if it is an operation finished event and if indicates a * successfull completion of operation * * @param event the event information to check */ static void check_operation_success (const struct GNUNET_TESTBED_EventInformation *event) { FAIL_TEST (NULL != event); FAIL_TEST (GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type); FAIL_TEST (event->op == op); FAIL_TEST (NULL == event->op_cls); FAIL_TEST (NULL == event->details.operation_finished.emsg); FAIL_TEST (NULL == event->details.operation_finished.generic); }
void test_peakgen() { START_TEST; if(!wf_peakgen__sync(WAV, WAV ".peak")){ FAIL_TEST("local peakgen failed"); } //create peakfile in the cache directory Waveform* w = waveform_new(WAV); char* p = waveform_ensure_peakfile__sync(w); assert(p, "cache dir peakgen failed"); FINISH_TEST; }
/* * Test reading of audio files. */ void test_audio_file() { START_TEST; char* filenames[] = {"data/mono_0:10.wav", "data/stereo_0:10.wav", "data/mono_0:10.mp3", "data/stereo_0:10.mp3", "data/mono_0:10.m4a", "data/stereo_0:10.m4a", "data/mono_0:10.opus", "data/stereo_0:10.opus"}; int i; for(i=0;i<G_N_ELEMENTS(filenames);i++){ WfDecoder f = {{0,}}; char* filename = find_wav(filenames[i]); if(!ad_open(&f, filename)) FAIL_TEST("file open: %s", filenames[i]); if(!g_str_has_suffix(filenames[i], ".opus")){ assert(f.info.sample_rate == 44100, "samplerate: %i (expected 44100)", f.info.sample_rate); }else{ assert(f.info.sample_rate == 48000, "samplerate: %i (expected 48000)", f.info.sample_rate); } int n = 8; int read_len = WF_PEAK_RATIO * n; int16_t data[f.info.channels][read_len]; WfBuf16 buf = { .buf = {data[0], data[1]}, .size = n * WF_PEAK_RATIO }; size_t readcount = 0; size_t total = 0; do { readcount = ad_read_short(&f, &buf); total += readcount; } while (readcount > 0); dbg(1, "diff=%zu", abs((int)total - (int)f.info.frames)); if(g_str_has_suffix(filenames[i], ".wav") || g_str_has_suffix(filenames[i], ".flac")){ assert(total == f.info.frames, "%s: incorrect number of frames read: %"PRIi64, filenames[i], f.info.frames); assert(!(total % 512) || !(total % 100), "%s: bad framecount: %zu", filenames[i], total); // test file sizes are always a round number }else{ // for some file types, f.info.frames is only an estimate assert(abs((int)total - (int)f.info.frames) < 2048, "%s: incorrect number of frames read: %"PRIi64, filenames[i], f.info.frames); } ad_close(&f); g_free(filename); }
void test_peakgen() { START_TEST; char* filename = find_wav(WAV); assert(filename, "cannot find file %s", WAV); if(!wf_peakgen__sync(filename, WAV ".peak", NULL)){ FAIL_TEST("local peakgen failed"); } // create peakfile in the cache directory Waveform* w = waveform_new(filename); g_free(filename); char* p = waveform_ensure_peakfile__sync(w); assert(p, "cache dir peakgen failed"); FINISH_TEST; }
/** * 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_cont (void *cls, const char *emsg) { rh = NULL; switch (result) { case MASTER_PEER_START_SUCCESS: FAIL_TEST (NULL == emsg); FAIL_TEST (NULL != mc); result = SLAVE1_REGISTERED; slave2 = GNUNET_TESTBED_host_create_with_id (2, "127.0.0.1", NULL, cfg, 0); FAIL_TEST (NULL != slave2); rh = GNUNET_TESTBED_register_host (mc, slave2, ®istration_cont, NULL); FAIL_TEST (NULL != rh); break; case SLAVE1_REGISTERED: FAIL_TEST (NULL == emsg); FAIL_TEST (NULL != mc); result = SLAVE2_REGISTERED; FAIL_TEST (NULL != cfg); op = GNUNET_TESTBED_controller_link (NULL, mc, slave, NULL, GNUNET_YES); FAIL_TEST (NULL != op); break; case MASTER_SLAVE2_PEERS_CONNECTED: FAIL_TEST (NULL == emsg); FAIL_TEST (NULL != mc); FAIL_TEST (NULL == op); result = SLAVE3_REGISTERED; op = GNUNET_TESTBED_controller_link (NULL, mc, slave3, NULL, GNUNET_YES); FAIL_TEST (NULL != op); break; default: GNUNET_break (0); do_abort_now (NULL); } }
/** * 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 (result) { case SLAVE2_REGISTERED: check_operation_success (event); GNUNET_TESTBED_operation_done (op); op = NULL; result = SLAVE1_LINK_SUCCESS; FAIL_TEST (NULL != slave2); FAIL_TEST (NULL != slave); op = GNUNET_TESTBED_peer_create (mc, slave, cfg, peer_create_cb, NULL); FAIL_TEST (NULL != op); break; case SLAVE1_PEER_START_SUCCESS: check_operation_success (event); GNUNET_TESTBED_operation_done (op); result = SLAVE2_LINK_SUCCESS; op = GNUNET_TESTBED_peer_create (mc, slave2, cfg, peer_create_cb, NULL); FAIL_TEST (NULL != op); break; case MASTER_PEER_CREATE_SUCCESS: FAIL_TEST (GNUNET_TESTBED_ET_PEER_START == event->type); FAIL_TEST (event->details.peer_start.host == host); FAIL_TEST (event->details.peer_start.peer == master_peer); GNUNET_TESTBED_operation_done (op); result = MASTER_PEER_START_SUCCESS; slave = GNUNET_TESTBED_host_create_with_id (1, "127.0.0.1", NULL, cfg, 0); FAIL_TEST (NULL != slave); rh = GNUNET_TESTBED_register_host (mc, slave, ®istration_cont, NULL); FAIL_TEST (NULL != rh); break; case SLAVE1_PEER_CREATE_SUCCESS: FAIL_TEST (GNUNET_TESTBED_ET_PEER_START == event->type); FAIL_TEST (event->details.peer_start.host == slave); FAIL_TEST (event->details.peer_start.peer == slave1_peer); GNUNET_TESTBED_operation_done (op); result = SLAVE1_PEER_START_SUCCESS; op = GNUNET_TESTBED_controller_link (NULL, mc, slave2, slave, GNUNET_YES); break; case SLAVE2_PEER_CREATE_SUCCESS: FAIL_TEST (GNUNET_TESTBED_ET_PEER_STOP == event->type); FAIL_TEST (event->details.peer_stop.peer == slave1_peer); GNUNET_TESTBED_operation_done (op); result = SLAVE1_PEER_STOP_SUCCESS; op = GNUNET_TESTBED_peer_start (NULL, slave2_peer, NULL, NULL); FAIL_TEST (NULL != op); break; case SLAVE3_PEER_CREATE_SUCCESS: FAIL_TEST (GNUNET_TESTBED_ET_PEER_START == event->type); FAIL_TEST (event->details.peer_start.host == slave3); FAIL_TEST (event->details.peer_start.peer == slave3_peer); GNUNET_TESTBED_operation_done (op); result = SLAVE3_PEER_START_SUCCESS; sleep (1); LOG_DEBUG ("**************************************\n"); op = GNUNET_TESTBED_overlay_connect (mc, NULL, NULL, slave2_peer, slave3_peer); FAIL_TEST (NULL != op); break; case SLAVE3_PEER_START_SUCCESS: FAIL_TEST (NULL != event); FAIL_TEST (GNUNET_TESTBED_ET_CONNECT == event->type); FAIL_TEST (event->details.peer_connect.peer1 == slave2_peer); FAIL_TEST (event->details.peer_connect.peer2 == slave3_peer); result = SLAVE2_SLAVE3_PEERS_CONNECTED; GNUNET_TESTBED_operation_done (op); op = NULL; delay_task_id = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1), &delay_task, NULL); break; case SLAVE1_PEER_STOP_SUCCESS: FAIL_TEST (GNUNET_TESTBED_ET_PEER_START == event->type); FAIL_TEST (event->details.peer_start.host == slave2); FAIL_TEST (event->details.peer_start.peer == slave2_peer); GNUNET_TESTBED_operation_done (op); result = SLAVE2_PEER_START_SUCCESS; op = GNUNET_TESTBED_overlay_connect (mc, NULL, NULL, master_peer, slave2_peer); break; case SLAVE2_PEER_START_SUCCESS: FAIL_TEST (NULL != event); FAIL_TEST (GNUNET_TESTBED_ET_CONNECT == event->type); FAIL_TEST (event->details.peer_connect.peer1 == master_peer); FAIL_TEST (event->details.peer_connect.peer2 == slave2_peer); result = MASTER_SLAVE2_PEERS_CONNECTED; GNUNET_TESTBED_operation_done (op); op = NULL; delay_task_id = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1), &delay_task, NULL); break; case SLAVE2_SLAVE3_PEERS_CONNECTED: FAIL_TEST (GNUNET_TESTBED_ET_PEER_STOP == event->type); FAIL_TEST (event->details.peer_stop.peer == slave2_peer); GNUNET_TESTBED_operation_done (op); result = SLAVE2_PEER_STOP_SUCCESS; op = GNUNET_TESTBED_peer_destroy (slave1_peer); FAIL_TEST (NULL != op); break; case SLAVE2_PEER_STOP_SUCCESS: check_operation_success (event); GNUNET_TESTBED_operation_done (op); result = SLAVE1_PEER_DESTROY_SUCCESS; op = GNUNET_TESTBED_peer_destroy (slave2_peer); FAIL_TEST (NULL != op); break; case SLAVE1_PEER_DESTROY_SUCCESS: check_operation_success (event); GNUNET_TESTBED_operation_done (op); op = NULL; result = SLAVE2_PEER_DESTROY_SUCCESS; op = GNUNET_TESTBED_get_slave_config (NULL, mc, slave3); FAIL_TEST (NULL != op); break; case SLAVE2_PEER_DESTROY_SUCCESS: FAIL_TEST (NULL != event); FAIL_TEST (GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type); FAIL_TEST (event->op == op); FAIL_TEST (NULL == event->op_cls); FAIL_TEST (NULL == event->details.operation_finished.emsg); cfg3 = GNUNET_CONFIGURATION_dup (event->details.operation_finished.generic); GNUNET_TESTBED_operation_done (op); result = SLAVE3_GET_CONFIG_SUCCESS; op = GNUNET_TESTBED_controller_link (NULL, mc, slave3, slave, GNUNET_NO); break; case SLAVE3_REGISTERED: check_operation_success (event); GNUNET_TESTBED_operation_done (op); op = NULL; result = SLAVE3_STARTED; op = GNUNET_TESTBED_peer_create (mc, slave3, cfg, peer_create_cb, NULL); FAIL_TEST (NULL != op); break; case SLAVE3_GET_CONFIG_SUCCESS: result = SLAVE3_LINK_SUCCESS; GNUNET_TESTBED_operation_done (op); op = GNUNET_TESTBED_peer_destroy (master_peer); break; case SLAVE3_LINK_SUCCESS: check_operation_success (event); result = MASTER_PEER_DESTROY_SUCCESS; GNUNET_TESTBED_operation_done (op); op = GNUNET_TESTBED_peer_destroy (slave3_peer); break; case MASTER_PEER_DESTROY_SUCCESS: result = SUCCESS; GNUNET_TESTBED_operation_done (op); op = NULL; GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1), &do_shutdown, NULL); break; default: FAIL_TEST (0); } }