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

	tst_require_root(NULL);

	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	TEST_PAUSE;

	/* make a temporary directory and cd to it */
	tst_tmpdir();
	if (chmod(tst_get_tmpdir(), S_IRWXU) == -1)
		tst_brkm(TBROK | TERRNO, cleanup, "chmod(%s, 700) failed",
			 tst_get_tmpdir());

	/* create a test file */
	sprintf(fname, "%s.%d", fname, getpid());
	if (mkdir(fname, 0444) == -1) {
		tst_resm(TFAIL, "creat(2) FAILED to creat temp file");
	} else {
		sprintf(path, "%s/%s", fname, fname);
		if ((fileHandle = creat(path, 0444)) == -1)
			tst_brkm(TFAIL | TERRNO, cleanup, "creat failed");
	}

	ltpuser = getpwnam(nobody_uid);
	if (ltpuser == NULL)
		tst_brkm(TBROK | TERRNO, cleanup, "getpwnam failed");
	if (seteuid(ltpuser->pw_uid) == -1) {
		tst_resm(TINFO | TERRNO, "seteuid failed to "
			 "to set the effective uid to %d", ltpuser->pw_uid);
	}

}
Beispiel #2
0
void setup(void)
{
	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	tst_tmpdir();

	/* Initialize test dir and file names */
	char *abs_path = tst_get_tmpdir();
	int p = getpid();

	sprintf(pathname, "fchmodattestdir%d", p);
	sprintf(testfile, "fchmodattest%d.txt", p);
	sprintf(testfile2, "%s/fchmodattest%d.txt", abs_path, p);
	sprintf(testfile3, "fchmodattestdir%d/fchmodattest%d.txt", p, p);

	free(abs_path);

	SAFE_MKDIR(cleanup, pathname, 0700);

	fds[0] = SAFE_OPEN(cleanup, pathname, O_DIRECTORY);
	fds[1] = fds[4] = fds[0];

	SAFE_OPEN(cleanup, testfile, O_CREAT | O_RDWR, 0600);
	SAFE_OPEN(cleanup, testfile2, O_CREAT | O_RDWR, 0600);

	fds[2] = SAFE_OPEN(cleanup, testfile3, O_CREAT | O_RDWR, 0600);
	fds[3] = 100;
	fds[5] = AT_FDCWD;

	filenames[0] = filenames[2] = filenames[3] = filenames[4] = testfile;
	filenames[1] = testfile2;
	filenames[5] = testfile3;

	TEST_PAUSE;
}
Beispiel #3
0
void setup(void)
{
	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	tst_tmpdir();

	char *abs_path = tst_get_tmpdir();

	SAFE_ASPRINTF(cleanup, &testfile3, "%s/fstatattestfile3.txt", abs_path);
	free(abs_path);

	SAFE_MKDIR(cleanup, pathname, 0700);

	fds[0] = SAFE_OPEN(cleanup, pathname, O_DIRECTORY);
	fds[1] = fds[4] = fds[0];

	SAFE_OPEN(cleanup, testfile, O_CREAT | O_RDWR, 0600);
	SAFE_OPEN(cleanup, testfile2, O_CREAT | O_RDWR, 0600);

	fds[2] =  SAFE_OPEN(cleanup, testfile3, O_CREAT | O_RDWR, 0600);

	fds[3] = 100;
	fds[5] = AT_FDCWD;

	filenames[0] = filenames[2] = filenames[3] = filenames[4] =
	    filenames[5] = testfile;
	filenames[1] = testfile3;

	TEST_PAUSE;
}
Beispiel #4
0
static void setup(void)
{
	char *tmpdir;

	if (tst_kvercmp(2, 6, 16) < 0)
		tst_brkm(TCONF, NULL, "This test needs kernel 2.6.16 or newer");

	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	TEST_PAUSE;

	tst_tmpdir();

	/* Initialize test dir and file names */
	tmpdir = tst_get_tmpdir();
	sprintf(testfilepath, PATHNAME"/mknodattestfile%d", getpid());
	sprintf(testfile, "mknodattestfile%d", getpid());
	sprintf(testfile2, "mknodattestfile2%d", getpid());
	sprintf(testfile3, "%s/mknodattestfile3%d", tmpdir, getpid());
	free(tmpdir);

	SAFE_MKDIR(cleanup, PATHNAME, 0700);

	dir_fd = SAFE_OPEN(cleanup, PATHNAME, O_DIRECTORY);
	fd = SAFE_OPEN(cleanup, testfile2, O_CREAT | O_RDWR, 0600);
}
Beispiel #5
0
int main(int ac, char **av)
{
	int lc;
	char *msg;

#if __WORDSIZE == 32
	tst_brkm(TCONF, NULL, "This test is only for 64bit");
#endif

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

	if (!Hflag) {
		tst_tmpdir();
		Hopt = tst_get_tmpdir();
	}
	if (sflag)
		hugepages = SAFE_STRTOL(NULL, nr_opt, 0, LONG_MAX);

	setup();

	map_sz = read_meminfo("Hugepagesize:") * 1024;

	for (lc = 0; TEST_LOOPING(lc); lc++) {
		fildes = open(TEMPFILE, O_RDWR | O_CREAT, 0666);
		if (fildes < 0)
			tst_brkm(TBROK | TERRNO, cleanup, "open %s", TEMPFILE);

		tst_count = 0;

		/* Attempt to mmap into highmem addr, should get ENOMEM */
		addr = mmap(HIGH_ADDR, map_sz, PROT_READ,
			    MAP_SHARED | MAP_FIXED, fildes, 0);
		if (addr != MAP_FAILED) {
			tst_resm(TFAIL, "mmap into high region "
				 "succeeded unexpectedly");
			goto fail;
		}
		if (errno != ENOMEM)
			tst_resm(TFAIL | TERRNO, "mmap into high region "
				 "failed unexpectedly - expect "
				 "errno=ENOMEM, got");
		else
			tst_resm(TPASS | TERRNO, "mmap into high region "
				 "failed as expected");
fail:
		close(fildes);
	}
	cleanup();
	tst_exit();
}
Beispiel #6
0
void setup(void)
{
	save_nr_hugepages();

	if (!Hopt)
		Hopt = tst_get_tmpdir();
	SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);

	if (nr_opt)
		hugepages = SAFE_STRTOL(nr_opt, 0, LONG_MAX);
	set_sys_tune("nr_hugepages", hugepages, 1);

	snprintf(TEMPFILE, sizeof(TEMPFILE), "%s/mmapfile%d", Hopt, getpid());
}
Beispiel #7
0
static void setup_iteration(int i)
{
	static char testdir[256];
	char *tmpdir = tst_get_tmpdir();

	/* Initialize test dir and file names */
	sprintf(testdir, "mkdirattestdir%d_%d", getpid(), i);
	sprintf(relpath, "mkdiratrelpath%d_%d", getpid(), i);
	sprintf(abspath, "%s/mkdiratrelpath%d_%d_2", tmpdir, getpid(), i);

	free(tmpdir);

	SAFE_MKDIR(cleanup, testdir, 0700);
	dir_fd = SAFE_OPEN(cleanup, testdir, O_DIRECTORY);
}
Beispiel #8
0
int main(int ac, char **av)
{
	int lc;
	int pid, status, retval;

	tst_parse_opts(ac, av, NULL, NULL);

	setup();

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

		if ((pid = FORK_OR_VFORK()) == -1) {
			tst_brkm(TBROK, cleanup, "Could not fork");
		}

		if (pid == 0) {
			retval = 0;

			if (chroot(tst_get_tmpdir()) == -1) {
				perror("chroot failed");
				retval = 1;
			} else {
				if (stat("/" TMP_FILENAME, &buf) == -1) {
					retval = 1;
					perror("stat failed");
				}
			}

			exit(retval);
		}

		/* parent */
		wait(&status);
		/* make sure the child returned a good exit status */
		if (WIFSIGNALED(status) ||
		    (WIFEXITED(status) && WEXITSTATUS(status) != 0))
			tst_resm(TFAIL, "chroot functionality incorrect");
		else
			tst_resm(TPASS, "chroot functionality correct");
	}

	cleanup();
	tst_exit();

}
Beispiel #9
0
static void setup(void)
{
	char *tmpdir;

	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	tst_tmpdir();

	SAFE_MKDIR(cleanup, TEST_DIR, 0700);
	dir_fd = SAFE_OPEN(cleanup, TEST_DIR, O_DIRECTORY);
	fd = SAFE_OPEN(cleanup, TEST_DIR TEST_FILE, O_CREAT | O_RDWR, 0600);

	tmpdir = tst_get_tmpdir();
	snprintf(glob_path, sizeof(glob_path), "%s/" TEST_DIR TEST_FILE,
	         tmpdir);
	free(tmpdir);

	TEST_PAUSE;
}
Beispiel #10
0
static void setup_ipc(void)
{
	size_t size = getpagesize();

	if (access("/dev/shm", F_OK) == 0) {
		snprintf(shm_path, sizeof(shm_path), "/dev/shm/ltp_%s_%d",
		         tid, getpid());
	} else {
		char *tmpdir;

		if (!tst_tmpdir_created())
			tst_tmpdir();

		tmpdir = tst_get_tmpdir();
		snprintf(shm_path, sizeof(shm_path), "%s/ltp_%s_%d",
		         tmpdir, tid, getpid());
		free(tmpdir);
	}

	ipc_fd = open(shm_path, O_CREAT | O_EXCL | O_RDWR, 0600);
	if (ipc_fd < 0)
		tst_brk(TBROK | TERRNO, "open(%s)", shm_path);
	SAFE_CHMOD(shm_path, 0666);

	SAFE_FTRUNCATE(ipc_fd, size);

	results = SAFE_MMAP(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, ipc_fd, 0);

	/* Checkpoints needs to be accessible from processes started by exec() */
	if (tst_test->needs_checkpoints) {
		sprintf(ipc_path, IPC_ENV_VAR "=%s", shm_path);
		putenv(ipc_path);
	} else {
		SAFE_UNLINK(shm_path);
	}

	SAFE_CLOSE(ipc_fd);

	if (tst_test->needs_checkpoints) {
		tst_futexes = (char*)results + sizeof(struct results);
		tst_max_futexes = (size - sizeof(struct results))/sizeof(futex_t);
	}
}
Beispiel #11
0
int main(void)
{
	char *tmp_dir;
	char *start_dir = getcwd(NULL, PATH_MAX);
	char *changed_dir;
	int fail_counter = 0;

	tst_tmpdir();

	tmp_dir = tst_get_tmpdir();
	changed_dir = getcwd(NULL, PATH_MAX);

	if (strcmp(tmp_dir, changed_dir) == 0 &&
	    strcmp(tmp_dir, start_dir) != 0) {
		printf("Temp directory successfully created and switched to\n");
	} else {
		printf("Temp directory is wrong!\n");
		fail_counter++;
	}

	tst_rmdir();

	if (chdir(tmp_dir) == -1 && errno == ENOENT) {
		printf("The temp directory was removed successfully\n");
	} else {
		printf("Failed to remove the temp directory!\n");
		fail_counter++;
	}

	if (fail_counter > 0)
		printf("Something failed please review!!\n");
	else
		printf("Test completed successfully!\n");

	return 0;
}
Beispiel #12
0
int main(int ac, char **av)
{
	int lc;
	int Hflag = 0;
	long page_sz, map_sz;
	int sflag = 0;

	option_t options[] = {
		{"H:", &Hflag, &Hopt},
		{"s:", &sflag, &nr_opt},
		{NULL, NULL, NULL}
	};

	tst_parse_opts(ac, av, options, &help);

	check_hugepage();

	if (!Hflag) {
		tst_tmpdir();
		Hopt = tst_get_tmpdir();
	}
	if (sflag)
		hugepages = SAFE_STRTOL(NULL, nr_opt, 0, LONG_MAX);

	page_sz = getpagesize();
	map_sz = read_meminfo("Hugepagesize:") * 1024 * 2;

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {
		/* Creat a temporary file used for huge mapping */
		fildes = open(TEMPFILE, O_RDWR | O_CREAT, 0666);
		if (fildes < 0)
			tst_brkm(TBROK | TERRNO, cleanup,
				 "opening %s failed", TEMPFILE);

		/* Creat a file used for normal mapping */
		nfildes = open("/dev/zero", O_RDONLY, 0666);
		if (nfildes < 0)
			tst_brkm(TBROK | TERRNO, cleanup,
				 "opening /dev/zero failed");

		tst_count = 0;

		/*
		 * Call mmap on /dev/zero 5 times
		 */
		for (i = 0; i < 5; i++) {
			addr = mmap(0, 256 * 1024 * 1024, PROT_READ,
				    MAP_SHARED, nfildes, 0);
			addrlist[i] = addr;
		}

		while (range_is_mapped(cleanup, low_addr, low_addr + map_sz) == 1) {
			low_addr = low_addr + 0x10000000;

			if (low_addr < LOW_ADDR)
				tst_brkm(TBROK | TERRNO, cleanup,
						"no empty region to use");
		}
		/* mmap using normal pages and a low memory address */
		addr = mmap((void *)low_addr, page_sz, PROT_READ,
			    MAP_SHARED | MAP_FIXED, nfildes, 0);
		if (addr == MAP_FAILED)
			tst_brkm(TBROK | TERRNO, cleanup,
				 "mmap failed on nfildes");

		while (range_is_mapped(cleanup, low_addr2, low_addr2 + map_sz) == 1) {
			low_addr2 = low_addr2 + 0x10000000;

			if (low_addr2 < LOW_ADDR2)
				tst_brkm(TBROK | TERRNO, cleanup,
						"no empty region to use");
		}
		/* Attempt to mmap a huge page into a low memory address */
		addr2 = mmap((void *)low_addr2, map_sz, PROT_READ | PROT_WRITE,
			     MAP_SHARED, fildes, 0);
#if __WORDSIZE == 64		/* 64-bit process */
		if (addr2 == MAP_FAILED) {
			tst_resm(TFAIL | TERRNO, "huge mmap failed unexpectedly"
				 " with %s (64-bit)", TEMPFILE);
			close(fildes);
			continue;
		} else {
			tst_resm(TPASS, "huge mmap succeeded (64-bit)");
		}
#else /* 32-bit process */
		if (addr2 == MAP_FAILED)
			tst_resm(TFAIL | TERRNO, "huge mmap failed unexpectedly"
				 " with %s (32-bit)", TEMPFILE);
		else if (addr2 > 0) {
			tst_resm(TCONF,
				 "huge mmap failed to test the scenario");
			close(fildes);
			continue;
		} else if (addr == 0)
			tst_resm(TPASS, "huge mmap succeeded (32-bit)");
#endif

		/* Clean up things in case we are looping */
		for (i = 0; i < 5; i++) {
			if (munmap(addrlist[i], 256 * 1024 * 1024) == -1)
				tst_resm(TBROK | TERRNO,
					 "munmap of addrlist[%d] failed", i);
		}

#if __WORDSIZE == 64
		if (munmap(addr2, map_sz) == -1)
			tst_brkm(TFAIL | TERRNO, NULL, "huge munmap failed");
#endif
		if (munmap(addr, page_sz) == -1)
			tst_brkm(TFAIL | TERRNO, NULL, "munmap failed");

		close(fildes);
	}

	cleanup();
	tst_exit();
}
int main(int ac, char **av)
{
	int lc;
	int Hflag = 0;
	int sflag = 0;
	int huge_pagesize = 0;

	option_t options[] = {
		{"H:", &Hflag, &Hopt},
		{"s:", &sflag, &nr_opt},
		{NULL, NULL, NULL}
	};

	tst_parse_opts(ac, av, options, &help);

	if (!Hflag) {
		tst_tmpdir();
		Hopt = tst_get_tmpdir();
	}
	if (sflag)
		hugepages = SAFE_STRTOL(NULL, nr_opt, 0, LONG_MAX);

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {
		/* Creat a temporary file used for huge mapping */
		fildes = open(TEMPFILE, O_RDWR | O_CREAT, 0666);
		if (fildes < 0)
			tst_brkm(TFAIL | TERRNO, cleanup, "open %s failed",
				 TEMPFILE);

		tst_count = 0;

		/* Note the number of free huge pages BEFORE testing */
		freepages = read_meminfo("HugePages_Free:");
		beforetest = freepages;

		/* Note the size of huge page size BEFORE testing */
		huge_pagesize = read_meminfo("Hugepagesize:");
		tst_resm(TINFO, "Size of huge pages is %d KB", huge_pagesize);

#if __WORDSIZE == 32
		tst_resm(TINFO, "Total amount of free huge pages is %d",
			 freepages);
		tst_resm(TINFO, "Max number allowed for 1 mmap file in"
			 " 32-bits is 128");
		if (freepages > 128)
			freepages = 128;
#endif
		mapsize = (long long)freepages *huge_pagesize * 1024;
		addr = mmap(NULL, mapsize, PROT_READ | PROT_WRITE,
			    MAP_SHARED, fildes, 0);
		sleep(2);
		if (addr == MAP_FAILED) {
			tst_resm(TFAIL | TERRNO, "mmap() Failed on %s",
				 TEMPFILE);
			close(fildes);
			continue;
		} else {
			tst_resm(TPASS,
				 "Succeeded mapping file using %ld pages",
				 freepages);
			/* force to allocate page and change HugePages_Free */
			*(int *)addr = 0;
		}

		/*
		 * Make sure the number of free huge pages
		 * AFTER testing decreased
		 */
		aftertest = read_meminfo("HugePages_Free:");
		hugepagesmapped = beforetest - aftertest;
		if (hugepagesmapped < 1)
			tst_resm(TWARN, "Number of HUGEPAGES_FREE stayed the"
				 " same. Okay if multiple copies running due"
				 " to test collision.");

		/* Clean up things in case we are looping */
		/* Unmap the mapped memory */
		if (munmap(addr, mapsize) != 0)
			tst_brkm(TFAIL | TERRNO, NULL, "munmap failed");

		close(fildes);
	}

	cleanup();
	tst_exit();
}
Beispiel #14
0
static void setup(void)
{
	char *tmpdir;
	const char *fs_type;
	int i;

	if ((tst_kvercmp(2, 6, 16)) < 0) {
		tst_brkm(TCONF, NULL,
			"This test can only run on kernels that are "
			"2.6.16 and higher");
	}

	tst_require_root();

	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	tst_tmpdir();

	fs_type = tst_dev_fs_type();
	device = tst_acquire_device(cleanup);

	if (!device)
		tst_brkm(TCONF, cleanup, "Failed to obtain block device");

	TEST_PAUSE;

	SAFE_TOUCH(cleanup, TESTFILE, FILEMODE, NULL);

	SAFE_TOUCH(cleanup, TESTFILE2, FILEMODE, NULL);
	tmpdir = tst_get_tmpdir();
	sprintf(absoldpath, "%s/%s", tmpdir, TESTFILE2);
	sprintf(absnewpath, "%s/%s", tmpdir, NEW_TESTFILE2);
	free(tmpdir);

	SAFE_MKDIR(cleanup, TESTDIR, DIRMODE);
	SAFE_TOUCH(cleanup, TESTFILE3, FILEMODE, NULL);
	SAFE_MKDIR(cleanup, NEW_TESTDIR, DIRMODE);

	olddirfd = SAFE_OPEN(cleanup, TESTDIR, O_DIRECTORY);
	newdirfd = SAFE_OPEN(cleanup, NEW_TESTDIR, O_DIRECTORY);

	filefd = SAFE_OPEN(cleanup, TESTFILE4,
				O_RDWR | O_CREAT, FILEMODE);

	/*
	 * NOTE: the ELOOP test is written based on that the
	 * consecutive symlinks limit in kernel is hardwired
	 * to 40.
	 */
	SAFE_MKDIR(cleanup, "loopdir", DIRMODE);
	SAFE_SYMLINK(cleanup, "../loopdir", "loopdir/loopdir");
	for (i = 0; i < 43; i++)
		strcat(looppathname, TESTDIR2);

	tst_mkfs(cleanup, device, fs_type, NULL, NULL);
	SAFE_MKDIR(cleanup, MNTPOINT, DIRMODE);
	if (mount(device, MNTPOINT, fs_type, 0, NULL) < 0) {
		tst_brkm(TBROK | TERRNO, cleanup,
			"mount device:%s failed", device);
	}
	mount_flag = 1;
	SAFE_TOUCH(cleanup, TESTFILE5, FILEMODE, NULL);
	if (mount(device, MNTPOINT, fs_type,
			MS_REMOUNT | MS_RDONLY, NULL) < 0) {
		tst_brkm(TBROK | TERRNO, cleanup,
			"mount device:%s failed", device);
	}

	SAFE_MKDIR(cleanup, TESTDIR3, DIRMODE);
	max_subdirs = tst_fs_fill_subdirs(cleanup, "testemlinkdir");
}
Beispiel #15
0
int main(int ac, char **av)
{
	int lc;
	const char *msg;
	int Hflag = 0;
	long page_sz = 0;
	int sflag = 0;

	option_t options[] = {
		{"H:", &Hflag, &Hopt},
		{"s:", &sflag, &nr_opt},
		{NULL, NULL, NULL}
	};

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

	if (!Hflag) {
		tst_tmpdir();
		Hopt = tst_get_tmpdir();
	}
	if (sflag)
		hugepages = SAFE_STRTOL(NULL, nr_opt, 0, LONG_MAX);

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {
		/* Creat a temporary file used for mapping */
		fildes = open(TEMPFILE, O_RDWR | O_CREAT, 0666);
		if (fildes < 0)
			tst_brkm(TFAIL | TERRNO, cleanup, "open %s failed",
				 TEMPFILE);

		tst_count = 0;

		/* Note the number of free huge pages BEFORE testing */
		beforetest = read_meminfo("HugePages_Free:");

		/* Note the size of huge page size BEFORE testing */
		page_sz = read_meminfo("Hugepagesize:") * 1024;

		addr = mmap(NULL, page_sz, PROT_READ | PROT_WRITE,
			    MAP_SHARED, fildes, 0);
		if (addr == MAP_FAILED) {
			tst_resm(TFAIL | TERRNO, "mmap() Failed on %s",
				 TEMPFILE);
			close(fildes);
			continue;
		} else {
			close(fildes);
			tst_resm(TPASS, "call succeeded");
			/* force to allocate page and change HugePages_Free */
			*(int *)addr = 0;
		}

		/*
		 * Make sure the number of free huge pages
		 * AFTER testing decreased
		 */
		aftertest = read_meminfo("HugePages_Free:");
		hugepagesmapped = beforetest - aftertest;
		if (hugepagesmapped < 1)
			tst_resm(TWARN, "Number of HUGEPAGES_FREE stayed the"
				 " same. Okay if multiple copies running due"
				 " to test collision.");

		/* Clean up things in case we are looping */
		/* Unmap the mapped memory */
		if (munmap(addr, page_sz) != 0)
			tst_brkm(TFAIL | TERRNO, NULL, "munmap failed");

		close(fildes);
	}

	cleanup();
	tst_exit();
}