Changeset View
Changeset View
Standalone View
Standalone View
tests/sys/kern/ptrace_test.c
Show First 20 Lines • Show All 231 Lines • ▼ Show 20 Lines | |||||
*/ | */ | ||||
ATF_TC_WITHOUT_HEAD(ptrace__parent_wait_after_attach); | ATF_TC_WITHOUT_HEAD(ptrace__parent_wait_after_attach); | ||||
ATF_TC_BODY(ptrace__parent_wait_after_attach, tc) | ATF_TC_BODY(ptrace__parent_wait_after_attach, tc) | ||||
{ | { | ||||
pid_t child, wpid; | pid_t child, wpid; | ||||
int cpipe[2], status; | int cpipe[2], status; | ||||
char c; | char c; | ||||
if (atf_tc_get_config_var_as_bool_wd(tc, "ci", false)) | |||||
atf_tc_skip("https://bugs.freebsd.org/244055"); | |||||
REQUIRE_EQ(pipe(cpipe), 0); | REQUIRE_EQ(pipe(cpipe), 0); | ||||
ATF_REQUIRE((child = fork()) != -1); | ATF_REQUIRE((child = fork()) != -1); | ||||
if (child == 0) { | if (child == 0) { | ||||
/* Child process. */ | /* Child process. */ | ||||
close(cpipe[0]); | close(cpipe[0]); | ||||
/* Wait for the parent to attach. */ | /* Wait for the parent to attach. */ | ||||
CHILD_REQUIRE_EQ(0, read(cpipe[1], &c, sizeof(c))); | CHILD_REQUIRE_EQ(0, read(cpipe[1], &c, sizeof(c))); | ||||
Show All 31 Lines | |||||
*/ | */ | ||||
ATF_TC_WITHOUT_HEAD(ptrace__parent_sees_exit_after_child_debugger); | ATF_TC_WITHOUT_HEAD(ptrace__parent_sees_exit_after_child_debugger); | ||||
ATF_TC_BODY(ptrace__parent_sees_exit_after_child_debugger, tc) | ATF_TC_BODY(ptrace__parent_sees_exit_after_child_debugger, tc) | ||||
{ | { | ||||
pid_t child, debugger, wpid; | pid_t child, debugger, wpid; | ||||
int cpipe[2], dpipe[2], status; | int cpipe[2], dpipe[2], status; | ||||
char c; | char c; | ||||
if (atf_tc_get_config_var_as_bool_wd(tc, "ci", false)) | |||||
atf_tc_skip("https://bugs.freebsd.org/239399"); | |||||
REQUIRE_EQ(pipe(cpipe), 0); | REQUIRE_EQ(pipe(cpipe), 0); | ||||
ATF_REQUIRE((child = fork()) != -1); | ATF_REQUIRE((child = fork()) != -1); | ||||
if (child == 0) { | if (child == 0) { | ||||
/* Child process. */ | /* Child process. */ | ||||
close(cpipe[0]); | close(cpipe[0]); | ||||
/* Wait for parent to be ready. */ | /* Wait for parent to be ready. */ | ||||
▲ Show 20 Lines • Show All 187 Lines • ▼ Show 20 Lines | |||||
*/ | */ | ||||
ATF_TC_WITHOUT_HEAD(ptrace__parent_exits_before_child); | ATF_TC_WITHOUT_HEAD(ptrace__parent_exits_before_child); | ||||
ATF_TC_BODY(ptrace__parent_exits_before_child, tc) | ATF_TC_BODY(ptrace__parent_exits_before_child, tc) | ||||
{ | { | ||||
ssize_t n; | ssize_t n; | ||||
int cpipe1[2], cpipe2[2], gcpipe[2], status; | int cpipe1[2], cpipe2[2], gcpipe[2], status; | ||||
pid_t child, gchild; | pid_t child, gchild; | ||||
if (atf_tc_get_config_var_as_bool_wd(tc, "ci", false)) | |||||
atf_tc_skip("https://bugs.freebsd.org/244056"); | |||||
REQUIRE_EQ(pipe(cpipe1), 0); | REQUIRE_EQ(pipe(cpipe1), 0); | ||||
REQUIRE_EQ(pipe(cpipe2), 0); | REQUIRE_EQ(pipe(cpipe2), 0); | ||||
REQUIRE_EQ(pipe(gcpipe), 0); | REQUIRE_EQ(pipe(gcpipe), 0); | ||||
REQUIRE_EQ(procctl(P_PID, getpid(), PROC_REAP_ACQUIRE, NULL), 0); | REQUIRE_EQ(procctl(P_PID, getpid(), PROC_REAP_ACQUIRE, NULL), 0); | ||||
ATF_REQUIRE((child = fork()) != -1); | ATF_REQUIRE((child = fork()) != -1); | ||||
if (child == 0) { | if (child == 0) { | ||||
▲ Show 20 Lines • Show All 322 Lines • ▼ Show 20 Lines | |||||
* the parent that forks is not a direct child of the debugger. | * the parent that forks is not a direct child of the debugger. | ||||
*/ | */ | ||||
ATF_TC_WITHOUT_HEAD(ptrace__follow_fork_both_attached_unrelated_debugger); | ATF_TC_WITHOUT_HEAD(ptrace__follow_fork_both_attached_unrelated_debugger); | ||||
ATF_TC_BODY(ptrace__follow_fork_both_attached_unrelated_debugger, tc) | ATF_TC_BODY(ptrace__follow_fork_both_attached_unrelated_debugger, tc) | ||||
{ | { | ||||
pid_t children[2], fpid, wpid; | pid_t children[2], fpid, wpid; | ||||
int cpipe[2], status; | int cpipe[2], status; | ||||
if (atf_tc_get_config_var_as_bool_wd(tc, "ci", false)) | |||||
atf_tc_skip("https://bugs.freebsd.org/239397"); | |||||
REQUIRE_EQ(pipe(cpipe), 0); | REQUIRE_EQ(pipe(cpipe), 0); | ||||
ATF_REQUIRE((fpid = fork()) != -1); | ATF_REQUIRE((fpid = fork()) != -1); | ||||
if (fpid == 0) { | if (fpid == 0) { | ||||
attach_fork_parent(cpipe); | attach_fork_parent(cpipe); | ||||
follow_fork_parent(false); | follow_fork_parent(false); | ||||
} | } | ||||
/* Parent process. */ | /* Parent process. */ | ||||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | |||||
* the parent that forks is not a direct child of the debugger. | * the parent that forks is not a direct child of the debugger. | ||||
*/ | */ | ||||
ATF_TC_WITHOUT_HEAD(ptrace__follow_fork_child_detached_unrelated_debugger); | ATF_TC_WITHOUT_HEAD(ptrace__follow_fork_child_detached_unrelated_debugger); | ||||
ATF_TC_BODY(ptrace__follow_fork_child_detached_unrelated_debugger, tc) | ATF_TC_BODY(ptrace__follow_fork_child_detached_unrelated_debugger, tc) | ||||
{ | { | ||||
pid_t children[2], fpid, wpid; | pid_t children[2], fpid, wpid; | ||||
int cpipe[2], status; | int cpipe[2], status; | ||||
if (atf_tc_get_config_var_as_bool_wd(tc, "ci", false)) | |||||
atf_tc_skip("https://bugs.freebsd.org/239292"); | |||||
REQUIRE_EQ(pipe(cpipe), 0); | REQUIRE_EQ(pipe(cpipe), 0); | ||||
ATF_REQUIRE((fpid = fork()) != -1); | ATF_REQUIRE((fpid = fork()) != -1); | ||||
if (fpid == 0) { | if (fpid == 0) { | ||||
attach_fork_parent(cpipe); | attach_fork_parent(cpipe); | ||||
follow_fork_parent(false); | follow_fork_parent(false); | ||||
} | } | ||||
/* Parent process. */ | /* Parent process. */ | ||||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | |||||
* that forks is not a direct child of the debugger. | * that forks is not a direct child of the debugger. | ||||
*/ | */ | ||||
ATF_TC_WITHOUT_HEAD(ptrace__follow_fork_parent_detached_unrelated_debugger); | ATF_TC_WITHOUT_HEAD(ptrace__follow_fork_parent_detached_unrelated_debugger); | ||||
ATF_TC_BODY(ptrace__follow_fork_parent_detached_unrelated_debugger, tc) | ATF_TC_BODY(ptrace__follow_fork_parent_detached_unrelated_debugger, tc) | ||||
{ | { | ||||
pid_t children[2], fpid, wpid; | pid_t children[2], fpid, wpid; | ||||
int cpipe[2], status; | int cpipe[2], status; | ||||
if (atf_tc_get_config_var_as_bool_wd(tc, "ci", false)) | |||||
atf_tc_skip("https://bugs.freebsd.org/239425"); | |||||
REQUIRE_EQ(pipe(cpipe), 0); | REQUIRE_EQ(pipe(cpipe), 0); | ||||
ATF_REQUIRE((fpid = fork()) != -1); | ATF_REQUIRE((fpid = fork()) != -1); | ||||
if (fpid == 0) { | if (fpid == 0) { | ||||
attach_fork_parent(cpipe); | attach_fork_parent(cpipe); | ||||
follow_fork_parent(false); | follow_fork_parent(false); | ||||
} | } | ||||
/* Parent process. */ | /* Parent process. */ | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | |||||
*/ | */ | ||||
ATF_TC_WITHOUT_HEAD(ptrace__getppid); | ATF_TC_WITHOUT_HEAD(ptrace__getppid); | ||||
ATF_TC_BODY(ptrace__getppid, tc) | ATF_TC_BODY(ptrace__getppid, tc) | ||||
{ | { | ||||
pid_t child, debugger, ppid, wpid; | pid_t child, debugger, ppid, wpid; | ||||
int cpipe[2], dpipe[2], status; | int cpipe[2], dpipe[2], status; | ||||
char c; | char c; | ||||
if (atf_tc_get_config_var_as_bool_wd(tc, "ci", false)) | |||||
atf_tc_skip("https://bugs.freebsd.org/240510"); | |||||
REQUIRE_EQ(pipe(cpipe), 0); | REQUIRE_EQ(pipe(cpipe), 0); | ||||
ATF_REQUIRE((child = fork()) != -1); | ATF_REQUIRE((child = fork()) != -1); | ||||
if (child == 0) { | if (child == 0) { | ||||
/* Child process. */ | /* Child process. */ | ||||
close(cpipe[0]); | close(cpipe[0]); | ||||
/* Wait for parent to be ready. */ | /* Wait for parent to be ready. */ | ||||
▲ Show 20 Lines • Show All 1,068 Lines • ▼ Show 20 Lines | ATF_TC_BODY(ptrace__PT_KILL_competing_stop, tc) | ||||
int status; | int status; | ||||
cpuset_t setmask; | cpuset_t setmask; | ||||
pthread_t t; | pthread_t t; | ||||
pthread_barrier_t barrier; | pthread_barrier_t barrier; | ||||
lwpid_t main_lwp; | lwpid_t main_lwp; | ||||
struct ptrace_lwpinfo pl; | struct ptrace_lwpinfo pl; | ||||
struct sched_param sched_param; | struct sched_param sched_param; | ||||
if (atf_tc_get_config_var_as_bool_wd(tc, "ci", false)) | |||||
atf_tc_skip("https://bugs.freebsd.org/220841"); | |||||
ATF_REQUIRE((fpid = fork()) != -1); | ATF_REQUIRE((fpid = fork()) != -1); | ||||
if (fpid == 0) { | if (fpid == 0) { | ||||
trace_me(); | trace_me(); | ||||
/* Bind to one CPU so only one thread at a time will run. */ | /* Bind to one CPU so only one thread at a time will run. */ | ||||
CPU_ZERO(&setmask); | CPU_ZERO(&setmask); | ||||
CPU_SET(0, &setmask); | CPU_SET(0, &setmask); | ||||
cpusetid_t setid; | cpusetid_t setid; | ||||
▲ Show 20 Lines • Show All 2,077 Lines • ▼ Show 20 Lines | |||||
* after returning to parent - waitid(P_ALL). | * after returning to parent - waitid(P_ALL). | ||||
*/ | */ | ||||
ATF_TC_WITHOUT_HEAD(ptrace__procdesc_reparent_wait_child); | ATF_TC_WITHOUT_HEAD(ptrace__procdesc_reparent_wait_child); | ||||
ATF_TC_BODY(ptrace__procdesc_reparent_wait_child, tc) | ATF_TC_BODY(ptrace__procdesc_reparent_wait_child, tc) | ||||
{ | { | ||||
pid_t traced, debuger, wpid; | pid_t traced, debuger, wpid; | ||||
int pd, status; | int pd, status; | ||||
if (atf_tc_get_config_var_as_bool_wd(tc, "ci", false)) | |||||
arichardson: This one does look like it could be flaky since there is no pipe() call to synchronized between… | |||||
Done Inline ActionsYou mean, the second child may attach before the first one has raised SIGSTOP? markj: You mean, the second child may attach before the first one has raised SIGSTOP? | |||||
Done Inline ActionsYes, I think that could theoretically happen here. arichardson: Yes, I think that could theoretically happen here. | |||||
Done Inline ActionsShouldn't it be sufficient to add waitpid(traced, &status, WSTOPPED); before the fork() call? markj: Shouldn't it be sufficient to add
```
waitpid(traced, &status, WSTOPPED);
```
before the… | |||||
atf_tc_skip("https://bugs.freebsd.org/243605"); | |||||
traced = pdfork(&pd, 0); | traced = pdfork(&pd, 0); | ||||
ATF_REQUIRE(traced >= 0); | ATF_REQUIRE(traced >= 0); | ||||
if (traced == 0) { | if (traced == 0) { | ||||
raise(SIGSTOP); | raise(SIGSTOP); | ||||
exit(0); | exit(0); | ||||
} | } | ||||
ATF_REQUIRE(pd >= 0); | ATF_REQUIRE(pd >= 0); | ||||
/* Wait until the child process has stopped before fork()ing again. */ | |||||
REQUIRE_EQ(traced, waitpid(traced, &status, WSTOPPED)); | |||||
debuger = fork(); | debuger = fork(); | ||||
ATF_REQUIRE(debuger >= 0); | ATF_REQUIRE(debuger >= 0); | ||||
if (debuger == 0) { | if (debuger == 0) { | ||||
/* The traced process is reparented to debuger. */ | /* The traced process is reparented to debuger. */ | ||||
REQUIRE_EQ(ptrace(PT_ATTACH, traced, 0, 0), 0); | REQUIRE_EQ(ptrace(PT_ATTACH, traced, 0, 0), 0); | ||||
wpid = waitpid(traced, &status, 0); | wpid = waitpid(traced, &status, 0); | ||||
REQUIRE_EQ(wpid, traced); | REQUIRE_EQ(wpid, traced); | ||||
ATF_REQUIRE(WIFSTOPPED(status)); | ATF_REQUIRE(WIFSTOPPED(status)); | ||||
▲ Show 20 Lines • Show All 97 Lines • Show Last 20 Lines |
This one does look like it could be flaky since there is no pipe() call to synchronized between parent and child, but otherwise they all seem like they shouldn't fail.