Example #1
0
/*
 * setup() - performs all ONE TIME setup for this test.
 *
 * Get system page size.
 * Set the old address point some high address which is not mapped.
 */
void setup(void)
{
	int page_sz;		/* system page size */

	tst_sig(FORK, DEF_HANDLER, cleanup);

	TEST_PAUSE;

	/* Get the system page size */
	if ((page_sz = getpagesize()) < 0) {
		tst_brkm(TFAIL, NULL,
			 "getpagesize() fails to get system page size");
	}

	/* Get the size of virtual memory area to be mapped */
	memsize = (1000 * page_sz);

	/* Get the New size of virtual memory block after resize */
	newsize = (memsize * 2);

	/*
	 * Set the old virtual address point to some address
	 * which is not mapped.
	 */
	addr = (char *)get_high_address();
}
Example #2
0
int main(int ac, char **av)
{
	int lc;			/* loop counter */
	char *msg;		/* message returned from parse_opts */
	char *file_name;	/* name of the testfile */
	int access_mode;	/* specified access mode for testfile */
	int i;

	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++) {
			file_name = test_cases[i].pathname;
			access_mode = test_cases[i].a_mode;

#if !defined(UCLINUX)
			if (file_name == high_address_node)
				file_name = get_high_address();
#endif

			/*
			 * Call access(2) to test different test conditions.
			 * verify that it fails with -1 return value and
			 * sets appropriate errno.
			 */
			TEST(access(file_name, access_mode));

			if (TEST_RETURN != -1) {
				tst_resm(TFAIL,
				    "access(%s, %#o) succeeded unexpectedly",
				    file_name, access_mode);
				continue;
			}

			if (TEST_ERRNO == test_cases[i].exp_errno)
				tst_resm(TPASS|TTERRNO,
				    "access failed as expected");
			else
				tst_resm(TFAIL|TTERRNO,
				    "access failed unexpectedly; expected: "
				    "%d - %s",
				    test_cases[i].exp_errno,
				    strerror(test_cases[i].exp_errno));
		}
	}

	cleanup();

	tst_exit();

}
Example #3
0
int main(int ac, char **av)
{
	int lc;
	char *msg;
	char *file_name;
	int i;
	uid_t user_id;
	gid_t group_id;

	msg = parse_opts(ac, av, options, help);
	if (msg != NULL)
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
	if (!dflag) {
		tst_brkm(TBROK, NULL, "you must specify the device used for "
			 "mounting with -D option");
	}

	setup();

	TEST_EXP_ENOS(exp_enos);

	user_id = geteuid();
	group_id = getegid();

	for (lc = 0; TEST_LOOPING(lc); lc++) {

		tst_count = 0;

		for (i = 0; i < TST_TOTAL; i++) {
			file_name = test_cases[i].pathname;

			if (file_name == high_address_node)
				file_name = get_high_address();

			TEST(chown(file_name, user_id, group_id));

			if (TEST_RETURN == 0) {
				tst_resm(TFAIL, "chown succeeded unexpectedly");
				continue;
			} else if (TEST_ERRNO == test_cases[i].exp_errno)
				tst_resm(TPASS | TTERRNO, "chown failed");
			else {
				tst_resm(TFAIL | TTERRNO,
					 "chown failed; expected: %d - %s",
					 test_cases[i].exp_errno,
					 strerror(test_cases[i].exp_errno));
			}
		}
	}

	cleanup();
	tst_exit();

}
Example #4
0
File: access05.c Project: disdi/ltp
static void setup(void)
{
	int fd;

	tst_sig(NOFORK, DEF_HANDLER, cleanup);
	tst_require_root(NULL);

	ltpuser = SAFE_GETPWNAM(cleanup, nobody_uid);
	SAFE_SETUID(cleanup, ltpuser->pw_uid);
	TEST_PAUSE;

#if !defined(UCLINUX)
	bad_addr = mmap(0, 1, PROT_NONE,
			MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
	if (bad_addr == MAP_FAILED)
		tst_brkm(TBROK | TERRNO, NULL, "mmap failed");
	test_cases[4].pathname = bad_addr;

	test_cases[5].pathname = get_high_address();
#endif

	tst_tmpdir();

	/*
	 * create TEST_FILE1 to test R_OK EACCESS
	 */
	fd = SAFE_CREAT(cleanup, TEST_FILE1, 0333);
	SAFE_CLOSE(cleanup, fd);

	/*
	 * create TEST_FILE2 to test W_OK EACCESS
	 */
	fd = SAFE_CREAT(cleanup, TEST_FILE2, 0555);
	SAFE_CLOSE(cleanup, fd);

	/*
	 * create TEST_FILE3 to test X_OK EACCESS
	 */
	fd = SAFE_CREAT(cleanup, TEST_FILE3, 0666);
	SAFE_CLOSE(cleanup, fd);

	/*
	 * create TEST_FILE4 to test EINVAL
	 */
	fd = SAFE_CREAT(cleanup, TEST_FILE4, 0333);
	SAFE_CLOSE(cleanup, fd);

	/*
	 *setup to create a node with a name length exceeding
	 *the MAX length of PATH_MAX.
	 */
	memset(longpathname, 'a', sizeof(longpathname) - 1);
}
Example #5
0
void setup(void)
{
	struct passwd *ltpuser;
	char *bad_addr;
	struct rlimit rlim;
	sigset_t signalset;

	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	tst_require_root();

	ltpuser = SAFE_GETPWNAM(cleanup, "nobody");
	SAFE_SETEUID(cleanup, ltpuser->pw_uid);

	TEST_PAUSE;

	tst_tmpdir();

	SAFE_TOUCH(cleanup, TEST_FILE1, NEW_MODE, NULL);

	SAFE_TOUCH(cleanup, "t_file", FILE_MODE, NULL);

#if !defined(UCLINUX)
	test_cases[2].pathname = (char *)get_high_address();

	bad_addr = SAFE_MMAP(cleanup, 0, 1, PROT_NONE,
			MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
	test_cases[3].pathname = bad_addr;
#endif

	memset(long_pathname, 'a', PATH_MAX + 1);

	SAFE_MKDIR(cleanup, TEST_DIR1, DIR_MODE);

	SAFE_TOUCH(cleanup, TEST_FILE3, FILE_MODE, NULL);

	SAFE_SYMLINK(cleanup, TEST_SYM1, TEST_SYM2);
	SAFE_SYMLINK(cleanup, TEST_SYM2, TEST_SYM1);

	rlim.rlim_cur = MAX_FSIZE;
	rlim.rlim_max = MAX_FSIZE;
	SAFE_SETRLIMIT(cleanup, RLIMIT_FSIZE, &rlim);

	sigemptyset(&signalset);
	sigaddset(&signalset, SIGXFSZ);
	TEST(sigprocmask(SIG_BLOCK, &signalset, NULL));
	if (TEST_RETURN != 0)
		tst_brkm(TBROK | TTERRNO, cleanup, "sigprocmask");
}
Example #6
0
/******************************************************************
 * high_address_setup() - generates an address that should cause a segfault
 ******************************************************************/
int
high_address_setup()
{
    int ind;

    for (ind=0; Test_cases[ind].desc != NULL; ind++ ) {
	if ( Test_cases[ind].pathname == High_address ) {
	/*if ( strcmp(Test_cases[ind].pathname, HIGH_ADDRESS) == 0 ) { ***/
	    Test_cases[ind].pathname = get_high_address();
	    break;
	}
    }
    return 0;

}
Example #7
0
void setup()
{

	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	TEST_PAUSE;

	low_addr = mmap(0, 1, PROT_NONE,
			MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
	if (low_addr == MAP_FAILED)
		tst_brkm(TBROK | TERRNO, NULL, "mmap failed");
	high_addr = get_high_address();
	if (high_addr == NULL)
		tst_brkm(TBROK | TERRNO, NULL, "get_high_address failed");
	high_addr++;

	tst_tmpdir();
}
Example #8
0
/*
 * void
 * setup() - performs all ONE TIME setup for this test.
 *
 * Get system page size,
 * Set the virtual address points to some high address which is not mapped.
 */
void
setup()
{
    /* capture signals */
    tst_sig(NOFORK, DEF_HANDLER, cleanup);

    /* Pause if that option was specified */
    TEST_PAUSE;

    /* Get the system page size */
    if ((page_sz = getpagesize()) < 0) {
        tst_brkm(TBROK, cleanup,
                 "getpagesize() fails to get system page size");
    }

    /*
     * Set the virtual address point to some high address
     * which is not mapped.
     */
    addr = (char *)get_high_address();
}
Example #9
0
static void setup(void)
{
	size_t nwrite = 0;
	char write_buf[BUF_SIZE];
	struct rlimit rl;

	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	TEST_EXP_ENOS(exp_enos);

	tst_tmpdir();

	TEST_PAUSE;

	page_sz = (size_t)sysconf(_SC_PAGESIZE);

	fd = SAFE_OPEN(cleanup, TEMPFILE, O_RDWR | O_CREAT, 0666);

	memset(write_buf, 'a', BUF_SIZE);
	while (nwrite < page_sz) {
		SAFE_WRITE(cleanup, 1, fd, write_buf, BUF_SIZE);
		nwrite += BUF_SIZE;
	}

	addr1 = SAFE_MMAP(cleanup, 0, page_sz, PROT_READ | PROT_WRITE,
			  MAP_SHARED | MAP_LOCKED, fd, 0);

	/* addr2 is not a multiple of PAGESIZE */
	addr2 = addr1 + 1;

	/* addr3 is outside the address space of the process */
	if (getrlimit(RLIMIT_DATA, &rl) < 0)
		tst_brkm(TBROK | TERRNO, NULL, "getrlimit failed");
	addr3 = (char *)rl.rlim_max;

#if !defined(UCLINUX)
	/* memory pointed to by addr4 was not mapped */
	addr4 = get_high_address();
#endif
}
Example #10
0
void setup(void)
{
	struct passwd *ltpuser;
	char *bad_addr;

	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	tst_require_root(NULL);

	ltpuser = SAFE_GETPWNAM(cleanup, "nobody");
	SAFE_SETEUID(cleanup, ltpuser->pw_uid);

	TEST_PAUSE;

	tst_tmpdir();

	SAFE_TOUCH(cleanup, TEST_FILE1, NEW_MODE, NULL);

	SAFE_TOUCH(cleanup, "t_file", FILE_MODE, NULL);

#if !defined(UCLINUX)
	test_cases[2].pathname = (char *)get_high_address();

	bad_addr = SAFE_MMAP(cleanup, 0, 1, PROT_NONE,
			MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
	test_cases[3].pathname = bad_addr;
#endif

	memset(long_pathname, 'a', PATH_MAX + 1);

	SAFE_MKDIR(cleanup, TEST_DIR1, DIR_MODE);

	SAFE_TOUCH(cleanup, TEST_FILE3, FILE_MODE, NULL);

	SAFE_SYMLINK(cleanup, TEST_SYM1, TEST_SYM2);
	SAFE_SYMLINK(cleanup, TEST_SYM2, TEST_SYM1);
}
Example #11
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();

	/* set the expected errnos... */
	TEST_EXP_ENOS(exp_enos);

	for (lc = 0; TEST_LOOPING(lc); lc++) {

		tst_count = 0;

		/*
		 * TEST CASE: 1
		 * mkdir() call with pointer below allocated address space.
		 */

		/* Call mkdir(2) */
		TEST(mkdir(bad_addr, 0777));

		/* check return code */
		if (TEST_RETURN == -1) {
			TEST_ERROR_LOG(TEST_ERRNO);
		}

		if (STD_FUNCTIONAL_TEST) {
			if (TEST_RETURN == -1) {
				if (TEST_ERRNO == EFAULT) {
					tst_resm(TPASS,
						 "mkdir - path argument pointing below allocated address space failed as expected with errno %d : %s",
						 TEST_ERRNO,
						 strerror(TEST_ERRNO));
				} else {
					tst_resm(TFAIL,
						 "mkdir - path argument pointing below allocated address space failed with errno %d : %s but expected %d (EFAULT)",
						 TEST_ERRNO,
						 strerror(TEST_ERRNO), EFAULT);
				}
			} else {
				tst_resm(TFAIL,
					 "mkdir - path argument pointing below allocated address space succeeded unexpectedly.");

			}
		}
#if !defined(UCLINUX)
		/*
		 * TEST CASE: 2
		 * mkdir() call with pointer above allocated address space.
		 */

		/* Call mkdir(2) */
		TEST(mkdir(get_high_address(), 0777));

		/* check return code */
		if (TEST_RETURN == -1) {
			TEST_ERROR_LOG(TEST_ERRNO);
		}

		if (STD_FUNCTIONAL_TEST) {
			if (TEST_RETURN == -1) {
				if (TEST_ERRNO == EFAULT) {
					tst_resm(TPASS,
						 "mkdir - path argument pointing above allocated address space failed as expected with errno %d : %s",
						 TEST_ERRNO,
						 strerror(TEST_ERRNO));
				} else {
					tst_resm(TFAIL,
						 "mkdir - path argument pointing above allocated address space failed with errno %d : %s but expected %d (EFAULT)",
						 TEST_ERRNO,
						 strerror(TEST_ERRNO), EFAULT);
				}
			} else {
				tst_resm(TFAIL,
					 "mkdir - path argument pointing above allocated address space succeeded unexpectedly.");

			}
		}
#endif /* if !defined(UCLINUX) */

	}

	cleanup();
	tst_exit();

}
Example #12
0
/***********************************************************************
 * Main
 ***********************************************************************/
int main(int ac, char **av)
{
	int lc;
	const char *msg;
	char *fname;
	char *desc;
	int ind;

    /***************************************************************
     * parse standard options
     ***************************************************************/
	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
		tst_exit();
	}

    /***************************************************************
     * 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;

		for (ind = 0; Test_cases[ind].desc != NULL; ind++) {

			fname = Test_cases[ind].pathname;
			desc = Test_cases[ind].desc;

#if !defined(UCLINUX)
			if (fname == High_address)
				fname = get_high_address();
#endif
			/*
			 *  Call unlink(2)
			 */
			TEST(unlink(fname));

			/* check return code */
			if (TEST_RETURN == -1) {
				if (TEST_ERRNO ==
				    Test_cases[ind].exp_errno)
					tst_resm(TPASS,
						 "unlink(<%s>) Failed, errno=%d",
						 desc, TEST_ERRNO);
				else
					tst_resm(TFAIL,
						 "unlink(<%s>) Failed, errno=%d, expected errno:%d",
						 desc, TEST_ERRNO,
						 Test_cases
						 [ind].exp_errno);
			} else {
				tst_resm(TFAIL,
					 "unlink(<%s>) returned %ld, expected -1, errno:%d",
					 desc, TEST_RETURN,
					 Test_cases[ind].exp_errno);
			}
		}

	}

	cleanup();
	tst_exit();
}
Example #13
0
File: mknod06.c Project: 1587/ltp
int main(int ac, char **av)
{
	int lc;
	char *node_name;	/* ptr. for node name created */
	char *test_desc;	/* test specific error message */
	int ind;		/* counter to test different test conditions */

	tst_parse_opts(ac, av, NULL, NULL);

	/*
	 * Invoke setup function to call individual test setup functions
	 * for the test which run as root/super-user.
	 */
	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {

		tst_count = 0;

		for (ind = 0; Test_cases[ind].desc != NULL; ind++) {
			node_name = Test_cases[ind].pathname;
			test_desc = Test_cases[ind].desc;

#if !defined(UCLINUX)
			if (node_name == High_address_node) {
				node_name = get_high_address();
			}
#endif

			/*
			 * Call mknod(2) to test different test conditions.
			 * verify that it fails with -1 return value and
			 * sets appropriate errno.
			 */
			TEST(mknod(node_name, MODE_RWX, 0));

			/* Check return code from mknod(2) */
			if (TEST_RETURN != -1) {
				tst_resm(TFAIL,
					 "mknod() returned %ld, expected "
					 "-1, errno:%d", TEST_RETURN,
					 Test_cases[ind].exp_errno);
				continue;
			}

			if (TEST_ERRNO == Test_cases[ind].exp_errno) {
				tst_resm(TPASS, "mknod() fails, %s, errno:%d",
					 test_desc, TEST_ERRNO);
			} else {
				tst_resm(TFAIL, "mknod() fails, %s, errno:%d, "
					 "expected errno:%d", test_desc,
					 TEST_ERRNO, Test_cases[ind].exp_errno);
			}
		}

	}

	/*
	 * Invoke cleanup() to delete the test directories created
	 * in the setup().
	 */
	cleanup();

	tst_exit();
}
Example #14
0
/***********************************************************************
 * Main
 ***********************************************************************/
