ATF_TC_BODY(cleanup__mount_point__busy, tc) { ATF_REQUIRE(mkdir("root", 0755) != -1); ATF_REQUIRE(mkdir("root/dir1", 0755) != -1); mount_tmpfs("root/dir1"); pid_t pid = fork(); ATF_REQUIRE(pid != -1); if (pid == 0) { if (chdir("root/dir1") == -1) abort(); atf_utils_create_file("dont-delete-me", "%s", ""); atf_utils_create_file("../../done", "%s", ""); pause(); exit(EXIT_SUCCESS); } else { fprintf(stderr, "Waiting for child to finish preparations\n"); while (!atf_utils_file_exists("done")) {} fprintf(stderr, "Child done; cleaning up\n"); ATF_REQUIRE(kyua_error_is_set(kyua_fs_cleanup("root"))); ATF_REQUIRE(atf_utils_file_exists("root/dir1/dont-delete-me")); fprintf(stderr, "Killing child\n"); ATF_REQUIRE(kill(pid, SIGKILL) != -1); int status; ATF_REQUIRE(waitpid(pid, &status, 0) != -1); ATF_REQUIRE(!kyua_error_is_set(kyua_fs_cleanup("root"))); ATF_REQUIRE(!lookup(".", "root", DT_DIR)); } }
ATF_TC_BODY(file_exists, tc) { atf_utils_create_file("test.txt", "foo"); ATF_REQUIRE( atf_utils_file_exists("test.txt")); ATF_REQUIRE( atf_utils_file_exists("./test.txt")); ATF_REQUIRE(!atf_utils_file_exists("./test.tx")); ATF_REQUIRE(!atf_utils_file_exists("test.txt2")); }
ATF_TC_BODY(unmount__ok, tc) { ATF_REQUIRE(mkdir("mount_point", 0755) != -1); atf_utils_create_file("mount_point/test1", "%s", ""); mount_tmpfs("mount_point"); atf_utils_create_file("mount_point/test2", "%s", ""); ATF_REQUIRE(!atf_utils_file_exists("mount_point/test1")); ATF_REQUIRE( atf_utils_file_exists("mount_point/test2")); kyua_fs_unmount("mount_point"); ATF_REQUIRE( atf_utils_file_exists("mount_point/test1")); ATF_REQUIRE(!atf_utils_file_exists("mount_point/test2")); }
FILE *setup(struct pollfd fd[], const char *name) { au_mask_t fmask, nomask; fmask = get_audit_mask(name); nomask = get_audit_mask("no"); FILE *pipestream; ATF_REQUIRE((fd[0].fd = open("/dev/auditpipe", O_RDONLY)) != -1); ATF_REQUIRE((pipestream = fdopen(fd[0].fd, "r")) != NULL); fd[0].events = POLLIN; /* * Disable stream buffering for read operations from /dev/auditpipe. * Otherwise it is possible that fread(3), called via au_read_rec(3), * can store buffered data in user-space unbeknown to ppoll(2), which * as a result, reports that /dev/auditpipe is empty. */ ATF_REQUIRE_EQ(0, setvbuf(pipestream, NULL, _IONBF, 0)); /* Set local preselection audit_class as "no" for audit startup */ set_preselect_mode(fd[0].fd, &nomask); ATF_REQUIRE_EQ(0, system("service auditd onestatus || \ { service auditd onestart && touch started_auditd ; }")); /* If 'started_auditd' exists, that means we started auditd(8) */ if (atf_utils_file_exists("started_auditd")) check_audit_startup(fd, "audit startup", pipestream); /* Set local preselection parameters specific to "name" audit_class */ set_preselect_mode(fd[0].fd, &fmask); return (pipestream); }
ATF_TC_BODY(test__invalid_test_case_name, tc) { check(EXIT_INTERNAL_ERROR, "", "kyua-plain-tester: Unknown test case 'foo'\n", "test", "./non-existent", "foo", "test-result", NULL); ATF_REQUIRE(!atf_utils_file_exists("test-result")); }
ATF_TC_BODY(test__missing_test_program, tc) { check(EXIT_INTERNAL_ERROR, "", "kyua-plain-tester: execvp failed: No such file or directory\n", "test", "./non-existent", "main", "test-result", NULL); ATF_REQUIRE(!atf_utils_file_exists("test-result")); }
bool atf::utils::file_exists(const std::string& path) { return atf_utils_file_exists(path.c_str()); }
/// Subprocess that validates that the umask has been reset. /// /// \param cookie The name of a file to expect in the current directory. /// /// \post Exits with success if the umask matches the expected value; failure /// otherwise. static void check_work_directory(const void* cookie) { const char* exp_file = (const char*)cookie; exit(atf_utils_file_exists(exp_file) ? EXIT_SUCCESS : EXIT_FAILURE); }
void cleanup(void) { if (atf_utils_file_exists("started_auditd")) system("service auditd onestop > /dev/null 2>&1"); }