Example #1
0
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");
}
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();

}
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();

}
Example #4
0
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(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(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(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;
	*/
}
Example #10
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();
}
Example #12
0
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;
}
Example #13
0
int gen_make_symbolic_int (const char *fn, int line, void *int_retval, int int_retval_size) {
    unsigned char orig_retval_unsigned_char = 0;
    unsigned short orig_retval_unsigned_short = 0;
    unsigned int orig_retval_unsigned_int = 0;
    unsigned long long orig_retval_unsigned_long_long = 0;

    // We'll assume the code generator includes the check.
    // If you change this assumption, change gen_make_symbolic_ptr too.
    // assert (g_sym_retval != 0, "Fix the code generator.");
    if (g_sym_retval == 0) {
        return g_sym_retval;
    }

    acquire_global_lock();
    assert (int_retval_size == sizeof(unsigned char) ||
            int_retval_size == sizeof(unsigned short) ||
            int_retval_size == sizeof(unsigned int) ||
            int_retval_size == sizeof(unsigned long long),
            "Invalid size specified in %s.  Size %d",
            __func__, int_retval_size);

    assert (sizeof(unsigned char) == 1 &&
            sizeof(unsigned short) == 2 && 
            sizeof(unsigned int) == 4 &&
            sizeof(unsigned long long) == 8,
            "Wrong size for primitive type");
    
    MAKE_SYMBOLIC_INIT(unsigned char, unsigned_char);
    MAKE_SYMBOLIC_INIT(unsigned short, unsigned_short);
    MAKE_SYMBOLIC_INIT(unsigned int, unsigned_int);
    MAKE_SYMBOLIC_INIT(unsigned long long, unsigned_long_long);
    s2e_make_symbolic (int_retval, int_retval_size, "symbolic_retval_int");
    MAKE_SYMBOLIC_INT_HELPER(unsigned char, unsigned_char);
    MAKE_SYMBOLIC_INT_HELPER(unsigned short, unsigned_short);
    MAKE_SYMBOLIC_INT_HELPER(unsigned int, unsigned_int);
    MAKE_SYMBOLIC_INT_HELPER(unsigned long long, unsigned_long_long);
    release_global_lock();

    return g_sym_retval;
}
Example #14
0
static void handler_symbwrite(const char **args)
{
    int n_bytes = -1;
    int i;

    n_bytes = atoi(args[0]);
    if (n_bytes < 0) {
        fprintf(stderr, "number of bytes may not be negative\n");
        return;
    } else if (n_bytes == 0) {
        return;
    }

    char *buffer = calloc(1, n_bytes + 1);
    s2e_make_symbolic(buffer, n_bytes, "buffer");

    for (i = 0; i < n_bytes; ++i) {
        putchar(buffer[i]);
    }

    free(buffer);

    return;
}
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(&times[0], NULL);
			gettimeofday(&times[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);
}
Example #16
0
static char *__get_sym_str(int numChars, char *name) {
    char *s = malloc(numChars+1);
    s2e_make_symbolic(s, numChars, name);
    s[numChars] = '\0';
    return s;
}
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();

}
Example #18
0
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;
}
Example #23
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;
}