diff --git a/utils/process/Kyuafile b/utils/process/Kyuafile index 37ab6629..1eb47ef5 100644 --- a/utils/process/Kyuafile +++ b/utils/process/Kyuafile @@ -6,7 +6,7 @@ atf_test_program{name="child_test"} atf_test_program{name="deadline_killer_test"} atf_test_program{name="exceptions_test"} atf_test_program{name="executor_test"} -atf_test_program{name="executor_pid_test"} +atf_test_program{name="executor_pid_test", required_user="root"} atf_test_program{name="fdstream_test"} atf_test_program{name="isolation_test"} atf_test_program{name="operations_test"} diff --git a/utils/process/Makefile.am.inc b/utils/process/Makefile.am.inc index a0137075..31cd8db7 100644 --- a/utils/process/Makefile.am.inc +++ b/utils/process/Makefile.am.inc @@ -84,8 +84,8 @@ utils_process_executor_test_CXXFLAGS = $(UTILS_CFLAGS) $(ATF_CXX_CFLAGS) utils_process_executor_test_LDADD = $(UTILS_LIBS) $(ATF_CXX_LIBS) tests_utils_process_PROGRAMS += utils/process/executor_pid_test -utils_process_executor_pid_test_SOURCES = utils/process/executor_pid_test.cpp -utils_process_executor_pid_test_CXXFLAGS = $(UTILS_CFLAGS) $(ATF_CXX_CFLAGS) +utils_process_executor_pid_test_SOURCES = utils/process/executor_pid_test.c +utils_process_executor_pid_test_CFLAGS = $(UTILS_CFLAGS) $(ATF_CXX_CFLAGS) utils_process_executor_pid_test_LDADD = $(UTILS_LIBS) $(ATF_CXX_LIBS) tests_utils_process_PROGRAMS += utils/process/fdstream_test diff --git a/utils/process/executor_pid_test.cpp b/utils/process/executor_pid_test.c similarity index 57% rename from utils/process/executor_pid_test.cpp rename to utils/process/executor_pid_test.c index 22e0b90b..17f9bc02 100644 --- a/utils/process/executor_pid_test.cpp +++ b/utils/process/executor_pid_test.c @@ -69,28 +69,33 @@ Abort trap (core dumped) #include -#include +#include +#include #include #include +#include +#include +#include #include -#include -#include - void -leak_work_dir() +leak_work_dir(void) { int fd; - ATF_REQUIRE((fd = open("unforgettable", O_CREAT|O_EXCL|O_WRONLY, 0600)) - >= 0); - ATF_REQUIRE_EQ(0, fchflags(fd, UF_NOUNLINK)); + fd = open("unforgettable", O_CREAT|O_EXCL|O_WRONLY, 0600); + ATF_REQUIRE_MSG(fd != -1, + "open(..., O_CREAT|O_EXCL|O_WRONLY, 0600) failed unexpectedly: %s", + strerror(errno)); + ATF_REQUIRE_EQ_MSG(0, fchflags(fd, SF_NOUNLINK), + "fchflags(..., UF_NOUNLINK): failed unexpectedly: %s", + strerror(errno)); ATF_REQUIRE_EQ(0, close(fd)); } void -wrap_pids() +wrap_pids(void) { pid_t begin, current, target; bool wrapped; @@ -119,90 +124,87 @@ wrap_pids() } void -test_work_dir_reuse() +test_work_dir_reuse(void) { // If kyua is built with debugging, it would abort here before the fix. } void -clean_up() +clean_up(void) +{ + (void)system("chflags -R nosunlink ../.."); +} + +#define LEAK_WORKDIR_TC(name) \ + ATF_TC_WITHOUT_HEAD(name); \ + ATF_TC_BODY(name, tc) { \ + leak_work_dir(); \ + } + +LEAK_WORKDIR_TC(leak_0) +LEAK_WORKDIR_TC(leak_1) +LEAK_WORKDIR_TC(leak_2) +LEAK_WORKDIR_TC(leak_3) +LEAK_WORKDIR_TC(leak_4) +LEAK_WORKDIR_TC(leak_5) +LEAK_WORKDIR_TC(leak_6) +LEAK_WORKDIR_TC(leak_7) +LEAK_WORKDIR_TC(leak_8) +LEAK_WORKDIR_TC(leak_9) + +ATF_TC_WITHOUT_HEAD(pid_wrap); +ATF_TC_BODY(pid_wrap, tc) { wrap_pids(); } + +#define PID_WRAP_TC(name) \ + ATF_TC_WITHOUT_HEAD(name); \ + ATF_TC_BODY(name, tc) { \ + test_work_dir_reuse(); \ + } + +PID_WRAP_TC(pid_wrap_0) +PID_WRAP_TC(pid_wrap_1) +PID_WRAP_TC(pid_wrap_2) +PID_WRAP_TC(pid_wrap_3) +PID_WRAP_TC(pid_wrap_4) +PID_WRAP_TC(pid_wrap_5) +PID_WRAP_TC(pid_wrap_6) +PID_WRAP_TC(pid_wrap_7) +PID_WRAP_TC(pid_wrap_8) +PID_WRAP_TC(pid_wrap_9) + +ATF_TC_WITHOUT_HEAD(really_clean_up); +ATF_TC_BODY(really_clean_up, tc) { - (void)system("chflags -R nouunlink ../.."); + clean_up(); } -ATF_TEST_CASE_WITHOUT_HEAD(leak_0); -ATF_TEST_CASE_BODY(leak_0) { leak_work_dir(); } -ATF_TEST_CASE_WITHOUT_HEAD(leak_1); -ATF_TEST_CASE_BODY(leak_1) { leak_work_dir(); } -ATF_TEST_CASE_WITHOUT_HEAD(leak_2); -ATF_TEST_CASE_BODY(leak_2) { leak_work_dir(); } -ATF_TEST_CASE_WITHOUT_HEAD(leak_3); -ATF_TEST_CASE_BODY(leak_3) { leak_work_dir(); } -ATF_TEST_CASE_WITHOUT_HEAD(leak_4); -ATF_TEST_CASE_BODY(leak_4) { leak_work_dir(); } -ATF_TEST_CASE_WITHOUT_HEAD(leak_5); -ATF_TEST_CASE_BODY(leak_5) { leak_work_dir(); } -ATF_TEST_CASE_WITHOUT_HEAD(leak_6); -ATF_TEST_CASE_BODY(leak_6) { leak_work_dir(); } -ATF_TEST_CASE_WITHOUT_HEAD(leak_7); -ATF_TEST_CASE_BODY(leak_7) { leak_work_dir(); } -ATF_TEST_CASE_WITHOUT_HEAD(leak_8); -ATF_TEST_CASE_BODY(leak_8) { leak_work_dir(); } -ATF_TEST_CASE_WITHOUT_HEAD(leak_9); -ATF_TEST_CASE_BODY(leak_9) { leak_work_dir(); } - -ATF_TEST_CASE_WITHOUT_HEAD(pid_wrap); -ATF_TEST_CASE_BODY(pid_wrap) { wrap_pids(); } - -ATF_TEST_CASE_WITHOUT_HEAD(pid_wrap_0); -ATF_TEST_CASE_BODY(pid_wrap_0) { test_work_dir_reuse(); } -ATF_TEST_CASE_WITHOUT_HEAD(pid_wrap_1); -ATF_TEST_CASE_BODY(pid_wrap_1) { test_work_dir_reuse(); } -ATF_TEST_CASE_WITHOUT_HEAD(pid_wrap_2); -ATF_TEST_CASE_BODY(pid_wrap_2) { test_work_dir_reuse(); } -ATF_TEST_CASE_WITHOUT_HEAD(pid_wrap_3); -ATF_TEST_CASE_BODY(pid_wrap_3) { test_work_dir_reuse(); } -ATF_TEST_CASE_WITHOUT_HEAD(pid_wrap_4); -ATF_TEST_CASE_BODY(pid_wrap_4) { test_work_dir_reuse(); } -ATF_TEST_CASE_WITHOUT_HEAD(pid_wrap_5); -ATF_TEST_CASE_BODY(pid_wrap_5) { test_work_dir_reuse(); } -ATF_TEST_CASE_WITHOUT_HEAD(pid_wrap_6); -ATF_TEST_CASE_BODY(pid_wrap_6) { test_work_dir_reuse(); } -ATF_TEST_CASE_WITHOUT_HEAD(pid_wrap_7); -ATF_TEST_CASE_BODY(pid_wrap_7) { test_work_dir_reuse(); } -ATF_TEST_CASE_WITHOUT_HEAD(pid_wrap_8); -ATF_TEST_CASE_BODY(pid_wrap_8) { test_work_dir_reuse(); } -ATF_TEST_CASE_WITHOUT_HEAD(pid_wrap_9); -ATF_TEST_CASE_BODY(pid_wrap_9) { test_work_dir_reuse(); } - -ATF_TEST_CASE_WITHOUT_HEAD(really_clean_up); -ATF_TEST_CASE_BODY(really_clean_up) { clean_up(); } - -ATF_INIT_TEST_CASES(tcs) +ATF_TP_ADD_TCS(tcs) { - ATF_ADD_TEST_CASE(tcs, leak_0); - ATF_ADD_TEST_CASE(tcs, leak_1); - ATF_ADD_TEST_CASE(tcs, leak_2); - ATF_ADD_TEST_CASE(tcs, leak_3); - ATF_ADD_TEST_CASE(tcs, leak_4); - ATF_ADD_TEST_CASE(tcs, leak_5); - ATF_ADD_TEST_CASE(tcs, leak_6); - ATF_ADD_TEST_CASE(tcs, leak_7); - ATF_ADD_TEST_CASE(tcs, leak_8); - ATF_ADD_TEST_CASE(tcs, leak_9); - - ATF_ADD_TEST_CASE(tcs, pid_wrap); - - ATF_ADD_TEST_CASE(tcs, pid_wrap_0); - ATF_ADD_TEST_CASE(tcs, pid_wrap_1); - ATF_ADD_TEST_CASE(tcs, pid_wrap_2); - ATF_ADD_TEST_CASE(tcs, pid_wrap_3); - ATF_ADD_TEST_CASE(tcs, pid_wrap_4); - ATF_ADD_TEST_CASE(tcs, pid_wrap_5); - ATF_ADD_TEST_CASE(tcs, pid_wrap_6); - ATF_ADD_TEST_CASE(tcs, pid_wrap_7); - ATF_ADD_TEST_CASE(tcs, pid_wrap_8); - ATF_ADD_TEST_CASE(tcs, pid_wrap_9); - - ATF_ADD_TEST_CASE(tcs, really_clean_up); + ATF_TP_ADD_TC(tcs, leak_0); + ATF_TP_ADD_TC(tcs, leak_1); + ATF_TP_ADD_TC(tcs, leak_2); + ATF_TP_ADD_TC(tcs, leak_3); + ATF_TP_ADD_TC(tcs, leak_4); + ATF_TP_ADD_TC(tcs, leak_5); + ATF_TP_ADD_TC(tcs, leak_6); + ATF_TP_ADD_TC(tcs, leak_7); + ATF_TP_ADD_TC(tcs, leak_8); + ATF_TP_ADD_TC(tcs, leak_9); + + ATF_TP_ADD_TC(tcs, pid_wrap); + + ATF_TP_ADD_TC(tcs, pid_wrap_0); + ATF_TP_ADD_TC(tcs, pid_wrap_1); + ATF_TP_ADD_TC(tcs, pid_wrap_2); + ATF_TP_ADD_TC(tcs, pid_wrap_3); + ATF_TP_ADD_TC(tcs, pid_wrap_4); + ATF_TP_ADD_TC(tcs, pid_wrap_5); + ATF_TP_ADD_TC(tcs, pid_wrap_6); + ATF_TP_ADD_TC(tcs, pid_wrap_7); + ATF_TP_ADD_TC(tcs, pid_wrap_8); + ATF_TP_ADD_TC(tcs, pid_wrap_9); + + ATF_TP_ADD_TC(tcs, really_clean_up); + + return atf_no_error(); }