int
main(int ac, char **av)
{
    int lc;		/* loop counter */
    const char *msg;		/* message returned from parse_opts */
    char *fname;
    char *desc;
    int ind;
    
    /***************************************************************
     * parse standard options
     ***************************************************************/
    if ( (msg=parse_opts(ac, av, (option_t *)NULL, NULL)) != (char *) NULL ) {
	tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
	tst_exit();
    }


    /***************************************************************
     * 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++) {

	/* reset Tst_count in case we are looping. */
	Tst_count=0;
	

        for (ind=0; Test_cases[ind].desc != NULL; ind++ ) {

	    fname = Test_cases[ind].pathname;
	    desc = Test_cases[ind].desc;

	    if ( fname == High_address )
		fname = get_high_address();
       
            /*
	     *  Call unlink(2)
	     */
	    TEST(unlink(fname));
	
	    /* check return code */
	    if ( TEST_RETURN == -1 ) {
	        if ( STD_FUNCTIONAL_TEST ) {
		    if ( TEST_ERRNO == Test_cases[ind].exp_errno )
	                tst_resm(TPASS, "unlink(<%s>) Failed, errno=%d",
			    desc, TEST_ERRNO);
		    else
			tst_resm(TFAIL,
			    "unlink(<%s>) Failed, errno=%d, expected errno:%d",
                            desc, TEST_ERRNO, Test_cases[ind].exp_errno);
	        }
		else
		   Tst_count++;
	    } else  {
	        tst_resm(TFAIL,
		    "unlink(<%s>) returned %d, expected -1, errno:%d",
		    desc, TEST_RETURN, Test_cases[ind].exp_errno);
	    }
	}
	
    }	/* End for TEST_LOOPING */

    /***************************************************************
     * cleanup and exit
     ***************************************************************/
    cleanup();

    return 0;
}	/* End main */
Example #15
0
File: lchown02.c Project: 1587/ltp
/*
 * setup_efault() -- setup for a test condition where lchown(2) returns -1 and
 *                   sets errno to EFAULT.
 *
 * Use ltp function get_high_address() to compute high address.
 */
