void run_tests(TestState *parent, int selectedTest) { TestState state; initState(&state, "Test", parent); state.selectedTest = selectedTest; if (startTest(&state, "the empty command")) { if (serialRequest(&state, "")) checkSerialResponse(&state, "=S,0"); } if (startTest(&state, "an invalid command")) { if (serialRequest(&state, "FOO")) checkSerialResponse(&state, "=E,1"); } #ifdef DO_BLINK_TEST if (startTest(&state, "Blink LEDs on GPIO13 and GPIO15")) { if (test_blink(&state)) passTest(&state, ""); else failTest(&state, ""); } #endif if (state.ssid) { if (startTest(&state, "switch to STA+AP mode")) { if (serialRequest(&state, "SET:wifi-mode,3")) checkSerialResponse(&state, "=S,0"); } if (startTest(&state, "JOIN")) { if (serialRequest(&state, "JOIN:%s,%s", state.ssid, state.passwd)) checkSerialResponse(&state, "=S,0"); if (state.testPassed) msleep(10000); // wait for WX to disconnect. It has a .5 second delay } beginGroup(&state); if (startTest(&state, "CHECK:station-ipaddr")) { if (!skipTest(&state)) { char ipaddr[32]; do { if (!serialRequest(&state, "CHECK:station-ipaddr")) break; } while (!waitAndCheckSerialResponse(&state, "=S,0.0.0.0", "=S,^s", ipaddr, sizeof(ipaddr))); if (state.testPassed) { infoTest(&state, "got '%s'", ipaddr); if (GetInternetAddress(ipaddr, 80, &state.moduleAddr) != 0) infoTest(&state, "error: failed to parse IP address '%s'", ipaddr); } } } } if (startTest(&state, "simple transaction")) { if (test_001(&state)) passTest(&state, ""); else failTest(&state, ""); } testResults(&state); }
int main(int argc, char *argv[]) { GError *error = NULL; GOptionContext *context; atexit(safeExit); // init log system gp_log_init(APP_LOGFILE); // Get some application/host data appInfo(); /* if (isAppRunning()) { printf("Application is already running\n"); exit(0); g_critical("Application is already running"); } */ // parse command line arguments context = g_option_context_new (APP_DESCRIPTION); g_option_context_add_main_entries (context, entries, NULL); if (!g_option_context_parse (context, &argc, &argv, &error)) { g_print ("option parsing failed: %s\n", error->message); exit (1); } // enable verbose mode if (opt_verbose) { gp_log_set_verbose(TRUE); } g_message("Program start\n"); // print version information if (opt_version) { printf("Program version %s\nBuild ("__DATE__" "__TIME__")\n", APP_VERSION); exit(0); } // Error Test if (opt_errorTest) { errorTest(); exit(0); } // thread test if (opt_threadTest) { threadTest(); exit(0); } // info test if (opt_info) { infoTest(); exit(0); } // daemon test if (opt_daemonTest) { daemonTest(); exit(0); } // queue test if (opt_queueTest) { queueTest(); exit(0); } // pipe test if (opt_pipeTest) { pipeTest(); exit(0); } // domain socket test if (opt_domainTest) { domainTest(); exit(0); } return 0; }