您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ tst_parse_opts函数代码示例

51自学网 2021-06-03 08:59:44
  C++
这篇教程C++ tst_parse_opts函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中tst_parse_opts函数的典型用法代码示例。如果您正苦于以下问题:C++ tst_parse_opts函数的具体用法?C++ tst_parse_opts怎么用?C++ tst_parse_opts使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了tst_parse_opts函数的24个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: main

int main(int ac, char **av){	int lc;	int rval;	pid_t pid, pid1;	int status;	/*	 * parse standard options	 */	tst_parse_opts(ac, av, NULL, NULL);	/*	 * perform global setup for test	 */	setup();	/*	 * check looping state if -i option given	 */	for (lc = 0; TEST_LOOPING(lc); lc++) {		tst_count = 0;		/* Initialize the test directories name */		sprintf(tstdir1, "tstdir1.%d", getpid());		if ((pid = FORK_OR_VFORK()) < 0) {			tst_brkm(TBROK, cleanup, "fork #1 failed");		}		if (pid == 0) {	/* first child */			rval = setreuid(nobody_uid, nobody_uid);			if (rval < 0) {				tst_resm(TFAIL, "setreuid failed to "					 "to set the real uid to %d and "					 "effective uid to %d",					 nobody_uid, nobody_uid);				perror("setreuid");				exit(1);			}			/* create the parent directory with 0700 permits */			if (mkdir(tstdir1, PERMS) == -1) {				tst_resm(TFAIL, "mkdir(%s, %#o) Failed",					 tstdir1, PERMS);				exit(1);			}			/* create tstdir1 succeeded */			exit(0);		}		wait(&status);		if (WEXITSTATUS(status) != 0) {			tst_brkm(TFAIL, cleanup,				 "Test to check mkdir EACCES failed"				 "in create parent directory");		}		sprintf(tstdir2, "%s/tst", tstdir1);		if ((pid1 = FORK_OR_VFORK()) < 0) {			tst_brkm(TBROK, cleanup, "fork #2 failed");		}		if (pid1 == 0) {	/* second child */			rval = setreuid(bin_uid, bin_uid);			if (rval < 0) {				tst_resm(TFAIL, "setreuid failed to "					 "to set the real uid to %d and "					 "effective uid to %d",					 bin_uid, bin_uid);				perror("setreuid");				exit(1);			}			if (mkdir(tstdir2, PERMS) != -1) {				tst_resm(TFAIL, "mkdir(%s, %#o) unexpected "					 "succeeded", tstdir2, PERMS);				exit(1);			}			if (errno != EACCES) {				tst_resm(TFAIL, "Expected EACCES got %d",					 errno);				exit(1);			}			/* PASS */			exit(0);		}		waitpid(pid1, &status, 0);		if (WEXITSTATUS(status) == 0) {			tst_resm(TPASS, "Test to attempt to creat a directory "				 "in a directory having no permissions "				 "SUCCEEDED in setting errno to EACCES");		} else {			tst_resm(TFAIL, "Test to attempt to creat a directory "				 "in a directory having no permissions FAILED");			cleanup();		}	}	/*	 * cleanup and exit	 *///.........这里部分代码省略.........
开发者ID:Nan619,项目名称:ltp,代码行数:101,


示例2: main

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();}
开发者ID:foss-for-synopsys-dwc-arc-processors,项目名称:ltp,代码行数:88,


示例3: main

