void test_nl_langinfo_1(const char *locale, struct langinfo_test *test) { char tname[128]; char *v; test_t t; (void) snprintf(tname, sizeof (tname), "nl_langinfo (locale %s)", locale); t = test_start(tname); v = setlocale(LC_ALL, locale); if (v == NULL) { test_failed(t, "setlocale failed: %s", strerror(errno)); } if (strcmp(v, locale) != 0) { test_failed(t, "setlocale got %s instead of %s", v, locale); } for (int i = 0; test[i].value != NULL; i++) { v = nl_langinfo(test[i].param); test_debugf(t, "%d: expect [%s], got [%s]", test[i].param, test[i].value, v); if (strcmp(v, test[i].value) != 0) { test_failed(t, "param %d wrong, expected [%s], got [%s]", test[i].param, test[i].value, v); } } test_passed(t); }
void test_list() { int actuals[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; const char* test_name = "linked list"; testing(); int i = 0; list_t* list = list_create(); if (!list) test_failed("null list"); for (i = 0; i < 10; i++) { int* val = kmalloc(sizeof(int)); *val = i + 1; list_push(list, val); } int* val = NULL; for (i = 9; i >= 0; i--) { val = (int*)list_pop(list); if (!val) test_failed("null value"); if (*val != actuals[i]) { kprintf("*val == %d, actuals[%d] == %d\n", *val, i, actuals[i]); test_failed("bad value"); } } list_destroy(list); }
int main(int argc, char *argv[]) { void *ptr; int i; for (i = 0; i < 4; i++) { ptr = shmem_access(i); if (ptr == NULL) { test_failed(); } } int pid = fork(); if (pid < 0) { test_failed(); } else if (pid == 0) { exec("echo", args); //echo represents shmem_access_exec2_helper.c printf(1, "exec failed!\n"); test_failed(); exit(); } else { wait(); } exit(); }
void test_wcsrtombs_negative(void) { mbstate_t ms; const wchar_t *wcs; char mbs[32]; char *dst; int e; wchar_t src[32] = BAD_WCS; test_t t; int cnt; t = test_start("wcsrtombs_negative"); (void) memset(&ms, 0, sizeof (ms)); if (setlocale(LC_ALL, "ru_RU.UTF-8") == NULL) { test_failed(t, "setlocale failed: %s", strerror(errno)); } wcs = src; dst = mbs; cnt = wcsrtombs(dst, &wcs, sizeof (mbs), &ms); if (cnt != -1) { test_failed(t, "bogus success (%d)", cnt); } if ((e = errno) != EILSEQ) { test_failed(t, "wrong errno, wanted %d (EILSEQ), got %d: %s", EILSEQ, e, strerror(e)); } test_passed(t); }
void test_wcsrtombs_thr_iter(test_t t, const char *locale, struct wcsrtombs_test *test) { locale_t loc; mbstate_t ms; loc = newlocale(LC_ALL_MASK, locale, NULL); if (loc == NULL) { test_failed(t, "newlocale failed: %s", strerror(errno)); } for (int i = 0; test[i].mbs[0] != 0; i++) { char mbs[32]; const wchar_t *wcs = test[i].wcs; size_t cnt; (void) memset(&ms, 0, sizeof (ms)); (void) memset(mbs, 0, sizeof (mbs)); cnt = wcsrtombs_l(mbs, &wcs, sizeof (mbs), &ms, loc); if (cnt != strlen(test[i].mbs)) { test_failed(t, "incorrect return value: %d != %d", cnt, strlen(test[i].mbs)); } if (strcmp(mbs, test[i].mbs) != 0) { test_failed(t, "wrong result: %s != %s", mbs, test[i].mbs); } if (extra_debug) { test_debugf(t, "mbs is %s", mbs); } } freelocale(loc); }
/* Test start */ void user_entry() { unsigned i; /* * Sine/cosine values on interval -1..1 computed using 10 terms of * Taylor series. */ for(i = 0; i<ARRAY_LENGTH(ten_terms); ++i) { fixed_t sin = sine_fxp(ten_terms[i], 10); fixed_t cos = cosine_fxp(ten_terms[i], 10); if(sin != sin10[i] || cos != cos10[i]) test_failed(); } /* * Sine/cosine values on interval -PI..PI computed using 4 terms of * Taylor series. */ for(i = 0; i<ARRAY_LENGTH(four_terms); ++i) { fixed_t sin = sine_fxp(four_terms[i], 4); fixed_t cos = cosine_fxp(four_terms[i], 4); if(sin != sin4[i] || cos != cos4[i]) test_failed(); } test_passed(); }
static void test_size(size_t size) { char buf[32]; void * const encode_end = lzjbstream_size_encode(buf, sizeof buf, size); if(encode_end == NULL) { test_failed("Failed to encode %zu, out of buffer space\n", size); return; } const size_t encoded_length = (char *) encode_end - buf; size_t size_out; const void * const decode_end = lzjbstream_size_decode(buf, encoded_length, &size_out); if(decode_end == NULL) { test_failed("Failed to decode %zu from %zu bytes of encoded data, ran out of input\n", size, encoded_length); return; } if(size != size_out) { test_failed("Failed to decode %zu, got %zu instead (from %zu bytes)\n", size, size_out, encoded_length); return; } test_passed(); }
int main(int argc, char *argv[]) { void *ptr; int n; int i; for (i = 0; i < 4; i++) { ptr = shmem_access(i); if (ptr == NULL) { test_failed(); } } int pid = fork(); if (pid < 0) { test_failed(); } else if (pid == 0) { for (i = 0; i < 4; i++) { n = shmem_count(i); if (n != 2) { test_failed(); } } exit(); } else { wait(); } test_passed(); exit(); }
int main(int argc, char *argv[]) { int fd; char buf[MAX]; char buf2[MAX]; int n; int i; for(i = 0; i < MAX; i++){ buf[i] = (char)(i+(int)'0'); } if((fd = open("test_file.txt", O_CREATE | O_SMALLFILE | O_RDWR)) < 0){ printf(1, "Failed to create the small file\n"); test_failed(); exit(); } if((n = write(fd, buf, MAX)) < 0){ printf(1, "Write failed!\n"); test_failed(); } printf(1, "bytes written = %d\n", n); close(fd); if(n != (NDIRECT+1)*4){ printf(1, "Failed to write the right amount to the small file.\n"); test_failed(); } if((fd = open("test_file.txt", O_CREATE | O_SMALLFILE | O_RDWR)) < 0){ printf(1, "Failed to create the small file\n"); exit(); } if((n = read(fd, buf2, MAX)) < 0){ printf(1, "Read failed!\n"); exit(); } printf(1, "bytes read = %d\n", n); close(fd); if(n != (NDIRECT+1)*4){ printf(1, "Failed to read the right amount to the small file.\n"); test_failed(); } for(i = 0; i < (NDIRECT+1)*4; i++){ if(buf[i] != buf2[i]){ printf(1, "Data mismatch.\n"); test_failed(); } } test_passed(); exit(); }
/* Calls test_failed() if it doesn't match the appropriate event */ void check_testevent(char *desc, char *comment) { if(check_testevent_num > testevent_num) { test_failed(comment); } if(strcmp(desc, testevents[check_testevent_num])) { test_failed(comment); } check_testevent_num++; }
int main(int argc, char *argv[]) { char *ptr; int i; char d, arr[6] = "CS537"; int pid = fork(); if (pid < 0) { test_failed(); } else if (pid == 0) { // printf(1, "child shmem_counter before access: %d\n", shmem_count(3)); ptr = shmem_access(3); if (ptr == NULL) { test_failed(); } for (i = 0; i < 5; i++) { *(ptr+i) = arr[i]; printf(1, "write: %c\n", *(ptr+i)); } for (i = 0; i < 5; i++) { d = *(ptr+i); printf(1, "read in child: %c\n", d); } // printf(1, "child shmem_counter after access: %d\n", shmem_count(3)); exit(); } else { wait(); // printf(1, "parent shmem_counter before access: %d\n", shmem_count(3)); ptr = shmem_access(3); // printf(1, "parent shmem_counter after access: %d\n", shmem_count(3)); if (ptr == NULL) { test_failed(); } for (i = 0; i < 5; i++) { printf(1, "read in parent: %c\n", *(ptr+i)); if (*(ptr+i) != arr[i]) { printf(1, "%d\t%c\t%c\n", shmem_count(3), *(ptr+i), arr[i]); test_failed(); } } } test_passed(); exit(); }
void test_dispatcher_5_process_d(PROCESS self, PARAM param) { kprintf("Process: %s\n\n", self->name); print_all_processes(kernel_window); kprintf("\n"); if (check_sum != 2) test_failed(23); check_sum += 1; resign(); test_failed(24); }
void test_dispatcher_7_process_e(PROCESS self, PARAM param) { kprintf("%s\n", self->name); if (check_sum != 1) test_failed(23); check_sum += 2; remove_ready_queue(self); check_num_proc_on_ready_queue(3); if (test_result != 0) test_failed(test_result); resign(); test_failed(26); }
// For internal use by the TEST() macro. // Report an exception. inline void test_exception(std::exception const& ex, char const* expr, char const* file, int line) { std::string msg{ expr }; msg += " threw an exception: "; msg += ex.what(); test_failed(msg.c_str(), file, line); }
int client(int protocol_type, pid_t server_pid) { client_done = false; client_event_num = 0; // Sleep for 1ms to give the server time to start. usleep(1000); char address[256]; snprintf(address, 256, "%s://127.0.0.1:%d", protocol_type == msg_udp ? "udp" : "tcp", protocol_type == msg_udp ? udp_port : tcp_port); Context *ctx = malloc(sizeof(Context)); ctx->address = strdup(address); ctx->num_tries = 0; msg_connect(address, client_update, ctx); int timeout_in_ms = 10; while (!client_done) { msg_runloop(timeout_in_ms); // Check to see if the server process ended before we expected it to. int status; if (!client_done && waitpid(server_pid, &status, WNOHANG)) { test_failed("Client: Server process ended before client expected."); } } free(ctx->address); free(ctx); return test_success; }
/* * This test creates two processes with the same priority. Doing * a resign() in the main process should continue execution in * test_process_e(). When this process does a resign(), execution * should resume in test_process_d(). Then the execution should * be passed back to test_process_e(). This basically tests Round- * Robin of ready processes. */ void test_dispatcher_5() { test_reset(); create_process(test_dispatcher_5_process_e, 5, 0, "Test process E"); kprintf("Created process E\n"); create_process(test_dispatcher_5_process_d, 5, 0, "Test process D"); kprintf("Created process D\n"); check_sum = 0; resign(); if(check_sum == 0) test_failed(21); if(check_sum != 7) test_failed(25); }
int main(int _argc, char **_argv) { const char * oversion; const char * env_seed; int env_used; if(_argc>2) { fprintf(stderr,"Usage: %s [<seed>]\n",_argv[0]); return 1; } env_used=0; env_seed=getenv("SEED"); if(_argc>1)iseed=atoi(_argv[1]); else if(env_seed) { iseed=atoi(env_seed); env_used=1; } else iseed=(opus_uint32)time(NULL)^((getpid()&65535)<<16); Rw=Rz=iseed; oversion=opus_get_version_string(); if(!oversion)test_failed(); fprintf(stderr,"Testing %s decoder. Random seed: %u (%.4X)\n", oversion, iseed, fast_rand() % 65535); if(env_used)fprintf(stderr," Random seed set from the environment (SEED=%s).\n", env_seed); /*Setting TEST_OPUS_NOFUZZ tells the tool not to send garbage data into the decoders. This is helpful because garbage data may cause the decoders to clip, which angers CLANG IOC.*/ test_decoder_code0(getenv("TEST_OPUS_NOFUZZ")!=NULL); return 0; }
/* * Creates two new processes with different priorities. When the main * thread calls resign(), execution should continue with test_process_c() * This process then removes itself from the ready queue and calls resign() * again. Execution should then continue in test_process_a() */ void test_dispatcher_4() { test_reset(); create_process(test_dispatcher_4_process_a, 5, 42, "Test process A"); kprintf("Created process A\n"); create_process(test_dispatcher_4_process_c, 7, 0, "Test process C"); kprintf("Created process C\n"); check_sum = 0; resign(); if (check_sum == 0) test_failed(21); if (check_sum != 3) test_failed(22); }
void __test_assert(int result, const char* condition, const char* file, int line) { assert_count++; if (!result) { test_failed(condition, file, line); exit(1); } }
int main(int argc, char *argv[]) { int fd; char buf[MAX]; char buf2[MAX]; int n; int i; for(i = 0; i < MAX; i++) { buf[i] = (char)(i+(int)'0'); } memset(buf2, 0, MAX); //create and write if((fd = open("test_file.txt", O_CREATE | O_SMALLFILE | O_RDWR)) < 0) { printf(1, "Failed to create the small file\n"); test_failed(); exit(); } if((n = write(fd, buf, MAX)) != MAX) { printf(1, "Write failed!\n"); test_failed(); } close(fd); //read if((fd = open("test_file.txt", O_CREATE | O_SMALLFILE | O_RDWR)) < 0) { printf(1, "Failed to open the small file\n"); test_failed(); } for(i = 0; i < MAX; i++) { if((n = read(fd, &buf2[i], 1)) != 1) { printf(1, "Read failed!\n"); test_failed(); } if(buf[i] != buf2[i]) { printf(1, "Data mismatch.\n"); test_failed(); } } close(fd); test_passed(); exit(); }
void test_wcsrtombs_partial(void) { test_t t; mbstate_t ms; wchar_t src[32] = HELLO_RU_WCS; char mbs[32]; char *dst; const wchar_t *wcs; size_t cnt; (void) memset(&ms, 0, sizeof (ms)); t = test_start("wcsrtombs_partial"); if (setlocale(LC_ALL, "ru_RU.UTF-8") == NULL) { test_failed(t, "setlocale failed: %s", strerror(errno)); } wcs = src; dst = mbs; cnt = wcsrtombs(dst, &wcs, 1, &ms); if (cnt != 0) { test_failed(t, "gave back a conversion cnt %d != 0", cnt); } if (wcs != src) { test_failed(t, "incorrectly advanced wcs"); } cnt = wcsrtombs(dst, &wcs, 2, &ms); if (cnt != 2) { test_failed(t, "gave back a conversion cnt %d != 2", cnt); } dst += cnt; cnt = wcsrtombs(dst, &wcs, 4, &ms); dst += cnt; cnt = wcsrtombs(dst, &wcs, sizeof (mbs) - strlen(mbs), &ms); if (extra_debug) { test_debugf(t, "mbs is %s", mbs); } if (strcmp(mbs, HELLO_RU_MBS) != 0) { test_failed(t, "wrong result: %s != %s", mbs, HELLO_RU_MBS); } test_passed(t); }
int main(int argc, char *argv[]) { int fd; char buf[NITERATIONS]; char result; //character read from file int n; int i; for(i = 0; i < NITERATIONS; i++){ printf(1, "writing %d\n", (i+(int)'0')); buf[i] = (char)(i+(int)'0'); } //open, write 1 byte, close for(i = 0; i < NITERATIONS; i++){ if((fd = open("test_file.txt", O_CREATE | O_SMALLFILE | O_RDWR)) < 0){ printf(1, "Failed to create the small file\n"); test_failed(); } if((n = write(fd, &buf[i], 1)) != 1){ printf(1, "Write failed!\n"); test_failed(); } close(fd); } //read if((fd = open("test_file.txt", O_CREATE | O_SMALLFILE | O_RDWR)) < 0){ printf(1, "Failed to open the small file\n"); test_failed(); } if((n = read(fd, &result, 10)) != 1){ printf(1, "Read failed! %d\n", n); test_failed(); } close(fd); printf(1, "returned %c\n", result); if(result != buf[NITERATIONS-1]){ printf(1, "Data mismatch.\n"); test_failed(); } test_passed(); exit(); }
void test_dispatcher_5_process_e(PROCESS self, PARAM param) { kprintf("\nProcess: %s\n\n", self->name); if (check_sum != 0) test_failed(23); check_sum += 2; resign(); kprintf("Back to %s", self->name); if (check_sum != 3) test_failed(24); check_sum += 4; return_to_boot(); }
int main() { test_failed(); test_right_failed(); test_content(); test_unallocated(); return 0; }
void test_ipc_6_sender_process_3(PROCESS self, PARAM param) { PORT receiver_port = (PORT) param; int data = 33; check_process("Receiver", STATE_RECEIVE_BLOCKED, FALSE); check_process("Sender 2", STATE_READY, TRUE); check_process("Sender 1", STATE_READY, TRUE); if (test_result != 0) { print_all_processes(kernel_window); test_failed(test_result); } kprintf("%s: sending a message to port 3...\n", self->name); message(receiver_port, &data); test_failed(37); }
void test_ipc_6_sender_process_1(PROCESS self, PARAM param) { PORT receiver_port = (PORT) param; int data = 11; check_process("Receiver", STATE_RECEIVE_BLOCKED, FALSE); check_process("Sender 3", STATE_MESSAGE_BLOCKED, FALSE); check_process("Sender 2", STATE_MESSAGE_BLOCKED, FALSE); if (test_result != 0) { print_all_processes(kernel_window); test_failed(test_result); } kprintf("%s: sending a message to port 1...", self->name); send(receiver_port, &data); test_failed(40); }
/* Standard startup hook * * $Req: artf1226 $ */ void StartupHook(void) { #ifdef USESTARTUPHOOK SET_TESTEVENT("StartupHook"); #else test_failed(OS_HERE); #endif }
void test_wcsrtombs_l(const char *locale, struct wcsrtombs_test *test) { test_t t; locale_t loc; char *v; mbstate_t ms; t = test_start("wcsrtombs_l (locale %s)", locale); v = setlocale(LC_ALL, "C"); if (v == NULL) { test_failed(t, "setlocale failed: %s", strerror(errno)); } if (strcmp(v, "C") != 0) { test_failed(t, "setlocale got %s instead of %s", v, "C"); } loc = newlocale(LC_ALL_MASK, locale, NULL); if (loc == NULL) { test_failed(t, "newlocale failed: %s", strerror(errno)); } for (int i = 0; test[i].mbs[0] != 0; i++) { char mbs[32]; const wchar_t *wcs = test[i].wcs; size_t cnt; (void) memset(&ms, 0, sizeof (ms)); (void) memset(mbs, 0, sizeof (mbs)); cnt = wcsrtombs_l(mbs, &wcs, sizeof (mbs), &ms, loc); if (cnt != strlen(test[i].mbs)) { test_failed(t, "incorrect return value: %d != %d", cnt, strlen(test[i].mbs)); } if (strcmp(mbs, test[i].mbs) != 0) { test_failed(t, "wrong result: %s != %s", mbs, test[i].mbs); } if (extra_debug) { test_debugf(t, "mbs is %s", mbs); } } test_passed(t); }
int main(int argc, char **argv) { AST_node *expr1, *expr2, *expr3; Eval_return ret_status; Value val; expr1= create_variable_node("x"); expr2= create_operator_node(ASSIGN, create_variable_node("x"), create_int_constant_node(3)); expr3= create_operator_node(TIMES, create_double_constant_node(2.01), create_variable_node("x")); ret_status= evaluate(expr1, &val); if(ret_status != NOT_EVALUATED) test_failed(__LINE__); ret_status= evaluate(expr2, &val); if(ret_status != EVALUATED || val.value_type != IS_INT_VALUE || val.number.int_value != 3) test_failed(__LINE__); ret_status= evaluate(expr1, &val); if(ret_status != EVALUATED || val.value_type != IS_INT_VALUE || val.number.int_value != 3) test_failed(__LINE__); ret_status= evaluate(expr3, &val); if(ret_status != EVALUATED || val.value_type != IS_DOUBLE_VALUE || val.number.double_value - 6.03 > 0.0001) test_failed(__LINE__); clear(&expr1); clear(&expr2); clear(&expr3); printf("Test passed!\n"); return 0; }
void test_ipc_3_sender_process(PROCESS self, PARAM param) { PORT receiver_port = (PORT) param; int data1= 42; int data2= 24; check_sum += 1; /* * send the first message */ check_process("Receiver", STATE_RECEIVE_BLOCKED, FALSE); if (test_result != 0) { print_all_processes(kernel_window); test_failed(48); } kprintf("%s: sending a message using send()...\n", self->name); send(receiver_port, &data1); if (check_sum != 3) test_failed(49); check_sum += 4; kprintf("%s: received = %d\n", self->name, data1); if (data1 != 11) test_failed(41); /* * send the second message */ kprintf("%s: sending a message using message()...\n", self->name); message(receiver_port, &data2); if (check_sum != 15) test_failed(54); kprintf("%s: woken up from message()\n", self->name); return_to_boot(); }