int main(int argc, char **argv) { tests_init(argc, argv); static const char *expected = "Watchdog is active\r\n" "Waiting for Watchdog to kick\r\n" "Watchdog kicked us!\r\n"; tests_assert_uart_receive("atmega48_watchdog_test.axf", 1000000, expected, '0'); tests_success(); return 0; }
int main(int argc, char **argv) { tests_init(argc, argv); static const char *expected = "Read 8 ADC channels to test interrupts\r\n" "All done. Now reading the 1.1V value in pooling mode\r\n" "Read ADC value 0155 = 1098 mvolts -- ought to be 1098\r\n"; tests_assert_uart_receive("atmega644_adc_test.axf", 100000, expected, '0'); tests_success(); return 0; }
int main(int argc, char **argv) { tests_init(argc, argv); switch(tests_init_and_run_test("atmega48_disabled_timer.axf", 100000000)) { case LJR_CYCLE_TIMER: // the cycle timer fired break; case LJR_SPECIAL_DEINIT: // sleep with interrupts off or some other such reason fail("AVR woke up from sleep while it shouldn't have (after %" PRI_avr_cycle_count " cycles)", tests_cycle_count); default: fail("Error in test case: Should never reach this."); } tests_success(); return 0; }
int tests_begin(int argc, char * const *argv) { const char *testcase = NULL; bool initialized = false; int verbose=0; int testix = -1; int ch; int retval; char *seed=NULL; for (;;) { while (!testcase && (ch = getopt(argc, argv, "vws:")) != -1) { switch (ch) { case 's': seed = optarg; break; case 'w': sleep(100); break; case 'v': verbose=1; break; case '?': default: printf("invalid option %c\n",ch); usage(argv[0]); } } if (optind < argc) { testix = tests_named_index(argv[optind]); if(testix<0) { printf("invalid test %s\n",argv[optind]); usage(argv[0]); } argc -= optind; argv += optind; } if (testix < 0) { if (!initialized) { //initialized = true; if (tests_init(seed)!=0) return -1; tests_run_all(argc, argv); } break; } else { if (!initialized) { if (tests_init(seed)!=0) return -1; initialized = true; } tests_run_index(testix, argc, argv); testix = -1; } } retval=tests_summary(verbose); /* Cleanups */ tests_end(); return retval; }
int main() { int fd; uint32_t magic = 0xffff5555; uint32_t w1 = 0xcafef00d, w2 = 0xdeadbeef, w3 = 0xd00d, w4 = 0xbabe; const char *s1 = "0123456789abcdef, end here."; const char *s2 = "some other more reasonable string"; uint32_t w; const char *s; comm_msg_t *msg; /* Serializing. */ msg = comm_msg_new(20, 0); comm_msg_put_magic(msg, magic); comm_msg_put_int(msg, w1); comm_msg_put_int(msg, w2); comm_msg_put_str(msg, s1); comm_msg_put_str(msg, s2); comm_msg_put_int(msg, w3); comm_msg_put_int(msg, w4); fd = open(test_file, O_WRONLY | O_CREAT, 0644); if (fd < 0) die(1, "cannot create file"); comm_msg_send(fd, msg); comm_msg_destroy(msg); close(fd); /* Deserializing. */ msg = comm_msg_new(5, 0); fd = open(test_file, O_RDONLY, 0644); if (fd < 0) die(2, "cannot open file"); comm_msg_recv(fd, msg); tests_init(8); if (comm_msg_get_magic(msg, &w)) test_cmp_int(magic, w); if (comm_msg_get_int(msg, &w)) test_cmp_int(w1, w); if (comm_msg_get_int(msg, &w)) test_cmp_int(w2, w); if (comm_msg_get_str(msg, &s)) test_cmp_str(s1, s); if (comm_msg_get_str(msg, &s)) test_cmp_str(s2, s); if (comm_msg_get_int(msg, &w)) test_cmp_int(w3, w); if (comm_msg_get_int(msg, &w)) test_cmp_int(w4, w); comm_msg_destroy(msg); close(fd); unlink(test_file); /* Capped buffer. */ msg = comm_msg_new(4, 8); comm_msg_put_int(msg, w1); comm_msg_put_int(msg, w2); test_failure(comm_msg_put_int(msg, w3)); comm_msg_destroy(msg); return tests_summary() ? 0 : 1; }
int tests_begin(int argc, char * const *argv) { const char *testcase = NULL; bool initialized = false; bool print_security_logs = false; int testix = -1; int failcount = 0; int ch; int loop = 0; int list = 0; // TODO Currently our callers do this, but we can move this here together with the build date info. const char *progname = strrchr(argv[0], '/'); progname = progname ? progname + 1 : argv[0]; for (;;) { while (!testcase && (ch = getopt(argc, argv, "bklL1vwqs")) != -1) { switch (ch) { #ifdef NO_SERVER case 'k': keep_scratch_dir = true; break; #endif case 's': print_security_logs = true; break; case 'b': test_strict_bats = 0; break; case 'v': test_verbose++; break; case 'w': sleep(100); break; case 'l': loop=1; break; case 'L': list=1; break; case '1': test_onebatstest=1; break; case '?': default: printf("invalid option %c\n",ch); usage(argv[0]); } } if (optind < argc) { testix = tests_named_index(argv[optind]); if(testix<0) { printf("invalid test %s\n",argv[optind]); usage(argv[0]); } } if (print_security_logs) { add_security_log_handler(^(int level, CFStringRef scope, const char *function, const char *file, int line, CFStringRef message) { time_t now = time(NULL); char *date = ctime(&now); date[19] = '\0'; CFStringRef logStr = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%s %@ %s %@\n"), date + 4, scope ? scope : CFSTR(""), function, message); CFShow(logStr); CFReleaseSafe(logStr); }); } if (!list && !initialized && !test_onebatstest) fprintf(stdout, "[TEST] %s\n", progname); if (testix < 0) { if (!initialized) { tests_init(); initialized = true; (void)initialized; if (!list) failcount+=tests_run_all(argc, argv); } break; } else { if (!initialized) { tests_init(); initialized = true; for (int i = 0; testlist[i].name; ++i) { testlist[i].off = 1; } } optind++; testlist[testix].off = 0; if (!list) failcount+=tests_run_index(testix, argc, argv); testix = -1; } }