Beispiel #1
0
/* setup() - performs all ONE TIME setup for this test */
void setup()
{
	tst_sig(FORK, DEF_HANDLER, cleanup);

	/* Check whether we are root */
	if (geteuid() != 0) {
		tst_brkm(TBROK, NULL, "Test must be run as root");
	}

	TEST_PAUSE;

	tst_tmpdir();

	if (tst_is_cwd_tmpfs()) {
		tst_brkm(TCONF, cleanup,
			 "Cannot do swapon on a file located on a tmpfs filesystem");
	}

	if (tst_is_cwd_nfs()) {
		tst_brkm(TCONF, cleanup,
			 "Cannot do swapon on a file located on a nfs filesystem");
	}

	make_swapfile(cleanup, "swapfile01");
}
Beispiel #2
0
/***************************************************************
 * setup() - performs all ONE TIME setup for this test
 ***************************************************************/
void setup()
{
	/* capture signals */
	tst_sig(FORK, DEF_HANDLER, cleanup);

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

	/* Check whether we are root */
	if (geteuid() != 0) {
		tst_brkm(TBROK, tst_exit, "Test must be run as root");
	}

	/* make a temp directory and cd to it */
	tst_tmpdir();

	if (tst_is_cwd_tmpfs()) {
		tst_brkm(TCONF, cleanup,
			 "Cannot do swapon on a file located on a tmpfs filesystem");
	}

	if (tst_is_cwd_nfs()) {
		tst_brkm(TCONF, cleanup,
			 "Cannot do swapon on a file located on a nfs filesystem");
	}

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

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

	tst_sig(FORK, DEF_HANDLER, cleanup);

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

	/* Check whether we are root */
	if (geteuid() != 0) {
		tst_brkm(TBROK, NULL, "Test must be run as root");
	}

	tst_tmpdir();

	if (tst_is_cwd_tmpfs()) {
		tst_brkm(TCONF, cleanup,
			 "Cannot do swapon on a file located on a tmpfs filesystem");
	}

	if (tst_is_cwd_nfs()) {
		tst_brkm(TCONF, cleanup,
			 "Cannot do swapon on a file located on a nfs filesystem");
	}

	TEST_PAUSE;

}
Beispiel #4
0
/* setup() - performs all ONE TIME setup for this test */
void setup()
{

	tst_sig(FORK, DEF_HANDLER, cleanup);

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

	/* Check whether we are root */
	if (geteuid() != 0) {
		tst_brkm(TBROK, NULL, "Test must be run as root");
	}

	TEST_PAUSE;

	tst_tmpdir();

	if (tst_is_cwd_tmpfs()) {
		tst_brkm(TCONF, cleanup,
			 "Cannot do swapon on a file located on a tmpfs filesystem");
	}

	if (tst_is_cwd_nfs()) {
		tst_brkm(TCONF, cleanup,
			 "Cannot do swapon on a file located on a nfs filesystem");
	}

	if (!tst_cwd_has_free(65536)) {
		tst_brkm(TBROK, cleanup,
			 "Insufficient disk space to create swap file");
	}

	/*create file */
	if (system
	    ("dd if=/dev/zero of=swapfile01 bs=1024  count=65536 > tmpfile"
	     " 2>&1") != 0) {
		tst_brkm(TBROK, cleanup, "Failed to create file for swap");
	}

	/* make above file a swap file */
	if (system("mkswap ./swapfile01 > tmpfile 2>&1") != 0) {
		tst_brkm(TBROK, cleanup, "Failed to make swapfile");
	}

	if (syscall(__NR_swapon, "./swapfile01", 0) != 0) {
		tst_brkm(TBROK, cleanup, "Failed to turn on the swap file."
			 " skipping  the test iteration");
	}

	need_swapfile_cleanup = 1;

}
Beispiel #5
0
/* setup() - performs all ONE TIME setup for this test */
void setup()
{

	tst_sig(FORK, DEF_HANDLER, cleanup);

	/* Check whether we are root */
	if (geteuid() != 0) {
		tst_brkm(TBROK, NULL, "Test must be run as root");
	}

	TEST_PAUSE;

	tst_tmpdir();

	if (tst_is_cwd_tmpfs()) {
		tst_brkm(TCONF, cleanup,
			 "Cannot do swapon on a file located on a tmpfs filesystem");
	}

	if (tst_is_cwd_nfs()) {
		tst_brkm(TCONF, cleanup,
			 "Cannot do swapon on a file located on a nfs filesystem");
	}

	if (!tst_cwd_has_free(65536)) {
		tst_brkm(TBROK, cleanup,
			 "Insufficient disk space to create swap file");
	}

	/*create file */
	if (system
	    ("dd if=/dev/zero of=swapfile01 bs=1024  count=65536 > tmpfile"
	     " 2>&1 ") != 0) {
		tst_brkm(TBROK, cleanup, "Failed to create file for swap");
	}

	/* make above file a swap file */
	if (system("mkswap swapfile01 > tmpfile 2>&1") != 0) {
		tst_brkm(TBROK, cleanup, "Failed to make swapfile");
	}

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

	/*
	 * check if the current filesystem is nfs
	 */
	if (tst_is_cwd_nfs()) {
		tst_brkm(TCONF, cleanup,
			 "Cannot do fcntl on a file located on an NFS filesystem");
	}

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

#ifdef F_SETLEASE
		/*
		 * Call fcntl(2) with F_SETLEASE & F_RDLCK argument on fname
		 */
		TEST(fcntl(fd, F_SETLEASE, F_RDLCK));

		/* check return code */
		if (TEST_RETURN == -1) {
			TEST_ERROR_LOG(TEST_ERRNO);
			tst_resm(TFAIL,
				 "fcntl(%s, F_SETLEASE, F_RDLCK) Failed, errno=%d : %s",
				 fname, TEST_ERRNO, strerror(TEST_ERRNO));
		} else {

	    /***************************************************************
	     * only perform functional verification if flag set (-f not given)
	     ***************************************************************/
			if (STD_FUNCTIONAL_TEST) {
				TEST(fcntl(fd, F_GETLEASE));
				if (TEST_RETURN != F_RDLCK)
					tst_resm(TFAIL,
						 "fcntl(%s, F_GETLEASE) did not return F_RDLCK, returned %ld",
						 fname, TEST_RETURN);
				else {
					TEST(fcntl(fd, F_SETLEASE, F_UNLCK));
					if (TEST_RETURN != 0)
						tst_resm(TFAIL,
							 "fcntl(%s, F_SETLEASE, F_UNLCK) did not return 0, returned %ld",
							 fname, TEST_RETURN);
					else
						tst_resm(TPASS,
							 "fcntl(%s, F_SETLEASE, F_RDLCK)",
							 fname);
				}
			}
			if (close(TEST_RETURN) == -1) {
				tst_resm(TWARN,
					 "close(%s) Failed, errno=%d : %s",
					 fname, errno, strerror(errno));
			}
		}
#else
		tst_resm(TINFO, "F_SETLEASE not defined, skipping test");
#endif
	}			/* End for TEST_LOOPING */

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

	return 0;
}				/* End main */
Beispiel #7
0
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, NULL, NULL)) != NULL)
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);

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

	/*
	 * check if the current filesystem is nfs
	 */
	if (tst_is_cwd_nfs()) {
		tst_brkm(TCONF, cleanup,
			 "Cannot do fcntl on a file located on an NFS filesystem");
	}

	/*
	 * check if the current filesystem is tmpfs
	 */
	if (tst_is_cwd_tmpfs()) {
		tst_brkm(TCONF, cleanup,
			 "Cannot do fcntl on a file located on an TMPFS filesystem");
	}

	/*
	 * check if the current filesystem is ramfs
	 */
	if (tst_is_cwd_ramfs()) {
		tst_brkm(TCONF, cleanup,
			 "Cannot do fcntl on a file located on an RAMFS filesystem");
	}

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

