| 1 | // SPDX-License-Identifier: GPL-2.0-or-latercxx . . $ `<file>/src/ssdd/ssdd.c`/ |
| 2 | |
| 3 | /* |
| 4 | * Copyright (C) 2019 Joe Korty <[email protected]> |
| 5 | */ |
| 6 | |
| 7 | /* |
| 8 | * Have a tracer do a bunch of PTRACE_SINGLESTEPs against |
| 9 | * a tracee as fast as possible. Create several of these |
| 10 | * tracer/tracee pairs and see if they can be made to |
| 11 | * interfere with each other. |
| 12 | * |
| 13 | * Usage: |
| 14 | * ssdd nforks niters |
| 15 | * Where: |
| 16 | * nforks - number of tracer/tracee pairs to fork off. |
| 17 | * default 10. |
| 18 | * niters - number of PTRACE_SINGLESTEP iterations to |
| 19 | * do before declaring success, for each tracer/ |
| 20 | * tracee pair set up. Default 10,000. |
| 21 | * |
| 22 | * The tracer waits on each PTRACE_SINGLESTEP with a waitpid(2) |
| 23 | * and checks that waitpid's return values for correctness. |
| 24 | * |
| 25 | */ |
| 26 | #include <stdio.h> |
| 27 | #include <stdlib.h> |
| 28 | #include <stddef.h> |
| 29 | #include <unistd.h> |
| 30 | #include <getopt.h> |
| 31 | #include <string.h> |
| 32 | #include <signal.h> |
| 33 | #include <time.h> |
| 34 | #include <errno.h> |
| 35 | |
| 36 | #include <sys/types.h> |
| 37 | #include <sys/wait.h> |
| 38 | #include <sys/ptrace.h> |
| 39 | |
| 40 | #include "rt-utils.h"cxx . . $ `<file>/src/include/rt-utils.h`/ |
| 41 | |
| 42 | /* do_wait return values */ |
| 43 | #define STATE_EXITEDcxx . . $ `src/ssdd/ssdd.c:43:9`! 1 |
| 44 | #define STATE_STOPPEDcxx . . $ `src/ssdd/ssdd.c:44:9`! 2 |
| 45 | #define STATE_SIGNALEDcxx . . $ `src/ssdd/ssdd.c:45:9`! 3 |
| 46 | #define STATE_UNKNOWNcxx . . $ `src/ssdd/ssdd.c:46:9`! 4 |
| 47 | #define STATE_ECHILDcxx . . $ `src/ssdd/ssdd.c:47:9`! 5 |
| 48 | #define STATE_EXITED_TSIGcxx . . $ `src/ssdd/ssdd.c:48:9`! 6 /* exited with termination signal */ |
| 49 | #define STATE_EXITED_ERRSTATcxx . . $ `src/ssdd/ssdd.c:49:9`! 7 /* exited with non-zero status */ |
| 50 | |
| 51 | static char *state_namecxx . . $ state_name.[] = { |
| 52 | [STATE_EXITEDcxx . . $ `src/ssdd/ssdd.c:43:9`!] = "STATE_EXITED", |
| 53 | [STATE_STOPPEDcxx . . $ `src/ssdd/ssdd.c:44:9`!] = "STATE_STOPPED", |
| 54 | [STATE_SIGNALEDcxx . . $ `src/ssdd/ssdd.c:45:9`!] = "STATE_SIGNALED", |
| 55 | [STATE_UNKNOWNcxx . . $ `src/ssdd/ssdd.c:46:9`!] = "STATE_UNKNOWN", |
| 56 | [STATE_ECHILDcxx . . $ `src/ssdd/ssdd.c:47:9`!] = "STATE_ECHILD", |
| 57 | [STATE_EXITED_TSIGcxx . . $ `src/ssdd/ssdd.c:48:9`!] = "STATE_EXITED_TSIG", |
| 58 | [STATE_EXITED_ERRSTATcxx . . $ `src/ssdd/ssdd.c:49:9`!] = "STATE_EXITED_ERRSTAT" |
| 59 | }; |
| 60 | |
| 61 | static const char *get_state_namecxx . . $ get_state_name(f7ae7e56280f18ae).(int state) |
| 62 | { |
| 63 | if (state < STATE_EXITEDcxx . . $ `src/ssdd/ssdd.c:43:9`! || state > STATE_EXITED_ERRSTATcxx . . $ `src/ssdd/ssdd.c:49:9`!) |
| 64 | return "?"; |
| 65 | return state_namecxx . . $ state_name.[state]; |
| 66 | } |
| 67 | |
| 68 | static int quietcxx . . $ quiet.; |
| 69 | static char jsonfilecxx . . $ jsonfile.[MAX_PATHcxx . . $ `src/include/rt-utils.h:9:9`!]; |
| 70 | |
| 71 | volatile int got_sigchldcxx . . $ got_sigchld.; |
| 72 | |
| 73 | enum option_valuecxx . . $ option_value# { OPT_NFORKScxx . . $ OPT_NFORKS.=1, OPT_NITERScxx . . $ OPT_NITERS., OPT_HELPcxx . . $ OPT_HELP., OPT_JSONcxx . . $ OPT_JSON., OPT_QUIETcxx . . $ OPT_QUIET. }; |
| 74 | |
| 75 | static void usagecxx . . $ usage(d4f767463ce0a6b3).(int error) |
| 76 | { |
| 77 | printfcxx . . $ printf(581fddd72a8db8fc).("ssdd V %1.2f\n", VERSIONcxx . . $ `<built-in>:412:9`!); |
| 78 | printfcxx . . $ printf(581fddd72a8db8fc).("Usage:\n" |
| 79 | "ssdd <options>\n\n" |
| 80 | "-f --forks=NUM number of forks\n" |
| 81 | "-h --help print this message\n" |
| 82 | " --json=FILENAME write final results into FILENAME, JSON formatted\n" |
| 83 | "-q --quiet suppress running output\n" |
| 84 | "-i --iters=NUM number of iterations, NUM must be at least 1\n" |
| 85 | ); |
| 86 | exitcxx . . $ exit(3ca292c338df9bb3).(error); |
| 87 | } |
| 88 | |
| 89 | static int do_waitcxx . . $ do_wait(aa23d0250da59a45).(pid_tcxx . . $ pid_t# *wait_pid, int *ret_sig) |
| 90 | { |
| 91 | int status, child_status; |
| 92 | |
| 93 | *ret_sig = -1; /* initially mark 'nothing returned' */ |
| 94 | |
| 95 | while (1) { |
| 96 | status = waitpidcxx . . $ waitpid(1df93256b606fe1f).(-1, &child_status, WUNTRACEDcxx . . $ `<external>/1585314143251398045/waitflags.h:26:9`! | __WALLcxx . . $ `<external>/1585314143251398045/waitflags.h:38:9`!); |
| 97 | if (status == -1) { |
| 98 | if (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == EINTRcxx . . $ `<external>/8987895939074593727/errno-base.h:8:9`!) |
| 99 | continue; |
| 100 | if (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == ECHILDcxx . . $ `<external>/8987895939074593727/errno-base.h:14:9`!) { |
| 101 | *wait_pid = (pid_tcxx . . $ pid_t#)0; |
| 102 | return STATE_ECHILDcxx . . $ `src/ssdd/ssdd.c:47:9`!; |
| 103 | } |
| 104 | printfcxx . . $ printf(581fddd72a8db8fc).("do_wait/%d: EXITING, ERROR: " |
| 105 | "waitpid() returned errno %d\n", |
| 106 | getpidcxx . . $ getpid(b126dc7c1de90089).(), errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!); |
| 107 | exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 108 | } |
| 109 | break; |
| 110 | } |
| 111 | *wait_pid = (pid_tcxx . . $ pid_t#)status; |
| 112 | |
| 113 | if (WIFEXITEDcxx . . $ `<external>/10696550936717951914/stdlib.h:47:10`!(child_status)) { |
| 114 | if (WIFSIGNALEDcxx . . $ `<external>/10696550936717951914/stdlib.h:48:10`!(child_status)) |
| 115 | return STATE_EXITED_TSIGcxx . . $ `src/ssdd/ssdd.c:48:9`!; |
| 116 | if (WEXITSTATUScxx . . $ `<external>/10696550936717951914/stdlib.h:44:10`!(child_status)) |
| 117 | return STATE_EXITED_ERRSTATcxx . . $ `src/ssdd/ssdd.c:49:9`!; |
| 118 | return STATE_EXITEDcxx . . $ `src/ssdd/ssdd.c:43:9`!; |
| 119 | } |
| 120 | if (WIFSTOPPEDcxx . . $ `<external>/10696550936717951914/stdlib.h:49:10`!(child_status)) { |
| 121 | *ret_sig = WSTOPSIGcxx . . $ `<external>/10696550936717951914/stdlib.h:46:10`!(child_status); |
| 122 | return STATE_STOPPEDcxx . . $ `src/ssdd/ssdd.c:44:9`!; |
| 123 | } |
| 124 | if (WIFSIGNALEDcxx . . $ `<external>/10696550936717951914/stdlib.h:48:10`!(child_status)) { |
| 125 | *ret_sig = WTERMSIGcxx . . $ `<external>/10696550936717951914/stdlib.h:45:10`!(child_status); |
| 126 | return STATE_SIGNALEDcxx . . $ `src/ssdd/ssdd.c:45:9`!; |
| 127 | } |
| 128 | return STATE_UNKNOWNcxx . . $ `src/ssdd/ssdd.c:46:9`!; |
| 129 | } |
| 130 | |
| 131 | static int check_sigchldcxx . . $ check_sigchld(f9c066a8ff75ee9d).(sigset_tcxx . . $ sigset_t# *set) |
| 132 | { |
| 133 | |
| 134 | struct timespeccxx . . $ timespec# timeout; |
| 135 | |
| 136 | timeout.tv_seccxx . . $ timespec#tv_sec. = 10; |
| 137 | timeout.tv_nseccxx . . $ timespec#tv_nsec. = 0; |
| 138 | int recv_sig = 0; |
| 139 | |
| 140 | /* |
| 141 | * Check the handler flag, then if need be, wait for the signal to |
| 142 | * arrive |
| 143 | */ |
| 144 | if (!got_sigchldcxx . . $ got_sigchld.) |
| 145 | recv_sig = sigtimedwaitcxx . . $ sigtimedwait(db78d0749561ebec).(set, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, &timeout); |
| 146 | |
| 147 | if (sigprocmaskcxx . . $ sigprocmask(7504382baa173b1).(SIG_UNBLOCKcxx . . $ `<external>/16635209305659446502/sigaction.h:80:9`!, set, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) == -1) { |
| 148 | printfcxx . . $ printf(581fddd72a8db8fc).("EXITING, ERROR: unable to mask signal set\n"); |
| 149 | exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 150 | } |
| 151 | |
| 152 | if (recv_sig == -1) { |
| 153 | printfcxx . . $ printf(581fddd72a8db8fc).("EXITING, ERROR: Timeout: no signal received in 10 seconds\n"); |
| 154 | exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 155 | } else if (recv_sig == SIGCHLDcxx . . $ `<external>/1457673850468744829/signum-arch.h:41:9`!) { |
| 156 | got_sigchldcxx . . $ got_sigchld. = 1; |
| 157 | } |
| 158 | |
| 159 | return got_sigchldcxx . . $ got_sigchld.; |
| 160 | } |
| 161 | |
| 162 | static pid_tcxx . . $ pid_t# parentcxx . . $ parent.; |
| 163 | static int nforkscxx . . $ nforks. = 10; |
| 164 | static int nstepscxx . . $ nsteps. = 10000; |
| 165 | |
| 166 | static void sigchldcxx . . $ sigchld(35b49605a50c0d85).(int sig, siginfo_tcxx . . $ siginfo_t# *info, void *arg) |
| 167 | { |
| 168 | got_sigchldcxx . . $ got_sigchld. = 1; |
| 169 | } |
| 170 | |
| 171 | static void child_processcxx . . $ child_process(49f6e7a06ebc5aa8).(void) |
| 172 | { |
| 173 | while (1) |
| 174 | ; |
| 175 | } |
| 176 | |
| 177 | static int forktestscxx . . $ forktests(7864480464b09eea).(int testid) |
| 178 | { |
| 179 | int i, status, ret_sig; |
| 180 | long pstatus; |
| 181 | pid_tcxx . . $ pid_t# child, wait_pid; |
| 182 | struct sigactioncxx . . $ sigaction# act, oact; |
| 183 | |
| 184 | parentcxx . . $ parent. = getpidcxx . . $ getpid(b126dc7c1de90089).(); |
| 185 | |
| 186 | child = forkcxx . . $ fork(b126dc7c1de90089).(); |
| 187 | if (child == -1) { |
| 188 | printfcxx . . $ printf(581fddd72a8db8fc).("forktest#%d/%d: EXITING, ERROR: " |
| 189 | "fork returned errno %d\n", testid, parentcxx . . $ parent., errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!); |
| 190 | exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 191 | } |
| 192 | if (!child) |
| 193 | child_processcxx . . $ child_process(49f6e7a06ebc5aa8).(); |
| 194 | |
| 195 | if (!quietcxx . . $ quiet.) |
| 196 | printfcxx . . $ printf(581fddd72a8db8fc).("forktest#%d/%d/%d: STARTING\n", testid, parentcxx . . $ parent., child); |
| 197 | |
| 198 | act.sa_sigactioncxx . . $ `<external>/16635209305659446502/sigaction.h:40:10`! = sigchldcxx . . $ sigchld(35b49605a50c0d85).; |
| 199 | sigemptysetcxx . . $ sigemptyset(f9c066a8ff75ee9d).(&act.sa_maskcxx . . $ sigaction#sa_mask.); |
| 200 | act.sa_flagscxx . . $ sigaction#sa_flags. = SA_SIGINFOcxx . . $ `<external>/16635209305659446502/sigaction.h:58:9`!; |
| 201 | status = sigactioncxx . . $ sigaction(53aba09fe16b06c7).(SIGCHLDcxx . . $ `<external>/1457673850468744829/signum-arch.h:41:9`!, &act, &oact); |
| 202 | if (status) { |
| 203 | printfcxx . . $ printf(581fddd72a8db8fc).("forktest#%d/%d: EXITING, ERROR: " |
| 204 | "sigaction returned %d, errno %d\n", |
| 205 | testid, parentcxx . . $ parent., status, errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!); |
| 206 | exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 207 | } |
| 208 | |
| 209 | /* |
| 210 | * Block the signal before it is generated |
| 211 | * Ensures we can synchronously wait for it. |
| 212 | */ |
| 213 | sigset_tcxx . . $ sigset_t# set; |
| 214 | |
| 215 | sigemptysetcxx . . $ sigemptyset(f9c066a8ff75ee9d).(&set); |
| 216 | sigaddsetcxx . . $ sigaddset(4917c6e3ecb7dbd5).(&set, SIGCHLDcxx . . $ `<external>/1457673850468744829/signum-arch.h:41:9`!); |
| 217 | |
| 218 | if (sigprocmaskcxx . . $ sigprocmask(7504382baa173b1).(SIG_BLOCKcxx . . $ `<external>/16635209305659446502/sigaction.h:79:9`!, &set, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) == -1) { |
| 219 | printfcxx . . $ printf(581fddd72a8db8fc).("EXITING, ERROR: unable to mask signal set\n"); |
| 220 | exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 221 | } |
| 222 | |
| 223 | /* |
| 224 | * Attach to the child. |
| 225 | */ |
| 226 | pstatus = ptracecxx . . $ ptrace(aece84b69c03923e).(PTRACE_ATTACHcxx . . $ PTRACE_ATTACH., child, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 227 | if (pstatus == ~0l) { |
| 228 | printfcxx . . $ printf(581fddd72a8db8fc).("forktest#%d/%d: EXITING, ERROR: " |
| 229 | "attach failed. errno %d\n", |
| 230 | testid, getpidcxx . . $ getpid(b126dc7c1de90089).(), errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!); |
| 231 | exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 232 | } |
| 233 | |
| 234 | /* |
| 235 | * The attach should cause the child to receive a signal. |
| 236 | */ |
| 237 | status = do_waitcxx . . $ do_wait(aa23d0250da59a45).(&wait_pid, &ret_sig); |
| 238 | if (wait_pid != child) { |
| 239 | printfcxx . . $ printf(581fddd72a8db8fc).("forktest#%d/%d: EXITING, ERROR: " |
| 240 | "attach: Unexpected wait pid %d\n", |
| 241 | testid, getpidcxx . . $ getpid(b126dc7c1de90089).(), wait_pid); |
| 242 | exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 243 | } |
| 244 | if (status != STATE_STOPPEDcxx . . $ `src/ssdd/ssdd.c:44:9`!) { |
| 245 | printfcxx . . $ printf(581fddd72a8db8fc).("forktest#%d/%d: EXITING, ERROR: " |
| 246 | "attach: wait on PTRACE_ATTACH returned %d " |
| 247 | "[%s, wanted STATE_STOPPED], signo %d\n", |
| 248 | testid, getpidcxx . . $ getpid(b126dc7c1de90089).(), status, get_state_namecxx . . $ get_state_name(f7ae7e56280f18ae).(status), |
| 249 | ret_sig); |
| 250 | exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 251 | } |
| 252 | if (!check_sigchldcxx . . $ check_sigchld(f9c066a8ff75ee9d).(&set)) { |
| 253 | printfcxx . . $ printf(581fddd72a8db8fc).("forktest#%d/%d: EXITING, ERROR: " |
| 254 | "wait on PTRACE_ATTACH saw a SIGCHLD count of %d, should be 1\n", |
| 255 | testid, getpidcxx . . $ getpid(b126dc7c1de90089).(), got_sigchldcxx . . $ got_sigchld.); |
| 256 | exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 257 | } |
| 258 | got_sigchldcxx . . $ got_sigchld. = 0; |
| 259 | |
| 260 | |
| 261 | /* |
| 262 | * Generate 'nsteps' PTRACE_SINGLESTEPs, make sure they all actually |
| 263 | * step the tracee. |
| 264 | */ |
| 265 | for (i = 0; i < nstepscxx . . $ nsteps.; i++) { |
| 266 | |
| 267 | if (sigprocmaskcxx . . $ sigprocmask(7504382baa173b1).(SIG_BLOCKcxx . . $ `<external>/16635209305659446502/sigaction.h:79:9`!, &set, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) == -1) { |
| 268 | printfcxx . . $ printf(581fddd72a8db8fc).("EXITING, ERROR: unable to mask signal set\n"); |
| 269 | exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 270 | } |
| 271 | |
| 272 | pstatus = ptracecxx . . $ ptrace(aece84b69c03923e).(PTRACE_SINGLESTEPcxx . . $ PTRACE_SINGLESTEP., child, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 273 | |
| 274 | if (pstatus) { |
| 275 | printfcxx . . $ printf(581fddd72a8db8fc).("forktest#%d/%d: EXITING, ERROR: " |
| 276 | "PTRACE_SINGLESTEP #%d: returned status %ld, " |
| 277 | "errno %d, signo %d\n", |
| 278 | testid, getpidcxx . . $ getpid(b126dc7c1de90089).(), i, pstatus, errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!, ret_sig); |
| 279 | exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 280 | } |
| 281 | |
| 282 | status = do_waitcxx . . $ do_wait(aa23d0250da59a45).(&wait_pid, &ret_sig); |
| 283 | if (wait_pid != child) { |
| 284 | printfcxx . . $ printf(581fddd72a8db8fc).("forktest#%d/%d: EXITING, ERROR: " |
| 285 | "wait on PTRACE_SINGLESTEP #%d: returned wrong pid %d, " |
| 286 | "expected %d\n", |
| 287 | testid, getpidcxx . . $ getpid(b126dc7c1de90089).(), i, wait_pid, child); |
| 288 | exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 289 | } |
| 290 | if (status != STATE_STOPPEDcxx . . $ `src/ssdd/ssdd.c:44:9`!) { |
| 291 | printfcxx . . $ printf(581fddd72a8db8fc).("forktest#%d/%d: EXITING, ERROR: " |
| 292 | "wait on PTRACE_SINGLESTEP #%d: wanted STATE_STOPPED, " |
| 293 | "saw %s instead (and saw signo %d too)\n", |
| 294 | testid, getpidcxx . . $ getpid(b126dc7c1de90089).(), i, |
| 295 | get_state_namecxx . . $ get_state_name(f7ae7e56280f18ae).(status), ret_sig); |
| 296 | exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 297 | } |
| 298 | if (ret_sig != SIGTRAPcxx . . $ `<external>/11773118241360591791/signum-generic.h:58:9`!) { |
| 299 | printfcxx . . $ printf(581fddd72a8db8fc).("forktest#%d/%d: EXITING, ERROR: " |
| 300 | "wait on PTRACE_SINGLESTEP #%d: returned signal %d, " |
| 301 | "wanted SIGTRAP\n", |
| 302 | testid, getpidcxx . . $ getpid(b126dc7c1de90089).(), i, ret_sig); |
| 303 | exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 304 | } |
| 305 | if (!check_sigchldcxx . . $ check_sigchld(f9c066a8ff75ee9d).(&set)) { |
| 306 | printfcxx . . $ printf(581fddd72a8db8fc).("forktest#%d/%d: EXITING, ERROR: " |
| 307 | "wait on PTRACE_SINGLESTEP #%d: no SIGCHLD seen " |
| 308 | "(signal count == 0), signo %d\n", |
| 309 | testid, getpidcxx . . $ getpid(b126dc7c1de90089).(), i, ret_sig); |
| 310 | exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 311 | } |
| 312 | got_sigchldcxx . . $ got_sigchld. = 0; |
| 313 | } |
| 314 | |
| 315 | /* There is no need for the tracer to kill the tracee. It will |
| 316 | * automatically exit when its owner, ie, us, exits. |
| 317 | */ |
| 318 | if (!quietcxx . . $ quiet.) |
| 319 | printfcxx . . $ printf(581fddd72a8db8fc).("forktest#%d/%d: EXITING, no error\n", testid, parentcxx . . $ parent.); |
| 320 | exitcxx . . $ exit(3ca292c338df9bb3).(0); |
| 321 | } |
| 322 | |
| 323 | int maincxx . . $ main(afcd3168fc1188a4).(int argc, char **argv) |
| 324 | { |
| 325 | int i, ret_sig, status; |
| 326 | pid_tcxx . . $ pid_t# child = 0, wait_pid; |
| 327 | int error = 0; |
| 328 | |
| 329 | setbufcxx . . $ setbuf(a7c976899de42135).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 330 | |
| 331 | rt_initcxx . . $ rt_init(c759356ac01a31e7).(argc, argv); |
| 332 | for (;;) { |
| 333 | int option_index = 0; |
| 334 | |
| 335 | static struct optioncxx . . $ option# long_options[] = { |
| 336 | {"forks", required_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:63:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, OPT_NFORKScxx . . $ OPT_NFORKS.}, |
| 337 | {"help", no_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:62:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, OPT_HELPcxx . . $ OPT_HELP.}, |
| 338 | {"json", required_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:63:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, OPT_JSONcxx . . $ OPT_JSON.}, |
| 339 | {"quiet", no_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:62:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, OPT_QUIETcxx . . $ OPT_QUIET.}, |
| 340 | {"iters", required_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:63:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, OPT_NITERScxx . . $ OPT_NITERS.}, |
| 341 | {NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0}, |
| 342 | }; |
| 343 | int c = getopt_longcxx . . $ getopt_long(41f665c090816971).(argc, argv, "f:hqi:", long_options, &option_index); |
| 344 | if (c == -1) |
| 345 | break; |
| 346 | switch(c) { |
| 347 | case 'f': |
| 348 | case OPT_NFORKScxx . . $ OPT_NFORKS.: |
| 349 | nforkscxx . . $ nforks. = atoicxx . . $ atoi(5c4306d8553b3696).(optargcxx . . $ optarg.); |
| 350 | break; |
| 351 | case 'h': |
| 352 | case OPT_HELPcxx . . $ OPT_HELP.: |
| 353 | usagecxx . . $ usage(d4f767463ce0a6b3).(0); |
| 354 | break; |
| 355 | case OPT_JSONcxx . . $ OPT_JSON.: |
| 356 | strncpycxx . . $ strncpy(255158a415b673b0).(jsonfilecxx . . $ jsonfile., optargcxx . . $ optarg., strnlencxx . . $ strnlen(ac5a385650b4bde5).(optargcxx . . $ optarg., MAX_PATHcxx . . $ `src/include/rt-utils.h:9:9`!-1)); |
| 357 | break; |
| 358 | case OPT_QUIETcxx . . $ OPT_QUIET.: |
| 359 | case 'q': |
| 360 | quietcxx . . $ quiet. = 1; |
| 361 | break; |
| 362 | case 'i': |
| 363 | case OPT_NITERScxx . . $ OPT_NITERS.: |
| 364 | nstepscxx . . $ nsteps. = atoicxx . . $ atoi(5c4306d8553b3696).(optargcxx . . $ optarg.); |
| 365 | if (nstepscxx . . $ nsteps. < 1) { |
| 366 | usagecxx . . $ usage(d4f767463ce0a6b3).(0); |
| 367 | } |
| 368 | break; |
| 369 | default: |
| 370 | usagecxx . . $ usage(d4f767463ce0a6b3).(1); |
| 371 | break; |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | if (!quietcxx . . $ quiet.) { |
| 376 | printfcxx . . $ printf(581fddd72a8db8fc).("#main : %d\n", getpidcxx . . $ getpid(b126dc7c1de90089).()); |
| 377 | printfcxx . . $ printf(581fddd72a8db8fc).("#forks: %d\n", nforkscxx . . $ nforks.); |
| 378 | printfcxx . . $ printf(581fddd72a8db8fc).("#steps: %d\n", nstepscxx . . $ nsteps.); |
| 379 | printfcxx . . $ printf(581fddd72a8db8fc).("\n"); |
| 380 | } |
| 381 | |
| 382 | for (i = 0; i < nforkscxx . . $ nforks.; i++) { |
| 383 | child = forkcxx . . $ fork(b126dc7c1de90089).(); |
| 384 | if (child == -1) { |
| 385 | printfcxx . . $ printf(581fddd72a8db8fc).("main: fork returned errno %d\n", errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!); |
| 386 | exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 387 | } |
| 388 | if (!child) |
| 389 | forktestscxx . . $ forktests(7864480464b09eea).(i); |
| 390 | } |
| 391 | |
| 392 | for (i = 0; i < nforkscxx . . $ nforks.; i++) { |
| 393 | status = do_waitcxx . . $ do_wait(aa23d0250da59a45).(&wait_pid, &ret_sig); |
| 394 | if (status != STATE_EXITEDcxx . . $ `src/ssdd/ssdd.c:43:9`!) { |
| 395 | if (0) printfcxx . . $ printf(581fddd72a8db8fc).("main/%d: ERROR: " |
| 396 | "forktest#%d unexpected do_wait status %d " |
| 397 | "[%s, wanted STATE_EXITED]\n", |
| 398 | getpidcxx . . $ getpid(b126dc7c1de90089).(), wait_pid, status, |
| 399 | get_state_namecxx . . $ get_state_name(f7ae7e56280f18ae).(status)); |
| 400 | error = 1; |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | printfcxx . . $ printf(581fddd72a8db8fc).("%s.\n", error ? |
| 405 | "One or more tests FAILED" : |
| 406 | "All tests PASSED"); |
| 407 | |
| 408 | if (strlencxx . . $ strlen(751346f8406fd082).(jsonfilecxx . . $ jsonfile.) != 0) |
| 409 | rt_write_jsoncxx . . $ rt_write_json(969c696bbc9a09ad).(jsonfilecxx . . $ jsonfile., error, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 410 | |
| 411 | exitcxx . . $ exit(3ca292c338df9bb3).(error); |
| 412 | } |