int main(int ac, char **av) { int lc; 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; /* loop counter */ char *msg; /* message returned from parse_opts */ int i, start_pers; /* parse standard options */ if ((msg = parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *)NULL) { tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg); } setup(); /* global setup */ start_pers = personality(PER_LINUX); if (start_pers == -1) { printf("personality01: Test Failed\n"); exit(-1); } /* The following checks the looping state if -i option given */ for (lc = 0; TEST_LOOPING(lc); lc++) { /* reset Tst_count in case we are looping */ Tst_count = 0; /* * Start looping through our series of personalities and * make sure that we can change to each one and the return * value is the previous one. */ for (i = 0; i < TST_TOTAL; i++) { TEST(personality(pers[i])); if (TEST_RETURN == -1) { tst_resm(TFAIL, "call failed - " "errno = %d - %s", TEST_ERRNO, strerror(TEST_ERRNO)); continue; } if (STD_FUNCTIONAL_TEST) { /* * check to make sure that the return value * is the previous personality in our list. * * i == 0 is a special case since the return * value should equal pers[0]. */ if (TEST_RETURN == pers[i == 0 ? 0 : i - 1]) { tst_resm(TPASS, "personality set " "correctly"); } else { tst_resm(TFAIL, "returned persona " "was not expected"); } } else { tst_resm(TPASS, "call succeeded"); } } /* * set our personality back to PER_LINUX */ if (personality(start_pers) == -1) { tst_brkm(TBROK, cleanup, "failed personality reset"); } } cleanup(); /*NOTREACHED*/ return 0; }
/* * setup() - performs all the ONE TIME setup for this test. */ void setup(void) { key_t shmkey2; /* Switch to nobody user for correct error code collection */ if (geteuid() != 0) { tst_brkm(TBROK, tst_exit, "Test must be run as root"); } ltpuser = getpwnam(nobody_uid); if (setuid(ltpuser->pw_uid) == -1) { tst_resm(TINFO, "setuid failed to " "to set the effective uid to %d", ltpuser->pw_uid); perror("setuid"); } /* capture signals */ tst_sig(NOFORK, DEF_HANDLER, cleanup); /* Set up the expected error numbers for -e option */ TEST_EXP_ENOS(exp_enos); /* Pause if that option was specified */ TEST_PAUSE; /* * Create a temporary directory and cd into it. * This helps to ensure that a unique msgkey is created. * See ../lib/libipc.c for more information. */ tst_tmpdir(); /* get an IPC resource key */ shmkey = getipckey(); /* create a shared memory resource with read and write permissions */ /* also post increment the shmkey for the next shmget call */ if ((shm_id_2 = shmget(shmkey, INT_SIZE, SHM_RW | IPC_CREAT | IPC_EXCL)) == -1) { tst_brkm(TBROK, cleanup, "Failed to create shared memory " "resource #1 in setup()"); } /* Get an new IPC resource key. */ shmkey2 = getipckey(); /* create a shared memory resource without read and write permissions */ if ((shm_id_3 = shmget(shmkey2, INT_SIZE, IPC_CREAT | IPC_EXCL)) == -1) { tst_brkm(TBROK, cleanup, "Failed to create shared memory " "resource #2 in setup()"); } /* Probe an available linear address for attachment */ if ((base_addr = shmat(shm_id_2, NULL, 0)) == (void *)-1) { tst_brkm(TBROK, cleanup, "Couldn't attach shared memory"); } if (shmdt((const void *)base_addr) == -1) { tst_brkm(TBROK, cleanup, "Couldn't detach shared memory"); } /* some architectures (e.g. parisc) are strange, so better always align to * next SHMLBA address. */ base_addr = (void *)(((unsigned long)(base_addr) & ~(SHMLBA - 1)) + SHMLBA); }
static int find_free_loopdev(void) { int ctl_fd, dev_fd, rc, i; struct loop_info loopinfo; /* since Linux 3.1 */ ctl_fd = open(LOOP_CONTROL_FILE, O_RDWR); if (ctl_fd > 0) { rc = ioctl(ctl_fd, LOOP_CTL_GET_FREE); close(ctl_fd); if (rc >= 0) { set_dev_path(rc); tst_resm(TINFO, "Found free device '%s'", dev_path); return 0; } tst_resm(TINFO, "Couldn't find free loop device"); return 1; } switch (errno) { case ENOENT: break; case EACCES: tst_resm(TINFO | TERRNO, "Not allowed to open " LOOP_CONTROL_FILE ". " "Are you root?"); break; default: tst_resm(TBROK | TERRNO, "Failed to open " LOOP_CONTROL_FILE); } /* * Older way is to iterate over /dev/loop%i and /dev/loop/%i and try * LOOP_GET_STATUS ioctl() which fails for free loop devices. */ for (i = 0; i < 256; i++) { if (!set_dev_path(i)) continue; dev_fd = open(dev_path, O_RDONLY); if (dev_fd < 0) continue; if (ioctl(dev_fd, LOOP_GET_STATUS, &loopinfo) == 0) { tst_resm(TINFO, "Device '%s' in use", dev_path); } else { if (errno != ENXIO) continue; tst_resm(TINFO, "Found free device '%s'", dev_path); close(dev_fd); return 0; } close(dev_fd); } tst_resm(TINFO, "No free devices found"); return 1; }
/* * handler() * * A signal handler that understands which test case is currently * being executed and compares the current conditions to the ones it * expects (based on the test case number). */ void handler(int sig, siginfo_t * sip, void *ucp) { struct sigaction oact; int err; sigset_t nmask, omask; /* * Get sigaction setting */ err = sigaction(SIGUSR1, NULL, &oact); if (err == -1) { perror("sigaction"); return; } /* * Get current signal mask */ sigemptyset(&nmask); sigemptyset(&omask); err = sigprocmask(SIG_BLOCK, &nmask, &omask); if (err == -1) { perror("sigprocmask"); tst_resm(TWARN, "sigprocmask() failed"); return; } switch (testcase_no) { case 1: /* * SA_RESETHAND and SA_SIGINFO were set. SA_SIGINFO should * be clear in Linux. In Linux kernel, SA_SIGINFO is not * cleared in psig(). */ if (!(oact.sa_flags & SA_SIGINFO)) { tst_resm(TFAIL, "SA_RESETHAND should not " "cause SA_SIGINFO to be cleared, but it was."); return; } if (sip == NULL) { tst_resm(TFAIL, "siginfo should not be NULL"); return; } tst_resm(TPASS, "SA_RESETHAND did not " "cause SA_SIGINFO to be cleared"); break; case 2: /* * In Linux, SA_RESETHAND doesn't imply SA_NODEFER; sig * should not be masked. The testcase should pass if * SA_NODEFER is not masked, ie. if SA_NODEFER is a member * of the signal list */ if (sigismember(&omask, sig) == 0) { tst_resm(TFAIL, "SA_RESETHAND should cause sig to" "be masked when the handler executes."); return; } tst_resm(TPASS, "SA_RESETHAND was masked when handler " "executed"); break; case 3: /* * SA_RESETHAND implies SA_NODEFER unless sa_mask already * included sig. */ if (!sigismember(&omask, sig)) { tst_resm(TFAIL, "sig should continue to be masked" "because sa_mask originally contained sig."); return; } tst_resm(TPASS, "sig has been masked " "because sa_mask originally contained sig"); break; case 4: /* * A signal generated from a mechanism that does not provide * siginfo should invoke the handler with a non-NULL siginfo * pointer. */ if (sip == NULL) { tst_resm(TFAIL, "siginfo pointer should not be NULL"); return; } tst_resm(TPASS, "siginfo pointer non NULL"); break; default: tst_resm(TFAIL, "invalid test case number: %d", testcase_no); exit(1); } }
int anyfail() { tst_resm(TFAIL, "Test failed\n"); tst_exit(); return 0; }
int main(int ac, char **av) { int lc; char *msg; struct stat buf; /* * 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 -i option given */ for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; /* * TEST mkdir() base functionality */ /* Initialize the test directory name */ sprintf(tstdir1, "tstdir1.%d", getpid()); /* Call mkdir(2) using the TEST macro */ TEST(mkdir(tstdir1, PERMS)); if (TEST_RETURN == -1) { tst_resm(TFAIL, "mkdir(%s, %#o) Failed", tstdir1, PERMS); continue; } if (STD_FUNCTIONAL_TEST) { if (stat(tstdir1, &buf) == -1) { tst_brkm(TBROK, cleanup, "failed to stat the " "new directory"); } /* check the owner */ if (buf.st_uid != geteuid()) { tst_resm(TFAIL, "mkdir() FAILED to set owner ID" " as process's effective ID"); continue; } /* check the group ID */ if (buf.st_gid != getegid()) { tst_resm(TFAIL, "mkdir() failed to set group ID" " as the process's group ID"); continue; } tst_resm(TPASS, "mkdir() functionality is correct"); } else { tst_resm(TPASS, "call succeeded"); } /* clean up things in case we are looping */ if (rmdir(tstdir1) == -1) { tst_brkm(TBROK, cleanup, "could not remove directory"); } } /* * cleanup and exit */ cleanup(); tst_exit(); }
/*--------------------------------------------------------------------*/ int main(int ac, char *av[]) { FILE *stream; char buf[10]; int nr, fd; int lc; /* * parse standard options */ tst_parse_opts(ac, av, NULL, NULL); tst_tmpdir(); local_flag = PASSED; for (lc = 0; TEST_LOOPING(lc); lc++) { local_flag = PASSED; sprintf(tempfile, "stream05.%d", getpid()); /*--------------------------------------------------------------------*/ //block0: if ((stream = fopen(tempfile, "a+")) == NULL) { tst_brkm(TFAIL, NULL, "fopen(%s) a+ failed: %s", tempfile, strerror(errno)); } fprintf(stream, "a"); fclose(stream); if ((stream = fopen(tempfile, "r+")) == NULL) { tst_brkm(TFAIL, NULL, "fopen(%s) r+ failed: %s", tempfile, strerror(errno)); } /* check that ferror returns zero */ if (ferror(stream) != 0) { tst_resm(TFAIL, "ferror did not return zero: %s", strerror(errno)); local_flag = FAILED; } if (local_flag == PASSED) { tst_resm(TPASS, "Test passed in block0."); } else { tst_resm(TFAIL, "Test failed in block0."); } local_flag = PASSED; /*--------------------------------------------------------------------*/ //block1: /* check that fileno returns valid file descriptor */ fd = fileno(stream); if ((nr = read(fd, buf, 1)) < 0) { tst_brkm(TFAIL, NULL, "read failed: %s", strerror(errno)); } if (nr != 1) { tst_resm(TFAIL, "read did not read right number"); local_flag = FAILED; } if (buf[0] != 'a') { tst_resm(TFAIL, "read returned bad values"); local_flag = FAILED; } if (local_flag == PASSED) { tst_resm(TPASS, "Test passed in block1."); } else { tst_resm(TFAIL, "Test failed in block1."); } local_flag = PASSED; /*--------------------------------------------------------------------*/ //block2: /* read to EOF and ensure feof returns non-zero */ fclose(stream); if ((stream = fopen(tempfile, "r+")) == NULL) { tst_brkm(TFAIL, NULL, "fopen(%s) r+ failed: %s", tempfile, strerror(errno)); } if (feof(stream) != 0) { tst_resm(TFAIL, "feof returned non-zero when it should not: %s", strerror(errno)); local_flag = FAILED; } fread(buf, 1, 2, stream); /* read to EOF */ if (feof(stream) == 0) { tst_resm(TFAIL, "feof returned zero when it should not: %s", strerror(errno)); local_flag = FAILED; } if (local_flag == PASSED) { tst_resm(TPASS, "Test passed in block2."); } else { tst_resm(TFAIL, "Test failed in block2."); } local_flag = PASSED; /*--------------------------------------------------------------------*/ //block3: /* ensure clearerr works */ clearerr(stream); if (feof(stream) != 0) { tst_resm(TFAIL, "clearerr failed: %s", strerror(errno)); local_flag = FAILED; } if (local_flag == PASSED) { tst_resm(TPASS, "Test passed in block3."); } else { tst_resm(TFAIL, "Test failed in block3."); } local_flag = PASSED; /*--------------------------------------------------------------------*/ //block4: /* test fopen "b" flags -- should be allowed but ignored */ (void)fclose(stream); if ((stream = fopen(tempfile, "rb")) == NULL) { tst_brkm(TFAIL, NULL, "fopen(%s) rb failed: %s", tempfile, strerror(errno)); } (void)fclose(stream); if ((stream = fopen(tempfile, "wb")) == NULL) { tst_brkm(TFAIL, NULL, "fopen(%s) wb failed: %s", tempfile, strerror(errno)); } (void)fclose(stream); if ((stream = fopen(tempfile, "ab")) == NULL) { tst_brkm(TFAIL, NULL, "fopen(%s) ab failed: %s", tempfile, strerror(errno)); } (void)fclose(stream); if ((stream = fopen(tempfile, "rb+")) == NULL) { tst_brkm(TFAIL, NULL, "fopen(%s) rb+ failed: %s", tempfile, strerror(errno)); } (void)fclose(stream); if ((stream = fopen(tempfile, "wb+")) == NULL) { tst_brkm(TFAIL, NULL, "fopen(%s) wb+ failed: %s", tempfile, strerror(errno)); } (void)fclose(stream); if ((stream = fopen(tempfile, "ab+")) == NULL) { tst_brkm(TFAIL, NULL, "fopen(%s) ab+ failed: %s", tempfile, strerror(errno)); } (void)fclose(stream); tst_resm(TPASS, "Test passed in block4."); /*--------------------------------------------------------------------*/ unlink(tempfile); } /* end for */ tst_rmdir(); tst_exit(); }
int main(int ac, char **av) { int lc; /* loop counter */ const char *msg; /* message returned from parse_opts */ long tret; /*************************************************************** * 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(0); } /*************************************************************** * perform global setup for test ***************************************************************/ setup(); #ifdef __CYGWIN__ /* we need to initialize output buffer before first sbrk. otherwise, when memory is freed bu second sbrk, fwrite will fail */ tst_resm(TINFO, "Entering test"); #endif /*************************************************************** * 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; /* * TEST CASE: * Increase by 8192 bytes */ Increment = 8192; /* Call sbrk(2) */ #if defined(sgi) tret=(long)sbrk(Increment); /* Remove -64 IRIX compiler warning */ TEST_ERRNO=errno; #else TEST(sbrk(Increment)); tret=TEST_RETURN; #endif /* check return code */ if ( tret == -1 ) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, "sbrk - Increase by 8192 bytes 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, "sbrk - Increase by 8192 bytes returned %d", tret); } } /* * TEST CASE: * Decrease to original size */ Increment=(Increment * -1); /* Call sbrk(2) */ #ifdef CRAY TEST(sbrk(Increment)); tret=TEST_RETURN; #else tret=(long)sbrk(Increment); TEST_ERRNO=errno; #endif /* check return code */ if ( tret == -1 ) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, "sbrk - Decrease to original 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, "sbrk - Decrease to original size returned %d", tret); } } } /* End for TEST_LOOPING */ /*************************************************************** * cleanup and exit ***************************************************************/ cleanup(); return 0; } /* End main */
int main(int ac, char **av) { int ret; int lc; key_serial_t ne_key; char *msg; if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); tst_exit(); } setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { Tst_count = 0; for (testno = 1; testno < TST_TOTAL; ++testno) { /* Call keyctl() and ask for a keyring's ID. */ ret = syscall(__NR_keyctl, KEYCTL_GET_KEYRING_ID, KEY_SPEC_USER_SESSION_KEYRING); if (ret != -1) { tst_resm(TPASS, "KEYCTL_GET_KEYRING_ID succeeded"); } else { tst_resm(TFAIL | TERRNO, "KEYCTL_GET_KEYRING_ID"); } for (ne_key = INT32_MAX; ne_key > INT32_MIN; ne_key--) { ret = syscall(__NR_keyctl, KEYCTL_READ, ne_key); if (ret == -1 && errno == ENOKEY) break; } /* Call keyctl. */ ret = syscall(__NR_keyctl, KEYCTL_REVOKE, ne_key); if (ret != -1) { tst_resm(TFAIL | TERRNO, "KEYCTL_REVOKE succeeded unexpectedly"); } else { /* Check for the correct error num. */ if (errno == ENOKEY) { tst_resm(TPASS | TERRNO, "KEYCTL_REVOKE got expected " "errno"); } else { tst_resm(TFAIL | TERRNO, "KEYCTL_REVOKE got unexpected " "errno"); } } } } cleanup(); return (1); }
int main(void) { tst_resm(TCONF, "keyctl syscall support not available on system"); tst_exit(); }
int main() { tst_resm(TPASS, "socket call test on this architecture disabled."); tst_exit(); tst_exit(); }
int main(int ac, char **av) { int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ struct itimerval *value; /* 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(); /* global setup */ /* The following loop checks looping state if -i option given */ for (lc = 0; TEST_LOOPING(lc); lc++) { /* reset Tst_count in case we are looping */ Tst_count = 0; /* allocate some space for a timer structure */ if ((value = (struct itimerval *)malloc((size_t) sizeof(struct itimerval))) == NULL) { tst_brkm(TBROK, cleanup, "value malloc failed"); } /* set up some reasonable values */ value->it_value.tv_sec = 30; value->it_value.tv_usec = 0; value->it_interval.tv_sec = 0; value->it_interval.tv_usec = 0; /* * issue the system call with the TEST() macro * ITIMER_REAL = 0, ITIMER_VIRTUAL = 1 and ITIMER_PROF = 2 */ /* call with a bad address */ TEST(setitimer(ITIMER_REAL, value, (struct itimerval *)-1)); if (TEST_RETURN == 0) { tst_resm(TFAIL, "call failed to produce EFAULT error " "- errno = %d - %s", TEST_ERRNO, strerror(TEST_ERRNO)); continue; } TEST_ERROR_LOG(TEST_ERRNO); switch (TEST_ERRNO) { case EFAULT: tst_resm(TPASS, "expected failure - errno = %d - %s", TEST_ERRNO, strerror(TEST_ERRNO)); break; default: tst_resm(TFAIL, "call failed to produce EFAULT error " "- errno = %d - %s", TEST_ERRNO, strerror(TEST_ERRNO)); } /* * clean up things in case we are looping */ free(value); value = NULL; } cleanup(); /*NOTREACHED*/ return(0); }
int main() { tst_resm(TINFO, "test is not available on uClinux"); return 0; }
int main(int ac, char **av) { struct stat stat_buf; /* struct buffer to hold file info. */ int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ time_t modf_time, access_time; /* file modification/access time */ /* 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; /* * Invoke utime(2) to set TEMP_FILE access and * modification times to that specified by * times argument. */ TEST(utime(TEMP_FILE, ×)); if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, "utime(%s) Failed, errno=%d : %s", TEMP_FILE, TEST_ERRNO, strerror(TEST_ERRNO)); } else { /* * Perform functional verification if test * executed without (-f) option. */ if (STD_FUNCTIONAL_TEST) { /* * Get the modification and access times of * temporary file using stat(2). */ if (stat(TEMP_FILE, &stat_buf) < 0) { tst_brkm(TFAIL, cleanup, "stat(2) of %s failed, " "error:%d", TEMP_FILE, TEST_ERRNO); } modf_time = stat_buf.st_mtime; access_time = stat_buf.st_atime; /* Now do the actual verification */ if ((modf_time != NEW_TIME) || (access_time != NEW_TIME)) { tst_resm(TFAIL, "%s access and " "modification times not set", TEMP_FILE); } else { tst_resm(TPASS, "Functionality of " "utime(%s, ×) successful", TEMP_FILE); } } 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, i; char *msg; msg = parse_opts(ac, av, options, &help); if (msg != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); /* Check for mandatory option of the testcase */ if (Dflag == 0) tst_brkm(TBROK, NULL, "You must specifiy the device used for " " mounting with -D option."); if (STD_COPIES != 1) { tst_resm(TINFO, "-c option has no effect for this testcase - " "%s doesn't allow running more than one instance " "at a time", TCID); STD_COPIES = 1; } setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; for (i = 0; i < TST_TOTAL; ++i) { if (setup_test(i, lc) != 0) { tst_resm(TWARN, "testcase setup failed"); continue; } /* Call mount(2) to test different test conditions. * verify that it fails with -1 return value and * sets appropriate errno. */ TEST(mount(Device, Mntpoint, Fstype, Flag, NULL)); /* check return code */ if (TEST_RETURN == -1 && TEST_ERRNO == exp_enos[i]) { tst_resm(TPASS | TERRNO, "mount got expected failure"); } else { if (umount(mntpoint) == -1) tst_brkm(TBROK | TERRNO, cleanup, "umount of %s failed", Mntpoint); tst_resm(TFAIL | TERRNO, "mount(2) failed to produce expected " "error (%d)", exp_enos[i]); } cleanup_test(i); } } cleanup(); tst_exit(); }
/***** LTP Port *****/ void ok_exit() { tst_resm(TPASS, "Test passed\n"); tst_exit(); }
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, options, &help)) != (char *)NULL) { tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); tst_exit(); } /* Check for mandatory option of the testcase */ if (Dflag == 0) { tst_brkm(TBROK, NULL, "You must specifiy the device used for " " mounting with -D option, Run '%s -h' for option " " information.", TCID); tst_exit(); } Type = (char *)malloc(FSTYPE_LEN); if (!Type) { tst_brkm(TBROK, NULL, "malloc - alloc of %d failed", FSTYPE_LEN); tst_exit(); } if (Tflag == 1) { strncpy(Type, fstype, (FSTYPE_LEN < strlen(fstype)) ? FSTYPE_LEN : strlen(fstype)); } else { strncpy(Type, DEFAULT_FSTYPE, strlen(DEFAULT_FSTYPE)); } if (STD_COPIES != 1) { tst_resm(TINFO, "-c option has no effect for this testcase - " "%s doesn't allow running more than one instance " "at a time", TCID); STD_COPIES = 1; } /* 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; for (i = 0; i < TST_TOTAL; ++i) { if (setup_test(i, lc)) { tst_resm(TWARN, "Not able to test mount(2) for " "error %s as setup failed", testcases[i].exp_errval); continue; } /* Call mount(2) to test different test conditions. * verify that it fails with -1 return value and * sets appropriate errno.*/ TEST(mount(Device, Mntpoint, Fstype, Flag, NULL)); /* check return code */ if ((TEST_RETURN == -1) && (TEST_ERRNO == testcases[i].exp_errno)) { tst_resm(TPASS, "mount(2) expected failure; " "Got errno - %s : %s", testcases[i].exp_errval, testcases[i].err_desc); } else { if (umount(mntpoint) == -1) { tst_brkm(TBROK, cleanup, "umount(2) " "failed to umount mntpoint %s " "errno - %d : %s", Mntpoint, TEST_ERRNO, strerror(TEST_ERRNO)); } tst_resm(TFAIL, "mount(2) failed to produce " "expected error; %d, errno:%s got %d", testcases[i].exp_errno, testcases[i].exp_errval, TEST_ERRNO); } TEST_ERROR_LOG(TEST_ERRNO); (void)cleanup_test(i); } /* End of TEST CASE LOOPING. */ } /* End for TEST_LOOPING */ /* cleanup and exit */ cleanup(); /*NOTREACHED*/ return 0; } /* End main */
/***** LTP Port *****/ void ok_exit() { tst_resm(TPASS, "Test passed\n"); tst_exit(); } int anyfail() { tst_resm(TFAIL, "Test failed\n"); tst_exit(); return 0; } #else /* defined(__i386__) || defined(__x86_64__) */ int main (void) { tst_resm (TCONF, "Test is only applicable for IA-32 and x86-64."); tst_exit (); }
/* * int * setup_test() - Setup function for test cases based on the error values * to be returned. */ int setup_test(int i, int cnt) { char temp[20]; Device = device; Fstype = Type; Mntpoint = mntpoint; Flag = 0; switch (i) { case 0: /* Setup for mount(2) returning errno ENODEV. */ strncpy(Type, "error", 5); Fstype = Type; return 0; case 1: /* Setup for mount(2) returning errno ENOTBLK. */ sprintf(Path, "./mydev_%d_%d", getpid(), cnt); TEST(mknod(Path, S_IFCHR | FILE_MODE, 0)); if (TEST_RETURN == 0) { Device = Path; return 0; } else { tst_resm(TWARN, "mknod(2) failed to creat device %s " "errno = %d : %s", Path, TEST_ERRNO, strerror(TEST_ERRNO)); return 1; } case 2: /* Setup for mount(2) returning errno EBUSY. */ TEST(mount(Device, Mntpoint, Fstype, 0, NULL)); if (TEST_RETURN != 0) { tst_resm(TWARN, "mount(2) failed to mount device %s " "errno = %d : %s", device, TEST_ERRNO, strerror(TEST_ERRNO)); return 1; } return 0; case 3: /* Setup for mount(2) returning errno EBUSY. */ TEST(mount(Device, Mntpoint, Fstype, 0, NULL)); if (TEST_RETURN != 0) { tst_resm(TWARN, "mount(2) failed to mount device %s " "errno = %d : %s", device, TEST_ERRNO, strerror(TEST_ERRNO)); return 1; } if (getcwd(Path, PATH_MAX) == NULL) { tst_resm(TWARN, "getcwd() failed to get current working" " directory errno = %d : %s", errno, strerror(errno)); return 1; } sprintf(temp, "/%s/t3_%d", mntpoint, cnt); strcat(Path, temp); if ((fd = open(Path, O_CREAT | O_RDWR, S_IRWXU)) == -1) { tst_resm(TWARN, "open() failed to create a file " " %s errno = %d : %s", Path, errno, strerror(errno)); return 1; } Flag = MS_REMOUNT | MS_RDONLY; return 0; case 4: /* Setup for mount(2) returning errno EINVAL. */ Device = NULL; break; case 5: /* Setup for mount(2) returning errno EINVAL. */ Fstype = NULL; break; case 6: /* Setup for mount(2) returning errno EINVAL. */ Flag = MS_REMOUNT; break; case 7: /* Setup for mount(2) returning errno EFAULT. */ Fstype = Einval; break; case 8: /* Setup for mount(2) returning errno EFAULT. */ Device = Einval; break; case 9: /* Setup for mount(2) returning errno ENAMETOOLONG. */ memset(Longpathname, 'a', PATH_MAX + 2); Mntpoint = Longpathname; break; case 10: /* Setup for mount(2) returning errno ENOENT. */ strncpy(Path, " ", 3); Mntpoint = Path; break; case 11: /* Setup for mount(2) returning errno ENOENT. */ sprintf(Path, "%s/noexistent", mntpoint); Mntpoint = Path; break; case 12: /* Setup for mount(2) returning errno ENOTDIR. */ if (getcwd(Path, PATH_MAX) == NULL) { tst_resm(TWARN, "getcwd() failed to get current working" " directory errno = %d : %s", errno, strerror(errno)); return 1; } sprintf(temp, "/t_%d_%d", getpid(), cnt); strcat(Path, temp); if ((fd = open(Path, O_CREAT, S_IRWXU)) == -1) { tst_resm(TWARN, "open() failed to create a file " " %s errno = %d : %s", Path, errno, strerror(errno)); return 1; } else { Mntpoint = Path; return 0; } } return 0; }
const char *tst_acquire_device_(void (cleanup_fn)(void), unsigned int size) { int fd; char *dev; struct stat st; unsigned int acq_dev_size; uint64_t ltp_dev_size; acq_dev_size = size > 150 ? size : 150; if (device_acquired) tst_brkm(TBROK, cleanup_fn, "Device allready acquired"); if (!tst_tmpdir_created()) { tst_brkm(TBROK, cleanup_fn, "Cannot acquire device without tmpdir() created"); } dev = getenv("LTP_DEV"); if (dev) { tst_resm(TINFO, "Using test device LTP_DEV='%s'", dev); SAFE_STAT(cleanup_fn, dev, &st); if (!S_ISBLK(st.st_mode)) { tst_brkm(TBROK, cleanup_fn, "%s is not a block device", dev); } fd = SAFE_OPEN(cleanup_fn, dev, O_RDONLY); SAFE_IOCTL(cleanup_fn, fd, BLKGETSIZE64, <p_dev_size); SAFE_CLOSE(cleanup_fn, fd); ltp_dev_size = ltp_dev_size/1024/1024; if (acq_dev_size <= ltp_dev_size) { if (tst_fill_file(dev, 0, 1024, 512)) { tst_brkm(TBROK | TERRNO, cleanup_fn, "Failed to clear the first 512k of %s", dev); } return dev; } tst_resm(TINFO, "Skipping $LTP_DEV size %"PRIu64"MB, requested size %uMB", ltp_dev_size, acq_dev_size); } if (tst_fill_file(DEV_FILE, 0, 1024, 1024 * acq_dev_size)) { tst_brkm(TBROK | TERRNO, cleanup_fn, "Failed to create " DEV_FILE); } if (find_free_loopdev()) return NULL; attach_device(cleanup_fn, dev_path, DEV_FILE); device_acquired = 1; return dev_path; }
int main(int ac, char **av) { struct stat stat_buf; /* stat structure buffer */ int lc; /* loop counter */ const 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(); /*NOTREACHED*/ } /* 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; /* * Call symlink(2) to create a symlink of * testfile. */ TEST(symlink(TESTFILE, SYMFILE)); /* Check return code of symlink(2) */ if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, "symlink(%s, %s) Failed, errno=%d : %s", TESTFILE, SYMFILE, TEST_ERRNO, strerror(TEST_ERRNO)); } else { /* * Perform functional verification if test * executed without (-f) option. */ if (STD_FUNCTIONAL_TEST) { /* * Get the symlink file status information * using lstat(2). */ if (lstat(SYMFILE, &stat_buf) < 0) { tst_brkm(TFAIL, cleanup, "lstat(2) of " "%s failed, error:%d", SYMFILE, errno); /*NOTREACHED*/ } /* Check if the st_mode contains a link */ if (!S_ISLNK(stat_buf.st_mode)) { tst_resm(TFAIL, "symlink of %s doesn't exist", TESTFILE); } else { tst_resm(TPASS, "symlink(%s, %s) " "functionality successful", TESTFILE, SYMFILE); } } else { tst_resm(TPASS, "Call succeeded"); } } /* Unlink the symlink file for next loop */ if (unlink(SYMFILE) == -1) { tst_brkm(TBROK, cleanup, "unlink(%s) Failed, errno=%d : %s", SYMFILE, errno, strerror(errno)); /*NOTREACHED*/ } Tst_count++; /* incr TEST_LOOP counter */ } /* End for TEST_LOOPING */ /* Call cleanup() to undo setup done for the test. */ cleanup(); /*NOTREACHED*/ } /* End main */
int main(int argc, char* argv[]) { int c; char *mem; float percent; unsigned int maxpercent = 0, dowrite = 0, verbose=0, j; unsigned long bytecount, alloc_bytes, max_pids; unsigned long long original_maxbytes, maxbytes = 0; unsigned long long pre_mem = 0, post_mem = 0; unsigned long long total_ram, total_free, D, C; int chunksize = 1024*1024; /* one meg at a time by default */ struct sysinfo sstats; int i, pid_cntr; pid_t pid, *pid_list; struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaction(SIGRTMIN, &act, 0); while ((c = getopt(argc, argv, "c:b:p:wvh")) != -1) { switch(c) { case 'c': chunksize = atoi(optarg); break; case 'b': if (maxpercent != 0) tst_brkm(TBROK, NULL, "ERROR: -b option cannot be used with -p " "option at the same time"); maxbytes = atoll(optarg); break; case 'p': if (maxbytes != 0) tst_brkm(TBROK, NULL, "ERROR: -p option cannot be used with -b " "option at the same time"); maxpercent = atoi(optarg); if (maxpercent <= 0) tst_brkm(TBROK, NULL, "ERROR: -p option requires number greater " "than 0"); if (maxpercent > 99) tst_brkm(TBROK, NULL, "ERROR: -p option cannot be greater than " "99"); break; case 'w': dowrite = 1; break; case 'v': verbose = 1; break; case 'h': default: printf("usage: %s [-c <bytes>] [-b <bytes>|-p <percent>] [-v]\n", argv[0]); printf("\t-c <num>\tsize of chunk in bytes to malloc on each pass\n"); printf("\t-b <bytes>\tmaximum number of bytes to allocate before stopping\n"); printf("\t-p <bytes>\tpercent of total memory used at which the program stops\n"); printf("\t-w\t\twrite to the memory after allocating\n"); printf("\t-v\t\tverbose\n"); printf("\t-h\t\tdisplay usage\n"); exit(1); } } sysinfo(&sstats); total_ram = sstats.totalram + sstats.totalswap; total_free = sstats.freeram + sstats.freeswap; /* Total Free Pre-Test RAM */ pre_mem = sstats.mem_unit * total_free; max_pids = total_ram / (unsigned long)FIVE_HUNDRED_MB + 1; if ((pid_list = malloc(max_pids * sizeof(pid_t))) == NULL) tst_brkm(TBROK|TERRNO, NULL, "malloc failed."); memset(pid_list, 0, max_pids * sizeof(pid_t)); /* Currently used memory */ C = sstats.mem_unit * (total_ram - total_free); tst_resm(TINFO, "Total memory already used on system = %llu kbytes", C / 1024); if (maxpercent) { percent = (float)maxpercent / 100.00; /* Desired memory needed to reach maxpercent */ D = percent * (sstats.mem_unit * total_ram); tst_resm(TINFO, "Total memory used needed to reach maximum = %llu kbytes", D / 1024); /* Are we already using more than maxpercent? */ if (C > D) { tst_resm(TFAIL, "More memory than the maximum amount you specified " " is already being used"); free(pid_list); tst_exit(); } /* set maxbytes to the extra amount we want to allocate */ maxbytes = D - C; tst_resm(TINFO, "Filling up %d%% of ram which is %llu kbytes", maxpercent, maxbytes / 1024); } original_maxbytes = maxbytes; i = 0; pid_cntr = 0; pid = fork(); if (pid != 0) pid_cntr++; pid_list[i] = pid; #if defined (_s390_) /* s390's 31bit addressing requires smaller chunks */ while (pid != 0 && maxbytes > FIVE_HUNDRED_MB) { i++; maxbytes -= FIVE_HUNDRED_MB; pid = fork(); if (pid != 0) { pid_cntr++; pid_list[i] = pid; } } if (maxbytes > FIVE_HUNDRED_MB) alloc_bytes = FIVE_HUNDRED_MB; else alloc_bytes = (unsigned long) maxbytes; #elif __WORDSIZE == 32 while (pid != 0 && maxbytes > ONE_GB) { i++; maxbytes -= ONE_GB; pid = fork(); if (pid != 0) { pid_cntr++; pid_list[i]=pid; } } if (maxbytes > ONE_GB) alloc_bytes = ONE_GB; else alloc_bytes = (unsigned long)maxbytes; #elif __WORDSIZE == 64 while (pid != 0 && maxbytes > THREE_GB) { i++; maxbytes -= THREE_GB; pid = fork(); if (pid != 0) { pid_cntr++; pid_list[i] = pid; } } if (maxbytes > THREE_GB) alloc_bytes = THREE_GB; else alloc_bytes = maxbytes; #endif if (pid == 0) { bytecount = chunksize; while (1) { if ((mem = malloc(chunksize)) == NULL) { tst_resm(TBROK|TERRNO, "stopped at %lu bytes", bytecount); free(pid_list); tst_exit(); } if (dowrite) for (j = 0; j < chunksize; j++) *(mem+j) = 'a'; if (verbose) tst_resm(TINFO, "allocated %lu bytes chunksize is %d", bytecount, chunksize); bytecount += chunksize; if (alloc_bytes && bytecount >= alloc_bytes) break; } if (dowrite) tst_resm(TINFO, "... %lu bytes allocated and used.", bytecount); else tst_resm(TINFO, "... %lu bytes allocated only.", bytecount); kill(getppid(), SIGRTMIN); while (1) sleep(1); } else { i = 0; sysinfo(&sstats); if (dowrite) { /* Total Free Post-Test RAM */ post_mem = (unsigned long long)sstats.mem_unit * sstats.freeram; post_mem = post_mem + (unsigned long long)sstats.mem_unit * sstats.freeswap; while ((((unsigned long long)pre_mem - post_mem) < (unsigned long long)original_maxbytes) && pid_count < pid_cntr) { sleep(1); sysinfo(&sstats); post_mem = (unsigned long long)sstats.mem_unit * sstats.freeram; post_mem = post_mem + (unsigned long long)sstats.mem_unit * sstats.freeswap; } } while (pid_list[i] != 0) { kill(pid_list[i], SIGKILL); i++; } if (dowrite) tst_resm(TPASS, "%llu kbytes allocated and used.", original_maxbytes / 1024); else tst_resm(TPASS, "%llu kbytes allocated only.", original_maxbytes / 1024); } free(pid_list); tst_exit(); }
int main(int argc, char *argv[]) { int msg_count; socklen_t len; int sk,sk1,pf_class,lstn_sk,acpt_sk,flag; char *message = "hello, world!\n"; char *message_rcv; int count; struct sockaddr_in conn_addr,lstn_addr,svr_addr; /* Rather than fflush() throughout the code, set stdout to * be unbufferd */ 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); message_rcv = malloc(512); 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); flag = MSG_NOSIGNAL; test_connect(sk, (struct sockaddr *) &conn_addr, len); acpt_sk = test_accept(lstn_sk, (struct sockaddr *)&svr_addr, &len); msg_count = strlen(message) + 1; /*sendto() TEST1: Sending data from client socket to server socket*/ count = sendto(sk, message, msg_count, flag, (const struct sockaddr *) &conn_addr, len); if (count != msg_count) tst_brkm(TBROK, tst_exit, "sendto from client to server " "count:%d, errno:%d", count, errno); tst_resm(TPASS, "sendto() from client to server - SUCCESS"); test_recv(acpt_sk, message_rcv, msg_count, flag); strncpy(message_rcv,"\0",512); /*sendto() TEST2: Sending data from accept socket to client socket*/ count = sendto(acpt_sk, message, msg_count, flag, (const struct sockaddr *) &svr_addr, len); if (count != msg_count) tst_brkm(TBROK, tst_exit, "sendto from accept socket to client " "count:%d, errno:%d", count, errno); tst_resm(TPASS, "sendto() from accept socket to client - SUCCESS"); test_recv(sk, message_rcv, msg_count, flag); close(sk); close(acpt_sk); sk1 = test_socket(pf_class, SOCK_STREAM, IPPROTO_SCTP); /*sendto() TEST3: Sending data from unconnected client socket to server socket*/ count = sendto(sk1, message, msg_count, flag, (const struct sockaddr *) &conn_addr, len); if (count != msg_count) tst_brkm(TBROK, tst_exit, "sendto from unconnected client to " "server count:%d, errno:%d", count, errno); tst_resm(TPASS, "sendto() from unconnected client to server - SUCCESS"); acpt_sk = test_accept(lstn_sk, (struct sockaddr *)&svr_addr, &len); test_recv(acpt_sk, message_rcv, msg_count, flag); /*send() TEST4: Sending less number of data from the buffer*/ /*Sending only 5 bytes so that only hello is received*/ test_sendto(sk, message, 5 , flag, (const struct sockaddr *)&conn_addr, len); test_recv(acpt_sk, message_rcv, 5, flag); tst_resm(TPASS, "sendto() partial data from a buffer - SUCCESS"); close(sk1); close(lstn_sk); close(acpt_sk); return 0; }
int main(int ac, char **av) { tst_resm(TCONF, "personality() not defined in your system"); tst_exit(); }
int main(int ac, char **av) { int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ /*************************************************************** * parse standard options ***************************************************************/ if ((msg = parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *)NULL) { tst_brkm(TBROK, 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; for (i = 0; i < TST_TOTAL; i++) { /* * Call fpathconf(2) with one of the valid arguments in the args array */ TEST(fpathconf(fd, args[i].value)); /* check return code -- if the return value is defined */ if ((TEST_RETURN == -1) && args[i].defined) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, "fpathconf(fd, %s) Failed, errno=%d : %s", 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, "fpathconf(fd, %s) returned %ld", args[i].define_tag, TEST_RETURN); } } } /* End for i */ } /* End for TEST_LOOPING */ /*************************************************************** * cleanup and exit ***************************************************************/ cleanup(); return 0; } /* End main */
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(Fd, (long)1, SEEK_SET)); /* check return code */ if ( TEST_RETURN == -1 ) { if ( STD_FUNCTIONAL_TEST ) { if ( TEST_ERRNO == ESPIPE ) tst_resm(TPASS, "lseek(fifofd, 1, SEEK_SET) Failed, errno=%d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); else tst_resm(TFAIL, "lseek(fifofd, 1, SEEK_SET) Failed, errno=%d %s, expected %d(ESPIPE)", TEST_ERRNO, strerror(TEST_ERRNO), EINVAL); } else Tst_count++; } else { tst_resm(TFAIL, "lseek(fifofd, 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) { #ifdef __NR_set_robust_list int lc; #endif #ifdef __NR_set_robust_list struct robust_list_head head; size_t len; /* size of structure struct robust_list_head */ int retval; #endif tst_parse_opts(argc, argv, NULL, NULL); setup(); #ifdef __NR_set_robust_list len = sizeof(struct robust_list_head); for (lc = 0; TEST_LOOPING(lc); ++lc) { tst_count = 0; /* * The set_robust_list function fails with EINVAL if the len argument * doesn't match the size of structure struct robust_list_head. */ TEST(retval = syscall(__NR_set_robust_list, &head, -1)); if (TEST_RETURN) { if (TEST_ERRNO == EINVAL) tst_resm(TPASS, "set_robust_list: retval = %ld (expected %d), " "errno = %d (expected %d)", TEST_RETURN, -1, TEST_ERRNO, EINVAL); else tst_resm(TFAIL, "set_robust_list: retval = %ld (expected %d), " "errno = %d (expected %d)", TEST_RETURN, -1, TEST_ERRNO, EINVAL); } else { tst_resm(TFAIL, "set_robust_list: retval = %ld (expected %d), " "errno = %d (expected %d)", TEST_RETURN, -1, TEST_ERRNO, EINVAL); } /* * This call to set_robust_list function should be sucessful. */ TEST(retval = syscall(__NR_set_robust_list, &head, len)); if (TEST_RETURN == 0) { tst_resm(TPASS, "set_robust_list: retval = %ld (expected %d), " "errno = %d (expected %d)", TEST_RETURN, 0, TEST_ERRNO, 0); } else { tst_resm(TFAIL, "set_robust_list: retval = %ld (expected %d), " "errno = %d (expected %d)", TEST_RETURN, 0, TEST_ERRNO, 0); } } #else tst_resm(TCONF, "set_robust_list: system call not available."); #endif cleanup(); exit(EXIT_SUCCESS); }
int main(int ac, char **av) { int lc; char *msg; pid_t pid; int i, rval; if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); } 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; /* * loop through the list of signals and test each one */ for (i = 0; i < TST_TOTAL; i++) { errno = 0; Tret = signal(siglist[i], &sighandler); TEST_ERRNO = errno; if (Tret == SIG_ERR) { tst_resm(TFAIL, "%s call failed - errno = %d " ": %s", TCID, TEST_ERRNO, strerror(TEST_ERRNO)); continue; } if (STD_FUNCTIONAL_TEST) { /* * Send the signals and make sure they are * handled in our handler. */ pid = getpid(); if ((rval = kill(pid, siglist[i])) != 0) { tst_brkm(TBROK, cleanup, "call to kill failed"); } if (siglist[i] == pass) { tst_resm(TPASS, "%s call succeeded", TCID); } else { tst_resm(TFAIL, "received unexpected signal"); } } else { tst_resm(TPASS, "Call succeeded"); } } } cleanup(); tst_exit(); }
int main(int ac, char **av) { struct stat stat_buf; /* stat struct. */ int lc; char *msg; mode_t dir_mode; /* mode permissions set on testdirectory */ 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 chmod(2) with mode argument to * set sticky bit on TESTDIR */ TEST(chmod(TESTDIR, PERMS)); if (TEST_RETURN == -1) { tst_resm(TFAIL|TTERRNO, "chmod(%s, %#o) failed", TESTDIR, PERMS); continue; } /* * Perform functional verification if test * executed without (-f) option. */ if (STD_FUNCTIONAL_TEST) { /* * Get the file information using * stat(2). */ if (stat(TESTDIR, &stat_buf) < 0) { tst_brkm(TFAIL, cleanup, "stat(2) of %s failed, errno:%d", TESTDIR, TEST_ERRNO); } dir_mode = stat_buf.st_mode; /* Verify STICKY BIT SET on directory */ if ((dir_mode & PERMS) == PERMS) { tst_resm(TPASS, "Functionality of " "chmod(%s, %#o) successful", TESTDIR, PERMS); } else { tst_resm(TFAIL, "%s: Incorrect modes 0%03o, " "Expected 0%03o", TESTDIR, dir_mode, PERMS); } } else tst_resm(TPASS, "call succeeded"); } cleanup(); tst_exit(); }