#ifdef F_SETLEASE
		/*
		 * Call fcntl(2) with F_SETLEASE & F_WRLCK argument on fname
		 */
		TEST(fcntl(fd, F_SETLEASE, F_WRLCK));

		/* check return code */
		if (TEST_RETURN == -1) {
			TEST_ERROR_LOG(TEST_ERRNO);
			tst_resm(TFAIL,
				 "fcntl(%s, F_SETLEASE, F_WRLCK) Failed, errno=%d : %s",
				 fname, TEST_ERRNO, strerror(TEST_ERRNO));
		} else {
			if (STD_FUNCTIONAL_TEST) {
				TEST(fcntl(fd, F_GETLEASE));
				if (TEST_RETURN != F_WRLCK)
					tst_resm(TFAIL,
						 "fcntl(%s, F_GETLEASE) did not return F_WRLCK, returned %ld",
						 fname, TEST_RETURN);
				else {
					TEST(fcntl(fd, F_SETLEASE, F_UNLCK));
					if (TEST_RETURN != 0)
						tst_resm(TFAIL,
							 "fcntl(%s, F_SETLEASE, F_UNLCK) did not return 0, returned %ld",
							 fname, TEST_RETURN);
					else
						tst_resm(TPASS,
							 "fcntl(%s, F_SETLEASE, F_WRLCK)",
							 fname);
				}
			}
		}
