int main (void) { char buf[256]; memset (buf, '\0', sizeof (buf) ); unsigned int given_low = 0; unsigned int given_high = 10; unsigned int symb; snprintf (buf, sizeof (buf), "Running Modifed S2E Tutorial1 (for Iteration)\n"); s2e_message (buf); printf ("%s\n", buf); symb = s2e_dasospreproc_fuzz (given_low, given_high); if (symb < given_low || symb > given_high) { snprintf (buf, sizeof (buf), "Error: should not be here, char is not in range: %02x<=%02x<=%02x:%u<=%u<=%u", given_low, symb, given_high, given_low, symb, given_high); s2e_warning (buf); printf ("%s\n", buf); s2e_kill_state (1, buf); return 1; } snprintf (buf, sizeof (buf), "Success: char is in range: %02x<=%02x<=%02x:%u<=%u<=%u", given_low, symb, given_high, given_low, symb, given_high); s2e_warning (buf); printf ("%s\n", buf); s2e_kill_state (0, buf); return 0; } // end fn main
// Called when: // - we are exiting an epwrapper // - the return value is successful // - symbolic kernel retvals are enabled static void verify_symretval(const char *fn, int line, unsigned long retval) { if (bad_path) { // This path was set up artificially // The kernel did something other than what the driver // thinks it did. uprintk ("At %s:%d exit point with retval %ld: this is a bad path\n", fn, line, s2e_get_example_uint (retval)); s2e_kill_state(1, 0, "Bad path returning to kernel"); return; } // This path is genuine in the sense that the kernel actually did // what the driver thinks it did. if (driver_call_stack >= 1) { // Path is genuine and there are more driver functions on call stack uprintk ("At %s:%d exit point with retval %ld: successful path but more to go ...\n", fn, line, s2e_get_example_uint (retval)); } else { // Path is genuine and there are no more driver functions on call stack uprintk ("At %s:%d exit point with retval %ld: successful path\n", fn, line, s2e_get_example_uint (retval)); //tfassert_detail (0, "Good path returning to kernel - reducing state explosion"); if (g_sym_retval == 1) { s2e_kill_state(1, 0, "Good path returning to kernel - reducing state explosion"); } else if (g_sym_retval == 2) { uprintk ("Good path completed -- deprioritizing..."); s2e_deprioritize(line); } else { tfassert_detail(0, "Expected g_sym_retval not to be %d\n", g_sym_retval); } } }
int main(int argc, char *argv[]) { char **vector; int args; s2e_disable_all_apic_interrupts(); s2e_enable_forking(); s2e_make_symbolic(&args, sizeof(args), "Number of arguments"); if (args < 1 || args > 4) { s2e_get_example(&args, sizeof(args)); printf("Bad value for args: %d\n", args); s2e_kill_state(0, "bad value for args"); return 2; } printf("Good value for args\n"); fflush(stdout); args= 5; s2e_get_example(&args, sizeof(args)); printf("Got value for args: %d\n", args); fflush(stdout); printf("Before malloc vector\n"); vector= malloc((args+1)*sizeof(*vector)); printf("After malloc vector\n"); s2e_kill_state(0, "after malloc"); }
static void handle_max_coverage (const char *fn, int line, int retval_valid, unsigned long retval, enum symdrive_WRAPPER_TYPE wrapper_type, enum symdrive_DIRECTION direction) { if (strcmp (fn, g_sym_starting_fn)) { return; } // We have a match if (direction == ENTRANCE) { uprintk ("Max coverage mode detected: %s:%d\n", fn, line); g_sym_retval = 1; s2e_kill_all_others(line); } else if (direction == EXIT) { if (retval_valid && IS_ERR_VALUE(retval)) { char temp[128]; sprintf (temp, "Terminating failed thorough coverage fn path (%s:%d)...", fn, line); s2e_kill_state(0, 0, temp); } else { // Disable favor successful and start exploring all other paths // through this function. char temp[128]; s2e_favor_successful(line, 0); sprintf (temp, "Terminating successful thorough coverage fn path (line %s/%d)...", fn, line); s2e_kill_state(0, 0, temp); } } else { tfassert_detail (0, "Failed %s: %s:%d\n", __func__, fn, line); } }
void main(void) { int x = 0; s2e_make_concolic(&x, sizeof(x), "x"); s2e_print_expression(x, "x before constraints"); if (x == 0) { s2e_print_expression(x, "x in if branch"); s2e_kill_state(0, "If branch terminated"); } else { s2e_print_expression(x, "x in else branch"); s2e_kill_state(0, "Else branch terminated"); } }
int main(int ac, char **av) { int lc; char *msg; if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); TEST_EXP_ENOS(exp_enos); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; s2e_enable_forking(); s2e_make_symbolic(&path, sizeof(path), "path"); TEST(chroot(path)); s2e_disable_forking(); s2e_kill_state(0, "program done"); if (TEST_RETURN != -1) tst_resm(TFAIL, "call succeeded unexpectedly"); else if (errno != EPERM) tst_resm(TFAIL | TTERRNO, "chroot failed unexpectedly"); else tst_resm(TPASS, "chroot set errno to EPERM."); } cleanup(); tst_exit(); }
static void verify_retval (const char *fn, int line, enum symdrive_WRAPPER_TYPE wrapper_type, enum symdrive_DIRECTION dir, int retval_valid, unsigned long retval) { tfassert (wrapper_type == STUBWRAPPER || wrapper_type == PREPOSTFN); tfassert (dir == ENTRANCE || dir == EXIT); // Precondition. We're either entering or leaving the driver. tfassert (driver_call_stack == 0); if (wrapper_type == PREPOSTFN && dir == EXIT) { if (retval_valid) { if (g_symdrive_annotations == 0) { // Proceed normally } else { // Convert retval to success uprintk ("At %s:%d exit point with retval %ld: allowing our path per annotation\n", fn, line, s2e_get_example_uint (retval)); g_symdrive_annotations = 0; retval = 0; } if (IS_ERR_VALUE(retval)) { uprintk ("At %s:%d exit point with retval %ld: terminating our path\n", fn, line, s2e_get_example_uint (retval)); s2e_kill_state(0, 0, "Test complete: failure detected on this path."); } if (!IS_ERR_VALUE(retval)) { // Driver entry point completed successfully if (g_sym_retval == 0) { uprintk ("At %s:%d exit point with retval %ld: calling s2e_concretize_kill\n", fn, line, s2e_get_example_uint (retval)); s2e_concretize_kill (line); } else if (g_sym_retval == 1 || g_sym_retval == 2) { verify_symretval(fn, line, retval); } else { tfassert_detail(0, "g_sym_retval should not be %d\n", g_sym_retval); } } } else { uprintk ("At %s:%d exit point with no retval: calling s2e_concretize_kill\n", fn, line); s2e_concretize_kill (line); uprintk ("At %s:%d exit point with no retval: Killed everything\n", fn, line); } } if (wrapper_type == STUBWRAPPER && dir == ENTRANCE) { // In this case, we're entering back into the driver // from a kernel function call. // Does not matter -- kernel function was successful, or not. //s2e_prioritize(line); } }
int main(int ac, char **av) { int lc; char *msg; /*************************************************************** * parse standard options ***************************************************************/ if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); /*************************************************************** * perform global setup for test ***************************************************************/ setup(); /* set the expected errnos... */ TEST_EXP_ENOS(exp_enos); /*************************************************************** * check looping state if -c option given ***************************************************************/ for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; /* * Call setpgid(2) */ s2e_enable_forking(); s2e_make_symbolic(&pgid,sizeof(pgid),"pgid"); TEST(setpgid(pid, pgid)); s2e_disable_forking(); s2e_kill_state(0,"program done!"); /* check return code */ if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, "setpgid(%d, %d) Failed, errno=%d : %s", pid, pgid, TEST_ERRNO, strerror(TEST_ERRNO)); } else { /*************************************************************** * only perform functional verification if flag set (-f not given) ***************************************************************/ if (STD_FUNCTIONAL_TEST) { /* No Verification test, yet... */ tst_resm(TPASS, "setpgid(%d, %d) returned %ld", pid, pgid, TEST_RETURN); } } } /*************************************************************** * cleanup and exit ***************************************************************/ cleanup(); tst_exit(); }
int main(int ac, char **av) { int test_index = 0; char *msg; if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); #if defined(__powerpc__) || defined(__powerpc64__) /* for PPC, kernel version > 2.6.21 needed */ if (tst_kvercmp(2, 16, 22) < 0) { tst_brkm(TCONF, NULL, "System doesn't support execution of the test"); } #else /* For other archs, need kernel version > 2.6.16 */ if (tst_kvercmp(2, 6, 17) < 0) { tst_brkm(TCONF, NULL, "System doesn't support execution of the test"); } #endif setup(); for (test_index = 0; test_index < TST_TOTAL; test_index++) { s2e_enable_forking(); s2e_make_symbolic(&test_data[test_index],sizeof(test_data[test_index]),"test_index"); TEST(syncfilerange (*(test_data[test_index].fd), test_data[test_index].offset, test_data[test_index].nbytes, test_data[test_index].flags)); s2e_disable_forking(); s2e_kill_state(0,"program done!"); if (TEST_RETURN != -1) { tst_resm(TFAIL, "call succeeded unexpectedly (%ld != -1)", TEST_RETURN); continue; } TEST_ERROR_LOG(TEST_ERRNO); if (TEST_ERRNO == test_data[test_index].error) { tst_resm(TPASS | TTERRNO, "got expected error"); } else { tst_resm(TFAIL | TTERRNO, "got unexpected error; " "expected %d", test_data[test_index].error); } } cleanup(); tst_exit(); }
int main() { s2e_enable_forking(); p.type=PERF_TYPE_SOFTWARE; // s2e_make_symbolic(&(p.type), sizeof(p.type), "type"); // s2e_make_symbolic(&(p.size), sizeof(p.size), "size"); s2e_make_symbolic(&(p.config), sizeof(p.config), "config"); syscall(336, &p, 0, -1, -1, 0); s2e_disable_forking(); s2e_kill_state(0, "ok!"); return 0; }
int main (void) { char buf[256]; memset (buf, '\0', sizeof (buf) ); char given_low = 'a'; char given_high = 'j'; char symb; //char i; snprintf (buf, sizeof (buf), "Running Modifed S2E Tutorial1 (for Iteration)\n"); s2e_message (buf); printf ("%s\n", buf); //s2e_disable_all_apic_interrupts(); // make faster //s2e_enable_forking (); //s2e_make_symbolic (&(symb), 1 * sizeof (char), "symb"); symb = s2e_dasospreproc_fuzz (given_low, given_high); if (symb < given_low || symb > given_high) { snprintf (buf, sizeof (buf), "Error: should not be here, char is not in range: %02x<=%02x<=%02x:%c<=%c<=%c", given_low, symb, given_high, given_low, symb, given_high); s2e_warning (buf); printf ("%s\n", buf); //s2e_dasospreproc_fuzz_kill_state (); s2e_kill_state (1, buf); return 1; } /* something goes here to make it print all possible examples */ //{ //s2e_get_example (&(symb), 1 * sizeof (char) ); snprintf (buf, sizeof (buf), "Success: char is in range: %02x<=%02x<=%02x:%c<=%c<=%c", given_low, symb, given_high, given_low, symb, given_high); s2e_warning (buf); printf ("%s\n", buf); //s2e_dasospreproc_fuzz_kill_state (); s2e_kill_state (0, buf); return 0; //} s2e_kill_state (1, "should never be here, outside of the forloop, program terminated"); return 1; } // end fn main
int main(int ac, char **av) { int lc; char *msg; int tc; msg = parse_opts(ac, av, NULL, NULL); if (msg != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; for (tc = 0; tc < TST_TOTAL; tc++) { s2e_enable_forking(); s2e_make_symbolic(&test_cases[tc].mode, sizeof(test_cases[tc].mode), "mode"); TEST(access(test_cases[tc].file, test_cases[tc].mode)); if (TEST_RETURN == -1 && test_cases[tc].experrno == 0) { tst_resm(TFAIL | TTERRNO, "access(%s, %s) failed", test_cases[tc].file, test_cases[tc].string); } else if (TEST_RETURN != -1 && test_cases[tc].experrno != 0) { tst_resm(TFAIL, "access(%s, %s) returned %ld, " "exp -1, errno:%d", test_cases[tc].file, test_cases[tc].string, TEST_RETURN, test_cases[tc].experrno); } else { if (STD_FUNCTIONAL_TEST) { tst_resm(TPASS, "access(%s, %s) returned %ld", test_cases[tc].file, test_cases[tc].string, TEST_RETURN); } } } } cleanup(); s2e_disable_forking(); s2e_kill_state(0, "program done!"); tst_exit(); }
int main(int argc, char *argv[]) { int lc; char *msg; int s; if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); for (lc = 0; TEST_LOOPING(lc); ++lc) { tst_count = 0; for (testno = 0; testno < TST_TOTAL; ++testno) { s2e_enable_forking(); s2e_make_symbolic(&tdat[testno],sizeof(tdat[testno]),"tdat[testno]"); TEST((s = socketpair(tdat[testno].domain, tdat[testno].type, tdat[testno].proto, tdat[testno].sv))); s2e_disable_forking(); s2e_kill_state(0,"program done!"); if (TEST_RETURN >= 0) { TEST_RETURN = 0; /* > 0 equivalent */ } else { TEST_ERROR_LOG(TEST_ERRNO); } if (TEST_RETURN != tdat[testno].retval || (TEST_RETURN && (TEST_ERRNO != tdat[testno].experrno && TEST_ERRNO != EPROTONOSUPPORT))) { tst_resm(TFAIL, "%s ; returned" " %d (expected %d), errno %d (expected" " %d)", tdat[testno].desc, s, tdat[testno].retval, TEST_ERRNO, tdat[testno].experrno); } else { tst_resm(TPASS, "%s successful", tdat[testno].desc); } (void)close(s); } } cleanup(); tst_exit(); }
int main() { unsigned a1, a2, b1, b2; s2e_make_symbolic(&a1, sizeof(a1), "a1"); s2e_make_symbolic(&a2, sizeof(a2), "a2"); s2e_make_symbolic(&b1, sizeof(b1), "b1"); s2e_make_symbolic(&b2, sizeof(b2), "b2"); //Just to make it a bit faster s2e_disable_all_apic_interrupts(); s2e_assert(correct_overlap(a1, a2, b1, b2) == student_overlap(a1, a2, b1, b2)); s2e_kill_state(0, "This execution path is correct (assertion check passed)"); return 0; }
int main() { uint64_t x; uint64_t max = 10; //Make x symbolic s2e_make_symbolic(&x, sizeof(x), "x"); uint64_t f1 = factorial1(x, max); uint64_t f2 = factorial2(x, max); //Check the equivalence of the two functions for each path s2e_assert(f1 == f2); //In case of success, terminate the state with the //appropriate message s2e_kill_state(0, "Success"); return 0; }
int main(int ac, char **av) { int lc; char *msg; if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); TEST_EXP_ENOS(exp_enos); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; for (i = 0; i < TST_TOTAL; i++) { s2e_enable_forking(); s2e_make_symbolic(&args[i].value, sizeof(int), "args[i].value"); TEST(fpathconf(fd, args[i].value)); s2e_disable_forking(); s2e_kill_state(0, "program done"); if (TEST_RETURN == -1 && args[i].defined) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL | TTERRNO, "fpathconf(fd, %s) failed", args[i].define_tag); } else { if (STD_FUNCTIONAL_TEST) { tst_resm(TPASS, "fpathconf(fd, %s) returned %ld", args[i].define_tag, TEST_RETURN); } } } } cleanup(); tst_exit(); }
int gen_make_symbolic_ptr (const char *fn, int line, void **ptr_retval) { void *orig_retval = *ptr_retval; if (g_sym_retval == 0) { return g_sym_retval; } acquire_global_lock(); s2e_make_symbolic (ptr_retval, sizeof (void *), "symbolic_retval_ptr"); if (*ptr_retval == orig_retval) { uprintk ("%s/%s: original retval: %p\n", fn, __func__, *ptr_retval); s2e_success_path(line, fn, 1); } else if (*ptr_retval == NULL && *ptr_retval != orig_retval) { uprintk ("%s/%s: NULL retval\n", fn, __func__); s2e_success_path(line, fn, -1); bad_path = 1; } else { s2e_kill_state(1, 0, "gen_make_symbolic_ptr: extra path\n"); } release_global_lock(); return g_sym_retval; }
int main(int ac,char **av) { system("echo \"ABCDEFG123\" > demo.txt"); char *filename = "demo.txt"; int length = 10; int prot = PROT_READ; int flags = MAP_PRIVATE; int offset = 0; char *addr; int fd = open(filename, O_RDONLY); if (fd == -1) exit(0); s2e_enable_forking(); s2e_make_symbolic(&(length),sizeof(length), "symbolic_var_length"); s2e_make_symbolic(&(prot),sizeof(prot), "symbolic_var_prot"); s2e_make_symbolic(&(flags),sizeof(flags), "symbolic_var_flags"); s2e_make_symbolic(&(offset),sizeof(offset), "symbolic_var_offset"); addr = mmap(NULL, length, prot, flags, fd, offset); write(STDOUT_FILENO, addr, length); s2e_disable_forking(); close(fd); s2e_kill_state(0,"program done!"); /* s2e_enable_forking(); s2e_make_symbolic(&(x),sizeof(x), "symbolic_var_x"); s2e_disable_forking(); s2e_kill_state(0,"program done!"); return 0; */ }
static void handler_kill(const char **args) { int status = atoi(args[0]); const char *message = args[1]; s2e_kill_state(status, message); }
int main(int ac, char **av) { struct sysinfo *sys_buf; int lc; char *msg; float l1, l2, l3; unsigned long l1_up, l2_up, l3_up; sys_buf = (struct sysinfo *)malloc(sizeof(struct sysinfo)); if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); } setup(); /* Global setup */ /* The following loop checks looping state if -i option given */ for (lc = 0; TEST_LOOPING(lc); lc++) { /* reset tst_count in case we are looping */ tst_count = 0; s2e_enable_forking(); s2e_make_symbolic(&sys_buf,sizeof(sys_buf),"sys_buf"); TEST(sysinfo(sys_buf)); s2e_disable_forking(); s2e_kill_state(0,"program done!"); /* check return code */ if (TEST_RETURN == -1) { /* To gather stats on errnos returned, log the errno */ tst_brkm(TFAIL, cleanup, "sysinfo() Failed, errno=%d" " : %s", TEST_ERRNO, strerror(TEST_ERRNO)); } else { /* Test succeeded */ /* This portion of the code generates information * used by sysinfo03 to test the functionality of * sysinfo. */ if (ac == 2 && !strncmp(av[1], "TEST3", 5)) { tst_resm(TINFO, "Generating info for " "sysinfo03"); l1 = sys_buf->loads[0] / 60000.0; l2 = sys_buf->loads[1] / 60000.0; l3 = sys_buf->loads[2] / 60000.0; l1_up = l1 * 100; l2_up = l2 * 100; l3_up = l3 * 100; sys_buf->loads[0] = sys_buf->loads[0] / 10; sys_buf->loads[1] = sys_buf->loads[1] / 10; sys_buf->loads[2] = sys_buf->loads[2] / 10; printf("uptime %lu\n", sys_buf->uptime); printf("load1 %lu\n", sys_buf->loads[0]); printf("load2 %lu\n", sys_buf->loads[1]); printf("load3 %lu\n", sys_buf->loads[2]); printf("l1 %lu\n", l1_up); printf("l2 %lu\n", l2_up); printf("l3 %lu\n", l3_up); printf("totalram %lu\n", sys_buf->totalram); printf("freeram %lu\n", sys_buf->freeram); printf("sharedram %lu\n", sys_buf->sharedram); printf("bufferram %lu\n", sys_buf->bufferram); printf("totalswap %lu\n", sys_buf->totalswap / (1024 * 1024)); printf("freeswap %lu\n", sys_buf->freeswap); printf("procs %lu\n", (unsigned long)sys_buf->procs); } else { tst_resm(TPASS, "Test to check the return code PASSED"); } } } cleanup(); tst_exit(); }
void main() { s2e_enable_forking(); int s; struct sockaddr_in addr; addr.sin_family = AF_INET;//? // s2e_make_symbolic(&(addr.sin_family), sizeof(addr.sin_family), "sin_family"); addr.sin_addr.s_addr = inet_addr("127.0.0.1"); addr.sin_port=htons(8080); int socket1 = PF_INET;//? int sockettype = SOCK_DGRAM;//? int socket3 = 0;//? // s2e_make_symbolic(&socket1, sizeof(socket1), "socket1"); // s2e_make_symbolic(&sockettype, sizeof(sockettype), "sockettype"); // s2e_make_symbolic(&socket3, sizeof(socket3), "socket3"); s = socket(socket1, sockettype, socket3);//---socket int level = SOL_SOCKET;//? int options = SO_REUSEADDR;//? char* val = malloc(4); memset(val, 't', sizeof(val)); int setlen = sizeof(val);//? s2e_make_symbolic(&level, sizeof(level), "set_level"); s2e_make_symbolic(&options, sizeof(options), "set_options"); s2e_make_symbolic(&setlen, sizeof(setlen), "set_len"); setsockopt(s, level, options, &val, setlen);//---setsockopt /* int alen = sizeof(addr);//? s2e_make_symbolic(&alen, sizeof(alen), "bind_len"); bind(s, &addr, alen);//---bind int addr_size = sizeof(addr);//? s2e_make_symbolic(&addr_size, sizeof(addr_size), "connet_addr_size"); connect(s, &addr, addr_size);//---connect int qlen = sizeof(addr);//? s2e_make_symbolic(&qlen, sizeof(qlen), "listen_len"); listen(s, qlen);//---listen int addr_size2 = sizeof(addr);//? s2e_make_symbolic(&addr_size2, sizeof(int), "accept_addr_size"); accept(s, &addr, addr_size2);//---accept char* buf = malloc(4); memset(buf,'v',sizeof(buf)); int nbytes = sizeof(buf);//? int flags = MSG_DONTROUTE;//? s2e_make_symbolic(&nbytes, sizeof(int), "send_len"); s2e_make_symbolic(&flags, sizeof(int), "send_flags"); send(s, buf, nbytes, flags);///---send int clen = sizeof(addr);//? s2e_make_symbolic(&clen, sizeof(int), "sendto_addr_len"); sendto(s, buf, nbytes, flags, &addr, clen);//sendto char* buf_recv = malloc(10); int recv_len = sizeof(buf_recv);//? int recv_flag = MSG_OOB;//? s2e_make_symbolic(&recv_len, sizeof(int), "recv_len"); s2e_make_symbolic(&recv_flag, sizeof(int), "recv_flag"); recv(s, buf_recv, recv_len, recv_flag);//---recv */ close(s); s2e_disable_forking(); s2e_kill_state(0, "program done!"); }
int main(int ac, char **av) { DIR *ddir, *opendir(); int fd; char *filname = "chdirtest"; char *filenames[3]; int lc; char *msg; if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); TEST_EXP_ENOS(exp_enos); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; SAFE_CHDIR(cleanup, testdir); fd = SAFE_CREAT(cleanup, filname, 0000); SAFE_CLOSE(cleanup, fd); if ((ddir = opendir(".")) == NULL) tst_brkm(TBROK | TERRNO, cleanup, "opendir(.) failed"); filenames[0] = "."; filenames[1] = ".."; filenames[2] = filname; checknames(filenames, sizeof(filenames) / sizeof(filenames[0]), ddir); closedir(ddir); s2e_enable_forking(); s2e_make_symbolic(filname, 20, "filename"); TEST(chdir(filname)); s2e_disable_forking(); s2e_kill_state(0, "program done!"); if (TEST_RETURN != -1) tst_resm(TFAIL, "call succeeded unexpectedly"); else if (TEST_ERRNO != ENOTDIR) tst_resm(TFAIL | TTERRNO, "failed unexpectedly; wanted ENOTDIR"); else tst_resm(TPASS, "failed as expected with ENOTDIR"); if (unlink(filname) == -1) tst_brkm(TBROK | TERRNO, cleanup, "Couldn't remove file"); SAFE_CHDIR(cleanup, ".."); } cleanup(); tst_exit(); }
int main(int ac, char **av) { char buffer[MAX_SIZE]; /* temporary buffer to hold symlink contents */ int lc; char *msg; if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; /* * Call readlink(2) to read the contents of * symlink into a buffer. */ s2e_enable_forking(); s2e_make_symbolic(&SYMFILE,sizeof(SYMFILE),"SYMFILE"); TEST(readlink(SYMFILE, buffer, sizeof(buffer))); s2e_disable_forking(); s2e_kill_state(0,"program done!"); if (TEST_RETURN == -1) { tst_resm(TFAIL, "readlink() on %s failed, errno=%d : %s", SYMFILE, TEST_ERRNO, strerror(TEST_ERRNO)); continue; } /* * Perform functional verification if test * executed without (-f) option. */ if (STD_FUNCTIONAL_TEST) { /* * Compare the return value of readlink() * with the expected value which is the * strlen() of testfile. */ if (TEST_RETURN == exp_val) { /* Check for the contents of buffer */ if (memcmp(buffer, TESTFILE, exp_val) != 0) { tst_resm(TFAIL, "Pathname %s and buffer" " contents %s differ", TESTFILE, buffer); } else { tst_resm(TPASS, "readlink() " "functionality on '%s' is " "correct", SYMFILE); } } else { tst_resm(TFAIL, "readlink() return value %ld " "does't match, Expected %d", TEST_RETURN, exp_val); } } else { tst_resm(TPASS, "call succeeded"); } } cleanup(); tst_exit(); }
static void do_test(int lfd, struct sockaddr_in *conn_addr, int closeonexec_flag, int nonblock_flag) { int connfd, acceptfd; int fdf, flf, fdf_pass, flf_pass; struct sockaddr_in claddr; socklen_t addrlen; #ifdef DEBUG tst_resm(TINFO, "=======================================\n"); #endif connfd = socket(AF_INET, SOCK_STREAM, 0); if (connfd == -1) die("Socket Error"); if (connect(connfd, (struct sockaddr *)conn_addr, sizeof(struct sockaddr_in)) == -1) die("Connect Error"); addrlen = sizeof(struct sockaddr_in); s2e_enable_forking(); s2e_make_symbolic(claddr, sizeof(struct sockaddr), "calddr"); s2e_make_symbolic(&addrlen, sizeof(struct sockaddr_in), "addrlen"); #if !(__GLIBC_PREREQ(2, 10)) acceptfd = accept4_01(lfd, (struct sockaddr *)&claddr, &addrlen, closeonexec_flag | nonblock_flag); #else acceptfd = accept4(lfd, (struct sockaddr *)&claddr, &addrlen, closeonexec_flag | nonblock_flag); #endif s2e_disable_forking(); s2e_kill_state(0, "program done!"); if (acceptfd == -1) { if (errno == ENOSYS) { tst_brkm(TCONF, cleanup, "syscall __NR_accept4 not supported"); } else { tst_brkm(TBROK | TERRNO, cleanup, "accept4 failed"); } } fdf = fcntl(acceptfd, F_GETFD); if (fdf == -1) die("fcntl:F_GETFD"); fdf_pass = ((fdf & FD_CLOEXEC) != 0) == ((closeonexec_flag & SOCK_CLOEXEC) != 0); #ifdef DEBUG tst_resm(TINFO, "Close-on-exec flag is %sset (%s); ", (fdf & FD_CLOEXEC) ? "" : "not ", fdf_pass ? "OK" : "failed"); #endif if (!fdf_pass) tst_resm(TFAIL, "Close-on-exec flag mismatch, should be %x, actual %x", fdf & FD_CLOEXEC, closeonexec_flag & SOCK_CLOEXEC); flf = fcntl(acceptfd, F_GETFL); if (flf == -1) die("fcntl:F_GETFD"); flf_pass = ((flf & O_NONBLOCK) != 0) == ((nonblock_flag & SOCK_NONBLOCK) != 0); #ifdef DEBUG tst_resm(TINFO, "nonblock flag is %sset (%s)\n", (flf & O_NONBLOCK) ? "" : "not ", flf_pass ? "OK" : "failed"); #endif if (!flf_pass) tst_resm(TFAIL, "nonblock flag mismatch, should be %x, actual %x", fdf & O_NONBLOCK, nonblock_flag & SOCK_NONBLOCK); close(acceptfd); close(connfd); if (fdf_pass && flf_pass) tst_resm(TPASS, "Test passed"); }
int main(int ac,char **av) { struct msghdr msghdr; struct iovec iovector[10]; int i,s; struct sockaddr_in sockad; char msg[128]; struct cmsghdr *cmsg,*cm2; char opts[12]; s=socket(PF_INET, /*SOCK_STREAM*/ SOCK_DGRAM, 0); sockad.sin_family = AF_INET; sockad.sin_addr.s_addr=inet_addr("127.0.0.1"); sockad.sin_port=htons(8080); connect(s,(struct sockaddr *) &sockad, sizeof(sockad)); memset(msg,'v',sizeof(msg)); memset(opts,0,sizeof(opts)); #define VV 1024*1024 cmsg = malloc(VV); memset(cmsg,0,VV); cmsg->cmsg_len = sizeof(struct cmsghdr) + sizeof(opts); cmsg->cmsg_level = SOL_IP; cmsg->cmsg_type = IP_RETOPTS; memcpy(CMSG_DATA(cmsg), opts, sizeof(opts)); int flags = 0; msghdr.msg_flags = 0; msghdr.msg_name = &sockad; msghdr.msg_namelen = sizeof(sockad); msghdr.msg_control=cmsg; msghdr.msg_controllen= cmsg->cmsg_len; msghdr.msg_iov = iovector; msghdr.msg_iovlen = 1; iovector[0].iov_base = msg; iovector[0].iov_len = sizeof(msg); system("sync"); s2e_enable_forking(); s2e_make_symbolic(&(flags), sizeof(flags), "flags"); // s2e_make_symbolic(&(msghdr.msg_namelen), sizeof(msghdr.msg_namelen), "msghdr.msg_namelen"); // s2e_make_symbolic(&(msghdr.msg_controllen), sizeof(msghdr.msg_controllen), "msghdr.msg_controllen"); // s2e_make_symbolic(&(msghdr.msg_iovlen), sizeof(msghdr.msg_iovlen), "msghdr.msg_iovlen"); // s2e_make_symbolic(&(msghdr.msg_flags), sizeof(msghdr.msg_flags), "msghdr.msg_flags"); // s2e_make_symbolic(&(cmsg->cmsg_len),sizeof(cmsg->cmsg_len), "cmsg->cmsg_len"); // s2e_make_symbolic(&(cmsg->cmsg_level),sizeof(cmsg->cmsg_level), "cmsg->cmsg_level"); s2e_make_symbolic(&(cmsg->cmsg_type),sizeof(cmsg->cmsg_type), "cmsg->cmsg_type"); // s2e_make_symbolic(&(iovector[0].iov_len), sizeof(iovector[0].iov_len), "iovector[0].iov_len"); /* s2e_make_symbolic(&(cm2->cmsg_len),sizeof(cm2->cmsg_len), "cm2->cmsg_len"); s2e_make_symbolic(&(cm2->cmsg_level),sizeof(cm2->cmsg_level), "cm2->cmsg_level"); s2e_make_symbolic(&(cm2->cmsg_type),sizeof(cm2->cmsg_type), "cm2->cmsg_type"); */ if (i = sendmsg(s, &msghdr, flags) < 0) perror("sendmsg"); s2e_disable_forking(); s2e_kill_state(0,"program done!"); return 42; }
int main(int ac, char **av) { int lc; char *msg; int i; /* Disable test if the version of the kernel is less than 2.6.16 */ if ((tst_kvercmp(2, 6, 16)) < 0) { tst_resm(TWARN, "This test can only run on kernels that are "); tst_resm(TWARN, "2.6.16 and higher"); exit(0); } /*************************************************************** * parse standard options ***************************************************************/ if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); /*************************************************************** * perform global setup for test ***************************************************************/ setup(); /*************************************************************** * check looping state if -c option given ***************************************************************/ for (lc = 0; TEST_LOOPING(lc); lc++) { setup_every_copy(); tst_count = 0; /* * Call futimesat */ for (i = 0; i < TST_TOTAL; i++) { gettimeofday(×[0], NULL); gettimeofday(×[1], NULL); s2e_enable_forking(); s2e_make_symbolic(&fds[i], sizeof(int), "fds[i]"); s2e_make_symbolic(filenames[i], 10, "filenames"); s2e_make_symbolic(times, sizeof(struct timeval) * 2, "times"); TEST(myfutimesat(fds[i], filenames[i], times)); s2e_disable_forking(); s2e_kill_state(0, "program done"); /* check return code */ if (TEST_ERRNO == expected_errno[i]) { /*************************************************************** * only perform functional verification if flag set (-f not given) ***************************************************************/ if (STD_FUNCTIONAL_TEST) { /* No Verification test, yet... */ tst_resm(TPASS, "futimesat() returned the expected errno %d: %s", TEST_ERRNO, strerror(TEST_ERRNO)); } } else { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, "futimesat() Failed, errno=%d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); } } } /*************************************************************** * cleanup and exit ***************************************************************/ cleanup(); return (0); }
int main (void) { char buf[32]; memset (buf, '\0', sizeof (buf) ); char given; char symb; // for non-symbolic: /* char str[3]; memset (str, '\0', 3); printf("Enter two characters: "); if (!fgets(str, sizeof(str), stdin)) return 1; symb = str[0]; given = str[1]; */ // for symbolic: //s2e_disable_all_apic_interrupts(); // make faster given = 'a'; s2e_enable_forking (); // Enable forking on symbolic conditions. s2e_make_symbolic (&(symb), 1 * sizeof (char), "symb"); // saves state // forks to creates a new state with symbolic (random) values for str[0] and str[1] // note, this means it only created and ran 1 set of symbolic value snprintf (buf, sizeof (buf), "Running S2E Tutorial1\n"); /*s2e_get_example (&(symb), 1 * sizeof (char) ); // gets the symbolic values that were used which reached this point snprintf (buf, sizeof (buf), "Running S2E Tutorial1:%02x%02x%c%c:\n", (unsigned char) symb, (unsigned char) given, symb, given);*/ s2e_message (buf); printf ("%s\n", buf); if (symb == '\0') { printf ("No input char\n"); s2e_get_example (&(symb), 1 * sizeof (char) ); // gets the symbolic values that were used which reached this point snprintf (buf, sizeof (buf), "s2e_get_example4:%02x%02x%c%c:\n", (unsigned char) symb, (unsigned char) given, symb, given); s2e_warning (buf); printf ("%s\n", buf); } else { s2e_get_example (&(symb), 1 * sizeof (char) ); // gets the symbolic values that were used which reached this point snprintf (buf, sizeof (buf), "s2e_get_example1:%02x%02x%c%c:\n", (unsigned char) symb, (unsigned char) given, symb, given); s2e_warning (buf); printf ("%s\n", buf); if (symb == given) { //s2e_warning ("symb equals 1\n"); printf ("Chars are the same: %c == %c\n", symb, given); s2e_get_example (&(symb), 1 * sizeof (char) ); // gets the symbolic values that were used which reached this point snprintf (buf, sizeof (buf), "s2e_get_example2:%02x%02x%c%c:\n", (unsigned char) symb, (unsigned char) given, symb, given); s2e_warning (buf); printf ("%s\n", buf); } } //s2e_disable_forking (); s2e_get_example (&(symb), 1 * sizeof (char) ); // gets the symbolic values that were used which reached this point snprintf (buf, sizeof (buf), "s2e_get_example3:%02x%02x%c%c:\n", (unsigned char) symb, (unsigned char) given, symb, given); s2e_warning (buf); printf ("%s\n", buf); s2e_kill_state (0, "program terminated"); return 0; }
static void handle_interesting_function(const char *fn, int line, enum symdrive_WRAPPER_TYPE wrapper_type, int retval_valid, unsigned long retval, const char *interesting_fn, enum symdrive_DIRECTION direction) { #if 0 if (interesting_fn[0] == 0) { return; } tfassert_detail(line >= 0 && line < MAX_INTERESTING_LINES, "File too large -- interesting function at line %d\n", line); interesting_function_lines[line]++; if (interesting_function_lines[line] > MAX_INTERESTING_PER_LINE && interesting_function_started == 0) { //uprintk ("Interesting function: %s:%d. Skipping, count too high: %d\n", // fn, line, interesting_function_lines[line]); return; } if (direction == ENTRANCE) { if (wrapper_type == PREPOSTFN) { // Precondition for interesting driver fn if (interesting_function_started == 0) { interesting_function_started++; tfassert_detail (interesting_function_success >= 0, "Failed %s: %s:%d\n", __func__, fn, line); } else if (interesting_function_started >= 1) { uprintk ("Interesting function: unconditional prioritize %s:%d\n", fn, line); s2e_prioritize (0); interesting_function_started++; } else { tfassert_detail (0, "Failed %s: %s:%d\n", __func__, fn, line); } } else if (wrapper_type == STUBWRAPPER) { // Precondition for kernel function if (interesting_function_started == 0) { // // This should never happen because if it does, it means that we're calling // an interesting kernel function but we've not already started the // corresponding interesting driver function. All interesting // kernel functions that are called must have a corresponding driver // function. // tfassert_detail (0, "Bug in test framework or static analysis\n"); } else if (interesting_function_started >= 1) { if (strcmp (fn, interesting_fn) == 0) { uprintk ("Interesting function: Unconditional prioritize -- kernel fn called %s:%d\n", fn, line); interesting_function_success++; s2e_prioritize (0); } else { uprintk ("Interesting function: Not prioritizing -- kernel fn called %s:%d expecting %s\n", fn, line, interesting_fn); } } else { tfassert_detail (0, "Failed %s: %s:%d\n", __func__, fn, line); } } else { tfassert_detail (0, "Failed %s: %s:%d\n", __func__, fn, line); } } else if (direction == EXIT) { if (wrapper_type == PREPOSTFN) { // Postcondition for interesting driver fn if (interesting_function_started == 0) { tfassert_detail (0, "Failed %s: %s:%d\n", __func__, fn, line); } else if (interesting_function_started >= 1) { if (interesting_function_success == 0) { char temp[128]; sprintf (temp, "Interesting function: %s:%d failed to complete successfully.", fn, line); s2e_kill_state(1, 0, temp); } else if (interesting_function_success >= 1) { s2e_prioritize(0); interesting_function_started--; if (interesting_function_started == 0) { uprintk ("Interesting function: Complete success, success at %d. %s:%d. Prioritized\n", interesting_function_success, fn, line); interesting_function_success--; } else if (interesting_function_started >= 1) { uprintk ("Interesting function: Success. %s:%d. Prioritize\n", fn, line); } else { tfassert_detail (0, "Failed %s: %s:%d\n", __func__, fn, line); } } else { tfassert_detail (0, "Failed %s: %s:%d\n", __func__, fn, line); } } else { tfassert_detail (0, "Failed %s: %s:%d\n", __func__, fn, line); } } else if (wrapper_type == STUBWRAPPER) { // Postcondition for interesting kernel fn. // No need to do anything here -- all logic is in the precondition, above } else { tfassert_detail (0, "Failed %s: %s:%d\n", __func__, fn, line); } } else { tfassert_detail (0, "Failed %s: %s:%d\n", __func__, fn, line); } #endif }