/*********************************************************************** * Main ***********************************************************************/int main(int ac, char **av){	int lc;	int cnt;	int nfiles, fd;	char fname[255];	DIR *test_dir;	struct dirent *dptr;	tst_parse_opts(ac, av, options, &help);	if (Nflag) {		if (sscanf(Nfilearg, "%i", &Nfiles) != 1) {			tst_brkm(TBROK, NULL, "--N option arg is not a number");		}	}    /***************************************************************     * perform global setup for test     ***************************************************************/	/* Next you should run a setup routine to make sure your environment is	 * sane.	 */	setup();    /***************************************************************     * check looping state     ***************************************************************/	/* TEST_LOOPING() is a macro that will make sure the test continues	 * looping according to the standard command line args.	 */	for (lc = 0; TEST_LOOPING(lc); lc++) {		tst_count = 0;		if (Nfiles)			nfiles = Nfiles;		else			/* min of 10 links and max of a 100 links */			nfiles = (lc % 90) + 10;		/* create a bunch of files to look at */		for (cnt = 0; cnt < nfiles; cnt++) {			sprintf(fname, "%s%d", Basename, cnt);			if ((fd = open(fname, O_RDWR | O_CREAT, 0700)) == -1) {				tst_brkm(TBROK, cleanup,					 "open(%s, O_RDWR|O_CREAT,0700) Failed, errno=%d : %s",					 fname, errno, strerror(errno));			} else if (write(fd, "hello/n", 6) < 0) {				tst_brkm(TBROK, cleanup,					 "write(%s, /"hello//n/", 6) Failed, errno=%d : %s",					 fname, errno, strerror(errno));			} else if (close(fd) < 0) {				tst_resm(TWARN,					"close(%s) Failed, errno=%d : %s",					fname, errno, strerror(errno));			}		}		if ((test_dir = opendir(".")) == NULL) {			tst_resm(TFAIL, "opendir(/"./") Failed, errno=%d : %s",				 errno, strerror(errno));		} else {			/* count the entries we find to see if any are missing */			cnt = 0;			errno = 0;			while ((dptr = readdir(test_dir)) != 0) {				if (strcmp(dptr->d_name, ".")				    && strcmp(dptr->d_name, ".."))					cnt++;			}			if (errno != 0) {				tst_resm(TFAIL,					 "readir(test_dir) Failed on try %d, errno=%d : %s",					 cnt + 1, errno, strerror(errno));			}			if (cnt == nfiles) {				tst_resm(TPASS,					 "found all %d that were created",					 nfiles);			} else if (cnt > nfiles) {				tst_resm(TFAIL,					 "found more files than were created");				tst_resm(TINFO, "created: %d, found: %d",					 nfiles, cnt);			} else {				tst_resm(TFAIL,					 "found less files than were created");				tst_resm(TINFO, "created: %d, found: %d",					 nfiles, cnt);			}		}		/* Here we clean up after the test case so we can do another iteration.		 *///.........这里部分代码省略.........
开发者ID:1587,项目名称:ltp,代码行数:101,


示例4: main

int main(int ac, char **av){	int lc;	int i;	int fork_ret, status;	int written;		/* no of chars read and written */	tst_parse_opts(ac, av, NULL, NULL);#ifdef UCLINUX	maybe_run_child(&do_child_uclinux, "ddddd", &fd[0], &fd[1], &kidid,			&ncperchild, &szcharbuf);#endif	setup();	for (lc = 0; TEST_LOOPING(lc); lc++) {		/* reset tst_count in case we are looping */		tst_count = 0;		TEST(pipe(fd));		if (TEST_RETURN != 0) {			tst_resm(TFAIL, "pipe creation failed");			continue;		}		written = write(fd[1], wrbuf, szcharbuf);		if (written != szcharbuf) {			tst_brkm(TBROK, cleanup, "write to pipe failed");		}refork:		++kidid;		fork_ret = FORK_OR_VFORK();		if (fork_ret < 0) {			tst_brkm(TBROK, cleanup, "fork() failed");		}		if ((fork_ret != 0) && (fork_ret != -1) && (kidid < numchild)) {			goto refork;		}		if (fork_ret == 0) {	/* child */#ifdef UCLINUX			if (self_exec(av[0], "ddddd", fd[0], fd[1], kidid,				      ncperchild, szcharbuf) < 0) {				tst_brkm(TBROK, cleanup, "self_exec failed");			}#else			do_child();#endif		}		/* parent */		sleep(5);		tst_resm(TINFO, "There are %d children to wait for", kidid);		for (i = 1; i <= kidid; ++i) {			wait(&status);			if (status == 0) {				tst_resm(TPASS, "child %d exitted successfully",					 i);			} else {				tst_resm(TFAIL, "child %d exitted with bad "					 "status", i);			}		}	}	cleanup();	tst_exit();}
开发者ID:1587,项目名称:ltp,代码行数:74,


示例5: main

int main(int ac, char **av){	struct stat stat_buf;	/* struct buffer to hold file info. */	int lc;	long type;	time_t modf_time, access_time;	time_t pres_time;	/* file modification/access/present time */	tst_parse_opts(ac, av, NULL, NULL);	setup();	switch ((type = tst_fs_type(cleanup, "."))) {	case TST_NFS_MAGIC:		if (tst_kvercmp(2, 6, 18) < 0)			tst_brkm(TCONF, cleanup, "Cannot do utime on a file"				" on %s filesystem before 2.6.18",				 tst_fs_type_name(type));		break;	case TST_V9FS_MAGIC:		tst_brkm(TCONF, cleanup,			 "Cannot do utime on a file on %s filesystem",			 tst_fs_type_name(type));		break;	}	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) {			tst_resm(TFAIL|TTERRNO, "utime(%s) failed", TEMP_FILE);		} else {			/*			 * 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)			 */			pres_time = time(NULL);			/*			 * Get the modification and access times of			 * temporary file using stat(2).			 */			SAFE_STAT(cleanup, TEMP_FILE, &stat_buf);			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);			}		}		tst_count++;	}	cleanup();	tst_exit();}
开发者ID:1587,项目名称:ltp,代码行数:80,


示例6: main

int main(int argc, char **argv){	int end_signum = -1;	int signum;	int start_signum = -1;	int status;	pid_t child;	tst_parse_opts(argc, argv, NULL, NULL);	if (start_signum == -1) {		start_signum = 0;	}	if (end_signum == -1) {		end_signum = SIGRTMAX;	}	for (signum = start_signum; signum <= end_signum; signum++) {		if (signum >= __SIGRTMIN && signum < SIGRTMIN)			continue;		switch (child = fork()) {		case -1:			tst_brkm(TBROK | TERRNO, NULL, "fork() failed");		case 0:			if (ptrace(PTRACE_TRACEME, 0, NULL, NULL) != -1) {				tst_resm(TINFO, "[child] Sending kill(.., %d)",					 signum);				if (kill(getpid(), signum) < 0) {					tst_resm(TINFO | TERRNO,						 "[child] kill(.., %d) failed.",						 signum);				}			} else {				/*				 * This won't increment the TST_COUNT var.				 * properly, but it'll show up as a failure				 * nonetheless.				 */				tst_resm(TFAIL | TERRNO,					 "Failed to ptrace(PTRACE_TRACEME, ...) "					 "properly");			}			/* Shouldn't get here if signum == 0. */			exit((signum == 0 ? 0 : 2));			break;		default:			waitpid(child, &status, 0);			switch (signum) {			case 0:				if (WIFEXITED(status)				    && WEXITSTATUS(status) == 0) {					tst_resm(TPASS,						 "kill(.., 0) exited "						 "with 0, as expected.");				} else {					tst_resm(TFAIL,						 "kill(.., 0) didn't exit "						 "with 0.");				}				break;			case SIGKILL:				if (WIFSIGNALED(status)) {					/* SIGKILL must be uncatchable. */					if (WTERMSIG(status) == SIGKILL) {						tst_resm(TPASS,							 "Killed with SIGKILL, "							 "as expected.");					} else {						tst_resm(TPASS,							 "Didn't die with "							 "SIGKILL (?!) ");					}				} else if (WIFEXITED(status)) {					tst_resm(TFAIL,						 "Exited unexpectedly instead "						 "of dying with SIGKILL.");				} else if (WIFSTOPPED(status)) {					tst_resm(TFAIL,						 "Stopped instead of dying "						 "with SIGKILL.");				}				break;				/* All other processes should be stopped. */			default:				if (WIFSTOPPED(status)) {					tst_resm(TPASS, "Stopped as expected");				} else {					tst_resm(TFAIL, "Didn't stop as "						 "expected.");					if (kill(child, 0)) {//.........这里部分代码省略.........
开发者ID:kraj,项目名称:ltp,代码行数:101,


示例7: main

int main(int argc, char **argv){	int lc;	char wbuf[BUFSIZ], rbuf[BUFSIZ];	int fd;	tst_parse_opts(argc, argv, NULL, NULL);	/* global setup */	setup();	/* The following loop checks looping state if -i option given */	for (lc = 0; TEST_LOOPING(lc); lc++) {		/* reset tst_count in case we are looping */		tst_count = 0;//block1:		tst_resm(TINFO, "Enter Block 1: test to check if write "			 "corrupts the file when write fails");		fd = creat(filename, 0644);		if (fd < 0) {			tst_resm(TBROK, "creating a new file failed");			cleanup();		}		(void)memset(wbuf, '0', 100);		if (write(fd, wbuf, 100) == -1) {			tst_resm(TFAIL, "failed to write to %s", filename);			cleanup();		}		if (write(fd, bad_addr, 100) != -1) {			tst_resm(TFAIL, "write(2) failed to fail");			cleanup();		}		close(fd);		if ((fd = open(filename, O_RDONLY)) == -1) {			tst_resm(TBROK, "open(2) failed, errno: %d", errno);			cleanup();		}		if (read(fd, rbuf, 100) == -1) {			tst_resm(TBROK, "read(2) failed, errno: %d", errno);			cleanup();		}		if (memcmp(wbuf, rbuf, 100) == 0) {			tst_resm(TPASS, "failure of write(2) didnot corrupt "				 "the file");		} else {			tst_resm(TFAIL, "failure of write(2) corrupted the "				 "file");		}		tst_resm(TINFO, "Exit block 1");		close(fd);	}	cleanup();	tst_exit();}
开发者ID:1587,项目名称:ltp,代码行数:64,


示例8: main

int main(int ac, char **av){	struct stat stat_buf;	/* stat(2) struct contents */	int lc;	int ind;		/* counter variable for chmod(2) tests */	int mode;		/* file mode permission */	TST_TOTAL = sizeof(Modes) / sizeof(int);	tst_parse_opts(ac, av, NULL, NULL);	setup();	for (lc = 0; TEST_LOOPING(lc); lc++) {		tst_count = 0;		for (ind = 0; ind < TST_TOTAL; ind++) {			mode = Modes[ind];			/*			 * Call fchmod(2) with different mode permission			 * bits to set it for "testfile".			 */			TEST(fchmod(fd, mode));			if (TEST_RETURN == -1) {				tst_resm(TFAIL, "fchmod(%d, %#o) Failed, "					 "errno=%d : %s", fd, mode, TEST_ERRNO,					 strerror(TEST_ERRNO));				continue;			}			/*			 * Get the testfile information using			 * fstat(2).			 */			if (fstat(fd, &stat_buf) < 0) {				tst_brkm(TFAIL, cleanup,					 "fstat(2) of "					 "%s failed, errno:%d",					 TESTFILE, TEST_ERRNO);			}			stat_buf.st_mode &= ~S_IFREG;			/*			 * Check for expected mode permissions			 * on testfile.			 */			if (stat_buf.st_mode == mode) {				tst_resm(TPASS,					 "Functionality of "					 "fchmod(%d, %#o) successful",					 fd, mode);			} else {				tst_resm(TFAIL, "%s: Incorrect modes "					 "0%03o, Expected 0%03o",					 TESTFILE, stat_buf.st_mode,					 mode);			}		}	}	cleanup();	tst_exit();}
开发者ID:1587,项目名称:ltp,代码行数:65,


示例9: main

int main(int ac, char **av){	pid_t pid1;	int lc;	int rval;	tst_parse_opts(ac, av, NULL, NULL);	setup();	for (lc = 0; TEST_LOOPING(lc); ++lc) {		tst_count = 0;		for (testno = 0; testno < TST_TOTAL; ++testno) {			pid1 = fork();	//call to fork()			if (pid1 == -1) {				tst_brkm(TFAIL | TERRNO, cleanup,					 "fork failed");			} else if (pid1 == 0) {				switch (unshare(CLONE_FILES)) {				case 0:					printf("unshare with CLONE_FILES call "					       "succeeded/n");					rval = 0;					break;				case -1:					if (errno == ENOSYS)						rval = 1;					else {						perror("unshare failed");						rval = 2;					}				}				exit(rval);			} else {				SAFE_WAIT(cleanup, &rval);				if (rval != 0 && WIFEXITED(rval)) {					switch (WEXITSTATUS(rval)) {					case 1:						tst_brkm(TCONF, cleanup,							 "unshare not supported in "							 "kernel");						break;					default:						tst_brkm(TFAIL, cleanup,							 "unshare failed");					}				}			}			pid1 = fork();			if (pid1 == -1) {				tst_brkm(TFAIL | TERRNO, cleanup,					 "fork failed");			} else if (pid1 == 0) {				switch (unshare(CLONE_FS)) {				case 0:					printf("unshare with CLONE_FS call "					       "succeeded/n");					rval = 0;					break;				case -1:					if (errno == ENOSYS)						rval = 1;					else {						perror("unshare failed");						rval = 2;					}				}				exit(rval);			} else {				SAFE_WAIT(cleanup, &rval);				if (rval != 0 && WIFEXITED(rval)) {					switch (WEXITSTATUS(rval)) {					case 1:						tst_brkm(TCONF, cleanup,							 "unshare not supported in "							 "kernel");						break;					default:						tst_brkm(TFAIL, cleanup,							 "unshare failed");					}				}			}			pid1 = fork();			if (pid1 == -1) {				tst_brkm(TFAIL | TERRNO, cleanup,					 "fork() failed.");			} else if (pid1 == 0) {				switch (unshare(CLONE_NEWNS)) {				case 0:					printf("unshare call with CLONE_NEWNS "					       "succeeded/n");					rval = 0;					break;				case -1:					if (errno == ENOSYS)						rval = 1;//.........这里部分代码省略.........
开发者ID:kraj,项目名称:ltp,代码行数:101,


示例10: main

int main(int argc, char *argv[]){	int lc;	int i;	tst_parse_opts(argc, argv, NULL, NULL);#ifdef UCLINUX	argv0 = argv[0];	maybe_run_child(&child_pid, "nd", 1, &sem_id_1);	maybe_run_child(&child_cnt, "ndd", 2, &sem_id_1, &sem_op);#endif	setup();	for (lc = 0; TEST_LOOPING(lc); lc++) {		tst_count = 0;		for (i = 0; i < TST_TOTAL; i++) {			/*			 * Set up any conditions if needed			 */			if (TC[i].func_setup != NULL) {				/* call the setup function */				switch (TC[i].cmd) {				case GETNCNT:					(*TC[i].func_setup) (-ONE);					break;				case GETZCNT:					(*TC[i].func_setup) (0);					break;				default:					(*TC[i].func_setup) ();					break;				}			}			TEST(semctl(*(TC[i].semid), TC[i].semnum, TC[i].cmd,				    TC[i].arg));			if (TEST_RETURN == -1) {				tst_resm(TFAIL, "%s call failed - errno = %d "					 ": %s", TCID, TEST_ERRNO,					 strerror(TEST_ERRNO));			} else {				/*				 * call the appropriate test function				 * and pass the return value where it				 * is needed to perform certain tests.				 */				switch (TC[i].cmd) {				case GETNCNT:				case GETZCNT:				case GETPID:				case GETVAL:				case IPC_INFO:				case SEM_STAT:					(*TC[i].func_test) (TEST_RETURN);					break;				default:					(*TC[i].func_test) ();					break;				}			}			/*			 * If testing GETNCNT or GETZCNT, clean up the children.			 */			switch (TC[i].cmd) {			case GETNCNT:			case GETZCNT:				kill_all_children();				break;			}		}		/*		 * recreate the semaphore resource if looping		 */		if (TEST_LOOPING(lc)) {			sem_id_1 = semget(semkey, PSEMS,					  IPC_CREAT | IPC_EXCL | SEM_RA);			if (sem_id_1 == -1)				tst_brkm(TBROK, cleanup,					 "couldn't recreate " "semaphore");		}	}	cleanup();	tst_exit();}
开发者ID:1587,项目名称:ltp,代码行数:92,


示例11: main

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();}
开发者ID:1587,项目名称:ltp,代码行数:65,


示例12: main

int main(int ac, char **av){	int child_pid;	int status;	int rval;	int lc;	tst_parse_opts(ac, av, NULL, NULL);#ifdef UCLINUX	maybe_run_child(&do_child, "");#endif	setup();	for (lc = 0; TEST_LOOPING(lc); lc++) {		tst_count = 0;		/* Child is in new session we are not alowed to change pgid */		if ((child_pid = FORK_OR_VFORK()) == -1)			tst_brkm(TBROK, cleanup, "fork() failed");		if (child_pid == 0) {#ifdef UCLINUX			if (self_exec(av[0], "") < 0)				tst_brkm(TBROK, cleanup, "self_exec failed");#else			do_child();#endif		}		TST_SAFE_CHECKPOINT_WAIT(cleanup, 0);		rval = setpgid(child_pid, getppid());		if (rval == -1 && errno == EPERM) {			tst_resm(TPASS, "setpgid failed with EPERM");		} else {			tst_resm(TFAIL,				"retval %d, errno %d, expected errno %d",				rval, errno, EPERM);		}		TST_SAFE_CHECKPOINT_WAKE(cleanup, 0);		if (wait(&status) < 0)			tst_resm(TFAIL | TERRNO, "wait() for child 1 failed");		if (!(WIFEXITED(status)) || (WEXITSTATUS(status) != 0))			tst_resm(TFAIL, "child 1 failed with status %d",				WEXITSTATUS(status));		/* Child after exec() we are no longer allowed to set pgid */		if ((child_pid = FORK_OR_VFORK()) == -1)			tst_resm(TFAIL, "Fork failed");		if (child_pid == 0) {			if (execlp(TEST_APP, TEST_APP, NULL) < 0)				perror("exec failed");			exit(127);		}		TST_SAFE_CHECKPOINT_WAIT(cleanup, 0);		rval = setpgid(child_pid, getppid());		if (rval == -1 && errno == EACCES) {			tst_resm(TPASS, "setpgid failed with EACCES");		} else {			tst_resm(TFAIL,				"retval %d, errno %d, expected errno %d",				rval, errno, EACCES);		}		TST_SAFE_CHECKPOINT_WAKE(cleanup, 0);		if (wait(&status) < 0)			tst_resm(TFAIL | TERRNO, "wait() for child 2 failed");		if (!(WIFEXITED(status)) || (WEXITSTATUS(status) != 0))			tst_resm(TFAIL, "child 2 failed with status %d",				WEXITSTATUS(status));	}	cleanup();	tst_exit();}
开发者ID:1587,项目名称:ltp,代码行数:82,


示例13: main

int main(int ac, char **av){	int exp_eno;	int lc;	char osname[OSNAMESZ];	int osnamelth, status;	int name[] = { CTL_KERN, KERN_OSTYPE };	pid_t pid;	struct passwd *ltpuser;	tst_parse_opts(ac, av, NULL, NULL);	setup();	if ((tst_kvercmp(2, 6, 32)) <= 0) {		exp_eno = EPERM;	} else {		/* ^^ Look above this warning. ^^ */		tst_resm(TINFO,			 "this test's results are based on potentially undocumented behavior in the kernel. read the NOTE in the source file for more details");		exp_eno = EACCES;		exp_enos[0] = EACCES;	}	for (lc = 0; TEST_LOOPING(lc); lc++) {		/* reset tst_count in case we are looping */		tst_count = 0;		strcpy(osname, "Linux");		osnamelth = SIZE(osname);		TEST(sysctl(name, SIZE(name), 0, 0, osname, osnamelth));		if (TEST_RETURN != -1) {			tst_resm(TFAIL, "sysctl(2) succeeded unexpectedly");		} else {			if (TEST_ERRNO == exp_eno) {				tst_resm(TPASS | TTERRNO, "Got expected error");			} else if (errno == ENOSYS) {				tst_resm(TCONF,					 "You may need to make CONFIG_SYSCTL_SYSCALL=y"					 " to your kernel config.");			} else {				tst_resm(TFAIL | TTERRNO,					 "Got unexpected error");			}		}		osnamelth = SIZE(osname);		if ((ltpuser = getpwnam("nobody")) == NULL) {			tst_brkm(TBROK, cleanup, "getpwnam() failed");		}		/* set process ID to "ltpuser1" */		if (seteuid(ltpuser->pw_uid) == -1) {			tst_brkm(TBROK, cleanup,				 "seteuid() failed, errno %d", errno);		}		if ((pid = FORK_OR_VFORK()) == -1) {			tst_brkm(TBROK, cleanup, "fork() failed");		}		if (pid == 0) {			TEST(sysctl(name, SIZE(name), 0, 0, osname, osnamelth));			if (TEST_RETURN != -1) {				tst_resm(TFAIL, "call succeeded unexpectedly");			} else {				if (TEST_ERRNO == exp_eno) {					tst_resm(TPASS | TTERRNO,						 "Got expected error");				} else if (TEST_ERRNO == ENOSYS) {					tst_resm(TCONF,						 "You may need to make CONFIG_SYSCTL_SYSCALL=y"						 " to your kernel config.");				} else {					tst_resm(TFAIL | TTERRNO,						 "Got unexpected error");				}			}			cleanup();		} else {			/* wait for the child to finish */			wait(&status);		}		/* set process ID back to root */		if (seteuid(0) == -1) {			tst_brkm(TBROK, cleanup, "seteuid() failed");		}	}	cleanup();	tst_exit();}
开发者ID:AbhiramiP,项目名称:ltp,代码行数:99,


示例14: main

int main(int ac, char **av){	int lc;	struct itimerval *value, *ovalue;	tst_parse_opts(ac, av, NULL, NULL);	setup();		/* global setup */	/* The following loop checks looping state if -i option given */	for (lc = 0; TEST_LOOPING(lc); lc++) {		/* reset tst_count in case we are looping */		tst_count = 0;		/* allocate some space for timer structures */		if ((value = malloc((size_t)sizeof(struct itimerval))) ==		    NULL) {			tst_brkm(TBROK, cleanup, "value malloc failed");		}		if ((ovalue = malloc((size_t)sizeof(struct itimerval))) ==		    NULL) {			tst_brkm(TBROK, cleanup, "value malloc failed");		}		/* set up some reasonable values */		value->it_value.tv_sec = 30;		value->it_value.tv_usec = 0;		value->it_interval.tv_sec = 0;		value->it_interval.tv_usec = 0;		/*		 * issue the system call with the TEST() macro		 * ITIMER_REAL = 0, ITIMER_VIRTUAL = 1 and ITIMER_PROF = 2		 */		/* make the first value negative to get a failure */		TEST(setitimer(-ITIMER_PROF, value, ovalue));		if (TEST_RETURN == 0) {			tst_resm(TFAIL, "call failed to produce expected error "				 "- errno = %d - %s", TEST_ERRNO,				 strerror(TEST_ERRNO));			continue;		}		switch (TEST_ERRNO) {		case EINVAL:			tst_resm(TPASS, "expected failure - errno = %d - %s",				 TEST_ERRNO, strerror(TEST_ERRNO));			break;		default:			tst_resm(TFAIL, "call failed to produce expected error "				 "- errno = %d - %s", TEST_ERRNO,				 strerror(TEST_ERRNO));		}		/*		 * clean up things in case we are looping		 */		free(value);		free(ovalue);		value = NULL;		ovalue = NULL;	}	cleanup();	tst_exit();}
开发者ID:1587,项目名称:ltp,代码行数:73,


示例15: main

int main(int ac, char **av){	int lc;	int gidsetsize;		/* total no. of groups */	int i;	char *test_desc;	/* test specific error message */	int ngroups_max = sysconf(_SC_NGROUPS_MAX);	/* max no. of groups in the current system */	tst_parse_opts(ac, av, NULL, NULL);	groups_list = malloc(ngroups_max * sizeof(GID_T));	if (groups_list == NULL) {		tst_brkm(TBROK, NULL, "malloc failed to alloc %zu errno "			 " %d ", ngroups_max * sizeof(GID_T), errno);	}	setup();	for (lc = 0; TEST_LOOPING(lc); lc++) {		tst_count = 0;		for (i = 0; i < TST_TOTAL; i++) {			if (Test_cases[i].setupfunc != NULL) {				Test_cases[i].setupfunc();			}			gidsetsize = ngroups_max + Test_cases[i].gsize_add;			test_desc = Test_cases[i].desc;			/*			 * Call setgroups() to test different test conditions			 * verify that it fails with -1 return value and			 * sets appropriate errno.			 */			TEST(SETGROUPS(cleanup, gidsetsize, groups_list));			if (TEST_RETURN != -1) {				tst_resm(TFAIL, "setgroups(%d) returned %ld, "					 "expected -1, errno=%d", gidsetsize,					 TEST_RETURN, Test_cases[i].exp_errno);				continue;			}			if (TEST_ERRNO == Test_cases[i].exp_errno) {				tst_resm(TPASS,					 "setgroups(%d) fails, %s, errno=%d",					 gidsetsize, test_desc, TEST_ERRNO);			} else {				tst_resm(TFAIL, "setgroups(%d) fails, %s, "					 "errno=%d, expected errno=%d",					 gidsetsize, test_desc, TEST_ERRNO,					 Test_cases[i].exp_errno);			}		}	}	cleanup();	tst_exit();}
开发者ID:1587,项目名称:ltp,代码行数:62,


示例16: main

int main(int argc, char **argv){    int lc;    struct robust_list_head head;    size_t len_ptr;		/* size of structure struct robust_list_head */    tst_parse_opts(argc, argv, NULL, NULL);    setup();    len_ptr = sizeof(struct robust_list_head);    for (lc = 0; TEST_LOOPING(lc); ++lc) {        tst_count = 0;        /*         * The get_robust_list function fails with EFAULT if the size of the         * struct robust_list_head can't be stored in the memory address space         * specified by len_ptr argument, or the head of the robust list can't         * be stored in the memory address space specified by the head_ptr         * argument.         */        TEST(ltp_syscall(__NR_get_robust_list, 0,                         (struct robust_list_head *)&head,                         NULL));        if (TEST_RETURN == -1) {            if (TEST_ERRNO == EFAULT)                tst_resm(TPASS,                         "get_robust_list failed as expected with "                         "EFAULT");            else                tst_resm(TFAIL | TTERRNO,                         "get_robust_list failed unexpectedly");        } else            tst_resm(TFAIL,                     "get_robust_list succeeded unexpectedly");        TEST(ltp_syscall(__NR_get_robust_list, 0,                         NULL,                         &len_ptr));        if (TEST_RETURN) {            if (TEST_ERRNO == EFAULT)                tst_resm(TPASS,                         "get_robust_list failed as expected with "                         "EFAULT");            else                tst_resm(TFAIL | TTERRNO,                         "get_robust_list failed unexpectedly");        } else            tst_resm(TFAIL,                     "get_robust_list succeeded unexpectedly");        /*         * The get_robust_list function fails with ESRCH if it can't         * find the task specified by the pid argument.         */        TEST(ltp_syscall(__NR_get_robust_list, unused_pid,                         (struct robust_list_head *)&head,                         &len_ptr));        if (TEST_RETURN == -1) {            if (TEST_ERRNO == ESRCH)                tst_resm(TPASS,                         "get_robust_list failed as expected with "                         "ESRCH");            else                tst_resm(TFAIL | TTERRNO,                         "get_robust_list failed unexpectedly");        } else            tst_resm(TFAIL,                     "get_robust_list succeeded unexpectedly");        TEST(ltp_syscall(__NR_get_robust_list, 0,                         (struct robust_list_head **)&head,                         &len_ptr));        if (TEST_RETURN == 0)            tst_resm(TPASS, "get_robust_list succeeded");        else            tst_resm(TFAIL | TTERRNO,                     "get_robust_list failed unexpectedly");        if (setuid(1) == -1)            tst_brkm(TBROK | TERRNO, cleanup, "setuid(1) failed");        TEST(ltp_syscall(__NR_get_robust_list, 1,                         (struct robust_list_head *)&head,                         &len_ptr));        if (TEST_RETURN == -1) {            if (TEST_ERRNO == EPERM)                tst_resm(TPASS,                         "get_robust_list failed as expected with "                         "EPERM");            else                tst_resm(TFAIL | TERRNO,//.........这里部分代码省略.........
开发者ID:HackLinux,项目名称:ltp,代码行数:101,


示例17: main

int main(int ac, char **av){	int lc;	struct stat buf;	/*	 * parse standard options	 */	tst_parse_opts(ac, av, NULL, NULL);	/*	 * perform global setup for test	 */	setup();	/*	 * check looping state if -i option given	 */	for (lc = 0; TEST_LOOPING(lc); lc++) {		tst_count = 0;		/*		 * TEST mkdir() base functionality		 */		/* Initialize the test directory name */		sprintf(tstdir1, "tstdir1.%d", getpid());		/* Call mkdir(2) using the TEST macro */		TEST(mkdir(tstdir1, PERMS));		if (TEST_RETURN == -1) {			tst_resm(TFAIL, "mkdir(%s, %#o) Failed",				 tstdir1, PERMS);			continue;		}		if (stat(tstdir1, &buf) == -1) {			tst_brkm(TBROK, cleanup, "failed to stat the "				 "new directory");		}		/* check the owner */		if (buf.st_uid != geteuid()) {			tst_resm(TFAIL, "mkdir() FAILED to set owner ID"				 " as process's effective ID");			continue;		}		/* check the group ID */		if (buf.st_gid != getegid()) {			tst_resm(TFAIL, "mkdir() failed to set group ID"				 " as the process's group ID");			continue;		}		tst_resm(TPASS, "mkdir() functionality is correct");		/* clean up things in case we are looping */		if (rmdir(tstdir1) == -1) {			tst_brkm(TBROK, cleanup, "could not remove directory");		}	}	cleanup();	tst_exit();}
开发者ID:1587,项目名称:ltp,代码行数:66,


示例18: main

int main(int ac, char **av){	int lc;	int fd[2];		/* fds for pipe read/write */	char wrbuf[BUFSIZ], rebuf[BUFSIZ];	int red, written;	/* no of chars read and */	/* written to pipe */	int length, greater, forkstat;	int retval = 0, status, e_code;	tst_parse_opts(ac, av, NULL, NULL);	setup();	for (lc = 0; TEST_LOOPING(lc); lc++) {		/* reset tst_count in case we are looping */		tst_count = 0;		TEST(pipe(fd));		if (TEST_RETURN == -1) {			retval = 1;			tst_resm(TFAIL, "pipe creation failed");			continue;		}		strcpy(wrbuf, "abcdefghijklmnopqrstuvwxyz");		length = strlen(wrbuf) + 1;		written = write(fd[1], wrbuf, length);		/* did write write at least some chars */		if ((written < 0) || (written > length)) {			tst_brkm(TBROK, cleanup, "write to pipe failed");		}		forkstat = FORK_OR_VFORK();		if (forkstat == -1) {			tst_brkm(TBROK, cleanup, "fork() failed");		}		if (forkstat == 0) {	/* child */			red = safe_read(fd[0], rebuf, written);			/* did read , get at least some chars */			if ((red < 0) || (red > written)) {				tst_brkm(TBROK, cleanup, "read pipe failed");			}			greater = strcmp(rebuf, wrbuf);			/* are the strings written and read equal */			if (greater == 0) {				tst_resm(TPASS, "functionality is correct");			} else {				retval = 1;				tst_resm(TFAIL, "read & write strings do "					 "not match");			}			exit(retval);		} else {	/* parent */			/* wait for the child to finish */			wait(&status);			/* make sure the child returned a good exit status */			e_code = status >> 8;			if (e_code != 0) {				tst_resm(TFAIL, "Failures reported above");			}		}	}	cleanup();	tst_exit();}
开发者ID:AbhiramiP,项目名称:ltp,代码行数:77,


示例19: main

int main(int argc, char **argv){	int i, j, sec, usec;	int failflag = 0;	int bflag = 0, nflag = 0, Fflag = 0;	char *optb, *optn, *optF;	struct io_event event;	static struct timespec ts;	struct timeval stv, etv;	option_t options[] = {		{"b:", &bflag, &optb},		{"n:", &nflag, &optn},		{"F:", &Fflag, &optF},		{NULL, NULL, NULL}	};	tst_parse_opts(argc, argv, options, &help);	bufsize = (bflag ? atoi(optb) : 8192);	nr = (nflag ? atoi(optn) : 10);	if (Fflag) {		sprintf(fname, "%s", optF);	} else {		sprintf(fname, "aiofile");	}	setup();/* TEST 1 */	pos = 0;	gettimeofday(&stv, NULL);	io_prep_pwrite(iocbs[0], fd, srcbuf, bufsize, pos);	for (i = 0; i < nr; i++) {		ts.tv_sec = 30;		ts.tv_nsec = 0;		do {			TEST(io_submit(io_ctx, 1, iocbs));		} while (TEST_RETURN == -EAGAIN);		if (TEST_RETURN < 0) {			tst_resm(TFAIL, "Test 1: io_submit failed - retval=%ld"				 ", errno=%d", TEST_RETURN, TEST_ERRNO);			failflag = 1;			continue;		}		while (io_getevents(io_ctx, 1, 1, &event, &ts) != 1) ;		gettimeofday(&etv, NULL);	}	if (!failflag) {		sec = etv.tv_sec - stv.tv_sec;		usec = etv.tv_usec - stv.tv_usec;		if (usec < 0) {			usec += 1000000;			sec--;		}		tst_resm(TPASS, "Test 1: %d writes in %3d.%06d sec",			 nr, sec, usec);	}/* TEST 2 */	pos = 0;	failflag = 0;	gettimeofday(&stv, NULL);	io_prep_pread(iocbs[0], fd, dstbuf, bufsize, pos);	for (i = 0; i < nr; i++) {		ts.tv_sec = 30;		ts.tv_nsec = 0;		do {			TEST(io_submit(io_ctx, 1, iocbs));		} while (TEST_RETURN == -EAGAIN);		if (TEST_RETURN < 0) {			tst_resm(TFAIL, "Test 2: io_submit failed - retval=%ld"				 ", errno=%d", TEST_RETURN, TEST_ERRNO);			failflag = 1;			continue;		}		while (io_getevents(io_ctx, 1, 1, &event, &ts) != 1) ;		gettimeofday(&etv, NULL);	}	if (!failflag) {		sec = etv.tv_sec - stv.tv_sec;		usec = etv.tv_usec - stv.tv_usec;		if (usec < 0) {			usec += 1000000;			sec--;		}		tst_resm(TPASS, "Test 2: %d reads in %3d.%06d sec",			 nr, sec, usec);	}/* TEST 3 */	pos = 0;	failflag = 0;	gettimeofday(&stv, NULL);	for (i = 0; i < nr; i++) {		io_prep_pwrite(iocbs[0], fd, srcbuf, bufsize, pos);		ts.tv_sec = 30;		ts.tv_nsec = 0;		do {			TEST(io_submit(io_ctx, 1, iocbs));//.........这里部分代码省略.........
开发者ID:1587,项目名称:ltp,代码行数:101,


示例20: main

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;		/*		 * TEST CASE:		 *  Dont change either real or effective gid		 */		gid = getgid();		GID16_CHECK(gid, setregid, NULL);		egid = getegid();		GID16_CHECK(egid, setregid, NULL);		TEST(SETREGID(NULL, -1, -1));		if (TEST_RETURN == -1) {			tst_resm(TFAIL,				 "setregid -  Dont change either real or effective gid failed, errno=%d : %s",				 TEST_ERRNO, strerror(TEST_ERRNO));		} else {			tst_resm(TPASS,				 "setregid -  Dont change either real or effective gid returned %ld",				 TEST_RETURN);		}		/*		 * TEST CASE:		 *  change effective to effective gid		 */		TEST(SETREGID(NULL, -1, egid));		if (TEST_RETURN == -1) {			tst_resm(TFAIL,				 "setregid -  change effective to effective gid failed, errno=%d : %s",				 TEST_ERRNO, strerror(TEST_ERRNO));		} else {			tst_resm(TPASS,				 "setregid -  change effective to effective gid returned %ld",				 TEST_RETURN);		}		/*		 * TEST CASE:		 *  change real to real gid		 */		TEST(SETREGID(NULL, gid, -1));		if (TEST_RETURN == -1) {			tst_resm(TFAIL,				 "setregid -  change real to real gid failed, errno=%d : %s",				 TEST_ERRNO, strerror(TEST_ERRNO));		} else {			tst_resm(TPASS,				 "setregid -  change real to real gid returned %ld",				 TEST_RETURN);		}		/*		 * TEST CASE:		 *  change effective to real gid		 */		TEST(SETREGID(NULL, -1, gid));		if (TEST_RETURN == -1) {			tst_resm(TFAIL,				 "setregid -  change effective to real gid failed, errno=%d : %s",				 TEST_ERRNO, strerror(TEST_ERRNO));		} else {			tst_resm(TPASS,				 "setregid -  change effective to real gid returned %ld",				 TEST_RETURN);		}		/*		 * TEST CASE:		 *  try to change real to current real		 */		TEST(SETREGID(NULL, gid, gid));		if (TEST_RETURN == -1) {			tst_resm(TFAIL | TTERRNO, "setregid failed");		} else {			tst_resm(TPASS, "setregid return %ld",				 TEST_RETURN);		}	}//.........这里部分代码省略.........
开发者ID:1587,项目名称:ltp,代码行数:101,


示例21: main

int main(int ac, char **av){	int lc;	int rval;	pid_t pid, pid1;	int status;	/*	 * parse standard options	 */	tst_parse_opts(ac, av, NULL, NULL);	/*	 * perform global setup for test	 */	setup();	/*	 * check looping state if -i option given	 */	for (lc = 0; TEST_LOOPING(lc); lc++) {		tst_count = 0;		if ((pid = FORK_OR_VFORK()) == -1) {			tst_brkm(TBROK, cleanup, "fork() #1 failed");		}		if (pid == 0) {	/* first child */			/* set to nobody */			rval = setreuid(nobody_uid, nobody_uid);			if (rval < 0) {				tst_resm(TWARN, "setreuid failed to "					 "to set the real uid to %d and "					 "effective uid to %d",					 nobody_uid, nobody_uid);				perror("setreuid");				exit(1);			}			/* create the a directory with 0700 permits */			if (mkdir(fdir, PERMS) == -1) {				tst_resm(TWARN, "mkdir(%s, %#o) Failed",					 fdir, PERMS);				exit(1);			}			/* create "old" file under it */			SAFE_TOUCH(cleanup, fname, 0700, NULL);			exit(0);		}		/* wait for child to exit */		wait(&status);		if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0)) {			tst_brkm(TBROK, cleanup, "First child failed to set "				 "up conditions for the test");		}		if ((pid1 = FORK_OR_VFORK()) == -1) {			tst_brkm(TBROK, cleanup, "fork() #2 failed");		}		if (pid1 == 0) {	/* second child */			/* set to bin */			if ((rval = seteuid(bin_uid)) == -1) {				tst_resm(TWARN, "seteuid() failed");				perror("setreuid");				exit(1);			}			/* create "new" directory */			if (mkdir(mdir, PERMS) == -1) {				tst_resm(TWARN, "mkdir(%s, %#o) failed",					 mdir, PERMS);				exit(1);			}			SAFE_TOUCH(cleanup, mname, 0700, NULL);			/* rename "old" to "new" */			TEST(rename(fname, mname));			if (TEST_RETURN != -1) {				tst_resm(TFAIL, "call succeeded unexpectedly");				continue;			}			if (TEST_ERRNO != EACCES) {				tst_resm(TFAIL, "Expected EACCES got %d",					 TEST_ERRNO);			} else {				tst_resm(TPASS, "rename() returned EACCES");			}			/* set the process id back to root */			if (seteuid(0) == -1) {				tst_resm(TWARN, "seteuid(0) failed");				exit(1);			}//.........这里部分代码省略.........
开发者ID:kraj,项目名称:ltp,代码行数:101,


示例22: main

int main(int ac, char **av){	int lc;	int i;	pid_t pid;	void do_child();	tst_parse_opts(ac, av, NULL, NULL);#ifdef UCLINUX	maybe_run_child(&do_child_uclinux, "dd", &i_uclinux, &sem_id_1);#endif	setup();		/* global setup */	/* The following loop checks looping state if -i option given */	for (lc = 0; TEST_LOOPING(lc); lc++) {		/* reset tst_count in case we are looping */		tst_count = 0;		for (i = 0; i < TST_TOTAL; i++) {			/* initialize the s_buf buffer */			s_buf.sem_op = TC[i].op;			s_buf.sem_flg = TC[i].flg;			s_buf.sem_num = TC[i].num;			/* initialize all of the primitive semaphores */			if (semctl(sem_id_1, TC[i].num, SETVAL, TC[i].semunptr)			    == -1) {				tst_brkm(TBROK, cleanup, "semctl() failed");			}			if ((pid = FORK_OR_VFORK()) == -1) {				tst_brkm(TBROK, cleanup, "could not fork");			}			if (pid == 0) {	/* child */#ifdef UCLINUX				if (self_exec(av[0], "dd", i, sem_id_1) < 0) {					tst_brkm(TBROK, cleanup,						 "could not self_exec");				}#else				do_child(i);#endif			} else {				TST_PROCESS_STATE_WAIT(cleanup, pid, 'S');				/*				 * If we are testing for EIDRM then remove				 * the semaphore, else send a signal that				 * must be caught as we are testing for				 * EINTR.				 */				if (TC[i].error == EIDRM) {					/* remove the semaphore resource */					rm_sema(sem_id_1);				} else {					SAFE_KILL(cleanup, pid, SIGHUP);				}				/* let the child carry on */				waitpid(pid, NULL, 0);			}			/*			 * recreate the semaphore resource if needed			 */			if (TC[i].error == EINTR) {				continue;			}			if ((sem_id_1 = semget(semkey, PSEMS, IPC_CREAT |					       IPC_EXCL | SEM_RA)) == -1) {				tst_brkm(TBROK, cleanup, "couldn't recreate "					 "semaphore");			}		}	}	cleanup();	tst_exit();}
开发者ID:kraj,项目名称:ltp,代码行数:87,


示例23: main

int main(int ac, char **av){    int lc;    pid_t pid, pid1;    int status;    tst_parse_opts(ac, av, NULL, NULL);    setup();    for (lc = 0; TEST_LOOPING(lc); lc++) {        tst_count = 0;        if ((pid = FORK_OR_VFORK()) < 0) {            tst_brkm(TBROK, cleanup, "first fork failed");        }        if (pid == 0) {            if (setreuid(nobody_uid, nobody_uid) != 0) {                perror("setreuid failed in child #1");                exit(1);            }            if (mkdir(good_dir, 00700) != 0) {                perror("mkdir failed in child #1");                exit(1);            }            exit(0);        }        wait(&status);        if ((pid1 = FORK_OR_VFORK()) < 0)            tst_brkm(TBROK, cleanup, "second fork failed");        if (pid1 == 0) {	/* second child */            int rval;            /*             * set the child's ID to ltpuser2 using seteuid()             * so that the ID can be changed back after the             * TEST call is made.             */            if (seteuid(bin_uid) != 0) {                perror("setreuid failed in child #2");                exit(1);            }            TEST(chdir(good_dir));            if (TEST_RETURN != -1) {                printf("call succeeded unexpectedly/n");                rval = 1;            } else if (TEST_ERRNO != EACCES) {                printf("didn't get EACCES as expected; got ");                rval = 1;            } else {                printf("got EACCES as expected/n");                rval = 0;            }            /* Only really required with vfork. */            if (seteuid(0) != 0) {                perror("seteuid(0) failed");                rval = 1;            }            exit(rval);        } else {            if (wait(&status) == -1)                tst_brkm(TBROK | TERRNO, cleanup,                         "wait failed");            if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)                tst_brkm(TBROK, cleanup,                         "child exited abnormally");            tst_resm(TPASS, "child reported success");        }        if (rmdir(good_dir) == -1) {            tst_brkm(TBROK | TERRNO, cleanup,                     "rmdir(%s) failed", good_dir);        }    }    cleanup();    tst_exit();}
开发者ID:HackLinux,项目名称:ltp,代码行数:86,


示例24: main

/*--------------------------------------------------------------------*/int main(int argc, char **argv){/***** BEGINNING OF MAIN. *****/	int pid, npid;	int nsig, exno, nexno, status;	int ret_val = 0;	int core;	void chsig();#ifdef UCLINUX	tst_parse_opts(argc, argv, NULL, NULL);	maybe_run_child(&do_child, "dd", &temp, &sig);#endif	setup();	//tempdir();            /* move to new directory */ 12/20/2003	blenter();	exno = 1;	if (sigset(SIGCHLD, chsig) == SIG_ERR) {		fprintf(temp, "/tsigset failed, errno = %d/n", errno);		fail_exit();	}	for (sig = 1; sig < 14; sig++) {		fflush(temp);		chflag = 0;		pid = FORK_OR_VFORK();		if (pid < 0) {			forkfail();		}		if (pid == 0) {#ifdef UCLINUX			if (self_exec(argv[0], "dd", temp, sig) < 0) {				tst_brkm(TBROK, NULL, "self_exec FAILED - "					 "terminating test.");			}#else			do_child();#endif		} else {			//fprintf(temp, "Testing signal %d/n", sig);			while (!chflag)	/* wait for child */				sleep(1);			kill(pid, sig);	/* child should ignroe this sig */			kill(pid, SIGCHLD);	/* child should exit */#ifdef BCS			while ((npid = wait(&status)) != pid			       || (npid == -1 && errno == EINTR)) ;			if (npid != pid) {				fprintf(temp,					"wait error: wait returned wrong pid/n");				ret_val = 1;			}#else			while ((npid = waitpid(pid, &status, 0)) != -1			       || errno == EINTR) ;#endif			/*			   nsig = status & 0177;			   core = status & 0200;			   nexno = (status & 0xff00) >> 8;			 */			/*****  LTP Port        *****/			nsig = WTERMSIG(status);#ifdef WCOREDUMP			core = WCOREDUMP(status);#endif			nexno = WIFEXITED(status);			/*****  **      **      *****/			/* nsig is the signal number returned by wait			   it should be 0, except when sig = 9          */			if ((sig == 9) && (nsig != sig)) {				fprintf(temp, "wait error: unexpected signal"					" returned when the signal sent was 9"					" The status of the process is %d /n",					status);				ret_val = 1;			}			if ((sig != 9) && (nsig != 0)) {				fprintf(temp, "wait error: unexpected signal "					"returned, the status of the process is "					"%d  /n", status);				ret_val = 1;			}			/* nexno is the exit number returned by wait			   it should be 1, except when sig = 9          *///.........这里部分代码省略.........
开发者ID:1587,项目名称:ltp,代码行数:101,



注:本文中的tst_parse_opts函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


C++ tst_require_root函数代码示例
C++ tst_kvercmp函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。