static void setup_highaddress(int pos)
{
	test_cases[pos].pathname = get_high_address();
}
Example #16
0
int
main(int ac, char **av)
{
    int lc;		/* loop counter */
    const char *msg;		/* message returned from parse_opts */
    

    /***************************************************************
     * parse standard options
     ***************************************************************/
    if ( (msg=parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *) NULL )
	tst_brkm(TBROK, cleanup, "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++) {

	/* reset Tst_count in case we are looping. */
	Tst_count=0;

	/* 
	 * TEST CASE: 1
	 * mkdir() call with pointer below allocated address space.
	 */

	/* Call mkdir(2) */
	TEST(mkdir((char *)-1,0777));
	
	/* check return code */
	if ( TEST_RETURN == -1 ) {
	    TEST_ERROR_LOG(TEST_ERRNO);
	}

	/***************************************************************
	 * only perform functional verification if flag set (-f not given)
	 ***************************************************************/
	if ( STD_FUNCTIONAL_TEST ) {
	  if ( TEST_RETURN == -1 ) {
	    if (TEST_ERRNO == EFAULT) {
	      tst_resm(TPASS, "mkdir - path argument pointing below allocated address space failed as expected with errno %d : %s", TEST_ERRNO, strerror(TEST_ERRNO));
	    }
	    else {
	      tst_resm(TFAIL, "mkdir - path argument pointing below allocated address space failed with errno %d : %s but expected %d (EFAULT)", TEST_ERRNO, strerror(TEST_ERRNO),EFAULT);
	    }
	  }
	  else {
	    tst_resm(TFAIL, "mkdir - path argument pointing below allocated address space succeeded unexpectedly.");

	  }
	} 
	

	/* 
	 * TEST CASE: 2
	 * mkdir() call with pointer above allocated address space.
	 */

	/* Call mkdir(2) */
	TEST(mkdir(get_high_address(),0777));
	
	/* check return code */
	if ( TEST_RETURN == -1 ) {
	    TEST_ERROR_LOG(TEST_ERRNO);
	}

	/***************************************************************
	 * only perform functional verification if flag set (-f not given)
	 ***************************************************************/
	if ( STD_FUNCTIONAL_TEST ) {
	  if ( TEST_RETURN == -1 ) {
	    if (TEST_ERRNO == EFAULT) {
	      tst_resm(TPASS, "mkdir - path argument pointing above allocated address space failed as expected with errno %d : %s", TEST_ERRNO, strerror(TEST_ERRNO));
	    }
	    else {
	      tst_resm(TFAIL, "mkdir - path argument pointing above allocated address space failed with errno %d : %s but expected %d (EFAULT)", TEST_ERRNO, strerror(TEST_ERRNO),EFAULT);
	    }
	  }
	  else {
	    tst_resm(TFAIL, "mkdir - path argument pointing above allocated address space succeeded unexpectedly.");

	  }
	} 

    }	/* End for TEST_LOOPING */

    /***************************************************************
     * cleanup and exit
     ***************************************************************/
    cleanup();

    return 0;
}	/* End main */
Example #17
0
int main(int ac, char **av)
{
	int lc;			/* loop counter */
	char *msg;		/* message returned from parse_opts */
	char *node_name;	/* ptr. for node name created */
	char *test_desc;	/* test specific error message */
	int ind;		/* counter to test different test conditions */

	/* Parse standard options given to run the test. */
	msg = parse_opts(ac, av, (option_t *) NULL, NULL);
	if (msg != (char *)NULL) {
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
		tst_exit();
	}

	/*
	 * Invoke setup function to call individual test setup functions
	 * for the test which run as root/super-user.
	 */
	setup();

	/* set the expected errnos... */
	TEST_EXP_ENOS(exp_enos);

	/* Check looping state if -i option given */
	for (lc = 0; TEST_LOOPING(lc); lc++) {
		/* Reset Tst_count in case we are looping. */
		Tst_count = 0;

		for (ind = 0; Test_cases[ind].desc != NULL; ind++) {
			node_name = Test_cases[ind].pathname;
			test_desc = Test_cases[ind].desc;

#if !defined(UCLINUX)
			if (node_name == High_address_node) {
				node_name = get_high_address();
			}
#endif

			/*
			 * Call mknod(2) to test different test conditions.
			 * verify that it fails with -1 return value and
			 * sets appropriate errno.
			 */
			TEST(mknod(node_name, MODE_RWX, 0));

			/* Check return code from mknod(2) */
			if (TEST_RETURN != -1) {
				tst_resm(TFAIL, "mknod() returned %ld, expected "
					 "-1, errno:%d", TEST_RETURN,
					 Test_cases[ind].exp_errno);
				continue;
			}

			TEST_ERROR_LOG(TEST_ERRNO);

			if (TEST_ERRNO == Test_cases[ind].exp_errno) {
				tst_resm(TPASS, "mknod() fails, %s, errno:%d",
					 test_desc, TEST_ERRNO);
			} else {
				tst_resm(TFAIL, "mknod() fails, %s, errno:%d, "
					 "expected errno:%d", test_desc,
					 TEST_ERRNO, Test_cases[ind].exp_errno);
			}
		}		/* End of TEST CASE LOOPING. */

	}			/* End for TEST_LOOPING */

	/*
	 * Invoke cleanup() to delete the test directories created
	 * in the setup().
	 */
	cleanup();

	 /*NOTREACHED*/ return 0;
}				/* End main */
Example #18
0
int main(int ac, char **av)
{
	int lc;
	char *msg;
	char *test_file;	/* testfile name */
	char *sym_file;		/* symbolic link file name */
	char *test_desc;	/* test specific error message */
	int ind;		/* counter to test different test conditions */

	/* Parse standard options given to run the test. */
	msg = parse_opts(ac, av, NULL, NULL);
	if (msg != NULL) {
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);

	 }

	/*
	 * Invoke setup function to call individual test setup functions
	 * to simulate test conditions.
	 */
	setup();

	/* set the expected errnos... */
	TEST_EXP_ENOS(exp_enos);

	for (lc = 0; TEST_LOOPING(lc); lc++) {

		Tst_count = 0;

		for (ind = 0; Test_cases[ind].desc != NULL; ind++) {
			test_file = Test_cases[ind].file;
			sym_file = Test_cases[ind].link;
			test_desc = Test_cases[ind].desc;
#if !defined(UCLINUX)
			if (sym_file == High_address_node) {
				sym_file = (char *)get_high_address();
			}
#endif
			/*
			 * Call symlink(2) to test different test conditions.
			 * verify that it fails with -1 return value and sets
			 * appropriate errno.
			 */
			TEST(symlink(test_file, sym_file));

			if (TEST_RETURN == -1) {
				/*
				 * Perform functional verification if
				 * test executed without (-f) option.
				 */
				TEST_ERROR_LOG(TEST_ERRNO);
				if (TEST_ERRNO == Test_cases[ind].exp_errno) {
					tst_resm(TPASS, "symlink() Fails, %s, "
						 "errno=%d", test_desc,
						 TEST_ERRNO);
				} else {
					tst_resm(TFAIL, "symlink() Fails, %s, "
						 "errno=%d, expected errno=%d",
						 test_desc, TEST_ERRNO,
						 Test_cases[ind].exp_errno);
				}
			} else {
				tst_resm(TFAIL, "symlink() returned %ld, "
					 "expected -1, errno:%d", TEST_RETURN,
					 Test_cases[ind].exp_errno);
			}
		}

		Tst_count++;	/* incr. TEST_LOOP counter */
	}

	cleanup();
	tst_exit();

}
Example #19
0
/***********************************************************************
 * Main
 ***********************************************************************/
