int main(int argc, char **argv) { int rc; int fd; int openflags; int offset; int length; int passflag; int flags; void *memmap; if (--argc != 5) { printf("usage: %s filename openflags offset length passflag\n", argv[0]); exit(-1); } passflag = atoi(argv[5]); if ((passflag != 0) && (passflag != 1)) { printf("%s error: invalid passflag %s\n", argv[0], argv[5]); exit(-1); } length = atoi(argv[4]); if (length < 0) { printf("%s error: invalid length %s\n", argv[0], argv[4]); exit(-1); } offset = atoi(argv[3]); if (offset < 0) { printf("%s error: invalid offset %s\n", argv[0], argv[3]); exit(-1); } if (offset & (PAGE_SIZE - 1)) { printf("%s error: unaligned offset %d\n", argv[0], offset); exit(-1); } openflags = atoi(argv[2]); if (openflags == O_RDONLY) { flags = PROT_READ; } else if (openflags == O_WRONLY) { flags = PROT_WRITE; } else if (openflags == O_RDWR) { flags = PROT_READ | PROT_WRITE; } else { printf("%s error: invalid openflags %s\n", argv[0], argv[2]); exit(-1); } printf("invoking open(%s, %d)\n", argv[1], openflags); fd = open(argv[1], openflags); if (fd == -1) { printf("%s error: open failed with rc = %d (errno = %d)\n", argv[0], rc, errno); exit(-1); } printf("invoking memmap(%d, %d, %s, %d)\n", length, flags, argv[1], offset); memmap = mmap(NULL, length, flags, MAP_SHARED, fd, offset); if (memmap == MAP_FAILED) { printf("%s error: mmap failed with errno = %d\n", argv[0], errno); if (passflag) { close(fd); exit(-1); } } EVENT_DELIVERY_DELAY; if (memmap != MAP_FAILED) { printf("invoking munmap(%p, %d)\n", memmap, length); munmap(memmap, length); } close(fd); _exit(0); tst_exit(); }
int main(int ac, char **av) { int lc; int fflag; tst_parse_opts(ac, av, NULL, NULL); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; /* * Attempt to create a filesystem node with group id (sgid) * bit set on a directory with group id (sgid) bit set * such that, the node created by mknod(2) should have * group id (sgid) bit set and node's gid should be equal * to that of effective gid of the process. */ TEST(mknod(node_name, MODE_SGID, 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_SGID, TEST_ERRNO, strerror(TEST_ERRNO)); continue; } /* 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 functionality flag */ fflag = 0; } /* Verify mode permissions of node */ if (!(buf.st_mode & S_ISGID)) { tst_resm(TFAIL, "%s: Incorrect modes, setgid bit not " "set", node_name); /* unset flag as functionality fails */ fflag = 0; } /* Verify group ID */ if (buf.st_gid != group2_gid) { 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_SGID); } /* 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 */ SAFE_CHDIR(cleanup, ".."); /* * Invoke cleanup() to delete the test directories created * in the setup() and exit main(). */ cleanup(); tst_exit(); }
int forkfail(void) { tst_resm(TBROK, "FORK FAILED - terminating test."); tst_exit(); }
int main(int ac, char **av) { int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ int status; /*************************************************************** * 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(); } #ifdef UCLINUX maybe_run_child(&do_child, ""); #endif /*************************************************************** * 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; /* make a child process so we can kill it */ /* If we cannot fork => we cannot test kill, so break and exit */ if ((fork_pid = FORK_OR_VFORK()) == -1) { tst_brkm(TBROK, cleanup, "fork() Failure. errno=%d : %s", errno, strerror(errno)); } if (fork_pid == 0) { /* CHILD */ #ifdef UCLINUX if (self_exec(av[0], "") < 0) { tst_brkm(TBROK, cleanup, "self_exec of child failed"); } #else do_child(); #endif } /* PARENT */ /* * Call kill(2) */ TEST(kill(fork_pid, SIGKILL)); /* check return code */ if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, "kill(%d, SIGKILL) Failed, errno=%d : %s", fork_pid, 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, "kill(%d, SIGKILL) returned %ld", fork_pid, TEST_RETURN); } } /* * wait for process to cleanup zombies. * */ waitpid(0, &status, WNOHANG); } /* End for TEST_LOOPING */ /*************************************************************** * cleanup and exit ***************************************************************/ cleanup(); return 0; } /* End main */
int main(int ac, char **av) { int lc, i; /* loop counter */ char *msg; /* message returned from parse_opts */ /* parse standard options */ if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { Tst_count = 0; for (i = 0; i < TST_TOTAL; i++) { if (testcase[i].setupfunc && testcase[i].setupfunc() == -1) { tst_resm(TWARN, "Failed to setup test %d." " Skipping test", i); continue; } else { TEST(syscall(__NR_swapoff, testcase[i].path)); } if (testcase[i].cleanfunc && testcase[i].cleanfunc() == -1) { tst_brkm(TBROK, cleanup, "cleanup failed," " quitting the test"); } /* check return code */ if ((TEST_RETURN == -1) && (TEST_ERRNO == testcase[i]. exp_errno)) { tst_resm(TPASS, "swapoff(2) expected failure;" " Got errno - %s : %s", testcase[i].exp_errval, testcase[i].err_desc); } else { tst_resm(TFAIL, "swapoff(2) failed to produce" " expected error; %d, errno" ": %s and got %d", testcase[i].exp_errno, testcase[i].exp_errval, TEST_ERRNO); if ((TEST_RETURN == 0) && (i == 2)) { if (syscall(__NR_swapon, "./swapfile01", 0) != 0) { tst_brkm(TBROK, cleanup, " Failed to turn on" " swap file"); } } } TEST_ERROR_LOG(TEST_ERRNO); } /*End of TEST LOOPS */ } /*Clean up and exit */ cleanup(); tst_exit(); } /*End of main */
int main(int ac, char **av) { int lc; char *msg; /*************************************************************** * parse standard options ***************************************************************/ if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); /*************************************************************** * perform global setup for test ***************************************************************/ setup(); /* * check if the current filesystem is nfs */ if (tst_is_cwd_nfs()) { tst_brkm(TCONF, cleanup, "Cannot do fcntl on a file located on an NFS filesystem"); } /* * check if the current filesystem is tmpfs */ if (tst_is_cwd_tmpfs()) { tst_brkm(TCONF, cleanup, "Cannot do fcntl on a file located on an TMPFS filesystem"); } /* * check if the current filesystem is ramfs */ if (tst_is_cwd_ramfs()) { tst_brkm(TCONF, cleanup, "Cannot do fcntl on a file located on an RAMFS filesystem"); } /* set the expected errnos... */ TEST_EXP_ENOS(exp_enos); /*************************************************************** * check looping state if -c option given ***************************************************************/ for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; #ifdef F_SETLEASE /* * Call fcntl(2) with F_SETLEASE & F_WRLCK argument on fname */ TEST(fcntl(fd, F_SETLEASE, F_WRLCK)); /* check return code */ if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, "fcntl(%s, F_SETLEASE, F_WRLCK) Failed, errno=%d : %s", fname, TEST_ERRNO, strerror(TEST_ERRNO)); } else { if (STD_FUNCTIONAL_TEST) { TEST(fcntl(fd, F_GETLEASE)); if (TEST_RETURN != F_WRLCK) tst_resm(TFAIL, "fcntl(%s, F_GETLEASE) did not return F_WRLCK, returned %ld", fname, TEST_RETURN); else { TEST(fcntl(fd, F_SETLEASE, F_UNLCK)); if (TEST_RETURN != 0) tst_resm(TFAIL, "fcntl(%s, F_SETLEASE, F_UNLCK) did not return 0, returned %ld", fname, TEST_RETURN); else tst_resm(TPASS, "fcntl(%s, F_SETLEASE, F_WRLCK)", fname); } } } #else tst_resm(TINFO, "F_SETLEASE not defined, skipping test"); #endif } /*************************************************************** * cleanup and exit ***************************************************************/ cleanup(); tst_exit(); }
static void dotest(int testers, int me, int fd) { int i, count, collide, chunk, whenmisc, xfr; char *bits, *hold_bits, *buf, *val_buf, *zero_buf; char val; nchunks = max_size / csize; if ((bits = calloc((nchunks + 7) / 8, 1)) == NULL) { perror("\tmalloc (bits)"); exit(1); } if ((hold_bits = calloc((nchunks + 7) / 8, 1)) == NULL) { perror("\tmalloc (bold_bits)"); exit(1); } if ((buf = (calloc(csize, 1))) == NULL) { perror("\tmalloc (buf)"); exit(1); } if ((val_buf = (calloc(csize, 1))) == NULL) { perror("\tmalloc (val_buf)"); exit(1); } if ((zero_buf = (calloc(csize, 1))) == NULL) { perror("\tmalloc (zero_buf)"); exit(1); } /* * No init sectors; allow file to be sparse. */ val = (64 / testers) * me + 1; /* * For each iteration: * zap bits array * loop: * pick random chunk, read it. * if corresponding bit off { * verify == 0. (sparse file) * ++count; * } else * verify == val. * write "val" on it. * repeat until count = nchunks. * ++val. */ srand(getpid()); if (misc_intvl) whenmisc = NEXTMISC; while (iterations-- > 0) { for (i = 0; i < NMISC; i++) misc_cnt[i] = 0; ftruncate(fd, 0); file_max = 0; memset(bits, 0, (nchunks + 7) / 8); memset(hold_bits, 0, (nchunks + 7) / 8); memset(val_buf, val, csize); memset(zero_buf, 0, csize); count = 0; collide = 0; while (count < nchunks) { chunk = rand() % nchunks; /* * Read it. */ if (lseek64(fd, CHUNK(chunk), 0) < (off64_t) 0) { tst_brkm(TFAIL | TERRNO, NULL, "\tTest[%d]: lseek64(0) fail at %Lx", me, CHUNK(chunk)); } if ((xfr = read(fd, buf, csize)) < 0) { tst_brkm(TFAIL | TERRNO, NULL, "\tTest[%d]: read fail at %Lx", me, CHUNK(chunk)); } /* * If chunk beyond EOF just write on it. * Else if bit off, haven't seen it yet. * Else, have. Verify values. */ //printf("%li %d", CHUNK(chunk), file_max ); if (CHUNK(chunk) >= file_max) { bits[chunk / 8] |= (1 << (chunk % 8)); ++count; } else if ((bits[chunk / 8] & (1 << (chunk % 8))) == 0) { if (xfr != csize) { //tst_resm(TINFO, "\tTest[%d]: xfr=%d != %d, zero read.", // me, xfr, csize); tst_exit(); } if (memcmp(buf, zero_buf, csize)) { tst_resm(TFAIL, "\tTest[%d] bad verify @ 0x%Lx for val %d count %d xfr %d file_max 0x%x, should be %d.", me, CHUNK(chunk), val, count, xfr, file_max, zero_buf[0]); tst_resm(TINFO, "\tTest[%d]: last_trunc = 0x%x.", me, last_trunc); sync(); ft_dumpbuf(buf, csize); ft_dumpbits(bits, (nchunks + 7) / 8); ft_orbits(hold_bits, bits, (nchunks + 7) / 8); tst_resm(TINFO, "\tHold "); ft_dumpbits(hold_bits, (nchunks + 7) / 8); tst_exit(); } bits[chunk / 8] |= (1 << (chunk % 8)); ++count; } else { if (xfr != csize) { tst_brkm(TFAIL, NULL, "\tTest[%d]: xfr=%d != %d, val read.", me, xfr, csize); } ++collide; if (memcmp(buf, val_buf, csize)) { tst_resm(TFAIL, "\tTest[%d] bad verify @ 0x%Lx for val %d count %d xfr %d file_max 0x%x.", me, CHUNK(chunk), val, count, xfr, file_max); tst_resm(TINFO, "\tTest[%d]: last_trunc = 0x%x.", me, last_trunc); sync(); ft_dumpbuf(buf, csize); ft_dumpbits(bits, (nchunks + 7) / 8); ft_orbits(hold_bits, bits, (nchunks + 7) / 8); tst_resm(TINFO, "\tHold "); ft_dumpbits(hold_bits, (nchunks + 7) / 8); tst_exit(); } } /* * Write it. */ if (lseek64(fd, -((off64_t) xfr), 1) < (off64_t) 0) { tst_brkm(TFAIL | TERRNO, NULL, "\tTest[%d]: lseek64(1) fail at %Lx", me, CHUNK(chunk)); } if ((xfr = write(fd, val_buf, csize)) < csize) { if (errno == ENOSPC) { tst_resm(TFAIL, "\tTest[%d]: no space, exiting.", me); fsync(fd); } else { tst_resm(TFAIL | TERRNO, "\tTest[%d]: write fail at %Lx xfr %d", me, CHUNK(chunk), xfr); } tst_exit(); } if (CHUNK(chunk) + csize > file_max) file_max = CHUNK(chunk) + csize; /* * If hit "misc" interval, do it. */ if (misc_intvl && --whenmisc <= 0) { ft_orbits(hold_bits, bits, (nchunks + 7) / 8); domisc(me, fd, bits); whenmisc = NEXTMISC; } if (count + collide > 2 * nchunks) break; } /* * End of iteration, maybe before doing all chunks. */ fsync(fd); ++misc_cnt[m_fsync]; //tst_resm(TINFO, "\tTest{%d} val %d done, count = %d, collide = {%d}", // me, val, count, collide); //for (i = 0; i < NMISC; i++) // tst_resm(TINFO, "\t\tTest{%d}: {%d} %s's.", me, misc_cnt[i], m_str[i]); ++val; } }
int main(int ac, char **av) { int lc; char *msg; /* message returned from parse_opts */ /* parse standard options */ if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); } setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { int i; /* reset Tst_count in case we are looping */ Tst_count = 0; for (i = 0; i < TST_TOTAL; i++) { /* Set the real or effective user id */ TEST(setreuid(*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) { TEST_ERROR_LOG(TEST_ERRNO); } /* * Perform functional verification if test * executed without (-f) option. */ if (STD_FUNCTIONAL_TEST) { uid_verify(test_data[i].exp_real_usr, test_data[i].exp_eff_usr, test_data[i].test_msg); } } } 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 argc, char *argv[]) { int ret, use_clone = T_NONE; char *tsttype = NONESTR; char buf[7]; int id; if (argc != 2) { tst_resm(TINFO, "Usage: %s <clone| unshare| none>", argv[0]); tst_resm(TINFO, " where clone, unshare, or fork specifies" " unshare method."); tst_exit(); } /* Using PIPE's to sync between containers and Parent */ if (pipe(p1) == -1) tst_brkm(TBROK|TERRNO, NULL, "pipe1 error"); if (pipe(p2) == -1) tst_brkm(TBROK|TERRNO, NULL, "pipe2 error"); if (strcmp(argv[1], "clone") == 0) { use_clone = T_CLONE; tsttype = CLONESTR; } else if (strcmp(argv[1], "unshare") == 0) { use_clone = T_UNSHARE; tsttype = UNSHARESTR; } tst_resm(TINFO, "Shared Memory namespace test : %s", tsttype); /* Create 2 containers */ ret = do_clone_unshare_test(use_clone, CLONE_NEWIPC, check_shmem1, NULL); if (ret < 0) tst_brkm(TFAIL, NULL, "clone/unshare failed"); ret = do_clone_unshare_test(use_clone, CLONE_NEWIPC, check_shmem2, NULL); if (ret < 0) tst_brkm(TFAIL, NULL, "clone/unshare failed"); close(p2[1]); read(p2[0], buf, 7); if (strcmp(buf, "exists") == 0) { if (use_clone == T_NONE) tst_resm(TPASS, "Plain cloned process able to access shmem " "segment created"); else tst_resm(TFAIL, "%s : In namespace2 found the shmem segment " "created in Namespace1", tsttype); } else { if (use_clone == T_NONE) tst_resm(TFAIL, "Plain cloned process didn't find shmem seg"); else tst_resm(TPASS, "%s : In namespace2 unable to access the shmem seg " "created in Namespace1", tsttype); } /* destroy the key */ id = shmget(TESTKEY, 100, 0); shmctl(id, IPC_RMID, NULL); tst_exit(); }
int main(int argc, char *argv[]) { #if HAVE_OPENSSL_SHA_H unsigned char boot_aggregate[SHA_DIGEST_LENGTH]; struct { struct { u_int32_t pcr; int type; unsigned char digest[SHA_DIGEST_LENGTH]; u_int16_t len; } header; unsigned char data[MAX_EVENT_DATA_SIZE]; } event; struct { unsigned char digest[SHA_DIGEST_LENGTH]; } pcr[NUM_PCRS]; FILE *fp; int i; int debug = 0; SHA_CTX c; if (argc != 2) { printf("format: %s binary_bios_measurement file\n", argv[0]); return 1; } fp = fopen(argv[1], "r"); if (!fp) { perror("unable to open pcr file\n"); return 1; } /* Initialize psuedo PCR registers 0 - 7 */ for ( i = 0; i < NUM_PCRS; i++) memset(&pcr[i].digest, 0, SHA_DIGEST_LENGTH); /* Extend the pseudo PCRs with the event digest */ while (fread(&event, sizeof(event.header), 1, fp)) { if (debug) { printf("%03u ", event.header.pcr); display_sha1_digest(event.header.digest); } SHA1_Init(&c); SHA1_Update(&c, pcr[event.header.pcr].digest, 20); SHA1_Update(&c, event.header.digest, 20); SHA1_Final(pcr[event.header.pcr].digest, &c); if (event.header.len > MAX_EVENT_DATA_SIZE) { printf("Error event too long"); break; } fread(event.data, event.header.len, 1, fp); } fclose(fp); /* Extend the boot aggregate with the pseudo PCR digest values */ memset(&boot_aggregate, 0, SHA_DIGEST_LENGTH); SHA1_Init(&c); for (i = 0; i < NUM_PCRS; i++) { if (debug) { printf("PCR-%2.2x: ", i); display_sha1_digest(pcr[i].digest); } SHA1_Update(&c, pcr[i].digest, 20); } SHA1_Final(boot_aggregate, &c); printf("boot_aggregate:"); display_sha1_digest(boot_aggregate); #else tst_resm(TCONF, "System doesn't have openssl/sha.h"); #endif tst_exit(); }
int main(int argc, char *argv[]) { #if HAVE_SYS_CAPABILITY_H int ret = 1; cap_value_t v[1]; cap_flag_value_t f; cap_t cur, tmpcap; /* We pick a random capability... let's use CAP_SYS_ADMIN */ /* make sure we have the capability now */ #if HAVE_DECL_CAP_BSET_READ ret = prctl(CAP_BSET_READ, CAP_SYS_ADMIN); #else errno = ENOSYS; ret = -1; #endif if (ret != 1) { tst_resm(TBROK, "Not starting with CAP_SYS_ADMIN\n"); tst_exit(); } /* Make sure it's in pI */ cur = cap_from_text("all=eip"); if (!cur) { tst_resm(TBROK, "Failed to create cap_sys_admin+i cap_t (errno %d)\n", errno); tst_exit(); } #if HAVE_DECL_CAP_SET_PROC ret = cap_set_proc(cur); #else errno = ENOSYS; ret = -1; #endif if (ret) { tst_resm(TBROK, "Failed to cap_set_proc with cap_sys_admin+i (ret %d errno %d)\n", ret, errno); tst_exit(); } #if HAVE_DECL_CAP_FREE cap_free(cur); #endif #if HAVE_DECL_CAP_GET_FLAG #if HAVE_DECL_CAP_GET_PROC cur = cap_get_proc(); ret = cap_get_flag(cur, CAP_SYS_ADMIN, CAP_INHERITABLE, &f); #else errno = ENOSYS; ret = -1; #endif #else errno = ENOSYS; ret = -1; #endif if (ret || f != CAP_SET) { tst_resm(TBROK, "Failed to add CAP_SYS_ADMIN to pI\n"); tst_exit(); } #if HAVE_DECL_CAP_FREE cap_free(cur); #endif /* drop the capability from bounding set */ #if HAVE_DECL_CAP_BSET_DROP ret = prctl(CAP_BSET_DROP, CAP_SYS_ADMIN); #else errno = ENOSYS; ret = -1; #endif if (ret) { tst_resm(TFAIL, "Failed to drop CAP_SYS_ADMIN from bounding set.\n"); tst_resm(TINFO, "(ret=%d, errno %d)\n", ret, errno); tst_exit(); } /* test 1: is CAP_SYS_ADMIN still in pI? */ #if HAVE_DECL_CAP_GET_FLAG #if HAVE_DECL_CAP_GET_PROC cur = cap_get_proc(); ret = cap_get_flag(cur, CAP_SYS_ADMIN, CAP_INHERITABLE, &f); #else errno = ENOSYS; ret = -1; #endif #else errno = ENOSYS; ret = -1; #endif if (ret || f != CAP_SET) { tst_resm(TFAIL, "CAP_SYS_ADMIN not in pI after dropping from bounding set\n"); tst_exit(); } tst_resm(TPASS, "CAP_SYS_ADMIN remains in pI after removing from bounding set\n"); tmpcap = cap_dup(cur); v[0] = CAP_SYS_ADMIN; ret = cap_set_flag(tmpcap, CAP_INHERITABLE, 1, v, CAP_CLEAR); if (ret) { tst_resm(TFAIL, "Failed to drop CAP_SYS_ADMIN from cap_t\n"); tst_exit(); } ret = cap_set_proc(tmpcap); if (ret) { tst_resm(TFAIL, "Failed to drop CAP_SYS_ADMIN from pI\n"); tst_exit(); } #if HAVE_DECL_CAP_FREE cap_free(tmpcap); #endif /* test 2: can we put it back in pI? */ #if HAVE_DECL_CAP_SET_PROC ret = cap_set_proc(cur); #endif if (ret == 0) { /* success means pI was not bounded by X */ tst_resm(TFAIL, "Managed to put CAP_SYS_ADMIN back into pI though not in X\n"); tst_exit(); } #if HAVE_DECL_CAP_FREE cap_free(cur); #endif tst_resm(TPASS, "Couldn't put CAP_SYS_ADMIN back into pI when not in bounding set\n"); #else tst_resm(TCONF, "System doesn't have POSIX capabilities."); #endif tst_exit(); }
static void dotest(int testers, int me, int fd) { char *bits, *buf; char val, val0; int count, collide, chunk, whenmisc, xfr, i; /* Stuff for the readv call */ struct iovec r_iovec[MAXIOVCNT]; int r_ioveclen; /* Stuff for the writev call */ struct iovec val0_iovec[MAXIOVCNT]; struct iovec val_iovec[MAXIOVCNT]; int w_ioveclen; nchunks = max_size / (testers * csize); whenmisc = 0; if ((bits = malloc((nchunks+7)/8)) == NULL) { tst_resm(TBROK, "\tmalloc failed(bits)"); tst_exit(); } if ((buf = (malloc(csize))) == NULL) { tst_resm(TBROK, "\tmalloc failed(buf)"); tst_exit(); } /*Allocate memory for the iovec buffers and init the iovec arrays */ r_ioveclen = w_ioveclen = csize / MAXIOVCNT; /* Please note that the above statement implies that csize * be evenly divisible by MAXIOVCNT. */ for (i = 0; i < MAXIOVCNT; i++) { if ((r_iovec[i].iov_base = malloc(r_ioveclen)) == NULL) { tst_resm(TBROK, "\tmalloc failed(r_iovec[])"); tst_exit(); } r_iovec[i].iov_len = r_ioveclen; /* Allocate unused memory areas between all the buffers to * make things more diffult for the OS. */ if (malloc((i+1)*8) == NULL) { tst_resm(TBROK, "\tmalloc failed"); tst_exit(); } if ((val0_iovec[i].iov_base = malloc(w_ioveclen)) == NULL) { tst_resm(TBROK, "\tmalloc failed(val0_iovec[])"); tst_exit(); } val0_iovec[i].iov_len = w_ioveclen; if (malloc((i+1)*8) == NULL) { tst_resm(TBROK, "\tmalloc failed"); tst_exit(); } if ((val_iovec[i].iov_base = malloc(w_ioveclen)) == NULL) { tst_resm(TBROK, "\tmalloc failed(iov_base)"); tst_exit(); } val_iovec[i].iov_len = w_ioveclen; if (malloc((i+1)*8) == NULL) { tst_resm(TBROK, "\tmalloc failed"); tst_exit(); } } /* * No init sectors; file-sys makes 0 to start. */ val = (64/testers) * me + 1; val0 = 0; /* * For each iteration: * zap bits array * loop: * pick random chunk, read it. * if corresponding bit off { * verify == 0. (sparse file) * ++count; * } else * verify == val. * write "val" on it. * repeat until count = nchunks. * ++val. */ srand(getpid()); if (misc_intvl) whenmisc = NEXTMISC; while (iterations-- > 0) { for (i = 0; i < NMISC; i++) misc_cnt[i] = 0; memset(bits, 0, (nchunks+7)/8); /* Have to fill the val0 and val iov buffers in a different manner */ for (i = 0; i < MAXIOVCNT; i++) { memset(val0_iovec[i].iov_base,val0,val0_iovec[i].iov_len); memset(val_iovec[i].iov_base,val,val_iovec[i].iov_len); } count = 0; collide = 0; while (count < nchunks) { chunk = rand() % nchunks; /* * Read it. */ if (lseek(fd, CHUNK(chunk), 0) < 0) { tst_resm(TFAIL, "\tTest[%d]: lseek(0) fail at %x, errno = %d.", me, CHUNK(chunk), errno); tst_exit(); } if ((xfr = readv(fd, &r_iovec[0], MAXIOVCNT)) < 0) { tst_resm(TFAIL, "\tTest[%d]: readv fail at %x, errno = %d.", me, CHUNK(chunk), errno); tst_exit(); } /* * If chunk beyond EOF just write on it. * Else if bit off, haven't seen it yet. * Else, have. Verify values. */ if (xfr == 0) { bits[chunk/8] |= (1<<(chunk%8)); } else if ((bits[chunk/8] & (1<<(chunk%8))) == 0) { if (xfr != csize) { tst_resm(TFAIL, "\tTest[%d]: xfr=%d != %d, zero read.", me, xfr, csize); tst_exit(); } for (i = 0; i < MAXIOVCNT; i++) { if (memcmp(r_iovec[i].iov_base, val0_iovec[i].iov_base, r_iovec[i].iov_len)) { tst_resm(TFAIL, "\tTest[%d] bad verify @ 0x%x for val %d count %d xfr %d.", me, CHUNK(chunk), val0, count, xfr); ft_dumpiov(&r_iovec[i]); ft_dumpbits(bits, (nchunks+7)/8); tst_exit(); } } bits[chunk/8] |= (1<<(chunk%8)); ++count; } else { if (xfr != csize) { tst_resm(TFAIL, "\tTest[%d]: xfr=%d != %d, val read.", me, xfr, csize); tst_exit(); } ++collide; for (i = 0; i < MAXIOVCNT; i++) { if (memcmp(r_iovec[i].iov_base, val_iovec[i].iov_base, r_iovec[i].iov_len)) { tst_resm(TFAIL, "\tTest[%d] bad verify @ 0x%x for val %d count %d xfr %d.", me, CHUNK(chunk), val, count, xfr); ft_dumpiov(&r_iovec[i]); ft_dumpbits(bits, (nchunks+7)/8); tst_exit(); } } } /* * Write it. */ if (lseek(fd, -xfr, 1) < 0) { tst_resm(TFAIL, "\tTest[%d]: lseek(1) fail at %x, errno = %d.", me, CHUNK(chunk), errno); tst_exit(); } if ((xfr = writev(fd, &val_iovec[0], MAXIOVCNT)) < csize) { if (errno == ENOSPC) { tst_resm(TFAIL, "\tTest[%d]: no space, exiting.", me); fsync(fd); tst_exit(); } tst_resm(TFAIL, "\tTest[%d]: writev fail at %x xfr %d, errno = %d.", me, CHUNK(chunk), xfr, errno); tst_exit(); } /* * If hit "misc" interval, do it. */ if (misc_intvl && --whenmisc <= 0) { domisc(me, fd); whenmisc = NEXTMISC; } if (count + collide > 2 * nchunks) break; } /* * End of iteration, maybe before doing all chunks. */ if (count < nchunks) { //tst_resm(TINFO, "\tTest{%d} val %d stopping @ %d, collide = {%d}.", // me, val, count, collide); for (i = 0; i < nchunks; i++) { if ((bits[i/8] & (1<<(i%8))) == 0) { if (lseek(fd, CHUNK(i), 0) < 0) { tst_resm(TFAIL, "\tTest[%d]: lseek fail at %x, errno = %d.", me, CHUNK(i), errno); tst_exit(); } if (writev(fd, &val_iovec[0], MAXIOVCNT) != csize) { tst_resm(TFAIL, "\tTest[%d]: writev fail at %x, errno = %d.", me, CHUNK(i), errno); tst_exit(); } } } } fsync(fd); ++misc_cnt[m_fsync]; //tst_resm(TINFO, "\tTest[%d] val %d done, count = %d, collide = %d.", // me, val, count, collide); //for (i = 0; i < NMISC; i++) // tst_resm(TINFO, "\t\tTest[%d]: %d %s's.", me, misc_cnt[i], m_str[i]); val0 = val++; } }
int main(int argc, char **argv) { int lc, retval; /* loop counter */ char *msg; /* message returned from parse_opts */ pid_t pid; /* parse standard options */ if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL) { tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); } /* 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; /* Testing Shared lock on Exclusive Locked file */ TEST(flock(fd, LOCK_EX)); if (TEST_RETURN == 0) { pid = FORK_OR_VFORK(); if (pid == 0) { fd1 = open(filename, O_RDWR); retval = flock(fd1, LOCK_SH | LOCK_NB); if (retval == -1) { tst_resm(TPASS, "flock() failed to acquire shared lock on an already" "exclusive locked file as expected"); } else { tst_resm(TFAIL, "flock() unexpectedly PASSED in acquiring shared lock on " "an already exclusive locked file"); } exit(0); } else { /* parent waiting */ wait(&status); } /* Testing Exclusive lock on a Exclusive Locked file */ pid = FORK_OR_VFORK(); if (pid == 0) { fd1 = open(filename, O_RDWR); retval = flock(fd1, LOCK_EX | LOCK_NB); if (retval == -1) { tst_resm(TPASS, "flock() failed to acquire exclusive lock on existing " " exclusive locked file as expected"); } else { tst_resm(TFAIL, "flock() unexpectedly passed in acquiring exclusive lock on " "an exclusive locked file"); } exit(0); } else { /* parent waiting */ wait(&status); } TEST(flock(fd, LOCK_UN)); } else { tst_resm(TFAIL, "flock() failed to acquire exclusive lock"); } } close(fd); close(fd1); cleanup(); tst_exit(); }
/*********************************************************************** * Main ***********************************************************************/ int main(int ac, char **av) { int lc; const char *msg; char *fname; char *desc; int ind; struct stat *stbuf; struct sigaction sa, osa; /*************************************************************** * parse standard options ***************************************************************/ if ((msg = parse_opts(ac, av, NULL, NULL)) != 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++) { tst_count = 0; for (ind = 0; Test_cases[ind].desc != NULL; ind++) { fname = Test_cases[ind].pathname; desc = Test_cases[ind].desc; stbuf = Test_cases[ind].stbuf; if (stbuf == (struct stat *)-1) { /* special sig11 case */ sa.sa_handler = &sig11_handler; sigemptyset(&sa.sa_mask); sa.sa_flags = 0; sigaction(SIGSEGV, NULL, &osa); sigaction(SIGSEGV, &sa, NULL); if (setjmp(sig11_recover)) { TEST_RETURN = -1; TEST_ERRNO = EFAULT; } else { TEST(stat(fname, stbuf)); } sigaction(SIGSEGV, &osa, NULL); } else { /* * Call stat(2) */ TEST(stat(fname, stbuf)); } /* check return code */ if (TEST_RETURN == -1) { if (TEST_ERRNO == Test_cases[ind].exp_errno) tst_resm(TPASS, "stat(<%s>, &stbuf) Failed, errno=%d", desc, TEST_ERRNO); else tst_resm(TFAIL, "stat(<%s>, &stbuf) Failed, errno=%d, expected errno:%d", desc, TEST_ERRNO, Test_cases [ind].exp_errno); } else { tst_resm(TFAIL, "stat(<%s>, &stbuf) returned %ld, expected -1, errno:%d", desc, TEST_RETURN, Test_cases[ind].exp_errno); } } } cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ char *node_name; /* ptr. for node name created */ char *test_desc; /* test specific error message */ int ind; /* counter to test different test conditions */ /* 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(); } /* * 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); /* 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; 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); } } /* End of TEST CASE LOOPING. */ } /* End for TEST_LOOPING */ /* * Invoke cleanup() to delete the test directories created * in the setup(). */ cleanup(); /*NOTREACHED*/ return 0; } /* End main */
int main(int ac, char **av) { int lc; pid_t pid; struct stat buf1; int e_code, status, status2; /* * parse standard options */ tst_parse_opts(ac, av, NULL, NULL); #ifdef UCLINUX maybe_run_child(&dochild1, "ns", 1, tstdir2); maybe_run_child(&dochild2, "ns", 2, tstdir4); #endif /* * perform global setup for test */ setup(); /* * check looping state if -i option given */ for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; //test1: $ /* * attempt to rmdir a file whose parent directory has * the sticky bit set without the root right * or effective uid */ if (stat(tstdir1, &buf1) != -1) { tst_brkm(TBROK, cleanup, "tmp directory %s found!", tstdir1); } /* create a directory */ if (mkdir(tstdir1, PERMS) == -1) { tst_brkm(TBROK, cleanup, "Couldnot create directory %s", tstdir1); } if (stat(tstdir1, &buf1) == -1) { perror("stat"); tst_brkm(TBROK, cleanup, "failed to stat directory %s " "in rmdir()", tstdir1); } /* set the sticky bit */ if (chmod(tstdir1, buf1.st_mode | S_ISVTX) != 0) { perror("chmod"); tst_brkm(TBROK, cleanup, "failed to set the S_ISVTX bit"); } /* create a sub directory under tstdir1 */ if (mkdir(tstdir2, PERMS) == -1) { tst_brkm(TBROK, cleanup, "Could not create directory %s", tstdir2); } if ((pid = FORK_OR_VFORK()) == -1) { tst_brkm(TBROK, cleanup, "fork() failed"); } if (pid == 0) { /* first child */ #ifdef UCLINUX if (self_exec(av[0], "ns", 1, tstdir2) < 0) { tst_brkm(TBROK, cleanup, "self_exec failed"); } #else dochild1(); #endif } /* Parent */ //test2: $ /* create the a directory with 0700 permits */ if (mkdir(tstdir3, 0700) == -1) { tst_brkm(TBROK, cleanup, "mkdir(%s, %#o) Failed", tstdir3, PERMS); } /* create the a directory with 0700 permits */ if (mkdir(tstdir4, 0777) == -1) { tst_brkm(TBROK, cleanup, "mkdir(%s, %#o) Failed", tstdir4, PERMS); } if ((pid = FORK_OR_VFORK()) == -1) { tst_brkm(TBROK, cleanup, "fork() failed"); } if (pid == 0) { /* child */ #ifdef UCLINUX if (self_exec(av[0], "ns", 2, tstdir4) < 0) { tst_brkm(TBROK, cleanup, "self_exec failed"); } #else dochild2(); #endif } else { /* parent */ /* wait for the child to finish */ wait(&status); wait(&status2); /* make sure the child returned a good exit status */ e_code = status >> 8; if (e_code != 0) { tst_resm(TFAIL, "Failures reported above"); } else { /* No error in the 1st one, check the 2nd */ e_code = status2 >> 8; if (e_code != 0) { tst_resm(TFAIL, "Failures reported above"); } } } /* clean up things in case we are looping */ (void)rmdir(tstdir2); (void)rmdir(tstdir1); (void)rmdir(tstdir4); (void)rmdir(tstdir3); } /* * cleanup and exit */ cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ /* 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); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { Tst_count = 0; /* * Call mmap to map the temporary file 'TEMPFILE' * with read access. */ errno = 0; addr = mmap(0, page_sz, PROT_READ, MAP_FILE | MAP_SHARED, fildes, 0); /* Check for the return value of mmap() */ if (addr == MAP_FAILED) { tst_resm(TFAIL|TERRNO, "mmap of %s failed", TEMPFILE); continue; } /* * Perform functional verification if test * executed without (-f) option. */ if (STD_FUNCTIONAL_TEST) { /* * Read the file contents into the dummy * string. */ if (read(fildes, dummy, page_sz) < 0) { tst_brkm(TFAIL|TERRNO, cleanup, "reading %s failed", TEMPFILE); } /* * Check whether mapped memory region has * the file contents. */ if (memcmp(dummy, addr, page_sz)) { tst_resm(TFAIL, "mapped memory area contains " "invalid data"); } else { tst_resm(TPASS, "Functionality of mmap() successful"); } } else { tst_resm(TPASS, "call succeeded"); } /* Clean up things in case we are looping */ /* Unmap the mapped memory */ if (munmap(addr, page_sz) != 0) { tst_brkm(TFAIL|TERRNO, cleanup, "munmapping failed"); } } cleanup(); tst_exit(); }
static void runtest(void) { int child, count, i, nwait, pid, status; nwait = 0; for (i = 0; i < nchild; i++) { test_name[0] = 'a' + i; test_name[1] = '\0'; fd = open(test_name, O_RDWR | O_CREAT | O_TRUNC, 0666); if (fd < 0) { tst_brkm(TBROK | TERRNO, NULL, "\tError creating %s/%s.", fuss, test_name); } if ((child = fork()) == 0) { dotest(nchild, i, fd); tst_exit(); } close(fd); if (child < 0) { tst_brkm(TBROK | TERRNO, NULL, "fork failed"); } else { pidlist[i] = child; nwait++; } } /* * Wait for children to finish. */ count = 0; while (1) { if ((child = wait(&status)) >= 0) { if (status != 0) { tst_resm(TFAIL, "\tTest{%d} failed, expected 0 exit.", child); local_flag = FAILED; } ++count; } else if (errno != EINTR) break; } /* * Should have collected all children. */ if (count != nwait) { tst_resm(TFAIL, "\tWrong # children waited on, count = %d", count); local_flag = FAILED; } chdir(homedir); pid = fork(); if (pid < 0) { tst_brkm(TBROK | TERRNO, sync, "fork failed"); tst_exit(); } if (pid == 0) { execl("/bin/rm", "rm", "-rf", fuss, NULL); exit(1); } wait(&status); if (status) { tst_resm(TINFO, "CAUTION - ftest05, '%s' may not be removed", fuss); } sync(); }
int main(int argc, char *argv[]) { socklen_t len; int ret; int sk,pf_class,lstn_sk,acpt_sk; int flag = 0; struct msghdr inmessage; char *message = "hello, world!\n"; struct iovec iov_rcv; int count; char * buffer_rcv; char incmsg[CMSG_SPACE(sizeof(sctp_cmsg_data_t))]; char *message1 = "hello, world!\n"; struct sockaddr_in conn_addr,lstn_addr,svr_addr; /* Rather than fflush() throughout the code, set stdout to * be unbuffered. */ setvbuf(stdout, NULL, _IONBF, 0); setvbuf(stderr, NULL, _IONBF, 0); pf_class = PF_INET; sk = test_socket(pf_class, SOCK_STREAM, IPPROTO_SCTP); lstn_sk = test_socket(pf_class, SOCK_STREAM, IPPROTO_SCTP); conn_addr.sin_family = AF_INET; conn_addr.sin_addr.s_addr = SCTP_IP_LOOPBACK; conn_addr.sin_port = htons(SCTP_TESTPORT_1); lstn_addr.sin_family = AF_INET; lstn_addr.sin_addr.s_addr = SCTP_IP_LOOPBACK; lstn_addr.sin_port = htons(SCTP_TESTPORT_1); /*Binding the listen socket*/ test_bind(lstn_sk, (struct sockaddr *) &lstn_addr, sizeof(lstn_addr)); /*Listening the socket*/ test_listen(lstn_sk, 10); len = sizeof(struct sockaddr_in); test_connect(sk, (struct sockaddr *) &conn_addr, len); acpt_sk = test_accept(lstn_sk, (struct sockaddr *)&svr_addr, &len); memset(&inmessage, 0, sizeof(inmessage)); buffer_rcv = malloc(REALLY_BIG); iov_rcv.iov_base = buffer_rcv; iov_rcv.iov_len = REALLY_BIG; inmessage.msg_iov = &iov_rcv; inmessage.msg_iovlen = 1; inmessage.msg_control = incmsg; inmessage.msg_controllen = sizeof(incmsg); /*recvmsg () TEST1: Bad socket descriptor, EBADF Expected error*/ count = recvmsg(-1, &inmessage, flag); if (count != -1 || errno != EBADF) tst_brkm(TBROK, NULL, "recvmsg with a bad socket " "descriptor count:%d, errno:%d", count, errno); tst_resm(TPASS, "recvmsg() with a bad socket descriptor - EBADF"); /*recvmsg () TEST2: Invalid socket , ENOTSOCK Expected error*/ count = recvmsg(0, &inmessage, flag); if (count != -1 || errno != ENOTSOCK) tst_brkm(TBROK, NULL, "recvmsg with invalid socket " "count:%d, errno:%d", count, errno); tst_resm(TPASS, "recvmsg() with invalid socket - ENOTSOCK"); /*recvmsg () TEST3: Invalid iovec pointer EFAULT, Expected error*/ inmessage.msg_iov = (struct iovec *)-1; count = recvmsg(acpt_sk, &inmessage, flag); if (count != -1 || errno != EFAULT) tst_brkm(TBROK, NULL, "recvmsg with invalid iovec " "pointer count:%d, errno:%d", count, errno); tst_resm(TPASS, "recvmsg() with invalid iovec ptr - EFAULT"); inmessage.msg_iov = &iov_rcv; /*recvmsg () TEST4: Invalid msghdr pointer EFAULT, Expected error*/ count = recvmsg(acpt_sk, (struct msghdr *)-1, flag); if (count != -1 || errno != EFAULT) tst_brkm(TBROK, NULL, "recvmsg with invalid msghdr " "pointer count:%d, errno:%d", count, errno); tst_resm(TPASS, "recvmsg() with invalid msghdr ptr - EFAULT"); /*recvmsg () TEST5:recvmsg on listening socket,ENOTCONN Expected error*/ count = recvmsg(lstn_sk, &inmessage, flag); if (count != -1 || errno != ENOTCONN) tst_brkm(TBROK, NULL, "recvmsg on listening socket " "count:%d, errno:%d", count, errno); tst_resm(TPASS, "recvmsg() on listening socket - ENOTCONN"); count = test_send(acpt_sk, message1, strlen(message), 0); ret = test_shutdown(sk, SHUT_WR); flag = MSG_NOSIGNAL; /*recvmsg () TEST6:reading on a socket that received SHUTDOWN*/ count = recvmsg(acpt_sk, &inmessage, flag); if (count < 0) tst_brkm(TBROK, NULL, "recvmsg on a socket that has " "received shutdown count:%d, errno:%d", count, errno); tst_resm(TPASS, "recvmsg() on a socket that has received shutdown - " "EOF"); /*recvmsg () TEST7:reading the pending message socket that sent SHUTDOWN*/ count = recvmsg(sk, &inmessage, flag); if (count < 0) tst_brkm(TBROK, NULL, "recvmsg on a socket with pending " "message that has sent shutdown count:%d, errno:%d", count, errno); tst_resm(TPASS, "recvmsg() on a socket with pending message that has " "sent shutdown - SUCCESS"); /*recvmsg () TEST8: No more message and association is shutdown, ENOTCONN Expected error*/ count = recvmsg(sk, &inmessage, flag); if (count != -1 || errno != ENOTCONN) tst_brkm(TBROK, NULL, "recvmsg on a socket with no " "pending messages and has sent shutdown count:%d, " "errno:%d", count, errno); tst_resm(TPASS, "recvmsg() on a socket with no pending messages and " " has sent shutdown - ENOTCONN"); close(sk); close(lstn_sk); close(acpt_sk); tst_exit(); }
int main() { char root[16]; //as pids can get much longer int gen_ret_val, ch_ret_val, level; int ret_val; int generate(), check(); char path_list_string[PATH_STRING_LENGTH + 1]; int status; int len; int term(); slash[0] = '/'; slash[1] = '\0'; strcpy(path_string, "inode"); sprintf(root, "A%d", getpid()); strcat(path_string, root); strcpy(rm_string, "rm -rf "); strcat(rm_string, path_string); setup(); if (signal(SIGTERM, (void (*)())term) == SIG_ERR) { fprintf(temp, "\tSIGTERM signal set failed!, errno=%d\n", errno); fail_exit(); } blenter(); /********************************/ /* */ /* make the root directory for */ /* the tree */ /* */ /********************************/ ret_val = mkdir(path_string, DIRECTORY_MODE); if (ret_val == -1) { perror("mkdir error"); fprintf(temp,"\tcreating directory '%s'\n", path_string); fprintf(temp,"\t\n%s Impossible to create directory %s\n", root, path_string); fail_exit(); } #ifdef PRINT printf("\n%s\n", path_string); #endif /****************************************/ /* */ /* create the "path_list" file, in */ /* which the list of generated paths */ /* will be stored so that they later */ /* may be checked */ /* */ /****************************************/ strcpy(path_list_string, path_string); strcat(path_list_string, slash); strcat(path_list_string, "path_list"); list_id = creat(path_list_string, FILE_MODE); if (list_id == -1) { fprintf(temp,"\t\n%s The path_list file cannot be created, errno=%d \n", root, errno); fail_exit(); } /****************************************/ /* */ /* and store its name in path_list */ /* */ /****************************************/ strcpy(write_string, path_string); len = strlen(write_string); write_string[len++] = 'D'; write_string[len] = '\0'; escrivez(write_string); /****************************************/ /* */ /* generate the directory-file tree */ /* */ /****************************************/ level = 0; #ifdef PRINT printf("\n\t%s\n\n", "GENERATING:"); #endif gen_ret_val = generate(path_string, level); if (gen_ret_val) { fprintf(temp,"Failure occured in generate routine, return value %d\n", gen_ret_val); local_flag = FAILED; } blexit(); blenter(); close(list_id); list_id = open(path_list_string, READ); if (list_id == -1) { fprintf(temp,"\t\n%s The path_list file cannot be opened for reading, errno=%d\n", root, errno); fail_exit(); } list_stream = fdopen(list_id, "r"); /****************************************/ /* */ /* check the directory-file tree */ /* for correctness */ /* */ /****************************************/ #ifdef PRINT printf("\n\t%s\n\n", "CHECKING:"); #endif ch_ret_val = check(); if (ch_ret_val) { fprintf(temp,"Failure occured in check routine, return value %d\n", ch_ret_val); local_flag = FAILED; } status = fclose(list_stream); if (status != 0) { fprintf(temp,"Failed to close list_stream: ret=%d errno=%d (%s)\n", status, errno, strerror(errno)); local_flag = FAILED; } blexit(); /* * Now fork and exec a system call to remove the directory. */ #ifdef DEBUG fprintf(temp,"\nClean up:\trm string = %s\n", rm_string); #endif fflush(stdout); fflush(temp); status = system(rm_string); if (status) { fprintf(temp,"Caution-``%s'' may have failed\n", rm_string); fprintf(temp, "rm command exit status = %d\n", status); } /****************************************/ /* */ /* .....and exit main */ /* */ /****************************************/ anyfail(); /***** NOT REACHED ******/ tst_exit(); }
int main(int argc, char **argv) { int lc; char *msg; int fail, pid, status, ret; msg = parse_opts(argc, argv, NULL, NULL); if (msg != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); #ifdef UCLINUX maybe_run_child(&do_exit_uclinux, ""); #endif setup(); pid = FORK_OR_VFORK(); if (pid < 0) { tst_brkm(TFAIL, cleanup, "Fork Failed"); } else if (pid == 0) { /* * Child: * Set up to catch SIGINT. The kids will wait till a * SIGINT has been received before they proceed. */ setup_sigint(); /* check for looping state if -i option is given */ for (lc = 0; TEST_LOOPING(lc); lc++) { /* reset tst_count in case we are looping */ tst_count = 0; intintr = 0; fail = 0; pid = FORK_OR_VFORK(); if (pid < 0) { tst_brkm(TFAIL, cleanup, "Fork failed."); } else if (pid == 0) { /* child */ #ifdef UCLINUX if (self_exec(argv[0], "") < 0) { tst_brkm(TFAIL, cleanup, "self_exec failed"); } #else do_exit(); #endif } else { /* parent */ /* *Check that waitpid with WNOHANG returns zero */ while (((ret = waitpid(pid, &status, WNOHANG)) != 0) || (errno == EINTR)) { if (ret == -1) continue; tst_resm(TFAIL, "return value for " "WNOHANG expected 0 got %d", ret); fail = 1; } #ifdef UCLINUX /* Give the kids a chance to setup SIGINT again, since * this is cleared by exec(). */ sleep(3); #endif /* send SIGINT to child to tell it to proceed */ if (kill(pid, SIGINT) < 0) { tst_resm(TFAIL, "Kill of child failed, " "errno = %d", errno); fail = 1; } while (((ret = waitpid(pid, &status, 0)) != -1) || (errno == EINTR)) { if (ret == -1) continue; if (ret != pid) { tst_resm(TFAIL, "Expected %d " "got %d as proc id of " "child", pid, ret); fail = 1; } if (status != 0) { tst_resm(TFAIL, "status value " "got %d expected 0", status); fail = 1; } } } pid = FORK_OR_VFORK(); if (pid < 0) { tst_brkm(TFAIL, cleanup, "Second fork failed."); } else if (pid == 0) { /* child */ exit(0); } else { /* parent */ /* Give the child time to startup and exit */ sleep(2); while (((ret = waitpid(pid, &status, WNOHANG)) != -1) || (errno == EINTR)) { if (ret == -1) continue; if (ret != pid) { tst_resm(TFAIL, "proc id %d " "and retval %d do not " "match", pid, ret); fail = 1; } if (status != 0) { tst_resm(TFAIL, "non zero " "status received %d", status); fail = 1; } } } if (fail) tst_resm(TFAIL, "case 1 FAILED"); else tst_resm(TPASS, "case 1 PASSED"); fail = 0; ret = waitpid(pid, &status, 0); if (ret != -1) { tst_resm(TFAIL, "Expected -1 got %d", ret); fail = 1; } TEST_ERROR_LOG(errno); if (errno != ECHILD) { tst_resm(TFAIL, "Expected ECHILD got %d", errno); fail = 1; } ret = waitpid(pid, &status, WNOHANG); if (ret != -1) { tst_resm(TFAIL, "WNOHANG: Expected -1 got %d", ret); fail = 1; } TEST_ERROR_LOG(errno); if (errno != ECHILD) { tst_resm(TFAIL, "WNOHANG: Expected ECHILD got " "%d", errno); fail = 1; } if (fail) tst_resm(TFAIL, "case 2 FAILED"); else tst_resm(TPASS, "case 2 PASSED"); } cleanup(); } else { /* wait for the child to return */ waitpid(pid, &status, 0); if (WEXITSTATUS(status) != 0) { tst_brkm(TBROK, cleanup, "child returned bad " "status"); } } tst_exit(); }
int main(int ac, char **av) { int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ int incr; /* increment */ long nbrkpt; /* new brk point value */ long cur_brk_val; /* current size returned by sbrk */ long aft_brk_val; /* current size returned by sbrk */ if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); /* * Attempt to control how fast we get to test max size. * Every MAX_SIZE_LC'th lc will be fastest test will reach max size. */ incr = (Max_brk_byte_size - Beg_brk_val) / (MAX_SIZE_LC / 2); if ((incr * 2) < 4096) /* make sure that process will grow */ incr += 4096 / 2; for (lc = 0; TEST_LOOPING(lc); lc++) { Tst_count = 0; /* * Determine new value to give brk * Every even lc value, grow by 2 incr and * every odd lc value, strink by one incr. * If lc is equal to 3, no change, special case. */ cur_brk_val = (long)sbrk(0); if (lc == 3) { nbrkpt = cur_brk_val; /* no change, special one time case */ } else if ((lc % 2) == 0) { /* * grow */ nbrkpt = cur_brk_val + (2 * incr); if (nbrkpt > Max_brk_byte_size) nbrkpt = Beg_brk_val; /* start over */ } else { /* * shrink */ nbrkpt = cur_brk_val - incr; } /**** printf("cur_brk_val = %d, nbrkpt = %d, incr = %d, lc = %d\n", cur_brk_val, nbrkpt, incr, lc); ****/ /* * Call brk(2) */ TEST(brk((char *)nbrkpt)); /* check return code */ if (TEST_RETURN == -1) { aft_brk_val = (long)sbrk(0); tst_resm(TFAIL|TTERRNO, "brk(%ld) failed (size before %ld, after %ld)", nbrkpt, cur_brk_val, aft_brk_val); } else { if (STD_FUNCTIONAL_TEST) { aft_brk_val = (long)sbrk(0); if (aft_brk_val == nbrkpt) { tst_resm(TPASS, "brk(%ld) returned %ld, new size verified by sbrk", nbrkpt, TEST_RETURN); } else { tst_resm(TFAIL, "brk(%ld) returned %ld, sbrk before %ld, after %ld", nbrkpt, TEST_RETURN, cur_brk_val, aft_brk_val); } } } } cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc, i; char *msg; int len; msg = parse_opts(ac, av, NULL, NULL); if (msg != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { /* * generate events */ for (i = 0; i < MAX_EVENTS + 1; i++) { sprintf(fname, "fname_%d", i); fd = SAFE_OPEN(cleanup, fname, O_RDWR | O_CREAT, 0644); SAFE_CLOSE(cleanup, fd); } while (1) { /* * get list on events */ len = read(fd_notify, &event, sizeof(event)); if (len < 0) { if (errno == -EAGAIN) { tst_resm(TFAIL, "Overflow event not " "generated!\n"); break; } tst_brkm(TBROK | TERRNO, cleanup, "read of notification event failed"); break; } if (event.fd != FAN_NOFD) close(event.fd); /* * check events */ if (event.mask != FAN_OPEN && event.mask != FAN_Q_OVERFLOW) { tst_resm(TFAIL, "get event: mask=%llx (expected %llx)" "pid=%u fd=%d", (unsigned long long)event.mask, (unsigned long long)FAN_OPEN, (unsigned)event.pid, event.fd); break; } if (event.mask == FAN_Q_OVERFLOW) { if (event.fd != FAN_NOFD) { tst_resm(TFAIL, "invalid overflow event: " "mask=%llx pid=%u fd=%d", (unsigned long long)event.mask, (unsigned)event.pid, event.fd); break; } tst_resm(TPASS, "get event: mask=%llx pid=%u fd=%d", (unsigned long long)event.mask, (unsigned)event.pid, event.fd); break; } } } cleanup(); tst_exit(); }
int main(int ac, char *av[]) { int *fildes; int ifile; char pfilname[40]; int min; int serrno; int lc; const char *msg; ifile = -1; if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); local_flag = PASSED; setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { min = getdtablesize(); /* get number of files allowed open */ fildes = malloc((min + 10) * sizeof(int)); if (fildes == NULL) tst_brkm(TBROK | TERRNO, cleanup, "malloc error"); sprintf(pfilname, "./dup205.%d\n", getpid()); unlink(pfilname); serrno = 0; if ((fildes[0] = creat(pfilname, 0666)) == -1) tst_brkm(TBROK | TERRNO, cleanup, "creat failed"); else { fildes[fildes[0]] = fildes[0]; for (ifile = fildes[0] + 1; ifile < min + 10; ifile++) { if ((fildes[ifile] = dup2(fildes[ifile - 1], ifile)) == -1) { serrno = errno; break; } else { if (fildes[ifile] != ifile) { tst_brkm(TFAIL, cleanup, "got wrong descriptor " "number back (%d != %d)", fildes[ifile], ifile); } } } /* end for */ if (ifile < min) { tst_resm(TFAIL, "Not enough files duped"); local_flag = FAILED; } else if (ifile > min) { tst_resm(TFAIL, "Too many files duped"); local_flag = FAILED; } if (serrno != EBADF && serrno != EMFILE && serrno != EINVAL) { tst_resm(TFAIL, "bad errno on dup2 failure"); local_flag = FAILED; } } unlink(pfilname); for (ifile = fildes[0]; ifile < min + 10; ifile++) close(fildes[ifile]); if (local_flag == PASSED) { tst_resm(TPASS, "Test passed."); } else { tst_resm(TFAIL, "Test failed."); } } cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc, i; char *msg; 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++) { Tst_count = 0; for (i = 0; i < TST_TOTAL; ++i) { /* * since Linux 2.6.26, if buf.offset value is outside * the acceptable range, it is simply normalized instead * of letting the syscall fail. so just skip this test * case. */ if ((i == 3 || i == 4) && tst_kvercmp(2, 6, 25) > 0) { tst_resm(TCONF, "this kernel normalizes buf." "offset value if it is outside" " the acceptable range."); continue; } buff = tim_save; buff.modes = SET_MODE; if ((test_cases[i].setup) && (test_cases[i].setup())) { tst_resm(TWARN, "setup() failed, skipping" " this test case"); continue; } /* Call adjtimex(2) */ TEST(adjtimex(test_cases[i].buffp)); if ((TEST_RETURN == -1) && (TEST_ERRNO == test_cases[i].exp_errno)) { tst_resm(TPASS | TTERRNO, "Test Passed, adjtimex() returned -1"); } else { tst_resm(TFAIL | TTERRNO, "Test Failed, adjtimex() returned %ld", TEST_RETURN); } TEST_ERROR_LOG(TEST_ERRNO); if (test_cases[i].cleanup) { test_cases[i].cleanup(); } } } /* cleanup and exit */ cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc; char *ptr; /* message returned from parse_opts */ gid_t group; int i; int entries; /* number of group entries */ initgroups("root", 0); if ((ptr = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", ptr); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { Tst_count = 0; TEST(getgroups(-1, gidset)); if (TEST_RETURN == 0) tst_resm(TFAIL, "getgroups succeeded unexpectedly"); else if (STD_FUNCTIONAL_TEST) { if (errno == EINVAL) tst_resm(TPASS, "getgroups failed as expected with EINVAL"); else tst_resm(TFAIL | TTERRNO, "getgroups didn't fail as expected with EINVAL"); } /* * Check that if ngrps is zero that the number of groups is * return and the the gidset array is not modified. * This is a POSIX special case. */ memset(gidset, 052, NGROUPS); memset(cmpset, 052, NGROUPS); TEST(getgroups(0, gidset)); if (TEST_RETURN == -1) tst_resm(TFAIL | TTERRNO, "getgroups failed"); else if (STD_FUNCTIONAL_TEST) { if (memcmp(cmpset, gidset, NGROUPS) != 0) tst_resm(TFAIL, "getgroups modified the gidset array"); else tst_resm(TPASS, "getgroups did not modify the gidset " "array"); } /* * Check to see that is -1 is returned and errno is set to * EINVAL when ngroups is not big enough to hold all groups. */ if (TEST_RETURN <= 1) tst_resm(TCONF, "getgroups returned %ld; unable to test that using ngrps >=1 but less than number of grps", TEST_RETURN); else { TEST(getgroups(TEST_RETURN - 1, gidset)); if (TEST_RETURN == -1) { if (STD_FUNCTIONAL_TEST) { if (errno == EINVAL) tst_resm(TPASS, "getgroups failed as " "expected with EINVAL"); else tst_resm(TFAIL | TERRNO, "getgroups didn't fail " "with EINVAL"); } } else tst_resm(TFAIL, "getgroups succeeded unexpectedly with %ld", TEST_RETURN); } TEST(getgroups(NGROUPS, gidset)); if ((entries = TEST_RETURN) == -1) tst_resm(TFAIL | TTERRNO, "getgroups failed unexpectedly"); else if (STD_FUNCTIONAL_TEST) { group = getgid(); for (i = 0; i < entries; i++) if (gidset[i] == group) { tst_resm(TPASS, "getgroups(NGROUPS,gidset) " "returned %d contains gid %d " "(from getgid)", entries, group); break; } if (i == entries) tst_resm(TFAIL, "getgroups(NGROUPS,gidset) ret %d, does " "not contain gid %d (from getgid)", entries, group); } } cleanup(); tst_exit(); }
int main(void) { tst_resm(TINFO, "test is not available on uClinux"); tst_exit(); }
/*--------------------------------------------------------------------*/ 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 const char *msg; if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL) { tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); } maybe_run_child(&do_child, "dd", &temp, &sig); #endif setup(); //tempdir(); /* move to new directory */ 12/20/2003 blenter(); exno = 1; if (sigset(SIGCLD, 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_resm(TBROK, "self_exec FAILED - " "terminating test."); tst_exit(); } #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, SIGCLD); /* 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 */ if (sig == 9) if (nexno != 0) { fprintf(temp, "signal error: unexpected" " exit number returned when" " signal sent was 9, the status" " of the process is %d \n", status); ret_val = 1; } else; else if (nexno != 1) { fprintf(temp, "signal error: unexpected exit " "number returned,the status of the" " process is %d\n", status); ret_val = 1; } } } if (ret_val) local_flag = FAILED; /*--------------------------------------------------------------------*/ anyfail(); tst_exit(); } /******** END OF MAIN. ********/
int main(int ac, char **av) { int lc; char *msg; char read_buf[1]; /* data read from temp. file */ /* 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); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { Tst_count = 0; /* * Invoke lseek(2) to move the read/write file * pointer/handle to the END of the file. */ TEST(lseek(fildes, 0, SEEK_END)); if (TEST_RETURN == -1) { tst_resm(TFAIL|TTERRNO, "lseek of %s failed", TEMP_FILE); continue; } /* * Perform functional verification if test * executed without (-f) option. */ if (STD_FUNCTIONAL_TEST) { /* * Check if the return value from lseek(2) * is equal to the file_size. */ if (TEST_RETURN != file_size) { tst_resm(TFAIL, "lseek() returned incorrect " "value %ld, expected %zu", TEST_RETURN, file_size); continue; } /* * The return value is okay, now attempt to read data * from the file. This should fail as the file pointer * should be pointing to END OF FILE. */ read_buf[0] = '\0'; if (read(fildes, &read_buf, sizeof(read_buf)) > 0) { tst_resm(TFAIL, "read() successful on %s", TEMP_FILE); } else { tst_resm(TPASS, "Functionality of lseek() on " "%s successful", TEMP_FILE); } } else { tst_resm(TPASS, "call succeeded"); } } cleanup(); tst_exit(); }