Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

perf test: Add a signal handler around running a test

Add a signal handler around running a test. If a signal occurs during
the test a siglongjmp unwinds the stack and output is flushed. The
global run_test_jmp_buf is either unique per forked child or not
shared during sequential execution.

Tested-by: James Clark <james.clark@linaro.org>
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Colin Ian King <colin.i.king@gmail.com>
Cc: Howard Chu <howardchu95@gmail.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Ilya Leoshkevich <iii@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Dapeng Mi <dapeng1.mi@linux.intel.com>
Cc: Athira Jajeev <atrajeev@linux.vnet.ibm.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Veronika Molnarova <vmolnaro@redhat.com>
Link: https://lore.kernel.org/r/20241025192109.132482-7-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>

authored by

Ian Rogers and committed by
Namhyung Kim
a6fffc60 2532be3d

+27 -1
+27 -1
tools/perf/tests/builtin-test.c
··· 8 8 #include <errno.h> 9 9 #include <poll.h> 10 10 #include <unistd.h> 11 + #include <setjmp.h> 11 12 #include <string.h> 12 13 #include <stdlib.h> 13 14 #include <sys/types.h> ··· 230 229 int subtest; 231 230 }; 232 231 232 + static jmp_buf run_test_jmp_buf; 233 + 234 + static void child_test_sig_handler(int sig) 235 + { 236 + siglongjmp(run_test_jmp_buf, sig); 237 + } 238 + 233 239 static int run_test_child(struct child_process *process) 234 240 { 235 - struct child_test *child = container_of(process, struct child_test, process); 241 + const int signals[] = { 242 + SIGABRT, SIGBUS, SIGFPE, SIGILL, SIGINT, SIGPIPE, SIGQUIT, SIGSEGV, SIGTERM, 243 + }; 244 + static struct child_test *child; 236 245 int err; 246 + 247 + err = sigsetjmp(run_test_jmp_buf, 1); 248 + if (err) { 249 + fprintf(stderr, "\n---- unexpected signal (%d) ----\n", err); 250 + err = err > 0 ? -err : -1; 251 + goto err_out; 252 + } 253 + 254 + child = container_of(process, struct child_test, process); 255 + for (size_t i = 0; i < ARRAY_SIZE(signals); i++) 256 + signal(signals[i], child_test_sig_handler); 237 257 238 258 pr_debug("--- start ---\n"); 239 259 pr_debug("test child forked, pid %d\n", getpid()); 240 260 err = test_function(child->test, child->subtest)(child->test, child->subtest); 241 261 pr_debug("---- end(%d) ----\n", err); 262 + 263 + err_out: 242 264 fflush(NULL); 265 + for (size_t i = 0; i < ARRAY_SIZE(signals); i++) 266 + signal(signals[i], SIG_DFL); 243 267 return -err; 244 268 } 245 269