int main(int ac, char **av)
{
	int lc;			/* loop counter */
	char *msg;		/* message returned from parse_opts */
	char *fname1, *fname2;
	char *desc1, *desc2;
	int ind;

    /***************************************************************
     * parse standard options
     ***************************************************************/
	if ((msg = parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *)NULL) {
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
		tst_exit();
	}

    /***************************************************************
     * perform global setup for test
     ***************************************************************/
	setup();

    /***************************************************************
     * check looping state if -c option given
     ***************************************************************/
	for (lc = 0; TEST_LOOPING(lc); lc++) {

		/* reset Tst_count in case we are looping. */
		Tst_count = 0;

		for (ind = 0; Test_cases[ind].desc1 != NULL; ind++) {

			fname1 = Test_cases[ind].file1;
			desc1 = Test_cases[ind].desc1;
			fname2 = Test_cases[ind].file2;
			desc2 = Test_cases[ind].desc2;

#if !defined(UCLINUX)
			if (fname1 == High_address)
				fname1 = get_high_address();

			if (fname2 == High_address)
				fname2 = get_high_address();
#endif

			/*
			 *  Call link(2)
			 */
			TEST(link(fname1, fname2));

			/* check return code */
			if (TEST_RETURN == -1) {
				if (STD_FUNCTIONAL_TEST) {
					if (TEST_ERRNO ==
					    Test_cases[ind].exp_errno)
						tst_resm(TPASS,
							 "link(<%s>, <%s>) Failed, errno=%d",
							 desc1, desc2,
							 TEST_ERRNO);
					else
						tst_resm(TFAIL,
							 "link(<%s>, <%s>) Failed, errno=%d, expected errno:%d",
							 desc1, desc2,
							 TEST_ERRNO,
							 Test_cases[ind].
							 exp_errno);
				} else
					Tst_count++;
			} else {
				tst_resm(TFAIL,
					 "link(<%s>, <%s>) returned %ld, expected -1, errno:%d",
					 desc1, desc2, TEST_RETURN,
					 Test_cases[ind].exp_errno);
			}
		}

	}			/* End for TEST_LOOPING */

    /***************************************************************
     * cleanup and exit
     ***************************************************************/
	cleanup();

	return 0;
}				/* End main */
Example #20
0
int main(int ac, char **av)
{
	int lc;
	char *msg;
	char *file_name;
	int i;
	mode_t mode;
	char nobody_uid[] = "nobody";
	struct passwd *ltpuser;

	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++) {

			file_name = test_cases[i].pathname;
			mode = test_cases[i].mode;

			if (file_name == High_address_node)
				file_name = get_high_address();
			if (i < 2) {
				ltpuser = getpwnam(nobody_uid);
				if (ltpuser == NULL)
					tst_brkm(TBROK|TERRNO, cleanup,
					    "getpwnam failed");
				if (seteuid(ltpuser->pw_uid) == -1)
					tst_brkm(TBROK|TERRNO, cleanup,
					    "seteuid failed");
			}
			if (i >= 2)
				seteuid(0);

			TEST(chmod(file_name, mode));

			if (TEST_RETURN != -1) {
				tst_resm(TFAIL, "chmod succeeded unexpectedly");
				continue;
			}

			TEST_ERROR_LOG(TEST_ERRNO);
			if (TEST_ERRNO == test_cases[i].exp_errno)
				tst_resm(TPASS|TTERRNO,
				    "chmod failed as expected");
			else
				tst_resm(TFAIL|TTERRNO,
				    "chmod failed unexpectedly; "
				    "expected %d - %s",
				    test_cases[i].exp_errno,
				    strerror(test_cases[i].exp_errno));
		}

	}

	cleanup();
	tst_exit();

}
Example #21
0
int main(int ac, char **av)
{
	int lc;			/* loop counter */
	char *msg;		/* message returned from parse_opts */
	char *file_name;	/* ptr. for file name whose mode is modified */
	char *test_desc;	/* test specific error message */
	int ind;		/* counter to test different test conditions */
	uid_t User_id;		/* Effective user id of a test process */
	gid_t Group_id;		/* Effective group id of a test process */

	/* Parse standard options given to run the test. */
	msg = parse_opts(ac, av, (option_t *) NULL, NULL);
	if (msg != (char *)NULL) {
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
		tst_exit();
	}

	/*
	 * Invoke setup function to call individual test setup functions
	 * to simulate test conditions.
	 */
	setup();

	/* set the expected errnos... */
	TEST_EXP_ENOS(exp_enos);

	/* Set uid/gid values to that of test process */
	User_id = geteuid();
	Group_id = getegid();

	/* Check looping state if -i option given */
	for (lc = 0; TEST_LOOPING(lc); lc++) {
		/* Reset Tst_count in case we are looping. */
		Tst_count = 0;

		for (ind = 0; Test_cases[ind].desc != NULL; ind++) {
			file_name = Test_cases[ind].pathname;
			test_desc = Test_cases[ind].desc;

			if (file_name == High_address_node) {
				file_name = (char *)get_high_address();
			}

			/*
			 * Call lchown(2) to test different test conditions.
			 * verify that it fails with -1 return value and
			 * sets appropriate errno.
			 */
			TEST(lchown(file_name, User_id, Group_id));

			/* Check return code from lchown(2) */
			if (TEST_RETURN == -1) {
				TEST_ERROR_LOG(TEST_ERRNO);
				if (TEST_ERRNO == Test_cases[ind].exp_errno) {
					tst_resm(TPASS,
						 "lchown() fails, %s, errno:%d",
						 test_desc, TEST_ERRNO);
				} else {
					tst_resm(TFAIL, "lchown() fails, %s, "
						 "errno:%d, expected errno:%d",
						 test_desc, TEST_ERRNO,
						 Test_cases[ind].exp_errno);
				}
			} else {
				tst_resm(TFAIL, "lchown() returned %ld, "
					 "expected -1, errno:%d", TEST_RETURN,
					 Test_cases[ind].exp_errno);
			}
		}		/* End of TEST CASE LOOPING. */
	}			/* End for TEST_LOOPING */

	/*
	 * Invoke cleanup() to delete the test directory/file(s) created
	 * in the setup().
	 */
	cleanup();

	 /*NOTREACHED*/ return 0;
}				/* End main */
Example #22
0
int main(int argc, char **argv)
{
	int lc;
	char *msg;

    /***************************************************************
     * parse standard options
     ***************************************************************/
	if ((msg = parse_opts(argc, argv, 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++) {

		tst_count = 0;

		/*
		 * TEST CASE: 1
		 * path points to the current directory
		 */

		/* Call rmdir(2) */
		TEST(rmdir("."));

		/* check return code */
		if (TEST_RETURN == -1) {
			TEST_ERROR_LOG(TEST_ERRNO);
		}

	/***************************************************************
	 * only perform functional verification if flag set (-f not given)
	 ***************************************************************/
		if (STD_FUNCTIONAL_TEST) {

			if (TEST_RETURN == -1) {
#if defined(sgi)
				if (TEST_ERRNO == EINVAL) {
#elif defined(linux)
				if (TEST_ERRNO & (EBUSY | ENOTEMPTY)) {
#endif

					/* For functionality tests, verify that the
					 * directory wasn't removed.
					 */
					if (stat(".", &stat_buf) == -1) {
						tst_resm(TFAIL,
							 "rmdir(\".\") removed the current working directory when it should have failed.");
					} else {
						tst_resm(TPASS,
							 "rmdir(\".\") failed to remove the current working directory. Returned %d : %s",
							 TEST_ERRNO,
							 strerror(TEST_ERRNO));
					}
				} else {
#if defined(sgi)
					tst_resm(TFAIL,
						 "rmdir(\".\") failed with errno %d : %s but expected %d (EINVAL)",
						 TEST_ERRNO,
						 strerror(TEST_ERRNO), EINVAL);
#elif defined(linux)
					tst_resm(TFAIL,
						 "rmdir(\".\") failed with errno %d : %s but expected %d (EBUSY)",
						 TEST_ERRNO,
						 strerror(TEST_ERRNO), EBUSY);
#endif
				}
			} else {
				tst_resm(TFAIL,
					 "rmdir(\".\") succeeded unexpectedly.");
			}
		}

		/*
		 * TEST CASE: 2
		 * path points to the "." (dot) entry of a directory
		 */
#if defined(linux)
		tst_resm(TCONF, "rmdir on \"dir/.\" supported on Linux");
#elif defined(sgi)
		/* Call rmdir(2) */
		TEST(rmdir("dir1/."));

		/* check return code */
		if (TEST_RETURN == -1) {
			TEST_ERROR_LOG(TEST_ERRNO);
		}

	/***************************************************************
	 * only perform functional verification if flag set (-f not given)
	 ***************************************************************/
		if (STD_FUNCTIONAL_TEST) {

			if (TEST_RETURN == -1) {
				if (TEST_ERRNO == EINVAL) {

					/* For functionality tests, verify that the
					 * directory wasn't removed.
					 */
					if (stat("dir1/.", &stat_buf) == -1) {
						tst_resm(TFAIL,
							 "rmdir(\"dir1/.\") removed the \".\" entry of a directory when it should have failed.");
					} else {
						tst_resm(TPASS,
							 "rmdir(\"dir1/.\") failed to remove the \".\" entry of a directory. Returned %d : %s",
							 TEST_ERRNO,
							 strerror(TEST_ERRNO));
					}
				} else {
					tst_resm(TFAIL,
						 "rmdir(\"dir1/.\") failed with errno %d : %s but expected %d (EINVAL)",
						 TEST_ERRNO,
						 strerror(TEST_ERRNO), EINVAL);
				}
			} else {
				tst_resm(TFAIL,
					 "rmdir(\"dir1/.\") - path points to the \".\" entry of a directory succeeded unexpectedly.");
			}
		}
#endif

#if defined(sgi)
		/*
		 * TEST CASE: 3
		 * the directory has been linked
		 */
		tst_resm(TCONF, "linked directories not valid on IRIX");
#elif defined(linux)
		tst_resm(TCONF,
			 "linked directories test not implemented on Linux");
#elif defined(CRAY)

		/* Call rmdir(2) */
		TEST(rmdir("dir2"));

		/* check return code */
		if (TEST_RETURN == -1) {
			TEST_ERROR_LOG(TEST_ERRNO);
		}

	/***************************************************************
	 * only perform functional verification if flag set (-f not given)
	 ***************************************************************/
		if (STD_FUNCTIONAL_TEST) {

			if (TEST_RETURN == -1) {
				if (TEST_ERRNO == EMLINK) {
					/* For functionality tests, verify that the directory wasn't
					 * removed.
					 */
					if (stat("dir2", &stat_buf) == -1) {
						tst_resm(TFAIL,
							 "rmdir(\"dir2\") removed a directory with multiple links when it should have failed.");
					} else {
						tst_resm(TPASS,
							 "rmdir(\"dir2\") failed to remove a directory with multiple links. Returned %d : %s",
							 TEST_ERRNO,
							 strerror(TEST_ERRNO));
					}
				} else {
					tst_resm(TFAIL,
						 "rmdir(\"dir2\") failed with errno %d : %s but expected %d (EMLINK)",
						 TEST_ERRNO,
						 strerror(TEST_ERRNO), EMLINK);
				}
			} else {
				tst_resm(TFAIL,
					 "rmdir(\"dir2\") - the directory has been linked succeeded unexpectedly.");
			}
		}
#endif /* linux */

		/*
		 * TEST CASE: 4
		 * path argument points below the minimum allocated address space
		 */

#if !defined(UCLINUX)
		/* Call rmdir(2) */
		TEST(rmdir(bad_addr));

		/* check return code */
		if (TEST_RETURN == -1) {
			TEST_ERROR_LOG(TEST_ERRNO);
		}

	/***************************************************************
	 * only perform functional verification if flag set (-f not given)
	 ***************************************************************/
		if (STD_FUNCTIONAL_TEST) {

			if (TEST_RETURN == -1) {
				if (TEST_ERRNO == EFAULT) {
					tst_resm(TPASS,
						 "rmdir() - path argument points below the minimum allocated address space failed as expected with errno %d : %s",
						 TEST_ERRNO,
						 strerror(TEST_ERRNO));
				} else {
					tst_resm(TFAIL,
						 "rmdir() - path argument points below the minimum allocated address space failed with errno %d : %s but expected %d (EFAULT)",
						 TEST_ERRNO,
						 strerror(TEST_ERRNO), EFAULT);
				}
			} else {
				tst_resm(TFAIL,
					 "rmdir() - path argument points below the minimum allocated address space succeeded unexpectedly.");
			}
		}

		/*
		 * TEST CASE: 5
		 * path argument points above the maximum allocated address space
		 */

		/* Call rmdir(2) */
		TEST(rmdir(get_high_address()));

		/* check return code */
		if (TEST_RETURN == -1) {
			TEST_ERROR_LOG(TEST_ERRNO);
		}

	/***************************************************************
	 * only perform functional verification if flag set (-f not given)
	 ***************************************************************/
		if (STD_FUNCTIONAL_TEST) {

			if (TEST_RETURN == -1) {
				if (TEST_ERRNO == EFAULT) {
					tst_resm(TPASS,
						 "rmdir() - path argument points above the maximum allocated address space failed as expected with errno %d : %s",
						 TEST_ERRNO,
						 strerror(TEST_ERRNO));
				} else {
					tst_resm(TFAIL,
						 "rmdir() - path argument points above the maximum allocated address space failed with errno %d : %s but expected %d (EFAULT)",
						 TEST_ERRNO,
						 strerror(TEST_ERRNO), EFAULT);
				}
			} else {
				tst_resm(TFAIL,
					 "rmdir() - path argument points above the maximum allocated address space succeeded unexpectedly.");
			}
		}
#endif

		/*
		 * TEST CASE: 6
		 * able to remove a directory
		 */

		/* Create a directory. */
		if (mkdir(dir_name, 0777) != 0) {
			tst_brkm(TBROK, cleanup,
				 "mkdir(\"%s\") failed with errno %d : %s",
				 dir_name, errno, strerror(errno));
		}

		/* Call rmdir(2) */
		TEST(rmdir(dir_name));

		/* check return code */
		if (TEST_RETURN == -1) {
			TEST_ERROR_LOG(TEST_ERRNO);
			tst_resm(TFAIL,
				 "rmdir(\"%s\") failed when it should have passed. Returned %d : %s",
				 dir_name, TEST_ERRNO, strerror(TEST_ERRNO));
		} else {

	  /***************************************************************
	   * only perform functional verification if flag set (-f not given)
	   ***************************************************************/
			if (STD_FUNCTIONAL_TEST) {

				/* Verify the directory was removed. */
				if (stat(dir_name, &stat_buf) != 0) {
					tst_resm(TPASS,
						 "rmdir(\"%s\") removed the directory as expected.",
						 dir_name);
				} else {
					tst_resm(TFAIL,
						 "rmdir(\"%s\") returned a zero exit status but failed to remove the directory.",
						 dir_name);
				}
			}
		}

	}

    /***************************************************************
     * cleanup and exit
     ***************************************************************/
	cleanup();
	tst_exit();

}

/***************************************************************
 * setup() - performs all ONE TIME setup for this test.
 ***************************************************************/
void setup(void)
{

	tst_sig(FORK, DEF_HANDLER, cleanup);

	TEST_PAUSE;

	/* Create a temporary directory and make it current. */
	tst_tmpdir();

	/* Create a directory. */
	if (mkdir("dir1", 0777) == -1) {
		tst_brkm(TBROK, cleanup, "mkdir() failed to create dir1.");
	}
#if defined(CRAY)
	/* NOTE: linking directories is NOT valid on IRIX  */

	/* Create a directory that has multiple links to it. */
	if (mkdir("dir2", 0777) == -1) {
		tst_brkm(TBROK, cleanup, "mkdir() failed to create dir2.");
	} else {
		if (system
		    ("runcmd `get_attrib -A link` dir2 mlink_dir > link.out 2>&1")
		    != 0) {
			tst_brk(TBROK, "link.out", cleanup,
				"link failed to link dir2 and mlink_dir.");
		}
	}

#endif

	/* Create a unique directory name. */
	sprintf(dir_name, "./dir_%d", getpid());

#if !defined(UCLINUX)
	bad_addr = mmap(0, 1, PROT_NONE,
			MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
	if (bad_addr == MAP_FAILED) {
		tst_brkm(TBROK, cleanup, "mmap failed");
	}
#endif
}
Example #23
0
File: stat03.c Project: dacongy/ltp
int main(int ac, char **av)
{
	struct stat stat_buf;	/* stat structure buffer */
	int lc;
	char *msg;
	char *file_name;	/* ptr. for file name whose mode is modified */
	char *test_desc;	/* test specific error message */
	int ind;		/* counter to test different test conditions */

	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);

	/*
	 * Invoke setup function to call individual test setup functions
	 * to simulate test conditions.
	 */
	setup();

	/* set the expected errnos... */
	TEST_EXP_ENOS(exp_enos);

	for (lc = 0; TEST_LOOPING(lc); lc++) {

		tst_count = 0;

		for (ind = 0; Test_cases[ind].desc != NULL; ind++) {
			file_name = Test_cases[ind].pathname;
			test_desc = Test_cases[ind].desc;

#if !defined(UCLINUX)
			if (file_name == High_address_node) {
				file_name = (char *)get_high_address();
			}
#endif

			/*
			 * Call stat(2) to test different test conditions.
			 * verify that it fails with -1 return value and
			 * sets appropriate errno.
			 */
			TEST(stat(file_name, &stat_buf));

			/* Check return code from stat(2) */
			if (TEST_RETURN == -1) {
				TEST_ERROR_LOG(TEST_ERRNO);
				if (TEST_ERRNO == Test_cases[ind].exp_errno) {
					tst_resm(TPASS,
						 "stat() fails, %s, errno:%d",
						 test_desc, TEST_ERRNO);
				} else {
					tst_resm(TFAIL,
						 "stat() fails, %s, errno:%d, expected errno:%d",
						 test_desc, TEST_ERRNO,
						 Test_cases[ind].exp_errno);
				}
			} else {
				tst_resm(TFAIL,
					 "stat(2) returned %ld, expected -1, errno:%d",
					 TEST_RETURN,
					 Test_cases[ind].exp_errno);
			}
		}
		tst_count++;	/* incr TEST_LOOP counter */
	}

	/*
	 * Invoke cleanup() to delete the test directory/file(s) created
	 * in the setup().
	 */
	cleanup();
	tst_exit();
	tst_exit();

}
int main(int ac, char **av)
{
	int lc;			/* loop counter */
	char *msg;		/* message returned from parse_opts */

    /***************************************************************
     * parse standard options
     ***************************************************************/
	if ((msg = parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *)NULL)
		tst_brkm(TBROK, cleanup, "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++) {

		/* reset Tst_count in case we are looping. */
		Tst_count = 0;

		/*
		 * TEST CASE:
		 *  R_OK on low pointer (-1) for path
		 */

		/* Call access(2) */
		TEST(access(bad_addr, R_OK));

		/* check return code */
		if (TEST_RETURN == -1) {
			TEST_ERROR_LOG(TEST_ERRNO);
		}

	/***************************************************************
	 * only perform functional verification if flag set (-f not given)
	 ***************************************************************/
		if (STD_FUNCTIONAL_TEST) {
			if (TEST_RETURN == -1) {
				if (TEST_ERRNO == EFAULT) {
					tst_resm(TPASS,
						 "access((char *)-1,R_OK) failed as expected with errno %d (EFAULT) : %s",
						 TEST_ERRNO,
						 strerror(TEST_ERRNO));
				} else {
					tst_resm(TFAIL,
						 "access((char *)-1,R_OK) failed with errno %d : %s but expected %d (EFAULT)",
						 TEST_ERRNO,
						 strerror(TEST_ERRNO), EFAULT);
                                        exit(1);
				}
			} else {
				tst_resm(TFAIL,
					 "access((char *)-1,R_OK) succeeded unexpectedly.");
                                exit(1);

			}
		}

		/*
		 * TEST CASE:
		 *  W_OK on low pointer (-1) for path
		 */

		/* Call access(2) */
		TEST(access(bad_addr, W_OK));

		/* check return code */
		if (TEST_RETURN == -1) {
			TEST_ERROR_LOG(TEST_ERRNO);
		}

	/***************************************************************
	 * only perform functional verification if flag set (-f not given)
	 ***************************************************************/
		if (STD_FUNCTIONAL_TEST) {
			if (TEST_RETURN == -1) {
				if (TEST_ERRNO == EFAULT) {
					tst_resm(TPASS,
						 "access((char *)-1,W_OK) failed as expected with errno %d (EFAULT) : %s",
						 TEST_ERRNO,
						 strerror(TEST_ERRNO));
				} else {
					tst_resm(TFAIL,
						 "access((char *)-1,W_OK) failed with errno %d : %s but expected %d (EFAULT)",
						 TEST_ERRNO,
						 strerror(TEST_ERRNO), EFAULT);
                                        exit(1);
				}
			} else {
				tst_resm(TFAIL,
					 "access((char *)-1,W_OK) succeeded unexpectedly."); 
                                exit(1);

			}
		}

		/*
		 * TEST CASE:
		 *  X_OK on low pointer (-1) for path
		 */

		/* Call access(2) */
		TEST(access(bad_addr, X_OK));

		/* check return code */
		if (TEST_RETURN == -1) {
			TEST_ERROR_LOG(TEST_ERRNO);
		}

	/***************************************************************
	 * only perform functional verification if flag set (-f not given)
	 ***************************************************************/
		if (STD_FUNCTIONAL_TEST) {
			if (TEST_RETURN == -1) {
				if (TEST_ERRNO == EFAULT) {
					tst_resm(TPASS,
						 "access((char*)-1,X_OK) failed as expected with errno %d (EFAULT) : %s",
						 TEST_ERRNO,
						 strerror(TEST_ERRNO));
				} else {
					tst_resm(TFAIL,
						 "access((char*)-1,X_OK) failed with errno %d : %s but expected %d (EFAULT)",
						 TEST_ERRNO,
						 strerror(TEST_ERRNO), EFAULT);
                                        exit(1);
				}
			} else {
				tst_resm(TFAIL,
					 "access((char*)-1,X_OK) succeeded unexpectedly.");
                                exit(1);

			}
		}

		/*
		 * TEST CASE:
		 *  F_OK on low pointer (-1) for path
		 */

		/* Call access(2) */
		TEST(access(bad_addr, F_OK));

		/* check return code */
		if (TEST_RETURN == -1) {
			TEST_ERROR_LOG(TEST_ERRNO);
		}

	/***************************************************************
	 * only perform functional verification if flag set (-f not given)
	 ***************************************************************/
		if (STD_FUNCTIONAL_TEST) {
			if (TEST_RETURN == -1) {
				if (TEST_ERRNO == EFAULT) {
					tst_resm(TPASS,
						 "access((char*)-1,F_OK) failed as expected with errno %d (EFAULT) : %s",
						 TEST_ERRNO,
						 strerror(TEST_ERRNO));
				} else {
					tst_resm(TFAIL,
						 "access((char*)-1,F_OK) failed with errno %d : %s but expected %d (EFAULT)",
						 TEST_ERRNO,
						 strerror(TEST_ERRNO), EFAULT); 
                                        exit(1);
				}
			} else {
				tst_resm(TFAIL,
					 "access((char*)-1,F_OK) succeeded unexpectedly.");
                                exit(1);

			}
		}

		/*
		 * TEST CASE:
		 *  R_OK on high pointer (sbrk(0)+1) for path
		 */

		/* Call access(2) */
		TEST(access(get_high_address(), R_OK));

		/* check return code */
		if (TEST_RETURN == -1) {
			TEST_ERROR_LOG(TEST_ERRNO);
		}

	/***************************************************************
	 * only perform functional verification if flag set (-f not given)
	 ***************************************************************/
		if (STD_FUNCTIONAL_TEST) {
			if (TEST_RETURN == -1) {
				if (TEST_ERRNO == EFAULT) {
					tst_resm(TPASS,
						 "access((char*)sbrk(0)+1,R_OK) failed as expected with errno %d (EFAULT) : %s",
						 TEST_ERRNO,
						 strerror(TEST_ERRNO));
				} else {
					tst_resm(TFAIL,
						 "access((char*)sbrk(0)+1,R_OK) failed with errno %d : %s but expected %d (EFAULT)",
						 TEST_ERRNO,
						 strerror(TEST_ERRNO), EFAULT); 
                                        exit(1);
				}
			} else {
				tst_resm(TFAIL,
					 "access((char*)sbrk(0)+1,R_OK) succeeded unexpectedly.");
                                exit(1);

			}
		}

		/*
		 * TEST CASE:
		 *  W_OK on high pointer (sbrk(0)+1) for path
		 */

		/* Call access(2) */
		TEST(access(get_high_address(), W_OK));

		/* check return code */
		if (TEST_RETURN == -1) {
			TEST_ERROR_LOG(TEST_ERRNO);
		}

	/***************************************************************
	 * only perform functional verification if flag set (-f not given)
	 ***************************************************************/
		if (STD_FUNCTIONAL_TEST) {
			if (TEST_RETURN == -1) {
				if (TEST_ERRNO == EFAULT) {
					tst_resm(TPASS,
						 "access((char*)sbrk(0)+1,W_OK) failed as expected with errno %d (EFAULT) : %s",
						 TEST_ERRNO,
						 strerror(TEST_ERRNO));
				} else {
					tst_resm(TFAIL,
						 "access((char*)sbrk(0)+1,W_OK) failed with errno %d : %s but expected %d (EFAULT)",
						 TEST_ERRNO,
						 strerror(TEST_ERRNO), EFAULT);
				}
			} else {
				tst_resm(TFAIL,
					 "access((char*)sbrk(0)+1,W_OK) succeeded unexpectedly.");

			}
		}

		/*
		 * TEST CASE:
		 *  X_OK on high pointer (sbrk(0)+1) for path
		 */

		/* Call access(2) */
		TEST(access(get_high_address(), X_OK));

		/* check return code */
		if (TEST_RETURN == -1) {
			TEST_ERROR_LOG(TEST_ERRNO);
		}

	/***************************************************************
	 * only perform functional verification if flag set (-f not given)
	 ***************************************************************/
		if (STD_FUNCTIONAL_TEST) {
			if (TEST_RETURN == -1) {
				if (TEST_ERRNO == EFAULT) {
					tst_resm(TPASS,
						 "access(high_address,X_OK) failed as expected with errno %d (EFAULT) : %s",
						 TEST_ERRNO,
						 strerror(TEST_ERRNO));
				} else {
					tst_resm(TFAIL,
						 "access(high_address,X_OK) failed with errno %d : %s but expected %d (EFAULT)",
						 TEST_ERRNO,
						 strerror(TEST_ERRNO), EFAULT);
				}
			} else {
				tst_resm(TFAIL,
					 "access(high_address,X_OK) succeeded unexpectedly.");

			}
		}

		/*
		 * TEST CASE:
		 *  F_OK on high pointer (sbrk(0)+1) for path
		 */

		/* Call access(2) */
		TEST(access(get_high_address(), F_OK));

		/* check return code */
		if (TEST_RETURN == -1) {
			TEST_ERROR_LOG(TEST_ERRNO);
		}

	/***************************************************************
	 * only perform functional verification if flag set (-f not given)
	 ***************************************************************/
		if (STD_FUNCTIONAL_TEST) {
			if (TEST_RETURN == -1) {
				if (TEST_ERRNO == EFAULT) {
					tst_resm(TPASS,
						 "access((char*)sbrk(0)+1,F_OK) failed as expected with errno %d (EFAULT) : %s",
						 TEST_ERRNO,
						 strerror(TEST_ERRNO));
				} else {
					tst_resm(TFAIL,
						 "access((char*)sbrk(0)+1,F_OK) failed with errno %d : %s but expected %d (EFAULT)",
						 TEST_ERRNO,
						 strerror(TEST_ERRNO), EFAULT);
				}
			} else {
				tst_resm(TFAIL,
					 "access((char*)sbrk(0)+1,F_OK) succeeded unexpectedly.");

			}
		}

	}			/* End for TEST_LOOPING */

    /***************************************************************
     * cleanup and exit
     ***************************************************************/
	cleanup();

	return 0;
}				/* End main */
Example #25
0
int main(int argc, char **argv)
{
	int lc;

	tst_parse_opts(argc, argv, NULL, NULL);

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {
		tst_count = 0;

		/*
		 * TEST CASE: 1
		 * path points to the current directory
		 */
		TEST(rmdir("."));

		if (TEST_RETURN == -1) {
		}

		if (TEST_RETURN == -1) {
			if (TEST_ERRNO & (EBUSY | ENOTEMPTY)) {
				/* For functionality tests, verify that the
				 * directory wasn't removed.
				 */
				if (stat(".", &stat_buf) == -1) {
					tst_resm(TFAIL,
						 "rmdir(\".\") removed the current working directory when it should have failed.");
				} else {
					tst_resm(TPASS,
						 "rmdir(\".\") failed to remove the current working directory. Returned %d : %s",
						 TEST_ERRNO,
						 strerror(TEST_ERRNO));
				}
			} else {
				tst_resm(TFAIL,
					 "rmdir(\".\") failed with errno %d : %s but expected %d (EBUSY)",
					 TEST_ERRNO,
					 strerror(TEST_ERRNO), EBUSY);
			}
		} else {
			tst_resm(TFAIL,
				 "rmdir(\".\") succeeded unexpectedly.");
		}

		/*
		 * TEST CASE: 2
		 * path points to the "." (dot) entry of a directory
		 */
		tst_resm(TCONF, "rmdir on \"dir/.\" supported on Linux");

		tst_resm(TCONF,
			 "linked directories test not implemented on Linux");

		/*
		 * TEST CASE: 4
		 * path argument points below the minimum allocated address space
		 */
#if !defined(UCLINUX)
		TEST(rmdir(bad_addr));

		if (TEST_RETURN == -1) {
		}

		if (TEST_RETURN == -1) {
			if (TEST_ERRNO == EFAULT) {
				tst_resm(TPASS,
					 "rmdir() - path argument points below the minimum allocated address space failed as expected with errno %d : %s",
					 TEST_ERRNO,
					 strerror(TEST_ERRNO));
			} else {
				tst_resm(TFAIL,
					 "rmdir() - path argument points below the minimum allocated address space failed with errno %d : %s but expected %d (EFAULT)",
					 TEST_ERRNO,
					 strerror(TEST_ERRNO), EFAULT);
			}
		} else {
			tst_resm(TFAIL,
				 "rmdir() - path argument points below the minimum allocated address space succeeded unexpectedly.");
		}

		/*
		 * TEST CASE: 5
		 * path argument points above the maximum allocated address space
		 */

		TEST(rmdir(get_high_address()));

		if (TEST_RETURN == -1) {
		}

		if (TEST_RETURN == -1) {
			if (TEST_ERRNO == EFAULT) {
				tst_resm(TPASS,
					 "rmdir() - path argument points above the maximum allocated address space failed as expected with errno %d : %s",
					 TEST_ERRNO,
					 strerror(TEST_ERRNO));
			} else {
				tst_resm(TFAIL,
					 "rmdir() - path argument points above the maximum allocated address space failed with errno %d : %s but expected %d (EFAULT)",
					 TEST_ERRNO,
					 strerror(TEST_ERRNO), EFAULT);
			}
		} else {
			tst_resm(TFAIL,
				 "rmdir() - path argument points above the maximum allocated address space succeeded unexpectedly.");
		}
#endif

		/*
		 * TEST CASE: 6
		 * able to remove a directory
		 */

		if (mkdir(dir_name, 0777) != 0) {
			tst_brkm(TBROK, cleanup,
				 "mkdir(\"%s\") failed with errno %d : %s",
				 dir_name, errno, strerror(errno));
		}

		TEST(rmdir(dir_name));

		if (TEST_RETURN == -1) {
			tst_resm(TFAIL,
				 "rmdir(\"%s\") failed when it should have passed. Returned %d : %s",
				 dir_name, TEST_ERRNO, strerror(TEST_ERRNO));
		} else {
			/* Verify the directory was removed. */
			if (stat(dir_name, &stat_buf) != 0) {
				tst_resm(TPASS,
					 "rmdir(\"%s\") removed the directory as expected.",
					 dir_name);
			} else {
				tst_resm(TFAIL,
					 "rmdir(\"%s\") returned a zero exit status but failed to remove the directory.",
					 dir_name);
			}
		}

	}

	cleanup();
	tst_exit();
}