예제 #1
0
파일: swapon03.c 프로젝트: AbhiramiP/ltp
int main(int ac, char **av)
{
	int lc;

	tst_parse_opts(ac, av, NULL, NULL);

	setup();

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

		if (setup_swap() < 0) {
			clean_swap();
			tst_brkm(TBROK, cleanup,
				 "Setup failed, quitting the test");
		}

		TEST(ltp_syscall(__NR_swapon, swap_testfiles[0].filename, 0));

		if ((TEST_RETURN == -1) && (TEST_ERRNO == expected_errno)) {
			tst_resm(TPASS, "swapon(2) got expected failure (%d),",
				 expected_errno);
		} else if (TEST_RETURN < 0) {
			tst_resm(TFAIL | TTERRNO,
				 "swapon(2) failed to produce expected error "
				 "(%d). System reboot recommended.",
				 expected_errno);
		} else {
			/* Probably the system supports MAX_SWAPFILES > 30,
			 * let's try with MAX_SWAPFILES == 32 */

			/* Call swapon sys call once again for 32
			 * now we can't receive an error */
			TEST(ltp_syscall
			     (__NR_swapon, swap_testfiles[1].filename, 0));

			/* Check return code (now we're expecting success) */
			if (TEST_RETURN < 0) {
				tst_resm(TFAIL | TTERRNO,
					 "swapon(2) got an unexpected failure");
			} else {
				/* Call swapon sys call once again for 33
				 * now we have to receive an error */
				TEST(ltp_syscall
				     (__NR_swapon, swap_testfiles[2].filename,
				      0));

				/* Check return code (should be an error) */
				if ((TEST_RETURN == -1)
				    && (TEST_ERRNO == expected_errno)) {
					tst_resm(TPASS,
						 "swapon(2) got expected failure;"
						 " Got errno = %d, probably your"
						 " MAX_SWAPFILES is 32",
						 expected_errno);
				} else {
					tst_resm(TFAIL,
						 "swapon(2) failed to produce"
						 " expected error: %d, got %s."
						 " System reboot after execution of LTP"
						 " test suite is recommended.",
						 expected_errno,
						 strerror(TEST_ERRNO));
				}

			}
		}

		if (clean_swap() < 0)
			tst_brkm(TBROK, cleanup,
				 "Cleanup failed, quitting the test");

	}

	cleanup();
	tst_exit();

}
예제 #2
0
파일: swapon03.c 프로젝트: ystk/debian-ltp
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, tst_exit, "OPTION PARSING ERROR - %s", msg);

	/***************************************************************
	 * perform global setup for test
	 ***************************************************************/
	uname(&uval);
	kmachine = uval.machine;
	setup();

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

		/* do the test setup */
		if (setup_swap() < 0) {
			clean_swap();
			tst_brkm(TBROK, cleanup,
				 "Setup failed, quitting the test");
		}

		/* Call swapon sys call for the first time */
		TEST(syscall(__NR_swapon,swap_testfiles[0].filename, 0));

		/* Check return code */
		if ((TEST_RETURN == -1) && (TEST_ERRNO == expected_errno)) {
			tst_resm(TPASS, "swapon(2) got expected failure;"
				 " Got errno - %d, probably your"
				 " MAX_SWAPFILES is 30", expected_errno);
		} else if (TEST_RETURN < 0) {
			tst_resm(TFAIL, "swapon(2) failed to produce"
				 " expected error: %d, got %d (%s)."
				 " System reboot after execution of LTP"
				 " test suite is recommended.", expected_errno,
				 TEST_ERRNO, strerror(TEST_ERRNO));
		} else {
			/* Probably the system supports MAX_SWAPFILES > 30,
			 * let's try with MAX_SWAPFILES == 32 */

			/* Call swapon sys call once again for 32
			 * now we can't receive an error */
			TEST(syscall(__NR_swapon, swap_testfiles[1].filename, 0));

			/* Check return code (now we're expecting success) */
			if (TEST_RETURN < 0) {
				tst_resm(TFAIL,
					 "swapon(2) got an unexpected failure;"
					 " Got errno = %d : %s", TEST_ERRNO,
					 strerror(TEST_ERRNO));
			} else {
				/* Call swapon sys call once again for 33
				 * now we have to receive an error */
				TEST(syscall(__NR_swapon, swap_testfiles[2].filename, 0));

				/* Check return code (should be an error) */
				if ((TEST_RETURN == -1)
				    && (TEST_ERRNO == expected_errno)) {
					tst_resm(TPASS,
						 "swapon(2) got expected failure;"
						 " Got errno - %d, probably your"
						 " MAX_SWAPFILES is 32",
						 expected_errno);
				} else {
					tst_resm(TFAIL,
						 "swapon(2) failed to produce"
						 " expected error: %d, got %s."
						 " System reboot after execution of LTP"
						 " test suite is recommended.",
						 expected_errno,
						 strerror(TEST_ERRNO));
				}

			}
		}

		/* do the clean */
		if (clean_swap() < 0)
			tst_brkm(TBROK, cleanup,
				 "Cleanup failed, quitting the test");

		TEST_ERROR_LOG(TEST_ERRNO);

	}			/* End of TEST LOOPING */

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

	return (0);

}				/* End of main */