static void setup(void) { tst_sig(NOFORK, DEF_HANDLER, cleanup); tst_require_root(NULL); TEST_EXP_ENOS(exp_enos); /* Load first kernel module */ tst_module_load(cleanup, DUMMY_MOD_KO, NULL); dummy_mod_loaded = 1; /* Load dependant kernel module */ tst_module_load(cleanup, DUMMY_MOD_DEP_KO, NULL); dummy_mod_dep_loaded = 1; if (STD_COPIES != 1) { tst_resm(TINFO, "-c option has no effect for this testcase - " "doesn't allow running more than one instance " "at a time"); STD_COPIES = 1; } TEST_PAUSE; }
int main(int argc, char *argv[]) { const char *msg; msg = parse_opts(argc, argv, NULL, NULL); if (msg != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); tst_require_root(NULL); if (tst_kvercmp(2, 6, 0) < 0) { tst_brkm(TCONF, NULL, "Test must be run with kernel 2.6 or newer"); } tst_sig(FORK, DEF_HANDLER, cleanup); tst_module_load(NULL, module_name, NULL); module_loaded = 1; test_run(); cleanup(); tst_exit(); }
int main(int argc, char **argv) { int lc; char *msg; msg = parse_opts(argc, argv, NULL, NULL); if (msg != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; /* insert dummy_del_mod.ko */ if (module_loaded == 0) { tst_module_load(NULL, MODULE_NAME_KO, NULL); module_loaded = 1; } TEST(ltp_syscall(__NR_delete_module, MODULE_NAME, 0)); if (TEST_RETURN == -1) { tst_resm(TFAIL | TTERRNO, "delete_module() failed to " "remove module entry for %s ", MODULE_NAME); } else { tst_resm(TPASS, "delete_module() successful"); module_loaded = 0; } } cleanup(); tst_exit(); }
static void test_run(void) { tst_module_load(cleanup, module_name, NULL); module_loaded = 1; char buf[6]; int i, j, fd, count; for (i = 0; i < MAX_BUS; ++i) { for (j = 0; j < MAX_DEVFN; ++j) { /* set pci device for the test */ fd = SAFE_OPEN(cleanup, dev_busslot, O_WRONLY); count = snprintf(buf, 6, "%u", i << 8 | j); errno = 0; if (write(fd, buf, count) < 0) { if (errno == ENODEV) { SAFE_CLOSE(cleanup, fd); continue; } tst_brkm(TBROK | TERRNO, cleanup, "write to '%s' failed", dev_busslot); } SAFE_CLOSE(cleanup, fd); run_pci_testcases(i, j); } } }
int main(int argc, char **argv) { int lc; char *msg; msg = parse_opts(argc, argv, NULL, NULL); if (msg != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; TEST(ltp_syscall(__NR_delete_module, DUMMY_MOD, 0)); TEST_ERROR_LOG(errno); if (TEST_RETURN < 0) { switch (errno) { case EWOULDBLOCK: tst_resm(TPASS | TTERRNO, "delete_module() failed as expected"); break; default: tst_resm(TFAIL | TTERRNO, "delete_module() " "failed unexpectedly; expected: " "%d - %s", EWOULDBLOCK, strerror(EWOULDBLOCK)); break; } } else { tst_resm(TFAIL, "delete_module()" "succeeded unexpectedly"); dummy_mod_loaded = 0; /* * insmod DUMMY_MOD_KO again in case running * with -i option */ tst_module_load(cleanup, DUMMY_MOD_KO, NULL); dummy_mod_loaded = 1; } } cleanup(); tst_exit(); }
static void test_run(void) { int off = 0; /* * test-cases #8 and #9 can crash the kernel. * We have to wait for kernel fix where register_blkdev() & * unregister_blkdev() checks the input device name parameter * against NULL pointer. */ if (!run_all_testcases) off = 2; tst_module_load(cleanup, module_name, NULL); module_loaded = 1; int i, pass = 0; for (i = 0; i < TST_TOTAL - off; ++i) { SAFE_FILE_PRINTF(cleanup, dev_tcase, "%d", i + 1); SAFE_FILE_SCANF(cleanup, dev_result, "%d", &pass); tst_resm((pass) ? TPASS : TFAIL, "Test-case '%d'", i + 1); } }
void setup(void) { dev_t devt; struct stat st; unsigned int i, valid_node_created; tst_require_root(); if (tst_kvercmp(2, 6, 0) < 0) { tst_brkm(TCONF, NULL, "Test must be run with kernel 2.6 or newer"); } tst_module_load(cleanup, module_name, NULL); module_loaded = 1; SAFE_FILE_SCANF(cleanup, "/sys/class/block/tbio/dev", "%d:0", &TBIO_MAJOR); devt = makedev(TBIO_MAJOR, 0); /* * Wait until udev creates the device node. * If the node is not created or invalid, create it manually. */ valid_node_created = 0; for (i = 0; i < 50; i++) { if (stat(DEVICE_NAME, &st)) { if (errno != ENOENT) tst_brkm(TBROK | TERRNO, cleanup, "stat() failed"); } else { if ((st.st_mode & S_IFBLK) && (st.st_rdev == devt)) { valid_node_created = 1; break; } } usleep(100000); } if (!valid_node_created) { tst_resm(TINFO, "The device file was not created by udev, " "proceeding with manual creation"); if (unlink(DEVICE_NAME) && (errno != ENOENT)) tst_brkm(TBROK | TERRNO, cleanup, "unlink() failed"); if (mknod(DEVICE_NAME, S_IFBLK | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP, devt)) tst_brkm(TBROK | TERRNO, cleanup, "mknod() failed"); } tbio_fd = open(DEVICE_NAME, O_RDWR); if (tbio_fd < 0) { tst_brkm(TBROK | TERRNO, cleanup, "open of %s failed", DEVICE_NAME); } tst_resm(TINFO, "Device opened successfully "); }