void run_basic_test() { char* name = "Basic Test"; start_test(name); flag = 0; did_run = 0; kernel_add_task(MED_PRI, &user_task); kernel_run(); assert_int_equals(1, did_run, "Basic Test: User Program Never Ran"); end_test(name); }
static int test_link(void) { const char *data = testdata; int datalen = testdatalen; int err = 0; int res; start_test("link"); res = create_file(testfile, data, datalen); if (res == -1) return -1; unlink(testfile2); res = link(testfile, testfile2); if (res == -1) { PERROR("link"); return -1; } res = check_type(testfile2, S_IFREG); if (res == -1) return -1; err += check_mode(testfile2, 0644); err += check_nlink(testfile2, 2); err += check_size(testfile2, datalen); err += check_data(testfile2, data, 0, datalen); res = unlink(testfile); if (res == -1) { PERROR("unlink"); return -1; } res = check_nonexist(testfile); if (res == -1) return -1; err += check_nlink(testfile2, 1); res = unlink(testfile2); if (res == -1) { PERROR("unlink"); return -1; } res = check_nonexist(testfile2); if (res == -1) return -1; if (err) return -1; success(); return 0; }
int main (int argc, char *argv[]) { char *storedir; EvaStreamMap *stream_map; EvaStore *store; EvaStorageFormat *storage_format; EvaStoreFormatEntry *format_entry; guint i; srand48 (1); eva_init_without_threads (&argc, &argv); //eva_debug_set_flags (EVA_DEBUG_ALL); storedir = g_strdup_printf ("store.%d", getpid ()); if (mkdir (storedir, 0700) != 0) { g_warning ("error creating directory %s", storedir); exit (1); } stream_map = EVA_STREAM_MAP (eva_file_stream_map_new (storedir)); g_return_val_if_fail (stream_map, 1); storage_format = g_object_new (EVA_TYPE_XML_FORMAT, NULL); g_return_val_if_fail (storage_format, 1); format_entry = g_object_new (EVA_TYPE_STORE_FORMAT_ENTRY, NULL); g_return_val_if_fail (format_entry, 1); format_entry->storage_format = storage_format; format_entry->format_id = 0; format_entry->value_type = G_TYPE_INVALID; store = g_object_new (EVA_TYPE_STORE, NULL); g_return_val_if_fail (store, 1); store->stream_map = stream_map; store->format_entries = g_ptr_array_new (); g_ptr_array_add (store->format_entries, format_entry); for (i = 0; i < 100; ++i) start_test (store, i, 0.99); eva_main_run (); fprintf (stderr, "\n"); rmdir (storedir); return had_error ? 1 : 0; }
static void testPushUntilFullAndPopUntilEmpty() { start_test("Lock free FIFO - push until full and pop until empty"); const int es = sizeof(int); const int c = 100; drLockFreeFIFO f; drLockFreeFIFO_init(&f, c, es); for (int i = 0; i < c; i++) { int success = drLockFreeFIFO_push(&f, &i); if (!success) { fail_unless(success == 1, "push to FIFO with free slots should succeed"); } } int success = drLockFreeFIFO_push(&f, &c); fail_unless(success == 0, "push to full FIFO should fail"); int full = drLockFreeFIFO_isFull(&f); fail_unless(full == 1, "full FIFO should report that it's full"); int empty = drLockFreeFIFO_isEmpty(&f); fail_unless(empty == 0, "full FIFO should not report that it's empty"); for (int i = 0; i < c; i++) { int val = 0; int success = drLockFreeFIFO_pop(&f, &val); if (success != 1) { fail_unless(success == 1, "popping from FIFO with one or more elements should succeed"); } if (val != i) { fail_unless(val == i, "popped element should have the expected value"); } } full = drLockFreeFIFO_isFull(&f); fail_unless(full == 0, "empty FIFO should not report that it's full"); empty = drLockFreeFIFO_isEmpty(&f); fail_unless(empty == 1, "empty FIFO should report that it's empty"); }
int main(int argc, char **argv) { (void)argc; (void)argv; start_test(); test_1(0); test_1(1); test_2(); end_test(); return EXIT_SUCCESS; }
static int test_truncate(int len) { const char *data = testdata; int datalen = testdatalen; int res; start_test("truncate(%u)", (int) len); res = create_file(testfile, data, datalen); if (res == -1) return -1; res = truncate(testfile, len); if (res == -1) { PERROR("truncate"); return -1; } res = check_size(testfile, len); if (res == -1) return -1; if (len > 0) { if (len <= datalen) { res = check_data(testfile, data, 0, len); if (res == -1) return -1; } else { res = check_data(testfile, data, 0, datalen); if (res == -1) return -1; res = check_data(testfile, zerodata, datalen, len - datalen); if (res == -1) return -1; } } res = unlink(testfile); if (res == -1) { PERROR("unlink"); return -1; } res = check_nonexist(testfile); if (res == -1) return -1; success(); return 0; }
static int test_rename_dir(void) { int err = 0; int res; start_test("rename dir"); res = create_dir(testdir, testdir_files); if (res == -1) return -1; rmdir(testdir2); res = rename(testdir, testdir2); if (res == -1) { PERROR("rename"); cleanup_dir(testdir, testdir_files, 1); return -1; } res = check_nonexist(testdir); if (res == -1) { cleanup_dir(testdir, testdir_files, 1); return -1; } res = check_type(testdir2, S_IFDIR); if (res == -1) { cleanup_dir(testdir2, testdir_files, 1); return -1; } err += check_mode(testdir2, 0755); err += check_dir_contents(testdir2, testdir_files); err += cleanup_dir(testdir2, testdir_files, 0); res = rmdir(testdir2); if (res == -1) { PERROR("rmdir"); return -1; } res = check_nonexist(testdir2); if (res == -1) return -1; if (err) return -1; success(); return 0; }
static void testTwoThreads() { start_test("Lock free FIFO - producer/consumer threads"); //TODO: actually check stuff const int es = sizeof(int); const int c = 100; drLockFreeFIFO f; drLockFreeFIFO_init(&f, c, es); thrd_t t1, t2; thrd_create(&t1, entryPointConsumer, &f); thrd_create(&t2, entryPointProducer, &f); int joinRes1, joinRes2; thrd_join(t1, &joinRes1); thrd_join(t2, &joinRes2); }
void handl_i2c_message(void) { if (stat.numr == 0) return; if(stat.is_tran == I2C_Direction_Transmitter) { switch (stat.bufr[0]) { case START_ADC: start_ADC(); break; case STOP_ADC: orders_to_stop(); break; case START_SPI0: *spi3 = 5; ++spi3Start; break; case START_SPI1: *spi1 = 3; ++spi1Start; break; case START_TEST: start_test(); break; case STOP_TEST: orders_to_stop_test(); case ENABLE_MONITORING: driver_stat.enable_monitoring = 1; break; case DISABLE_MONITORING: driver_stat.enable_monitoring = 0; break; case SET_GAIN: if(stat.numr == 5) setGainOut(&stat.bufr[1]); break; case CLEAR_SET_OVERLOAD: clear_set_debug(); break; } stat.numr = 0; } return; }
static int do_test_open_acc(int flags, const char *flags_str, int mode, int err) { const char *data = testdata; int datalen = testdatalen; int res; int fd; start_test("open_acc(%s) mode: 0%03o error: '%s'", flags_str, mode, strerror(err)); unlink(testfile); res = create_file(testfile, data, datalen); if (res == -1) return -1; res = chmod(testfile, mode); if (res == -1) { PERROR("chmod"); return -1; } res = check_mode(testfile, mode); if (res == -1) return -1; fd = open(testfile, flags); if (fd == -1) { if (err != errno) { PERROR("open"); return -1; } } else { if (err) { ERROR("open should have failed"); close(fd); return -1; } close(fd); } success(); return 0; }
static int do_test_create_ro_dir(int flags, const char *flags_str) { int res; int err = 0; int fd; start_test("open(%s) in read-only directory", flags_str); rmdir(testdir); res = mkdir(testdir, 0555); if (res == -1) { PERROR("mkdir"); return -1; } fd = open(subfile, flags, 0644); if (fd != -1) { close(fd); unlink(subfile); ERROR("open should have failed"); err--; } else { res = check_nonexist(subfile); if (res == -1) err--; } unlink(subfile); res = rmdir(testdir); if (res == -1) { PERROR("rmdir"); return -1; } res = check_nonexist(testdir); if (res == -1) return -1; if (err) return -1; success(); return 0; }
static void testSize() { start_test("Lock free FIFO - size"); const int es = sizeof(int); const int c = 100; const int nCases = 5; int nPush[nCases] = {10, 20, 30, 5, 90}; int nPop[nCases] = {5, 1, 60, 10, 90}; for (int i = 0; i < nCases; i++) { drLockFreeFIFO f; drLockFreeFIFO_init(&f, c, es); for (int j = 0; j < nPush[i]; j++) { int success = drLockFreeFIFO_push(&f, &j); } for (int j = 0; j < nPop[i]; j++) { int val = 0; int success = drLockFreeFIFO_pop(&f, &val); } const int expectedSize = fmaxf(0.0f, nPush[i] - nPop[i]); const int size = drLockFreeFIFO_getNumElements(&f); fail_unless(expectedSize == size, "FIFO size should be the same after pushing and popping the same number of items"); drLockFreeFIFO_deinit(&f); } }
static bool run_test(const char *cmd, struct test *test) { char *output, *newcmd; FILE *outf; int status; if (test->done) return test->answer; if (test->depends) { size_t len; const char *deps = test->depends; char *dep; /* Space-separated dependencies, could be ! for inverse. */ while ((len = strcspn(deps, " ")) != 0) { bool positive = true; if (deps[len]) { dep = strdup(deps); dep[len] = '\0'; } else { dep = (char *)deps; } if (dep[0] == '!') { dep++; positive = false; } if (run_test(cmd, find_test(dep)) != positive) { test->answer = false; test->done = true; return test->answer; } if (deps[len]) free(dep); deps += len; deps += strspn(deps, " "); } } outf = fopen(INPUT_FILE, verbose > 1 ? "w+" : "w"); if (!outf) c12r_err(EXIT_TROUBLE_RUNNING, "creating %s", INPUT_FILE); fprintf(outf, "%s", PRE_BOILERPLATE); if (strstr(test->style, "INSIDE_MAIN")) { fprintf(outf, "%s", MAIN_START_BOILERPLATE); fprintf(outf, "%s", test->fragment); fprintf(outf, "%s", MAIN_END_BOILERPLATE); } else if (strstr(test->style, "OUTSIDE_MAIN")) { fprintf(outf, "%s", test->fragment); fprintf(outf, "%s", MAIN_START_BOILERPLATE); fprintf(outf, "%s", MAIN_BODY_BOILERPLATE); fprintf(outf, "%s", MAIN_END_BOILERPLATE); } else if (strstr(test->style, "DEFINES_FUNC")) { fprintf(outf, "%s", test->fragment); fprintf(outf, "%s", MAIN_START_BOILERPLATE); fprintf(outf, "%s", USE_FUNC_BOILERPLATE); fprintf(outf, "%s", MAIN_BODY_BOILERPLATE); fprintf(outf, "%s", MAIN_END_BOILERPLATE); } else if (strstr(test->style, "DEFINES_EVERYTHING")) { fprintf(outf, "%s", test->fragment); } else c12r_errx(EXIT_BAD_TEST, "Unknown style for test %s: %s", test->name, test->style); if (verbose > 1) { fseek(outf, 0, SEEK_SET); fcopy(outf, stdout); } fclose(outf); newcmd = strdup(cmd); if (test->flags) { newcmd = realloc(newcmd, strlen(newcmd) + strlen(" ") + strlen(test->flags) + 1); strcat(newcmd, " "); strcat(newcmd, test->flags); if (verbose > 1) printf("Extra flags line: %s", newcmd); } if (test->link) { newcmd = realloc(newcmd, strlen(newcmd) + strlen(" ") + strlen(test->link) + 1); strcat(newcmd, " "); strcat(newcmd, test->link); if (verbose > 1) printf("Extra link line: %s", newcmd); } start_test("checking for ", test->desc); output = run(newcmd, &status); free(newcmd); if (status != 0 || strstr(output, "warning")) { if (verbose) printf("Compile %s for %s, status %i: %s\n", status ? "fail" : "warning", test->name, status, output); if (strstr(test->style, "EXECUTE") && !strstr(test->style, "MAY_NOT_COMPILE")) c12r_errx(EXIT_BAD_TEST, "Test for %s did not compile:\n%s", test->name, output); test->answer = false; free(output); } else { /* Compile succeeded. */ free(output); /* We run INSIDE_MAIN tests for sanity checking. */ if (strstr(test->style, "EXECUTE") || strstr(test->style, "INSIDE_MAIN")) { output = run("." DIR_SEP OUTPUT_FILE, &status); if (!strstr(test->style, "EXECUTE") && status != 0) c12r_errx(EXIT_BAD_TEST, "Test for %s failed with %i:\n%s", test->name, status, output); if (verbose && status) printf("%s exited %i\n", test->name, status); free(output); } test->answer = (status == 0); } test->done = true; end_test(test->answer); if (test->answer && test->overrides) { struct test *override = find_test(test->overrides); override->done = true; override->answer = true;
TEST(NetworkTest, test_switch_3) { start_test(1, 10000); }
static int test_ftruncate(int len, int mode) { const char *data = testdata; int datalen = testdatalen; int res; int fd; start_test("ftruncate(%u) mode: 0%03o", len, mode); res = create_file(testfile, data, datalen); if (res == -1) return -1; fd = open(testfile, O_WRONLY); if (fd == -1) { PERROR("open"); return -1; } res = fchmod(fd, mode); if (res == -1) { PERROR("fchmod"); close(fd); return -1; } res = check_mode(testfile, mode); if (res == -1) { close(fd); return -1; } res = ftruncate(fd, len); if (res == -1) { PERROR("ftruncate"); close(fd); return -1; } close(fd); res = check_size(testfile, len); if (res == -1) return -1; if (len > 0) { if (len <= datalen) { res = check_data(testfile, data, 0, len); if (res == -1) return -1; } else { res = check_data(testfile, data, 0, datalen); if (res == -1) return -1; res = check_data(testfile, zerodata, datalen, len - datalen); if (res == -1) return -1; } } res = unlink(testfile); if (res == -1) { PERROR("unlink"); return -1; } res = check_nonexist(testfile); if (res == -1) return -1; success(); return 0; }
void IridiumSBD::standby_loop(void) { if (_test_pending) { _test_pending = false; if (!strcmp(_test_command, "s")) { write(0, "kreczmer", 8); } else if (!strcmp(_test_command, "read")) { _rx_session_pending = true; } else { _test_timer = hrt_absolute_time(); start_test(); return; } } // check for incoming SBDRING, handled inside read_at_command() read_at_command(); if (_param_read_interval_s > 0 && ((hrt_absolute_time() - _last_read_time) > (uint64_t)_param_read_interval_s * 1000000)) { _rx_session_pending = true; } // write the MO buffer when the message stacking time expires if (_tx_buf_write_pending && ((hrt_absolute_time() - _last_write_time) > (uint64_t)_param_stacking_time_ms * 1000)) { write_tx_buf(); } // do not start an SBD session if there is still data in the MT buffer, or it will be lost if ((_tx_session_pending || _rx_session_pending) && !_rx_read_pending) { if (_signal_quality > 0) { // clear the MO buffer if we only want to read a message if (_rx_session_pending && !_tx_session_pending) { if (clear_mo_buffer()) { start_sbd_session(); return; } } else { start_sbd_session(); return; } } else { start_csq(); return; } } // start a signal check if requested and not a switch to another mode is scheduled if (((hrt_absolute_time() - _last_signal_check) > SATCOM_SIGNAL_REFRESH_DELAY) && (_new_state == SATCOM_STATE_STANDBY)) { start_csq(); return; } // only read the MT buffer if the higher layer (mavlink app) read the previous message if (_rx_read_pending && (_rx_msg_read_idx == _rx_msg_end_idx) && (_new_state == SATCOM_STATE_STANDBY)) { read_rx_buf(); return; } }
int main(int argc, char *argv[]) { int c, role = NOT_DEFINED; char *interface = NULL; struct sockaddr_in *t_addr; struct sockaddr_in6 *t_addr6; /* Parse the arguments. */ while ((c = getopt(argc, argv, ":H:L:P:h:p:c:d:lm:sx:X:o:M:r:Di:I:f:")) >= 0 ) { switch (c) { case 'H': local_host = optarg; break; case 'P': local_port = atoi(optarg); break; case 'h': remote_host = optarg; break; case 'p': remote_port = atoi(optarg); break; case 'l': if (role != NOT_DEFINED) { printf("%s: only -s or -l\n", argv[0]); usage(argv[0]); exit(1); } role = SERVER; break; case 's': if (role != NOT_DEFINED) { printf("%s: only -s or -l\n", argv[0]); usage(argv[0]); exit(1); } role = CLIENT; break; case 'D': drain = 1; break; case 'd': debug_level = atoi(optarg); if (debug_level < DEBUG_NONE || debug_level > DEBUG_MAX) { usage(argv[0]); exit(1); } break; case 'I': period = atoi(optarg); if (period < 0) { usage(argv[0]); exit(1); } break; case 'x': repeat = atoi(optarg); if (!repeat) { repeat = BIG_REPEAT; } break; case 'X': msg_cnt = atoi(optarg); if ((msg_cnt <= 0) || (msg_cnt > MSG_CNT)) { usage(argv[0]); exit(1); } break; case 'c': size_arg = atoi(optarg); if (size_arg < 0) { usage(argv[0]); exit(1); } break; case 'o': order_pattern = atoi(optarg); if (order_pattern < ORDER_PATTERN_UNORDERED || order_pattern > ORDER_PATTERN_RANDOM ) { usage(argv[0]); exit(1); } break; case 'M': max_stream = atoi(optarg); if (max_stream < 0 || max_stream >= (1<<16)) { usage(argv[0]); exit(1); } break; case 'm': max_msgsize = atoi(optarg); break; case 'i': interface = optarg; break; case 'f': statusfile = optarg; break; case '?': default: usage(argv[0]); exit(0); } } /* while() */ if (NOT_DEFINED == role) { usage(argv[0]); exit(1); } if (SERVER == role && NULL == local_host && remote_host != NULL) { fprintf(stderr, "%s: Server needs local address, " "not remote address\n", argv[0]); usage(argv[0]); exit(1); } if (CLIENT == role && NULL == remote_host) { fprintf(stderr, "%s: Client needs at least remote address " "& port\n", argv[0]); usage(argv[0]); exit(1); } if (optind < argc) { fprintf(stderr, "%s: non-option arguments are illegal: ", argv[0]); while (optind < argc) fprintf(stderr, "%s ", argv[optind++]); fprintf (stderr, "\n"); usage(argv[0]); exit(1); } if (remote_host != NULL && remote_port != 0) { struct addrinfo *res; int error; char *host_s, *serv_s; if ((host_s = malloc(NI_MAXHOST)) == NULL) { fprintf(stderr, "\n*** host_s malloc failed!!! ***\n"); exit(1); } if ((serv_s = malloc(NI_MAXSERV)) == NULL) { fprintf(stderr, "\n*** serv_s malloc failed!!! ***\n"); exit(1); } error = getaddrinfo(remote_host, 0, NULL, &res); if (error) { printf("%s.\n", gai_strerror(error)); usage(argv[0]); exit(1); } switch (res->ai_family) { case AF_INET: t_addr = (struct sockaddr_in *)&s_rem; t_addr->sin_family = AF_INET; t_addr->sin_port = htons(remote_port); inet_pton(AF_INET, remote_host, &t_addr->sin_addr); r_len = sizeof (struct sockaddr_in); #ifdef __FreeBSD__ t_addr->sin_len = r_len; #endif break; case AF_INET6: t_addr6 = (struct sockaddr_in6 *)&s_rem; if (interface) t_addr6->sin6_scope_id = if_nametoindex(interface); t_addr6->sin6_family = AF_INET6; t_addr6->sin6_port = htons(remote_port); inet_pton(AF_INET6, remote_host, &t_addr6->sin6_addr); r_len = sizeof (struct sockaddr_in6); #ifdef __FreeBSD__ t_addr6->sin6_len = r_len; #endif break; } getnameinfo((struct sockaddr *)&s_rem, r_len, host_s, NI_MAXHOST, serv_s, NI_MAXSERV, NI_NUMERICHOST); DEBUG_PRINT(DEBUG_MAX, "remote:addr=%s, port=%s, family=%d\n", host_s, serv_s, res->ai_family); } if (local_host != NULL) { struct addrinfo *res; int error; char *host_s, *serv_s; struct sockaddr_in *t_addr; struct sockaddr_in6 *t_addr6; if ((host_s = malloc(NI_MAXHOST)) == NULL) { fprintf(stderr, "\n*** host_s malloc failed!!! ***\n"); exit(1); } if ((serv_s = malloc(NI_MAXSERV)) == NULL) { fprintf(stderr, "\n*** serv_s malloc failed!!! ***\n"); exit(1); } if (strcmp(local_host, "0") == 0) local_host = "0.0.0.0"; error = getaddrinfo(local_host, 0, NULL, &res); if (error) { printf("%s.\n", gai_strerror(error)); usage(argv[0]); exit(1); } switch (res->ai_family) { case AF_INET: t_addr = (struct sockaddr_in *)&s_loc; t_addr->sin_family = AF_INET; t_addr->sin_port = htons(local_port); inet_pton(AF_INET, local_host, &t_addr->sin_addr); l_len = sizeof (struct sockaddr_in); #ifdef __FreeBSD__ t_addr->sin_len = l_len; #endif break; case AF_INET6: t_addr6 = (struct sockaddr_in6 *)&s_loc; if (interface) t_addr6->sin6_scope_id = if_nametoindex(interface); t_addr6->sin6_family = AF_INET6; t_addr6->sin6_port = htons(local_port); inet_pton(AF_INET6, local_host, &t_addr6->sin6_addr); l_len = sizeof (struct sockaddr_in6); #ifdef __FreeBSD__ t_addr6->sin6_len = l_len; #endif break; } error = getnameinfo((struct sockaddr *)&s_loc, l_len, host_s, NI_MAXHOST, serv_s, NI_MAXSERV, NI_NUMERICHOST); if (error) printf("%s..\n", gai_strerror(error)); DEBUG_PRINT(DEBUG_MAX, "local:addr=%s, port=%s, family=%d\n", host_s, serv_s, res->ai_family); } /* Let the testing begin. */ start_test(role); return 0; }
static int do_test_open(int exist, int flags, const char *flags_str, int mode) { char buf[4096]; const char *data = testdata; int datalen = testdatalen; unsigned currlen = 0; int err = 0; int res; int fd; loff_t off; start_test("open(%s, %s, 0%03o)", exist ? "+" : "-", flags_str, mode); unlink(testfile); if (exist) { res = create_file(testfile, testdata2, testdata2len); if (res == -1) return -1; currlen = testdata2len; } fd = open(testfile, flags, mode); if ((flags & O_CREAT) && (flags & O_EXCL) && exist) { if (fd != -1) { ERROR("open should have failed"); close(fd); return -1; } else if (errno == EEXIST) goto succ; } if (!(flags & O_CREAT) && !exist) { if (fd != -1) { ERROR("open should have failed"); close(fd); return -1; } else if (errno == ENOENT) goto succ; } if (fd == -1) { PERROR("open"); return -1; } if (flags & O_TRUNC) currlen = 0; err += check_type(testfile, S_IFREG); if (exist) err += check_mode(testfile, 0644); else err += check_mode(testfile, mode); err += check_nlink(testfile, 1); err += check_size(testfile, currlen); if (exist && !(flags & O_TRUNC) && (mode & 0400)) err += check_data(testfile, testdata2, 0, testdata2len); res = write(fd, data, datalen); if ((flags & O_ACCMODE) != O_RDONLY) { if (res == -1) { PERROR("write"); err --; } else if (res != datalen) { ERROR("write is short: %u instead of %u", res, datalen); err --; } else { if (datalen > (int) currlen) currlen = datalen; err += check_size(testfile, currlen); if (mode & 0400) { err += check_data(testfile, data, 0, datalen); if (exist && !(flags & O_TRUNC) && testdata2len > datalen) err += check_data(testfile, testdata2 + datalen, datalen, testdata2len - datalen); } } } else { if (res != -1) { ERROR("write should have failed"); err --; } else if (errno != EBADF) { PERROR("write"); err --; } } off = lseek(fd, SEEK_SET, 0); if (off == (loff_t) -1) { PERROR("lseek"); err--; } else if (off != 0) { ERROR("offset should have returned 0"); err --; } res = read(fd, buf, sizeof(buf)); if ((flags & O_ACCMODE) != O_WRONLY) { if (res == -1) { PERROR("read"); err--; } else { int readsize = currlen < sizeof(buf) ? currlen : sizeof(buf); if (res != readsize) { ERROR("read is short: %i instead of %u", res, readsize); err--; } else { if ((flags & O_ACCMODE) != O_RDONLY) { err += check_buffer(buf, data, datalen); if (exist && !(flags & O_TRUNC) && testdata2len > datalen) err += check_buffer(buf + datalen, testdata2 + datalen, testdata2len - datalen); } else if (exist) err += check_buffer(buf, testdata2, testdata2len); } } } else { if (res != -1) { ERROR("read should have failed"); err --; } else if (errno != EBADF) { PERROR("read"); err --; } } res = close(fd); if (res == -1) { PERROR("close"); return -1; } res = unlink(testfile); if (res == -1) { PERROR("unlink"); return -1; } res = check_nonexist(testfile); if (res == -1) return -1; if (err) return -1; succ: success(); return 0; }
void run_test(enum MCSType type) { const MCSCommandOptionsCommon *cmd; MCSPacket *pkt_wr, *pkt_rd; unsigned char *args; unsigned char data[] = "Hello World!"; int i, j; bool error = false; for(i = 0; i < mcs_command_list_size[type]; ++i) { start_test(); if(type == MCS_TYPE_MESSAGE) { cmd = &mcs_command_message_list[i].cmd; } else if(type == MCS_TYPE_STATE) { cmd = &mcs_command_state_list[i].cmd; } else if(type == MCS_TYPE_PAYLOAD) { cmd = &mcs_command_payload_list[i].cmd; } else { cmd = NULL; abs_test_printf("mcs_command_list_size is incorrect for type %d\n", type); abs_test_fail_and_exit("MCS Type"); } abs_test_printf("Testing command %s\n", cmd->name); if(cmd->nargs == 0) { args = NULL; } else { args = malloc(cmd->nargs); for(j = 0; j < cmd->nargs; ++j) { args[j] = j; } } if(type == MCS_TYPE_MESSAGE && mcs_command_message_list[i].destination != NULL && mcs_command_message_list[i].destination[0] == '@') { if(cmd->raw_data) { pkt_wr = mcs_create_packet_with_dest( (MCSCommand)((int)(type << 16) | i), "test_dest", cmd->nargs, args, strlen((char *)data), data); } else { pkt_wr = mcs_create_packet_with_dest( (MCSCommand)((int)(type << 16) | i), "test_dest", cmd->nargs, args, 0, NULL); } } else { if(cmd->raw_data) { pkt_wr = mcs_create_packet( (MCSCommand)((int)(type << 16) | i), cmd->nargs, args, strlen((char *)data), data); } else { pkt_wr = mcs_create_packet( (MCSCommand)((int)(type << 16) | i), cmd->nargs, args, 0, NULL); } } if(cmd->nargs != 0) { free(args); } if(pkt_wr != NULL) { if(mcs_write_command(pkt_wr, pipe_fd[1]) < 0) { abs_test_printf("mcs_write_command returned a wrong value\n"); error = true; } else { pkt_rd = mcs_read_command(pipe_fd[0], pipe_fd[1]); error = !mcs_cmp(pkt_wr, pkt_rd); mcs_free(pkt_rd); } } else { error = true; } mcs_free(pkt_wr); end_test(); if(error) { abs_test_add_result(FAIL, cmd->name); } else { abs_test_add_result(PASS, cmd->name); } } }
int main() { char cmd, data; char config[8]; // char state = 0; // State: 0=failure, 1=success int i; InitUart(); //Error: while(1) { if(!EmptyUart1()) { cmd = GetUart1(); switch(cmd) { // 'test' command case 't': if (start_test()) PutUart1('s'); else PutUart1('f'); break; // 'ready' inquiry case 'r': PutUart1('a'); // Acknowledge break; // 'memory' command case 'm': PutUart1('a'); // Acknowledge // flush_rx_buffer(); if(dump_memory()) PutUart1('s'); else PutUart1('f'); break; // 'configuration' command case 'c': #if REMOTE_CONFIG == 0 PutUart1('f'); #else PutUart1('a'); // Acknowledge for(i=0; i<8; i++) { if(!wait_for_answer(&data)) break; config[i] = data; } if(i<8) PutUart1('f'); else { INT_A_PERIOD = config[0]; INT_B_PERIOD = config[1]; INT_C_PERIOD = config[2]; INT_D_PERIOD = config[3]; BURST_WRITE = config[4]>0 ? 1 : 0; TIME_SCALER = config[5]>0 ? config[5] : 1; HOLD_TIME = config[6]; TEST_DURATION = config[7]; PutUart1('s'); } #endif break; default: break; } } } return( 0 ); }
int main(int argc, char *argv[]) { const char *cert = NULL; int err = 0; tlsperf.num = 1; tlsperf.proto = IPPROTO_TCP; for (;;) { const int c = getopt(argc, argv, "a:dc:e:p:n:s:hv"); if (0 > c) break; switch (c) { case 'c': cert = optarg; break; case 'd': tlsperf.proto = IPPROTO_UDP; break; case 'n': tlsperf.num = atoi(optarg); break; case 'v': tlsperf.verbose = true; break; case '?': err = EINVAL; /*@fallthrough@*/ case 'h': usage(); return err; } } err = libre_init(); if (err) goto out; re_printf("tlsperf -- TLS performance testing program\n"); re_printf("build: %H\n", sys_build_get, 0); re_printf("compiler: %s\n", __VERSION__); re_printf("libre: %s\n", sys_libre_version_get()); re_printf("os: %s\n", sys_os_get()); re_printf("arch: %s\n", sys_arch_get()); #ifdef USE_OPENSSL re_printf("openssl info: %s\n%s\n", SSLeay_version(SSLEAY_VERSION), SSLeay_version(SSLEAY_CFLAGS)); #endif re_printf("protocol: %s\n", tlsperf.proto == IPPROTO_TCP ? "TLS" : "DTLS"); err = tls_alloc(&tlsperf.tls, TLS_METHOD_SSLV23, cert, 0); if (err) goto out; if (cert) { re_printf("certificate: %s\n", cert); } else { re_printf("certificate: selfsigned RSA-1024\n"); err = tls_set_selfsigned(tlsperf.tls, "a@b"); if (err) goto out; } re_printf("starting tests now. (num=%u)\n", tlsperf.num); /* * Start timing now */ tlsperf.ts_start = tmr_jiffies(); err = start_test(); if (err) goto out; re_main(0); out: mem_deref(tlsperf.ep_srv); mem_deref(tlsperf.ep_cli); mem_deref(tlsperf.tls); libre_close(); /* check for memory leaks */ mem_debug(); tmr_debug(); return err ? err : tlsperf.err; }
int main(int argc, char *argv[]) { int c; char *interface = NULL; struct sockaddr_in *t_addr; struct sockaddr_in6 *t_addr6; struct sockaddr *tmp_addrs = NULL; /* Parse the arguments. */ while ((c = getopt(argc, argv, ":H:L:P:S:a:h:p:c:d:lm:sx:X:o:t:M:r:w:Di:TB:C:O:")) >= 0 ) { switch (c) { case 'H': local_host = optarg; break; case 'L': role = MIXED; listeners = atoi(optarg); if (listeners > MAX_POLL_SKS) { usage(argv[0]); exit(1); } break; case 'P': local_port = atoi(optarg); break; case 'S': role = MIXED; tosend = atoi(optarg); if (tosend > MAX_POLL_SKS) { usage(argv[0]); exit(1); } break; case 'a': assoc_pattern = atoi(optarg); if (assoc_pattern < ASSOC_PATTERN_SEQUENTIAL || assoc_pattern > ASSOC_PATTERN_RANDOM ) { usage(argv[0]); exit(1); } break; case 'h': remote_host = optarg; break; case 'D': drain = 1; do_exit = 0; break; case 'p': remote_port = atoi(optarg); break; case 's': if (role != NOT_DEFINED) { printf("%s: only -s or -l\n", argv[0]); usage(argv[0]); exit(1); } role = CLIENT; break; case 'l': if (role != NOT_DEFINED) { printf("%s: only -s or -l\n", argv[0]); usage(argv[0]); exit(1); } role = SERVER; break; case 'd': debug_level = atoi(optarg); if (debug_level < DEBUG_NONE || debug_level > DEBUG_MAX) { usage(argv[0]); exit(1); } break; case 'x': repeat = atoi(optarg); if (!repeat) { xflag = 1; repeat = BIG_REPEAT; } break; case 'X': msg_cnt = atoi(optarg); if ((msg_cnt <= 0) || (msg_cnt > MSG_CNT)) { usage(argv[0]); exit(1); } break; case 'c': test_case = atoi(optarg); if (test_case > NCASES) { usage(argv[0]); exit(1); } if (test_case < 0) { size_arg = -test_case; } break; case 'o': order_pattern = atoi(optarg); if (order_pattern < ORDER_PATTERN_UNORDERED || order_pattern > ORDER_PATTERN_RANDOM ) { usage(argv[0]); exit(1); } break; case 'O': timetolive = atoi(optarg); if (timetolive < 0) { usage(argv[0]); exit(1); } break; case 't': stream_pattern = atoi(optarg); if (stream_pattern < STREAM_PATTERN_SEQUENTIAL || stream_pattern > STREAM_PATTERN_RANDOM ) { usage(argv[0]); exit(1); } break; case 'M': max_stream = atoi(optarg); if (max_stream < 0 || max_stream >= (1<<16)) { usage(argv[0]); exit(1); } break; case 'r': seed = atoi(optarg); break; case 'm': max_msgsize = atoi(optarg); #if 0 if ((max_msgsize < DEFAULT_MIN_WINDOW) || (max_msgsize > 65515)) { usage(argv[0]); exit(1); } #endif break; case 'i': interface = optarg; if_index = if_nametoindex(interface); if (!if_index) { printf("Interface %s unknown\n", interface); exit(1); } break; case 'T': socket_type = SOCK_STREAM; break; case 'B': tmp_addrs = append_addr(optarg, bindx_add_addrs, &bindx_add_count); if (NULL == tmp_addrs) { fprintf(stderr, "No memory to add "); fprintf(stderr, "%s\n", optarg); exit(1); } bindx_add_addrs = tmp_addrs; break; case 'C': tmp_addrs = append_addr(optarg, connectx_addrs, &connectx_count); if (NULL == tmp_addrs) { fprintf(stderr, "No memory to add "); fprintf(stderr, "%s\n", optarg); exit(1); } connectx_addrs = tmp_addrs; break; case '?': default: usage(argv[0]); exit(0); } } /* while() */ if (NOT_DEFINED == role) { usage(argv[0]); exit(1); } if (SERVER == role && NULL == local_host && remote_host != NULL) { fprintf (stderr, "%s: Server needs local address, " "not remote address\n", argv[0]); usage(argv[0]); exit(1); } if (CLIENT == role && NULL == remote_host && connectx_count == 0) { fprintf (stderr, "%s: Client needs at least remote address " "& port\n", argv[0]); usage(argv[0]); exit(1); } if (MIXED == role) { if (listeners && NULL == local_host) { fprintf (stderr, "%s: Servers need local address\n", argv[0]); usage(argv[0]); exit(1); } if (tosend && NULL == remote_host) { fprintf (stderr, "%s: Clients need remote address ", argv[0]); fprintf (stderr, "& port\n"); usage(argv[0]); exit(1); } } if (optind < argc) { fprintf(stderr, "%s: non-option arguments are illegal: ", argv[0]); while (optind < argc) fprintf(stderr, "%s ", argv[optind++]); fprintf (stderr, "\n"); usage(argv[0]); exit(1); } if (remote_host != NULL && connectx_count != 0) { fprintf(stderr, "%s: You can not provide both -h and -C options.\n", argv[0]); usage(argv[0]); exit(1); } if (remote_host != NULL && remote_port != 0) { struct addrinfo *res; int error; char *host_s, *serv_s; if ((host_s = malloc(NI_MAXHOST)) == NULL) { fprintf(stderr, "\n*** host_s malloc failed!!! ***\n"); exit(1); } if ((serv_s = malloc(NI_MAXSERV)) == NULL) { fprintf(stderr, "\n*** serv_s malloc failed!!! ***\n"); exit(1); } error = getaddrinfo(remote_host, 0, NULL, &res); if (error) { printf("%s.\n", gai_strerror(error)); usage(argv[0]); exit(1); } switch (res->ai_family) { case AF_INET: t_addr = (struct sockaddr_in *)&s_rem; t_addr->sin_family = AF_INET; t_addr->sin_port = htons(remote_port); inet_pton(AF_INET, remote_host, &t_addr->sin_addr); r_len = sizeof (struct sockaddr_in); #ifdef __FreeBSD__ t_addr->sin_len = r_len; #endif break; case AF_INET6: t_addr6 = (struct sockaddr_in6 *)&s_rem; if (interface) t_addr6->sin6_scope_id = if_nametoindex(interface); t_addr6->sin6_family = AF_INET6; t_addr6->sin6_port = htons(remote_port); inet_pton(AF_INET6, remote_host, &t_addr6->sin6_addr); r_len = sizeof (struct sockaddr_in6); #ifdef __FreeBSD__ t_addr6->sin6_len = r_len; #endif break; } getnameinfo((struct sockaddr *)&s_rem, r_len, host_s, NI_MAXHOST, serv_s, NI_MAXSERV, NI_NUMERICHOST); DEBUG_PRINT(DEBUG_MAX, "remote:addr=%s, port=%s, family=%d\n", host_s, serv_s, res->ai_family); } if (connectx_count != 0) { switch (connectx_addrs->sa_family) { case AF_INET: t_addr = (struct sockaddr_in *)&s_rem; r_len = sizeof(struct sockaddr_in); memcpy(t_addr, connectx_addrs, r_len); t_addr->sin_port = htons(remote_port); break; case AF_INET6: t_addr6 = (struct sockaddr_in6 *)&s_rem; r_len = sizeof(struct sockaddr_in6); memcpy(t_addr6, connectx_addrs, r_len); t_addr6->sin6_port = htons(remote_port); break; } } if (local_host != NULL) { struct addrinfo *res; int error; char *host_s, *serv_s; struct sockaddr_in *t_addr; struct sockaddr_in6 *t_addr6; if ((host_s = malloc(NI_MAXHOST)) == NULL) { fprintf(stderr, "\n*** host_s malloc failed!!! ***\n"); exit(1); } if ((serv_s = malloc(NI_MAXSERV)) == NULL) { fprintf(stderr, "\n*** serv_s malloc failed!!! ***\n"); exit(1); } if (strcmp(local_host, "0") == 0) local_host = "0.0.0.0"; error = getaddrinfo(local_host, 0, NULL, &res); if (error) { printf("%s.\n", gai_strerror(error)); usage(argv[0]); exit(1); } switch (res->ai_family) { case AF_INET: t_addr = (struct sockaddr_in *)&s_loc; t_addr->sin_family = AF_INET; t_addr->sin_port = htons(local_port); inet_pton(AF_INET, local_host, &t_addr->sin_addr); l_len = sizeof (struct sockaddr_in); #ifdef __FreeBSD__ t_addr->sin_len = l_len; #endif break; case AF_INET6: t_addr6 = (struct sockaddr_in6 *)&s_loc; if (interface) t_addr6->sin6_scope_id = if_nametoindex(interface); t_addr6->sin6_family = AF_INET6; t_addr6->sin6_port = htons(local_port); inet_pton(AF_INET6, local_host, &t_addr6->sin6_addr); l_len = sizeof (struct sockaddr_in6); #ifdef __FreeBSD__ t_addr6->sin6_len = l_len; #endif break; } error = getnameinfo((struct sockaddr *)&s_loc, l_len, host_s, NI_MAXHOST, serv_s, NI_MAXSERV, NI_NUMERICHOST); if (error) printf("%s..\n", gai_strerror(error)); DEBUG_PRINT(DEBUG_MAX, "local:addr=%s, port=%s, family=%d\n", host_s, serv_s, res->ai_family); } /* A half-hearted attempt to seed rand() */ if (seed == 0 ) { seed = time(0); DEBUG_PRINT(DEBUG_NONE, "seed = %d\n", seed); } srand(seed); /* Let the testing begin. */ start_test(role); return 0; } /* main() */
int main(int argc, const char *argv[]) { int pipefds[2]; struct mevent *timer; ssize_t written; char *msgs[] = { "first", "second" }; char *msg; start_test(argv[0], 5); start_event_thread(); if (pipe(pipefds) != 0) { FAIL_ERRNO("pipe"); } if (fcntl(pipefds[0], F_SETFL, O_NONBLOCK) != 0) { FAIL_ERRNO("set pipe nonblocking"); } /* * First write */ msg = msgs[0]; read_event = mevent_add(pipefds[0], EVF_READ, munch, msg); ASSERT_PTR_NEQ(("mevent_add pipefd"), read_event, NULL); pthread_mutex_lock(&mtx); written = write(pipefds[1], msg, strlen(msg)); if (written < 0) { FAIL_ERRNO("bad write"); } ASSERT_INT64_EQ(("write '%s' failed", msg), written, strlen(msg)); /* * Wait for it to be read */ pthread_cond_wait(&cv, &mtx); ASSERT_INT_EQ(("wrong lastwake"), lastwake, CB_READ); pthread_mutex_unlock(&mtx); /* * Add timer, second write. */ msg = msgs[1]; timer = mevent_add(50, EVF_TIMER, tick, msg); ASSERT_PTR_NEQ(("mevent_add timer"), timer, NULL); pthread_mutex_lock(&mtx); written = write(pipefds[1], msg, strlen(msg)); if (written < 0) { FAIL_ERRNO("bad write"); } ASSERT_INT64_EQ(("write '%s' failed", msg), written, strlen(msg)); /* * Wait for timer to expire */ pthread_cond_wait(&cv, &mtx); ASSERT_INT_EQ(("wrong lastwake"), lastwake, CB_TIMER); pthread_mutex_unlock(&mtx); PASS(); }
int main(int argc,char **argv) { int status,wait_ret; uint i=0; MI_KEYDEF keyinfo[10]; MI_COLUMNDEF recinfo[10]; HA_KEYSEG keyseg[10][2]; MY_INIT(argv[0]); get_options(argc,argv); bzero((char*) keyinfo,sizeof(keyinfo)); bzero((char*) recinfo,sizeof(recinfo)); bzero((char*) keyseg,sizeof(keyseg)); keyinfo[0].seg= &keyseg[0][0]; keyinfo[0].seg[0].start=0; keyinfo[0].seg[0].length=8; keyinfo[0].seg[0].type=HA_KEYTYPE_TEXT; keyinfo[0].seg[0].flag=HA_SPACE_PACK; keyinfo[0].key_alg=HA_KEY_ALG_BTREE; keyinfo[0].keysegs=1; keyinfo[0].flag = (uint8) HA_PACK_KEY; keyinfo[0].block_length= 0; /* Default block length */ keyinfo[1].seg= &keyseg[1][0]; keyinfo[1].seg[0].start=8; keyinfo[1].seg[0].length=4; /* Long is always 4 in myisam */ keyinfo[1].seg[0].type=HA_KEYTYPE_LONG_INT; keyinfo[1].seg[0].flag=0; keyinfo[1].key_alg=HA_KEY_ALG_BTREE; keyinfo[1].keysegs=1; keyinfo[1].flag =HA_NOSAME; keyinfo[1].block_length= 0; /* Default block length */ recinfo[0].type=0; recinfo[0].length=sizeof(record.id); recinfo[1].type=0; recinfo[1].length=sizeof(record.nr); recinfo[2].type=0; recinfo[2].length=sizeof(record.text); puts("- Creating myisam-file"); my_delete(filename,MYF(0)); /* Remove old locks under gdb */ if (mi_create(filename,2,&keyinfo[0],2,&recinfo[0],0,(MI_UNIQUEDEF*) 0, (MI_CREATE_INFO*) 0,0)) exit(1); rnd_init(0); printf("- Starting %d processes\n",forks); fflush(stdout); for (i=0 ; i < forks; i++) { if (!fork()) { start_test(i+1); sleep(1); return 0; } (void) rnd(1); } for (i=0 ; i < forks ; i++) while ((wait_ret=wait(&status)) && wait_ret == -1); return 0; }
int main(int argc,char **argv) { int status,wait_ret; uint i=0; MARIA_KEYDEF keyinfo[10]; MARIA_COLUMNDEF recinfo[10]; HA_KEYSEG keyseg[10][2]; MY_INIT(argv[0]); get_options(argc,argv); fprintf(stderr, "WARNING! this program is to test 'external locking'" " (when several processes share a table through file locking)" " which is not supported by Maria at all; expect errors." " We may soon remove this program.\n"); maria_init(); bzero((char*) keyinfo,sizeof(keyinfo)); bzero((char*) recinfo,sizeof(recinfo)); bzero((char*) keyseg,sizeof(keyseg)); keyinfo[0].seg= &keyseg[0][0]; keyinfo[0].seg[0].start=0; keyinfo[0].seg[0].length=8; keyinfo[0].seg[0].type=HA_KEYTYPE_TEXT; keyinfo[0].seg[0].flag=HA_SPACE_PACK; keyinfo[0].key_alg=HA_KEY_ALG_BTREE; keyinfo[0].keysegs=1; keyinfo[0].flag = (uint8) HA_PACK_KEY; keyinfo[0].block_length= 0; /* Default block length */ keyinfo[1].seg= &keyseg[1][0]; keyinfo[1].seg[0].start=8; keyinfo[1].seg[0].length=4; /* Long is always 4 in maria */ keyinfo[1].seg[0].type=HA_KEYTYPE_LONG_INT; keyinfo[1].seg[0].flag=0; keyinfo[1].key_alg=HA_KEY_ALG_BTREE; keyinfo[1].keysegs=1; keyinfo[1].flag =HA_NOSAME; keyinfo[1].block_length= 0; /* Default block length */ recinfo[0].type=0; recinfo[0].length=sizeof(record.id); recinfo[1].type=0; recinfo[1].length=sizeof(record.nr); recinfo[2].type=0; recinfo[2].length=sizeof(record.text); puts("- Creating maria-file"); my_delete(filename,MYF(0)); /* Remove old locks under gdb */ if (maria_create(filename,BLOCK_RECORD, 2, &keyinfo[0],2,&recinfo[0],0, (MARIA_UNIQUEDEF*) 0, (MARIA_CREATE_INFO*) 0,0)) exit(1); rnd_init(0); printf("- Starting %d processes\n",forks); fflush(stdout); for (i=0 ; i < forks; i++) { if (!fork()) { start_test(i+1); sleep(1); return 0; } rnd(1); } for (i=0 ; i < forks ; i++) while ((wait_ret=wait(&status)) && wait_ret == -1); maria_end(); return 0; }