#else
		tst_resm(TINFO, "F_SETLEASE not defined, skipping test");
#endif
	}

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

}
Beispiel #8
0
int main(int ac, char **av)
{
	struct stat stat_buf;	/* struct buffer to hold file info. */
	int lc;			/* loop counter */
	char *msg;		/* message returned from parse_opts */
	time_t modf_time, access_time;
	time_t pres_time;	/* file modification/access/present time */

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

	}

	setup();

	/*
	 * check if the current filesystem is nfs
	 */
	if (tst_is_cwd_nfs()) {
		tst_brkm(TCONF, cleanup,
			 "Cannot do utime on a file located on an NFS filesystem");
	}

        if (tst_is_cwd_v9fs()) {
                tst_brkm(TCONF, cleanup,
                         "Cannot do utime on a file located on an 9P filesystem");
        }

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

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

		Tst_count = 0;

		/*
		 * Invoke utime(2) to set TEMP_FILE access and
		 * modification times to the current time.
		 */
		TEST(utime(TEMP_FILE, NULL));

		if (TEST_RETURN == -1) {
			TEST_ERROR_LOG(TEST_ERRNO);
			tst_resm(TFAIL, "utime(%s) Failed, errno=%d : %s",
				 TEMP_FILE, TEST_ERRNO, strerror(TEST_ERRNO));
		} else {
			/*
			 * Perform functional verification if test
			 * executed without (-f) option.
			 */
			if (STD_FUNCTIONAL_TEST) {
				/*
				 * Sleep for a second so that mod time and
				 * access times will be different from the
				 * current time
				 */
				sleep(2);

				/*
				 * Get the current time now, after calling
				 * utime(2)
				 */
				if ((pres_time = time(&tloc)) < 0) {
					tst_brkm(TFAIL, cleanup, "time() "
						 "failed to get present time "
						 "after utime, error=%d",
						 errno);
				 }

				/*
				 * Get the modification and access times of
				 * temporary file using stat(2).
				 */
				if (stat(TEMP_FILE, &stat_buf) < 0) {
					tst_brkm(TFAIL, cleanup, "stat(2) of "
						 "%s failed, error:%d",
						 TEMP_FILE, TEST_ERRNO);
				 }
				modf_time = stat_buf.st_mtime;
				access_time = stat_buf.st_atime;

				/* Now do the actual verification */
				if (modf_time <= curr_time ||
				    modf_time >= pres_time ||
				    access_time <= curr_time ||
				    access_time >= pres_time) {
					tst_resm(TFAIL, "%s access and "
						 "modification times not set",
						 TEMP_FILE);
				} else {
					tst_resm(TPASS, "Functionality of "
						 "utime(%s, NULL) successful",
						 TEMP_FILE);
				}
			} else {
				tst_resm(TPASS, "%s call succeeded", TCID);
			}
		}
		Tst_count++;
	}

	cleanup();
	tst_exit();

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

	/* Disable test if the version of the kernel is less than 2.6.17 */
	if (((results = tst_kvercmp(2, 6, 17)) < 0)) {
		tst_resm(TWARN, "This test can only run on kernels that are ");
		tst_resm(TWARN, "2.6.17 and higher");
		exit(0);
	}

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

	/*
	 * check if the current filesystem is nfs
	 */
	if (tst_is_cwd_nfs()) {
		tst_brkm(TCONF, cleanup,
			 "Cannot do tee on a file located on an NFS filesystem");
	}

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

		/*
		 * Call tee_test
		 */
		TEST(tee_test());

		/* check return code */
		if (TEST_RETURN < 0) {
			if (TEST_RETURN != -1) {
				TEST_ERRNO = -TEST_RETURN;
			}
			TEST_ERROR_LOG(TEST_ERRNO);
			tst_resm(TFAIL, "tee() Failed, errno=%d : %s",
				 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, "tee() returned %ld",
					 TEST_RETURN);
			}
		}

	}			/* End for TEST_LOOPING */

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

	return (0);
}				/* End main */
Beispiel #10
0
int main(int ac, char **av)
{
	struct stat stat_buf;	/* struct buffer to hold file info. */
	int lc;			/* loop counter */
	char *msg;		/* message returned from parse_opts */
	time_t modf_time, access_time;
	time_t pres_time;	/* file modification/access/present time */
	pid_t pid;

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

	}

	setup();

	/*
	 * check if the current filesystem is nfs
	 */
	if (tst_is_cwd_nfs()) {
		tst_brkm(TCONF, cleanup,
			 "Cannot do utime on a file located on an NFS filesystem");
	}

        if (tst_is_cwd_v9fs()) {
                tst_brkm(TCONF, cleanup,
                         "Cannot do utime on a file located on an 9P filesystem");
        }

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

	pid = FORK_OR_VFORK();

	if (pid == -1) {
		tst_brkm(TBROK, cleanup, "fork() failed");
	} else if (pid == 0) {
		if ((ltpuser = getpwnam(LTPUSER1)) == NULL) {
			tst_brkm(TBROK, cleanup, "%s not found in /etc/passwd",
				 LTPUSER1);
		}

		/* get uid/gid of user accordingly */
		user_uid = ltpuser->pw_uid;

		seteuid(user_uid);

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

			Tst_count = 0;

			/*
			 * Invoke utime(2) to set TEMP_FILE access and
			 * modification times to the current time.
			 */
			TEST(utime(TEMP_FILE, NULL));

			if (TEST_RETURN == -1) {
				TEST_ERROR_LOG(TEST_ERRNO);
				tst_resm(TFAIL,
					 "utime(%s) Failed, errno=%d : %s",
					 TEMP_FILE, TEST_ERRNO,
					 strerror(TEST_ERRNO));
			} else {
				/*
				 * Perform functional verification if test
				 * executed without (-f) option.
				 */
				if (STD_FUNCTIONAL_TEST) {
					/*
					 * Sleep for a second so that mod time
					 * and access times will be different
					 * from the current time.
					 */
					sleep(2);

					/*
					 * Get the current time now, after
					 * calling utime(2)
					 */
					if ((pres_time = time(&tloc)) < 0) {
						tst_brkm(TFAIL, cleanup,
							 "time() failed to get "
							 "present time after "
							 "utime, error=%d",
							 errno);
					 }

					/*
					 * Get the modification and access
					 * times of temporary file using
					 * stat(2).
					 */
					if (stat(TEMP_FILE, &stat_buf) < 0) {
						tst_brkm(TFAIL, cleanup,
							 "stat(2) of %s failed, "
							 "error:%d", TEMP_FILE,
							 TEST_ERRNO);
					 }
					modf_time = stat_buf.st_mtime;
					access_time = stat_buf.st_atime;

					/* Now do the actual verification */
					if (modf_time <= curr_time ||
					    modf_time >= pres_time ||
					    access_time <= curr_time ||
					    access_time >= pres_time) {
						tst_resm(TFAIL, "%s access and "
							 "modification times "
							 "not set", TEMP_FILE);
					} else {
						tst_resm(TPASS, "Functionality "
							 "of utime(%s, NULL) "
							 "successful",
							 TEMP_FILE);
					}
				} else {
					tst_resm(TPASS, "%s call succeeded",
						 TCID);
				}
			}
			Tst_count++;	/* incr. TEST_LOOP counter */
		}
	} else {
		waitpid(pid, &status, 0);
		_exit(0);	/*
				 * Exit here and let the child clean up.
				 * This allows the errno information set
				 * by the TEST_ERROR_LOG macro and the
				 * PASS/FAIL status to be preserved for
				 * use during cleanup.
				 */
	}

	cleanup();
	tst_exit();

}