int main(int argc, char *argv[]) { int fblocks = 1; /* Iterations. Default 1 */ int bufsize = BUFSIZE; int count, ret; int offset; int fd, newfd; int i, l_fail = 0, fail_count = 0, total = 0; int failed = 0; int shmsz = MMAP_GRANULARITY; int pagemask = ~(sysconf(_SC_PAGE_SIZE) - 1); char *buf0, *buf1, *buf2; caddr_t shm_base; /* Options */ while ((i = getopt(argc, argv, "b:")) != -1) { switch (i) { case 'b': if ((fblocks = atoi(optarg)) <= 0) { fprintf(stderr, "fblocks must be > 0\n"); prg_usage(); } break; default: prg_usage(); } } setup(); /* Open file and fill, allocate for buffer */ if ((fd = open(filename, O_DIRECT | O_RDWR | O_CREAT, 0666)) < 0) { tst_brkm(TBROK, cleanup, "open failed for %s: %s", filename, strerror(errno)); } if ((buf0 = valloc(bufsize)) == NULL) { tst_brkm(TBROK, cleanup, "valloc() buf0 failed: %s", strerror(errno)); } for (i = 1; i < fblocks; i++) { fillbuf(buf0, bufsize, (char)i); if (write(fd, buf0, bufsize) < 0) { tst_brkm(TBROK, cleanup, "write failed for %s: %s", filename, strerror(errno)); } } close(fd); if ((buf2 = valloc(bufsize)) == NULL) { tst_brkm(TBROK, cleanup, "valloc() buf2 failed: %s", strerror(errno)); } if ((fd = open(filename, O_DIRECT | O_RDWR)) < 0) { tst_brkm(TBROK, cleanup, "open failed for %s: %s", filename, strerror(errno)); } /* Test-1: Negative Offset */ offset = -1; count = bufsize; errno = 0; ret = lseek(fd, offset, SEEK_SET); if ((ret >= 0) || (errno != EINVAL)) { tst_resm(TFAIL, "lseek allows negative offset. returns %d:%s", ret, strerror(errno)); failed = TRUE; fail_count++; } else tst_resm(TPASS, "Negative Offset"); total++; /* Test-2: Removed */ tst_resm(TPASS, "removed"); /* Test-3: Odd count of read and write */ offset = 0; count = 1; lseek(fd, 0, SEEK_SET); if (write(fd, buf2, 4096) == -1) { tst_resm(TFAIL, "can't write to file %d", ret); } switch (fs_type) { case TST_NFS_MAGIC: case TST_BTRFS_MAGIC: tst_resm(TCONF, "%s supports odd count IO", tst_fs_type_name(fs_type)); break; default: ret = runtest_f(fd, buf2, offset, count, EINVAL, 3, "odd count"); testcheck_end(ret, &failed, &fail_count, "Odd count of read and write"); } total++; /* Test-4: Read beyond the file size */ offset = bufsize * (fblocks + 10); count = bufsize; if (lseek(fd, offset, SEEK_SET) < 0) { tst_resm(TFAIL, "lseek failed: %s", strerror(errno)); failed = TRUE; fail_count++; tst_resm(TFAIL, "Read beyond the file size"); } else { errno = 0; ret = read(fd, buf2, count); if (ret > 0 || (ret < 0 && errno != EINVAL)) { tst_resm(TFAIL, "allows read beyond file size. returns %d: %s", ret, strerror(errno)); failed = TRUE; fail_count++; } else tst_resm(TPASS, "Read beyond the file size"); } total++; /* Test-5: Invalid file descriptor */ offset = 4096; count = bufsize; newfd = -1; ret = runtest_f(newfd, buf2, offset, count, EBADF, 5, "negative fd"); testcheck_end(ret, &failed, &fail_count, "Invalid file descriptor"); total++; /* Test-6: Out of range file descriptor */ count = bufsize; offset = 4096; if ((newfd = getdtablesize()) < 0) { tst_resm(TFAIL, "getdtablesize() failed: %s", strerror(errno)); failed = TRUE; tst_resm(TFAIL, "Out of range file descriptor"); } else { ret = runtest_f(newfd, buf2, offset, count, EBADF, 6, "out of range fd"); testcheck_end(ret, &failed, &fail_count, "Out of range file descriptor"); } close(newfd); total++; /* Test-7: Closed file descriptor */ offset = 4096; count = bufsize; SAFE_CLOSE(cleanup, fd); ret = runtest_f(fd, buf2, offset, count, EBADF, 7, "closed fd"); testcheck_end(ret, &failed, &fail_count, "Closed file descriptor"); total++; /* Test-9: removed */ tst_resm(TPASS, "removed"); /* Test-9: Character device (/dev/null) read, write */ offset = 0; count = bufsize; if ((newfd = open("/dev/null", O_DIRECT | O_RDWR)) < 0) { tst_resm(TCONF, "Direct I/O on /dev/null is not supported"); } else { ret = runtest_s(newfd, buf2, offset, count, 9, "/dev/null"); testcheck_end(ret, &failed, &fail_count, "character device read, write"); } close(newfd); total++; /* Test-10: read, write to a mmaped file */ shm_base = (char *)(((long)sbrk(0) + (shmsz - 1)) & ~(shmsz - 1)); if (shm_base == NULL) { tst_brkm(TBROK, cleanup, "sbrk failed: %s", strerror(errno)); } offset = 4096; count = bufsize; if ((fd = open(filename, O_DIRECT | O_RDWR)) < 0) { tst_brkm(TBROK, cleanup, "can't open %s: %s", filename, strerror(errno)); } shm_base = mmap(shm_base, 0x100000, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, fd, 0); if (shm_base == (caddr_t) - 1) { tst_brkm(TBROK, cleanup, "can't mmap file: %s", strerror(errno)); } ret = runtest_s(fd, buf2, offset, count, 10, "mmapped file"); testcheck_end(ret, &failed, &fail_count, "read, write to a mmaped file"); total++; /* Test-11: read, write to an unmaped file with munmap */ if ((ret = munmap(shm_base, 0x100000)) < 0) { tst_brkm(TBROK, cleanup, "can't unmap file: %s", strerror(errno)); } ret = runtest_s(fd, buf2, offset, count, 11, "unmapped file"); testcheck_end(ret, &failed, &fail_count, "read, write to an unmapped file"); close(fd); total++; /* Test-12: read from file not open for reading */ offset = 4096; count = bufsize; if ((fd = open(filename, O_DIRECT | O_WRONLY)) < 0) { tst_brkm(TBROK, cleanup, "can't open %s: %s", filename, strerror(errno)); } if (lseek(fd, offset, SEEK_SET) < 0) { tst_resm(TFAIL, "lseek failed: %s", strerror(errno)); failed = TRUE; fail_count++; } else { errno = 0; ret = read(fd, buf2, count); if (ret >= 0 || errno != EBADF) { tst_resm(TFAIL, "allows read on file not open for reading. returns %d: %s", ret, strerror(errno)); failed = TRUE; fail_count++; } else tst_resm(TPASS, "read from file not open for reading"); } close(fd); total++; /* Test-13: write to file not open for writing */ offset = 4096; count = bufsize; if ((fd = open(filename, O_DIRECT | O_RDONLY)) < 0) { tst_brkm(TBROK, cleanup, "can't open %s: %s", filename, strerror(errno)); } if (lseek(fd, offset, SEEK_SET) < 0) { tst_resm(TFAIL, "lseek failed: %s", strerror(errno)); failed = TRUE; fail_count++; } else { errno = 0; ret = write(fd, buf2, count); if (ret >= 0 || errno != EBADF) { tst_resm(TFAIL, "allows write on file not open for writing. returns %d: %s", ret, strerror(errno)); failed = TRUE; fail_count++; } else tst_resm(TPASS, "write to file not open for writing"); } close(fd); total++; /* Test-14: read, write with non-aligned buffer */ offset = 4096; count = bufsize; if ((fd = open(filename, O_DIRECT | O_RDWR)) < 0) { tst_brkm(TBROK, cleanup, "can't open %s: %s", filename, strerror(errno)); } switch (fs_type) { case TST_NFS_MAGIC: case TST_BTRFS_MAGIC: tst_resm(TCONF, "%s supports non-aligned buffer", tst_fs_type_name(fs_type)); break; default: ret = runtest_f(fd, buf2 + 1, offset, count, EINVAL, 14, " nonaligned buf"); testcheck_end(ret, &failed, &fail_count, "read, write with non-aligned buffer"); } close(fd); total++; /* Test-15: read, write buffer in read-only space */ offset = 4096; count = bufsize; l_fail = 0; if ((fd = open(filename, O_DIRECT | O_RDWR)) < 0) { tst_brkm(TBROK, cleanup, "can't open %s: %s", filename, strerror(errno)); } if (lseek(fd, offset, SEEK_SET) < 0) { tst_resm(TFAIL, "lseek before read failed: %s", strerror(errno)); l_fail = TRUE; } else { errno = 0; ret = read(fd, (char *)((ulong) ADDRESS_OF_MAIN & pagemask), count); if (ret >= 0 || errno != EFAULT) { tst_resm(TFAIL, "read to read-only space. returns %d: %s", ret, strerror(errno)); l_fail = TRUE; } } if (lseek(fd, offset, SEEK_SET) < 0) { tst_resm(TFAIL, "lseek before write failed: %s", strerror(errno)); l_fail = TRUE; } else { ret = write(fd, (char *)((ulong) ADDRESS_OF_MAIN & pagemask), count); if (ret < 0) { tst_resm(TFAIL, "write to read-only space. returns %d: %s", ret, strerror(errno)); l_fail = TRUE; } } testcheck_end(l_fail, &failed, &fail_count, "read, write buffer in read-only space"); close(fd); total++; /* Test-16: read, write in non-existant space */ offset = 4096; count = bufsize; if ((buf1 = (char *)(((long)sbrk(0) + (shmsz - 1)) & ~(shmsz - 1))) == NULL) { tst_brkm(TBROK | TERRNO, cleanup, "sbrk failed"); } if ((fd = open(filename, O_DIRECT | O_RDWR)) < 0) { tst_brkm(TBROK | TERRNO, cleanup, "open(%s, O_DIRECT|O_RDWR) failed", filename); } ret = runtest_f(fd, buf1, offset, count, EFAULT, 16, " nonexistant space"); testcheck_end(ret, &failed, &fail_count, "read, write in non-existant space"); total++; close(fd); /* Test-17: read, write for file with O_SYNC */ offset = 4096; count = bufsize; if ((fd = open(filename, O_DIRECT | O_RDWR | O_SYNC)) < 0) { tst_brkm(TBROK, cleanup, "open(%s, O_DIRECT|O_RDWR|O_SYNC failed)", filename); } ret = runtest_s(fd, buf2, offset, count, 17, "opened with O_SYNC"); testcheck_end(ret, &failed, &fail_count, "read, write for file with O_SYNC"); total++; close(fd); unlink(filename); if (failed) tst_resm(TINFO, "%d/%d test blocks failed", fail_count, total); else tst_resm(TINFO, "%d testblocks completed", total); cleanup(); tst_exit(); }
void alarmfunc(int sig) { /* for some reason tst_brkm doesn't seem to work in a signal handler */ tst_brkm(TFAIL, cleanup, "one or more children did't die in 60 second " "time limit"); }
int main(int ac, char **av) { int lc; /* loop counter */ int fflag; /* functionality flag variable */ char *msg; /* message returned from parse_opts */ /* 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(); } /* Perform global setup for test */ setup(); /* 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; /* * Call mknod() to creat a node on a directory without * set group-ID (sgid) bit set. */ TEST(mknod(node_name, MODE_RWX, 0)); /* Check return code from mknod(2) */ if (TEST_RETURN == -1) { tst_resm(TFAIL, "mknod(%s, %#o, 0) failed, errno=%d : %s", node_name, MODE_RWX, TEST_ERRNO, strerror(TEST_ERRNO)); continue; } /* * Perform functional verification if test executed * without (-f) option. */ if (STD_FUNCTIONAL_TEST) { /* Set the functionality flag */ fflag = 1; /* Check for node's creation */ if (stat(node_name, &buf) < 0) { tst_resm(TFAIL, "stat() of %s failed, errno:%d", node_name, TEST_ERRNO); /* unset flag as functionality fails */ fflag = 0; } /* Verify mode permissions of node */ if (buf.st_mode & S_ISGID) { tst_resm(TFAIL, "%s: Incorrect modes, setgid " "bit set", node_name); /* unset flag as functionality fails */ fflag = 0; } /* Verify group ID */ if (buf.st_gid != mygid) { tst_resm(TFAIL, "%s: Incorrect group", node_name); /* unset flag as functionality fails */ fflag = 0; } if (fflag) { tst_resm(TPASS, "Functionality of mknod(%s, " "%#o, 0) successful", node_name, MODE_RWX); } } else { tst_resm(TPASS, "call succeeded"); } /* Remove the node for the next go `round */ if (unlink(node_name) == -1) { tst_resm(TWARN, \ "unlink(%s) failed, errno:%d %s", node_name, errno, strerror(errno)); } } /* Change the directory back to temporary directory */ chdir(".."); /* * Invoke cleanup() to delete the test directories created * in the setup() and exit main(). */ cleanup(); /*NOTREACHED*/ return(0); } /* End main */
int main(int ac, char **av) { int lc; char *msg; pid_t c_pid; int status, e_code; if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); } #ifdef UCLINUX #define PIPE_NAME "msgsnd06" maybe_run_child(&do_child, "d", &msg_q_1); #endif setup(); /* global setup */ if (sync_pipe_create(sync_pipes, PIPE_NAME) == -1) tst_brkm(TBROK, cleanup, "sync_pipe_create failed"); /* 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; msgkey = getipckey(); /* create a message queue with read/write permission */ if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW)) == -1) { tst_brkm(TBROK, cleanup, "Can't create message queue"); } /* initialize the message buffer */ init_buf(&msg_buf, MSGTYPE, MSGSIZE); /* write messages to the queue until it is full */ while (msgsnd(msg_q_1, &msg_buf, MSGSIZE, IPC_NOWAIT) != -1) { msg_buf.mtype += 1; } /* * fork a child that will attempt to write a message * to the queue without IPC_NOWAIT */ if ((c_pid = FORK_OR_VFORK()) == -1) { tst_brkm(TBROK, cleanup, "could not fork"); } if (c_pid == 0) { /* child */ #ifdef UCLINUX if (self_exec(av[0], "d", msg_q_1) < 0) { tst_brkm(TBROK, cleanup, "could not self_exec"); } #else do_child(); #endif } else { /* parent */ if (sync_pipe_wait(sync_pipes) == -1) tst_brkm(TBROK, cleanup, "sync_pipe_wait failed"); if (sync_pipe_close(sync_pipes, PIPE_NAME) == -1) tst_brkm(TBROK, cleanup, "sync_pipe_close failed"); /* After son has been created, give it a chance to execute the * msgsnd command before we continue. Without this sleep, on SMP machine * the father rm_queue could be executed before the son msgsnd. */ sleep(2); /* remove the queue */ rm_queue(msg_q_1); /* 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(); }
int main(int ac, char **av) { int lc; int i; int fildes; /* file descriptor of test file */ size_t nbytes; /* no. of bytes to be written */ off_t offset; /* offset position in the specified file */ char *test_desc; /* test specific error message */ tst_parse_opts(ac, av, NULL, NULL); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; /* loop through the test cases */ for (i = 0; Test_cases[i].desc != NULL; i++) { fildes = Test_cases[i].fd; test_desc = Test_cases[i].desc; nbytes = Test_cases[i].nb; offset = Test_cases[i].offst; if (fildes == 1) { fildes = pfd[0]; } else if (fildes == 2) { fildes = fd1; } /* * Call pread() with the specified file descriptor, * no. of bytes to be read from specified offset. * and verify that call should fail with appropriate * errno set. */ TEST(pread(fildes, read_buf[0], nbytes, offset)); /* Check for the return code of pread() */ if (TEST_RETURN != -1) { tst_brkm(TFAIL, cleanup, "pread() returned " "%ld, expected -1, errno:%d", TEST_RETURN, Test_cases[i].exp_errno); } /* * Verify whether expected errno is set. */ if (TEST_ERRNO == Test_cases[i].exp_errno) { tst_resm(TPASS, "pread() fails, %s, errno:%d", test_desc, TEST_ERRNO); } else { tst_resm(TFAIL, "pread() fails, %s, unexpected " "errno:%d, expected:%d", test_desc, TEST_ERRNO, Test_cases[i].exp_errno); } } } cleanup(); tst_exit(); }
/* * Kernel Samepage Merging (KSM) for NUMA * * Basic tests were to start several programs with same and different * memory contents and ensure only to merge the ones with the same * contents. When changed the content of one of merged pages in a * process and to the mode "unmerging", it should discard all merged * pages there. Also tested it is possible to disable KSM. There are * also command-line options to specify the memory allocation size, and * number of processes have same memory contents so it is possible to * test more advanced things like KSM + OOM etc. * * Prerequisites: * * 1) ksm and ksmtuned daemons need to be disabled. Otherwise, it could * distrub the testing as they also change some ksm tunables depends * on current workloads. * * The test steps are: * - Check ksm feature and backup current run setting. * - Change run setting to 1 - merging. * - 3 memory allocation programs have the memory contents that 2 of * them are all 'a' and one is all 'b'. * - Check ksm statistics and verify the content. * - 1 program changes the memory content from all 'a' to all 'b'. * - Check ksm statistics and verify the content. * - All programs change the memory content to all 'd'. * - Check ksm statistics and verify the content. * - Change one page of a process. * - Check ksm statistics and verify the content. * - Change run setting to 2 - unmerging. * - Check ksm statistics and verify the content. * - Change run setting to 0 - stop. * * Copyright (C) 2010 Red Hat, Inc. * * This program is free software; you can redistribute it and/or * modify it under the terms of version 2 of the GNU General Public * License as published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Further, this software is distributed without any warranty that it * is free of the rightful claim of any third person regarding * infringement or the like. Any license provided herein, whether * implied or otherwise, applies only to this software file. Patent * licenses, if any, provided herein do not apply to combinations of * this program with other software, or any other product whatsoever. * * You should have received a copy of the GNU General Public License * along with this program; if not, write the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA. */ #include "config.h" #include <sys/types.h> #include <sys/stat.h> #include <errno.h> #include <fcntl.h> #if HAVE_NUMAIF_H #include <numaif.h> #endif #include <signal.h> #include <stdio.h> #include <unistd.h> #include "test.h" #include "mem.h" char *TCID = "ksm02"; int TST_TOTAL = 1; static int merge_across_nodes; #if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \ && HAVE_MPOL_CONSTANTS option_t ksm_options[] = { {"n:", &opt_num, &opt_numstr}, {"s:", &opt_size, &opt_sizestr}, {"u:", &opt_unit, &opt_unitstr}, {NULL, NULL, NULL} }; int main(int argc, char *argv[]) { int lc; int size = 128, num = 3, unit = 1; unsigned long nmask[MAXNODES / BITS_PER_LONG] = { 0 }; unsigned int node; tst_parse_opts(argc, argv, ksm_options, ksm_usage); node = get_a_numa_node(tst_exit); set_node(nmask, node); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; check_ksm_options(&size, &num, &unit); if (set_mempolicy(MPOL_BIND, nmask, MAXNODES) == -1) { if (errno != ENOSYS) tst_brkm(TBROK | TERRNO, cleanup, "set_mempolicy"); else tst_brkm(TCONF, cleanup, "set_mempolicy syscall is not " "implemented on your system."); } create_same_memory(size, num, unit); write_cpusets(node); create_same_memory(size, num, unit); } cleanup(); tst_exit(); } void cleanup(void) { if (access(PATH_KSM "merge_across_nodes", F_OK) == 0) FILE_PRINTF(PATH_KSM "merge_across_nodes", "%d", merge_across_nodes); restore_max_page_sharing(); umount_mem(CPATH, CPATH_NEW); } void setup(void) { tst_require_root(); if (tst_kvercmp(2, 6, 32) < 0) tst_brkm(TCONF, NULL, "2.6.32 or greater kernel required"); if (access(PATH_KSM, F_OK) == -1) tst_brkm(TCONF, NULL, "KSM configuration is not enabled"); save_max_page_sharing(); if (access(PATH_KSM "merge_across_nodes", F_OK) == 0) { SAFE_FILE_SCANF(NULL, PATH_KSM "merge_across_nodes", "%d", &merge_across_nodes); SAFE_FILE_PRINTF(NULL, PATH_KSM "merge_across_nodes", "1"); } tst_sig(FORK, DEF_HANDLER, cleanup); TEST_PAUSE; mount_mem("cpuset", "cpuset", NULL, CPATH, CPATH_NEW); } #else /* no NUMA */ int main(void) { tst_brkm(TCONF, NULL, "no NUMA development packages installed."); }
/*********************************************************************** * Main ***********************************************************************/ int main(int ac, char **av) { int lc; /* loop counter */ const char *msg; /* message returned from parse_opts */ struct stat fbuf, lbuf; int cnt; char lname[255]; /*************************************************************** * parse standard options ***************************************************************/ if ( (msg=parse_opts(ac, av, options, &help)) != (char *) NULL ) { tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); tst_exit(); } if ( Nflag ) { if ( sscanf(Noptlinks, "%i", &nlinks) != 1 ) { tst_brkm(TBROK, cleanup, "-N option invalid, must be numeric"); } } /*************************************************************** * 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(cnt=1; cnt < nlinks; cnt++) { sprintf(lname, "%s%d", Basename, cnt); /* * Call link(2) */ TEST(link(Fname, lname)); /* check return code */ if ( TEST_RETURN == -1 ) { tst_resm(TFAIL, "link(%s, %s) Failed, errno=%d : %s", Fname, lname, TEST_ERRNO, strerror(TEST_ERRNO)); } } /*************************************************************** * only perform functional verification if flag set (-f not given) ***************************************************************/ if ( STD_FUNCTIONAL_TEST ) { stat(Fname, &fbuf); for(cnt=1; cnt < nlinks; cnt++) { sprintf(lname, "%s%d", Basename, cnt); stat(lname, &lbuf); if ( fbuf.st_nlink <= 1 || lbuf.st_nlink <= 1 || (fbuf.st_nlink != lbuf.st_nlink) ) { tst_resm(TFAIL, "link(%s, %s[1-%d]) ret %d for %d files, stat values do not match %d %d", Fname, Basename, nlinks, TEST_RETURN, nlinks, fbuf.st_nlink, lbuf.st_nlink); break; } } if ( cnt >= nlinks ) { tst_resm(TPASS, "link(%s, %s[1-%d]) ret %d for %d files, stat linkcounts match %d", Fname, Basename, nlinks, TEST_RETURN, nlinks, fbuf.st_nlink); } } else Tst_count++; #ifdef CRAY /* * IRIX (xfs) systems do not have the 1000 link limit. * I tried 100000 links on 2/97 without error on IRIX 6.4. */ /* * Now check that one more link will put you over the top */ sprintf(lname, "%s%d", Basename, cnt); /* * Call link(2) */ TEST(link(Fname, lname)); /* check return code */ if ( TEST_RETURN == -1 ) { if ( STD_FUNCTIONAL_TEST ) { if ( TEST_ERRNO == EMLINK ) { tst_resm(TPASS, "link(%s, %s) ret %d on %d link, errno:%d", Fname, lname, TEST_RETURN, nlinks+1, EMLINK); } else { tst_resm(TFAIL, "link(%s, %s) ret %d on %d link, errno:%d, expected -1, errno:%d", Fname, lname, TEST_RETURN, nlinks+1, TEST_ERRNO, EMLINK); } } else Tst_count++; } else { tst_resm(TFAIL, "link(%s, %s) ret %d on %d link, expected -1, errno:%d", Fname, lname, TEST_RETURN, nlinks+1, EMLINK); } #endif /* CRAY */ for(cnt=1; cnt < nlinks; cnt++) { sprintf(lname, "%s%d", Basename, cnt); if (unlink(lname) == -1) { tst_res(TWARN, "unlink(%s) Failed, errno=%d : %s", Fname, errno, strerror(errno)); } } } /* End for TEST_LOOPING */ /*************************************************************** * cleanup and exit ***************************************************************/ cleanup(); return 0; } /* End main */
/* * check_functionality - check various conditions to make sure they * are correct. */ void check_functionality(int i) { void *orig_add; int *shared; int fail = 0; struct shmid_ds buf; shared = (int *)addr; /* stat the shared memory ID */ if (shmctl(shm_id_1, IPC_STAT, &buf) == -1) { tst_brkm(TBROK, cleanup, "couldn't stat shared memory"); } /* check the number of attaches */ if (buf.shm_nattch != 1) { tst_resm(TFAIL, "# of attaches is incorrect"); return; } /* check the size of the segment */ if (buf.shm_segsz != INT_SIZE) { tst_resm(TFAIL, "segment size is incorrect"); return; } /* check for specific conditions depending on the type of attach */ switch (i) { case 0: /* * Check the functionality of the first call by simply * "writing" a value to the shared memory space. * If this fails the program will get a SIGSEGV, dump * core and exit. */ *shared = CASE0; break; case 1: /* * Check the functionality of the second call by writing * a value to the shared memory space and then checking * that the original address given was rounded down as * specified in the man page. */ *shared = CASE1; orig_add = addr + ((unsigned long)TC[1].offset % SHMLBA); if (orig_add != base_addr + TC[1].offset) { tst_resm(TFAIL, "shared memory address is not " "correct"); fail = 1; } break; case 2: /* * This time the shared memory is read only. Read the value * and check that it is equal to the value set in case #2, * because shared memory is persistent. */ if (*shared != CASE1) { tst_resm(TFAIL, "shared memory value isn't correct"); fail = 1; } break; } if (!fail) { tst_resm(TPASS, "conditions and functionality are correct"); } }
int main(int ac, char **av) { int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ pid_t pid, fake_pid; int exno, status, fake_status, nsig; /* parse standard options */ if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); } #ifdef UCLINUX maybe_run_child(&do_child, ""); #endif setup(); /* global setup */ TEST_EXP_ENOS(exp_enos); /* 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; status = 1; exno = 1; pid = FORK_OR_VFORK(); if (pid < 0) { tst_brkm(TBROK, cleanup, "Fork failed"); } else if (pid == 0) { #ifdef UCLINUX if (self_exec(av[0], "") < 0) { tst_brkm(TBROK, cleanup, "self_exec of child failed"); } #else do_child(); #endif } else { fake_pid = FORK_OR_VFORK(); if (fake_pid < 0) { tst_brkm(TBROK, cleanup, "Second fork failed"); } else if (fake_pid == 0) { #ifdef UCLINUX if (self_exec(av[0], "") < 0) { tst_brkm(TBROK, cleanup, "second self_exec " "of child failed"); } #else do_child(); #endif } kill(fake_pid, TEST_SIG); waitpid(fake_pid, &fake_status, 0); TEST(kill(fake_pid, TEST_SIG)); kill(pid, TEST_SIG); waitpid(pid, &status, 0); } if (TEST_RETURN != -1) { tst_brkm(TFAIL, cleanup, "%s failed - errno = %d : %s " "Expected a return value of -1 got %ld", TCID, TEST_ERRNO, strerror(TEST_ERRNO), TEST_RETURN); } if (STD_FUNCTIONAL_TEST) { /* * Check to see if the errno was set to the expected * value of 3 : ESRCH */ nsig = WTERMSIG(status); TEST_ERROR_LOG(TEST_ERRNO); if (TEST_ERRNO == ESRCH) { tst_resm(TPASS, "errno set to %d : %s, as " "expected", TEST_ERRNO, strerror(TEST_ERRNO)); } else { tst_resm(TFAIL, "errno set to %d : %s expected " "%d : %s", TEST_ERRNO, strerror(TEST_ERRNO), 3, strerror(3)); } } } cleanup(); tst_exit(); }
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; if (write(fd, s, READ_BLOCK_SIZE) == -1) { tst_brkm(TBROK, cleanup, "write(%s, %s, %d) Failed, errno=%d : %s", fname, s, READ_BLOCK_SIZE, errno, strerror(errno)); } offset+=READ_BLOCK_SIZE; if (lseek(fd, (long)(offset-READ_BLOCK_SIZE), 0) == -1) { tst_brkm(TBROK, cleanup, "lseek(%s, %ld, 0) Failed, errno=%d : %s", fname, (long)(offset-READ_BLOCK_SIZE), errno, strerror(errno)); } /* * Call read(2) */ TEST(read(fd, s, READ_BLOCK_SIZE)); /* check return code */ if ( TEST_RETURN == -1 ) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, "read(fd, s, READ_BLOCK_SIZE) 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, "read(pfds) returned %d", TEST_RETURN); } } } /* End for TEST_LOOPING */ /*************************************************************** * cleanup and exit ***************************************************************/ cleanup(); return 0; } /* End main */
int main(int ac, char **av) { int lc; const char *msg; char read_buf[BUF_SIZE]; /* buffer to hold data read from file */ int nread = 0, count, err_flg = 0; if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; setup(); TEST(msync(addr, page_sz, MS_ASYNC)); if (TEST_RETURN == -1) { tst_resm(TFAIL | TERRNO, "msync failed"); continue; } if (STD_FUNCTIONAL_TEST) { if (lseek(fildes, (off_t) 100, SEEK_SET) != 100) tst_brkm(TBROK | TERRNO, cleanup, "lseek failed"); /* * Seeking to specified offset. successful. * Now, read the data (256 bytes) and compare * them with the expected. */ nread = read(fildes, read_buf, sizeof(read_buf)); if (nread != BUF_SIZE) tst_brkm(TBROK, cleanup, "read failed"); else { /* * Check whether read data (from mapped * file) contains the expected data * which was initialised in the setup. */ for (count = 0; count < nread; count++) if (read_buf[count] != 1) err_flg++; } if (err_flg != 0) tst_resm(TFAIL, "data read from file doesn't match"); else tst_resm(TPASS, "Functionality of msync() successful"); } else tst_resm(TPASS, "call succeeded"); cleanup(); } tst_exit(); }
int main(int ac, char **av) { int lc; char *msg; pid_t cpid; /* Child process id */ int status; /* child exit status */ /* Parse standard options given to run the test. */ if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); #ifdef UCLINUX maybe_run_child(&do_child, "dddd", &timereq.tv_sec, &timereq.tv_nsec, &timerem.tv_sec, &timerem.tv_nsec); #endif setup(); /* set the expected errnos... */ TEST_EXP_ENOS(exp_enos); for (lc = 0; TEST_LOOPING(lc); lc++) { Tst_count = 0; /* * Creat a child process and suspend its * execution using nanosleep() */ if ((cpid = FORK_OR_VFORK()) == -1) { tst_brkm(TBROK, cleanup, "fork() failed"); } if (cpid == 0) { /* Child process */ #ifdef UCLINUX if (self_exec(av[0], "dddd", timereq.tv_sec, timereq.tv_nsec, timerem.tv_sec, timerem.tv_nsec) < 0) { tst_brkm(TBROK, cleanup, "self_exec failed"); } #else do_child(); #endif } /* wait for child to time slot for execution */ sleep(1); /* Now send signal to child */ if (kill(cpid, SIGINT) < 0) { tst_brkm(TBROK, cleanup, "kill() fails send signal to child"); } /* Wait for child to execute */ wait(&status); if (WIFEXITED(status) && WEXITSTATUS(status) == 0) { tst_resm(TPASS, "nanosleep() failed, interrupted" " by signal (%d) as expected", EINTR); } else { tst_resm(TFAIL, "child process exited abnormally; " "status = %d", status); } } cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc; char *msg; int i; char *comp_string; comp_string = NULL; if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); 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) { osnamelth = SIZE(osname); switch (i) { case 0: comp_string = buf.sysname; break; case 1: comp_string = buf.release; break; case 2: comp_string = buf.version; break; } TEST(sysctl(TC[i].name, TC[i].size, TC[i].oldval, TC[i].oldlen, TC[i].newval, TC[i].newlen)); if (TEST_RETURN != 0) { if (TEST_ERRNO == ENOSYS) { tst_resm(TCONF, "You may need to make CONFIG_SYSCTL_SYSCALL=y" " to your kernel config."); } else { tst_resm(TFAIL, "sysctl(2) failed unexpectedly " "errno:%d", TEST_ERRNO); } continue; } if (!STD_FUNCTIONAL_TEST) { tst_resm(TPASS, "call succeeded"); continue; } if (strcmp(TC[i].oldval, comp_string) != 0) { tst_resm(TFAIL, "strings don't match - %s : %s", TC[i].oldval, comp_string); } else { tst_resm(TPASS, "%s is correct", TC[i].desc); } if (TC[i].cleanup) { (void)TC[i].cleanup(); } } } cleanup(); tst_exit(); }
int main() { tst_brkm(TCONF, NULL, "O_DIRECT is not defined."); }
int main(int ac, char **av) { struct stat stat_buf; /* stat(2) struct contents */ int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ off_t file_length; /* test file length */ /* 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(); /* set the expected errnos... */ TEST_EXP_ENOS(exp_enos); for (lc = 0; TEST_LOOPING(lc); lc++) { Tst_count = 0; /* * Call truncate(2) to truncate a test file to a * specified length. */ TEST(truncate(TESTFILE, TRUNC_LEN)); if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, "truncate(%s, %d) Failed, errno=%d : %s", TESTFILE, TRUNC_LEN, TEST_ERRNO, strerror(TEST_ERRNO)); } else { /* * Perform functional verification if test * executed without (-f) option. */ if (STD_FUNCTIONAL_TEST) { /* * Get the testfile information using * stat(2). */ if (stat(TESTFILE, &stat_buf) < 0) { tst_brkm(TFAIL, cleanup, "stat(2) of " "%s failed, error:%d", TESTFILE, errno); } stat_buf.st_mode &= ~S_IFREG; file_length = stat_buf.st_size; /* * Check for expected size of testfile after * truncate(2) on it. */ if (file_length != TRUNC_LEN) { tst_resm(TFAIL, "%s: Incorrect file " "size %"PRId64", Expected %d", TESTFILE, (int64_t)file_length, TRUNC_LEN); } else { tst_resm(TPASS, "Functionality of " "truncate(%s, %d) successful", TESTFILE, TRUNC_LEN); } } else { tst_resm(TPASS, "%s call succeeded", TCID); } } Tst_count++; /* incr TEST_LOOP counter */ } cleanup(); tst_exit(); }
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, 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; /* * Call lseek(2) */ TEST( lseek(-1, (long)1, SEEK_SET) ); /* check return code */ if ( TEST_RETURN == -1 ) { if ( STD_FUNCTIONAL_TEST ) { if ( TEST_ERRNO == EBADF ) tst_resm(TPASS, "lseek(-1, 1, SEEK_SET) Failed, errno=%d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); else tst_resm(TFAIL, "lseek(-1, 1, SEEK_SET) Failed, errno=%d : %s, expected %d(EBADF)", TEST_ERRNO, strerror(TEST_ERRNO), EBADF); } else Tst_count++; } else { tst_resm(TFAIL, "lseek(-1, 1, SEEK_SET) returned %d", TEST_RETURN); } } /* End for TEST_LOOPING */ /*************************************************************** * cleanup and exit ***************************************************************/ cleanup(); return 0; } /* End main */
int main(int ac, char **av) { int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ int i, red, wtstatus; int pipefd[2]; /* fds for pipe read/write */ char rebuf[BUFSIZ]; int Acnt = 0, Bcnt = 0; /* count 'A' and 'B' */ int fork_1, fork_2; /* ret values in parent */ /* 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); /*NOTREACHED*/ } setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { /* reset Tst_count in case we are looping */ Tst_count = 0; TEST(pipe(pipefd)); if (TEST_RETURN == -1) { tst_resm(TFAIL, "pipe() call failed"); continue; } if (!STD_FUNCTIONAL_TEST) { tst_resm(TWARN, "-f option should not be used"); tst_resm(TPASS, "call succeeded"); continue; } if ((fork_1 = FORK_OR_VFORK()) == -1) { tst_brkm(TBROK, cleanup, "fork() #1 failed"); /*NOTREACHED*/ } if (fork_1 == 0) { /* 1st child */ if (close(pipefd[0]) != 0) { tst_resm(TWARN, "pipefd[0] close failed, " "errno = %d", errno); exit(1); } for (i = 0; i < PIPEWRTCNT / 2; ++i) { if (write(pipefd[1], "A", 1) != 1) { tst_resm(TWARN, "write to pipe failed"); exit(1); } } exit(0); } /* parent */ waitpid(fork_1, &wtstatus, 0); if (WEXITSTATUS(wtstatus) != 0) { tst_brkm(TBROK, cleanup, "problem detected in child, " "wait status %d, errno = %d", wtstatus, errno); } if ((fork_2 = FORK_OR_VFORK()) == -1) { tst_brkm(TBROK, cleanup, "fork() #2 failed"); /*NOTREACHED*/ } if (fork_2 == 0) { /* 2nd child */ if (close(pipefd[0]) != 0) { tst_resm(TWARN, "pipefd[0] close " "failed, errno = %d", errno); exit(1); } for (i = 0; i < PIPEWRTCNT / 2; ++i) { if (write(pipefd[1], "B", 1) != 1) { tst_resm(TWARN, "write to pipe failed"); exit(1); } } exit(0); } /* parent */ waitpid(fork_2, &wtstatus, 0); if (WEXITSTATUS(wtstatus) != 0) { tst_brkm(TBROK, cleanup, "problem detected in child, " "wait status %d, errno = %d", wtstatus, errno); } if (close(pipefd[1]) != 0) { tst_brkm(TBROK, cleanup, "pipefd[1] close failed, " "errno = %d", errno); /*NOTREACHED*/ } while ((red = safe_read(pipefd[0], rebuf, 100)) > 0) { for (i = 0; i < red; i++) { if (rebuf[i] == 'A') { Acnt++; continue; } if (rebuf[i] == 'B') { Bcnt++; continue; } tst_resm(TFAIL, "got bogus '%c' character", rebuf[i]); break; } } if (red == -1) { tst_brkm(TBROK, cleanup, "Failure reading pipefd pipe, " "errno = %d", errno); } if (Bcnt == Acnt && Bcnt == (PIPEWRTCNT / 2)) { tst_resm(TPASS, "functionality appears to be correct"); } else { tst_resm(TFAIL, "functionality is not correct - Acnt " "= %d, Bcnt = %d", Acnt, Bcnt); } /* clean up things in case we are looping */ Acnt = Bcnt = 0; } cleanup(); /*NOTREACHED*/ return 0; }
int main(int ac, char **av) { int lc; char *msg; int i; /* Disable test if the version of the kernel is less than 2.6.16 */ if ((tst_kvercmp(2, 6, 16)) < 0) { tst_resm(TWARN, "This test can only run on kernels that are "); tst_resm(TWARN, "2.6.16 and higher"); exit(0); } /*************************************************************** * 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 looping state if -c option given ***************************************************************/ for (lc = 0; TEST_LOOPING(lc); lc++) { setup_every_copy(); Tst_count = 0; /* * Call openat */ for (i = 0; i < TST_TOTAL; i++) { TEST(myopenat (fds[i], filenames[i], O_CREAT | O_WRONLY, 0600)); /* check return code */ if (TEST_ERRNO == expected_errno[i]) { /*************************************************************** * only perform functional verification if flag set (-f not given) ***************************************************************/ if (STD_FUNCTIONAL_TEST) { /* No Verification test, yet... */ tst_resm(TPASS, "openat() returned the expected errno %d: %s", TEST_ERRNO, strerror(TEST_ERRNO)); } } else { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, "openat() Failed, errno=%d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); } } } /*************************************************************** * cleanup and exit ***************************************************************/ cleanup(); return (0); }
int main(int ac, char **av) { int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ struct passwd *nobody; pid_t pid; struct sched_param param; int status; /* 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); /*NOTREACHED*/} setup(); TEST_EXP_ENOS(exp_enos); /* check 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, "fork failed"); } if (pid == 0) { /* child */ param.sched_priority = 1; nobody = my_getpwnam(user1name); if (seteuid(nobody->pw_uid) == -1) { tst_brkm(TBROK, cleanup, "seteuid() failed"); } TEST(sched_setscheduler(pid, SCHED_FIFO, ¶m)); if (TEST_ERRNO) { TEST_ERROR_LOG(TEST_ERRNO); } if (TEST_RETURN != -1) { tst_resm(TFAIL, "sched_setscheduler(2) passed " "with non root priveledges"); } else if (TEST_ERRNO != EPERM) { tst_resm(TFAIL, "Expected EPERM, got %d", TEST_ERRNO); } else { tst_resm(TPASS, "got EPERM"); } } else { /* parent */ /* let the child carry on */ wait(&status); if (WIFEXITED(status) != 0) { /* Exit with errors */ exit(WEXITSTATUS(status)); } else { exit(0); } } if (seteuid(0) == -1) { tst_brkm(TBROK, cleanup, "seteuid(0) failed"); } } cleanup(); /*NOTREACHED*/ return 0; }
int main(int ac, char **av) { int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ int status; /* child process exit status */ int rval; /* return value for wait() */ /* Parse standard options given to run the test. */ msg = parse_opts(ac, av, (option_t *) NULL, NULL); if (msg != (char *)NULL) { tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg); } #ifdef UCLINUX maybe_run_child(&do_child_uclinux, ""); #endif /* Perform global setup for test */ 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; /* Creat a new process using fork() */ if ((cpid = FORK_OR_VFORK()) == -1) { tst_brkm(TBROK, cleanup, "fork() failed"); } if (cpid == 0) { /* Child process */ #ifdef UCLINUX if (self_exec(av[0], "") < 0) { tst_brkm(TBROK, cleanup, "self_exec failed"); } #else do_child(); #endif } /* Parent process */ /* sleep to ensure the child executes */ sleep(1); /* * Send the SIGINT signal now, so that child * returns from pause and resumes execution. */ kill(cpid, SIGINT); /* Sleep to ensure the signal sent is effected */ sleep(1); /* * In case pause() doesn't return witin 2 seconds, * set the alarm to send SIGKILL for the child. */ signal(SIGALRM, kill_handle); alarm(2); /* wait for child to exit */ wait(&status); TEST_ERROR_LOG(status >> 8); /* Reset the timer in case pause() returned */ alarm(0); /* * Verify that, wait() returned due to normal * or abnormal termination of child due to * receipt of signal SIGKILL. * Receipt of SIGKILL indicates that pause() * didn't returned after receipt of SIGINT. */ if (WTERMSIG(status) == SIGKILL) { rval = wait(&status); if ((rval == -1) && (errno == ECHILD)) { tst_resm(TFAIL, "pause() didn't return " "as expected"); } } } /* End for TEST_LOOPING */ /* Call cleanup() to undo setup done for the test. */ cleanup(); return 0; } /* End main */
int main(int ac, char **av) { int lc; char *msg; TST_TOTAL = (sizeof(args) / sizeof(args[0])) - 1; /*************************************************************** * parse standard options ***************************************************************/ if ((msg = parse_opts(ac, av, options, &help)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); if (!lflag) { path = strdup("/tmp"); } /*************************************************************** * 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 (i = 0; i < TST_TOTAL; i++) { errno = -4; /* * Call pathconf(2) */ TEST(pathconf(path, args[i].value)); /* * A test case can only fail if -1 is returned and the errno * was set. If the errno remains unchanged, the * system call did not fail. */ if (TEST_RETURN == -1 && errno != -4) { tst_resm(TFAIL, "pathconf(%s, %s) Failed, errno=%d : %s", path, args[i].define_tag, 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, "pathconf(%s, %s) returned %ld", path, args[i].define_tag, TEST_RETURN); } } } } /*************************************************************** * cleanup and exit ***************************************************************/ cleanup(); tst_exit(); }
int main(int argc, char **argv) { int lc; tst_parse_opts(argc, argv, NULL, NULL); setup(); pass = 0; for (lc = 0; TEST_LOOPING(lc); lc++) { int i, pid; tst_count = 0; if ((pid = FORK_OR_VFORK()) == -1) { tst_brkm(TBROK, cleanup, "fork failed"); } else if (pid == 0) { /* child */ for (i = 0; i < TST_TOTAL; i++) { /* Set the real or effective user id */ TEST(SETREUID(cleanup, *test_data[i].real_uid, *test_data[i].eff_uid)); if (TEST_RETURN == *test_data[i].exp_ret) { if (TEST_RETURN == neg_one) { if (TEST_ERRNO != EPERM) { tst_resm(TFAIL, "setreuid(%d, %d) " "did not set errno " "value as expected.", *test_data [i].real_uid, *test_data [i].eff_uid); continue; } tst_resm(TPASS, "setreuid(%d, %d) " "failed as expected.", *test_data[i].real_uid, *test_data[i].eff_uid); } else { tst_resm(TPASS, "setreuid(%d, %d) " "succeeded as expected.", *test_data[i].real_uid, *test_data[i].eff_uid); } } else { tst_resm(TFAIL, "setreuid(%d, %d) " "did not return as expected.", *test_data[i].real_uid, *test_data[i].eff_uid); } if (TEST_RETURN == -1) { } uid_verify(test_data[i].exp_real_usr, test_data[i].exp_eff_usr, test_data[i].test_msg); } tst_exit(); } else { /* parent */ tst_record_childstatus(cleanup, pid); } } cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc; char *msg; char *node_name; /* ptr. for node name created */ char *test_desc; /* test specific error message */ int ind; /* counter to test different test conditions */ 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 * for the test which run as root/super-user. */ 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++) { 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); } } } /* * Invoke cleanup() to delete the test directories created * in the setup(). */ cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ int i; /* * 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 */ 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; /* loop through the test cases */ for (i = 0; i < TST_TOTAL; i++) { TEST(rename(TC[i].fd1, TC[i].fd2)); if (TEST_RETURN != -1) { tst_resm(TFAIL, "call succeeded unexpectedly"); continue; } TEST_ERROR_LOG(TEST_ERRNO); if (TEST_ERRNO == TC[i].error) { tst_resm(TPASS, "expected failure - " "errno = %d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); } else { tst_resm(TFAIL, "unexpected error - %d : %s - " "expected %d", TEST_ERRNO, strerror(TEST_ERRNO), TC[i].error); } } } /* End for TEST_LOOPING */ /* * cleanup and exit */ cleanup(); /*NOTREACHED*/ return 0; }
int main(int ac, char **av) { int lc,getmaxid=0; /* loop counter */ char *msg; /* message returned from parse_opts */ FILE *fp; /* parse standard options */ if ((msg = parse_opts(ac, av, (option_t *)NULL, NULL)) != (char *)NULL){ tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg); } /* Set the MAXIDS for the specific machine by reading the system limit for SEMMNI - The maximum number of sempahore sets */ if((fp = fopen("/proc/sys/kernel/sem", "r")) != NULL) { for(lc= 0; lc < 4; lc++) { if(lc == 3) { if(getmaxid > MAXIDS) MAXIDS=getmaxid; } } } if(fp) fclose(fp); sem_id_arr = (int*)malloc(sizeof(int)*MAXIDS); 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; /* use the TEST macro to make the call */ TEST(semget(semkey + num_sems, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA)); /* printf("rc = %ld \n", TEST_RETURN); */ if (TEST_RETURN != -1) { tst_resm(TFAIL, "call succeeded when error expected"); continue; } TEST_ERROR_LOG(TEST_ERRNO); switch(TEST_ERRNO) { case ENOSPC: tst_resm(TPASS, "expected failure - errno " "= %d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); break; default: tst_resm(TFAIL, "unexpected error - %d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); break; } } cleanup(); /*NOTREACHED*/ return(0); }
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 */ cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc; char *msg; pid_t c1pid, c2pid; int wtstatus; int bytesread; int acnt = 0, bcnt = 0; char rbuf[BUFSIZ]; if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); #ifdef UCLINUX maybe_run_child(&c1func, "ndd", 1, &fildes[0], &fildes[1]); maybe_run_child(&c2func, "ndd", 2, &fildes[0], &fildes[1]); #endif setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { /* reset Tst_count in case we are looping */ Tst_count = 0; if (pipe(fildes) == -1) tst_brkm(TBROK, cleanup, "pipe() failed - errno %d", errno); if ((c1pid = FORK_OR_VFORK()) == -1) tst_brkm(TBROK, cleanup, "fork() failed - " "errno %d", errno); if (c1pid == 0) #ifdef UCLINUX if (self_exec(av[0], "ndd", 1, fildes[0], fildes[1]) < 0) { tst_brkm(TBROK, cleanup, "self_exec failed"); } #else c1func(); #endif if ((c2pid = FORK_OR_VFORK()) == -1) tst_brkm(TBROK, cleanup, "fork() failed - " "errno %d", errno); if (c2pid == 0) #ifdef UCLINUX if (self_exec(av[0], "ndd", 2, fildes[0], fildes[1]) < 0) { tst_brkm(TBROK, cleanup, "self_exec failed"); } #else c2func(); #endif /* PARENT */ if (close(fildes[1]) == -1) tst_resm(TWARN, "Could not close fildes[1] - errno %d", errno); /* * Read a bit from the children first */ while ((acnt < 100) && (bcnt < 100)) { bytesread = safe_read(fildes[0], rbuf, sizeof(rbuf)); if (bytesread < 0) { tst_resm(TFAIL, "Unable to read from pipe, " "errno=%d", errno); break; } switch (rbuf[1]) { case 'A': acnt++; break; case 'b': bcnt++; break; default: tst_resm(TFAIL, "Got bogus '%c' " "character", rbuf[1]); break; } } /* * Try to kill the children */ if (kill(c1pid, SIGKILL) == -1) tst_resm(TFAIL, "failed to kill child 1, errno=%d", errno); if (kill(c2pid, SIGKILL) == -1) tst_resm(TFAIL, "failed to kill child 1, errno=%d", errno); /* * Set action for the alarm */ if (signal(SIGALRM, alarmfunc) == SIG_ERR) tst_resm(TWARN|TERRNO, "call to signal failed"); /* * Set an alarm for 60 seconds just in case the child * processes don't die */ alarm(60); if (waitpid(c1pid, &wtstatus, 0) != -1) { if (wtstatus != SIGKILL) tst_resm(TFAIL|TERRNO, "unexpected wait status " "%d", wtstatus); else tst_resm(TPASS, "Child 1 killed while " "writing to a pipe"); } if (waitpid(c2pid, &wtstatus, 0) != -1) { if (!WIFSIGNALED(wtstatus) || WTERMSIG(wtstatus) != SIGKILL) tst_resm(TFAIL|TERRNO, "unexpected wait status " "%d", wtstatus); else tst_resm(TPASS, "Child 2 killed while " "writing to a pipe"); } if (alarm(0) <= 0) tst_resm(TWARN, "call to alarm(0) failed"); } cleanup(); tst_exit(); }
int main(int argc, char *argv[]) { int clt_sk, svr_sk, accept_sk; sockaddr_storage_t svr_loop, accept_loop; sockaddr_storage_t svr_local_addr, svr_peer_addr; sockaddr_storage_t clt_local_addr, clt_peer_addr; socklen_t len; int error; int pf_class; /* Rather than fflush() throughout the code, set stdout to * be unbuffered. */ setvbuf(stdout, NULL, _IONBF, 0); /* Initialize the server and client addresses. */ #if TEST_V6 pf_class = PF_INET6; svr_loop.v6.sin6_family = AF_INET6; svr_loop.v6.sin6_addr = (struct in6_addr)SCTP_IN6ADDR_ANY_INIT; svr_loop.v6.sin6_port = htons(SCTP_TESTPORT_1); #else pf_class = PF_INET; svr_loop.v4.sin_family = AF_INET; svr_loop.v4.sin_addr.s_addr = INADDR_ANY; svr_loop.v4.sin_port = htons(SCTP_TESTPORT_1); #endif /* Create and bind the listening server socket. */ svr_sk = test_socket(pf_class, SOCK_STREAM, IPPROTO_SCTP); test_bind(svr_sk, &svr_loop.sa, sizeof(svr_loop)); memset(&svr_local_addr, 0x00, sizeof(svr_local_addr)); len = sizeof(svr_local_addr); /* Verify that getsockname() on an unconnected socket works fine. */ error = getsockname(svr_sk, (struct sockaddr *)&svr_local_addr, &len); if (0 != error) tst_brkm(TBROK, NULL, "getsockname: %s", strerror(errno)); tst_resm(TPASS, "getsockname on an unconnected socket"); memset(&svr_peer_addr, 0x00, sizeof(svr_peer_addr)); len = sizeof(svr_peer_addr); /* Verify that getpeername() on an unconnected socket fails. */ error = getpeername(svr_sk, (struct sockaddr *)&svr_peer_addr, &len); if ((-1 != error) || (ENOTCONN != errno)) tst_brkm(TBROK, NULL, "getpeername on an unconnected " "socket error:%d, errno:%d", error, errno); tst_resm(TPASS, "getpeername on an unconnected socket"); /* Mark svr_sk as being able to accept new associations. */ test_listen(svr_sk, 5); /* Create the client socket. */ clt_sk = test_socket(pf_class, SOCK_STREAM, IPPROTO_SCTP); /* Do a blocking connect from clt_sk to svr_sk */ #if TEST_V6 svr_loop.v6.sin6_addr = in6addr_loopback; #else svr_loop.v4.sin_addr.s_addr = SCTP_IP_LOOPBACK; #endif test_connect(clt_sk, &svr_loop.sa, sizeof(svr_loop)); memset(&clt_local_addr, 0x00, sizeof(clt_local_addr)); len = sizeof(clt_local_addr); /* Get the client's local address. */ error = getsockname(clt_sk, (struct sockaddr *)&clt_local_addr, &len); if (0 != error) tst_brkm(TBROK, NULL, "getsockname on a connected client " "socket: %s", strerror(errno)); tst_resm(TPASS, "getsockname on a connected client socket"); memset(&clt_peer_addr, 0x00, sizeof(clt_peer_addr)); len = sizeof(clt_peer_addr); /* Get the client's peer address. */ error = getpeername(clt_sk, (struct sockaddr *)&clt_peer_addr, &len); if (0 != error) tst_brkm(TBROK, NULL, "getpeername on a connected client " "socket: %s", strerror(errno)); tst_resm(TPASS, "getpeername on a connected client socket"); /* Extract the association on the listening socket as a new socket. */ len = sizeof(accept_loop); accept_sk = test_accept(svr_sk, &accept_loop.sa, &len); memset(&svr_local_addr, 0x00, sizeof(svr_local_addr)); len = sizeof(svr_local_addr); /* Get the server's local address. */ error = getsockname(accept_sk, (struct sockaddr *)&svr_local_addr, &len); if (0 != error) tst_brkm(TBROK, NULL, "getsockname on a connected server " "socket: %s", strerror(errno)); tst_resm(TPASS, "getsockname on a connected server socket"); memset(&svr_peer_addr, 0x00, sizeof(svr_peer_addr)); len = sizeof(svr_peer_addr); /* Get the server's peer address. */ error = getpeername(accept_sk, (struct sockaddr *)&svr_peer_addr, &len); if (0 != error) tst_brkm(TBROK, NULL, "getpeername on a connected server " "socket: %s", strerror(errno)); tst_resm(TPASS, "getpeername on a connected server socket"); if (svr_local_addr.v4.sin_port != clt_peer_addr.v4.sin_port) tst_brkm(TBROK, NULL, "Server's local port(%d) doesn't " "match Client's peer port(%d)\n", svr_local_addr.v4.sin_port, clt_peer_addr.v4.sin_port); if (svr_peer_addr.v4.sin_port != clt_local_addr.v4.sin_port) tst_brkm(TBROK, NULL, "Server's peer port(%d) doesn't " "match Client's local port(%d)\n", svr_peer_addr.v4.sin_port, clt_local_addr.v4.sin_port); #if TEST_V6 if (memcmp(&svr_local_addr, &clt_peer_addr, len) != 0) tst_brkm(TBROK, NULL, "Server's local address and client's " "peer addresses do not match\n"); if (memcmp(&svr_peer_addr, &clt_local_addr, len) != 0) tst_brkm(TBROK, NULL, "Server's peer address and client's " "local addresses do not match\n"); #else if (svr_local_addr.v4.sin_addr.s_addr != clt_peer_addr.v4.sin_addr.s_addr) tst_brkm(TBROK, NULL, "Server's local address and client's " "peer addresses do not match\n"); if (svr_peer_addr.v4.sin_addr.s_addr != clt_local_addr.v4.sin_addr.s_addr) tst_brkm(TBROK, NULL, "Server's peer address and client's " "local addresses do not match\n"); #endif tst_resm(TPASS, "getsockname/getpeername server/client match"); memset(&clt_local_addr, 0x00, sizeof(clt_local_addr)); len = sizeof(clt_local_addr); /*getsockname(): Bad socket descriptor, EBADF expected error*/ error = getsockname(-1, (struct sockaddr *)&clt_local_addr, &len); if (error != -1 || errno != EBADF) tst_brkm(TBROK, NULL, "getsockname on a bad socket " "descriptor. error:%d errno:%d", error, errno); tst_resm(TPASS, "getsockname on a bad socket descriptor - EBADF"); /*getsockname(): Invalid socket, ENOTSOCK expected error*/ error = getsockname(0, (struct sockaddr *)&clt_local_addr, &len); if (error != -1 || errno != ENOTSOCK) tst_brkm(TBROK, NULL, "getsockname on an invalid socket " "error:%d errno:%d", error, errno); tst_resm(TPASS, "getsockname on an invalid socket - ENOTSOCK"); /*getsockname(): Invalid structure, EFAULT expected error*/ error = getsockname(clt_sk, (struct sockaddr *)-1, &len); if (error != -1 || errno != EFAULT) tst_brkm(TBROK, NULL, "getsockname with invalid buffer " "error:%d errno:%d", error, errno); tst_resm(TPASS, "getsockname with invalid buffer - EFAULT"); memset(&clt_peer_addr, 0x00, sizeof(clt_peer_addr)); len = sizeof(clt_peer_addr); /*getpeername(): Bad socket descriptor, EBADF expected error*/ error = getpeername(-1, (struct sockaddr *)&clt_local_addr, &len); if (error != -1 || errno != EBADF) tst_brkm(TBROK, NULL, "getpeername on a bad socket " "descriptor. error:%d errno:%d", error, errno); tst_resm(TPASS, "getpeername on a bad socket descriptor - EBADF"); /*getpeername(): Invalid socket, ENOTSOCK expected error*/ error = getpeername(0, (struct sockaddr *)&clt_local_addr, &len); if (error != -1 || errno != ENOTSOCK) tst_brkm(TBROK, NULL, "getpeername on an invalid socket " "error:%d errno:%d", error, errno); tst_resm(TPASS, "getpeername on an invalid socket - ENOTSOCK"); /*getpeername(): Invalid structure, EFAULT expected error*/ error = getpeername(clt_sk, (struct sockaddr *)-1, &len); if (error != -1 || errno != EFAULT) tst_brkm(TBROK, NULL, "getpeername with invalid buffer " "error:%d errno:%d", error, errno); tst_resm(TPASS, "getpeername with invalid buffer - EFAULT"); close(clt_sk); close(svr_sk); close(accept_sk); /* Indicate successful completion. */ tst_exit(); }
/* * setup(void) - performs all ONE TIME setup for this test. * Exit the test program on receipt of unexpected signals. * Create a temporary directory used to hold test directories created * and change the directory to it. * Verify that pid of process executing the test is root. * Create a test directory on temporary directory and set the ownership * of test directory to nobody user. * Set the effective uid/gid of the process to that of nobody user. */ void setup() { /* Capture unexpected signals */ tst_sig(NOFORK, DEF_HANDLER, cleanup); /* Check that the test process id is super/root */ if (geteuid() != 0) { tst_brkm(TBROK, NULL, "Must be super/root for this test!"); tst_exit(); } /* Pause if that option was specified */ TEST_PAUSE; /* Make a temp dir and cd to it */ tst_tmpdir(); /* fix permissions on the tmpdir */ if (chmod(".", 0711) != 0) { tst_brkm(TBROK, cleanup, "chmod() failed"); } /* Save the real user id of the test process */ save_myuid = getuid(); /* Save the process id of the test process */ mypid = getpid(); /* Get the node name to be created in the test */ sprintf(node_name, TNODE, mypid); /* Get the uid/gid of guest user - nobody */ if ((user1 = getpwnam(LTPUSER)) == NULL) { tst_brkm(TBROK, cleanup, "%s not in /etc/passwd", LTPUSER); } user1_uid = user1->pw_uid; group1_gid = user1->pw_gid; /* Get effective group id of the test process */ group2_gid = getegid(); /* * Create a test directory under temporary directory with the * specified mode permissions, with uid/gid set to that of guest * user and the test process. */ if (mkdir(DIR_TEMP, MODE_RWX) < 0) { tst_brkm(TBROK, cleanup, "mkdir(2) of %s failed", DIR_TEMP); } if (chown(DIR_TEMP, user1_uid, group2_gid) < 0) { tst_brkm(TBROK, cleanup, "chown(2) of %s failed", DIR_TEMP); } /* * Verify that test directory created with expected permission modes * and ownerships. */ if (stat(DIR_TEMP, &buf) < 0) { tst_brkm(TBROK, cleanup, "stat(2) of %s failed", DIR_TEMP); } /* Verify modes of test directory */ if (buf.st_mode & S_ISGID) { tst_brkm(TBROK, cleanup, "%s: Incorrect modes, setgid bit set", DIR_TEMP); } /* Verify group ID */ if (buf.st_gid != group2_gid) { tst_brkm(TBROK, cleanup, "%s: Incorrect group", DIR_TEMP); } /* * Set the effective group id and user id of the test process * to that of guest user. */ if (setgid(group1_gid) < 0) { tst_brkm(TBROK, cleanup, "Unable to set process gid to that of ltp user"); } if (setreuid(-1, user1_uid) < 0) { tst_brkm(TBROK, cleanup, "Unable to set process uid to that of ltp user"); } /* Save the real group ID of the current process */ mygid = getgid(); /* Change directory to DIR_TEMP */ if (chdir(DIR_TEMP) < 0) { tst_brkm(TBROK, cleanup, "Unable to change to %s directory", DIR_TEMP); } }
int main(int ac, char **av) { int lc; char *msg; int i; char *comp_string; /* 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); } setup(); /* check 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; for (i = 0; i < TST_TOTAL; ++i) { osnamelth = SIZE(osname); switch (i) { case 0: comp_string = buf.sysname; break; case 1: comp_string = buf.release; break; case 2: comp_string = buf.version; break; } TEST(sysctl(TC[i].name, TC[i].size, TC[i].oldval, TC[i].oldlen, TC[i].newval, TC[i].newlen)); if (TEST_RETURN != 0) { tst_resm(TFAIL, "sysctl(2) failed unexpectedly " "errno:%d", errno); continue; } if (!STD_FUNCTIONAL_TEST) { tst_resm(TPASS, "call succeeded"); continue; } if (strcmp(TC[i].oldval, comp_string) != 0) { tst_resm(TFAIL, "strings don't match - %s : %s", TC[i].oldval, comp_string); } else { tst_resm(TPASS, "%s is correct", TC[i].desc); } if (TC[i].cleanup) { (void)TC[i].cleanup(); } } } cleanup(); /*NOTREACHED*/ return(0); }