Files
TheRock/compiler/amd-llvm/compiler-rt/test/rtsan/fork_exec.cpp
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

65 lines
2.0 KiB
C++

// RUN: %clangxx -fsanitize=realtime -DIS_NONBLOCKING=1 %s -o %t
// RUN: %env_rtsan_opts="halt_on_error=true" not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-HALT
// RUN: %env_rtsan_opts="halt_on_error=false" %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NOHALT
// RUN: %clangxx -fsanitize=realtime -DIS_NONBLOCKING=0 %s -o %t
// RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-OK
// RUN: %env_rtsan_opts="halt_on_error=false" %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-OK
// UNSUPPORTED: ios
// Intent: Ensure fork/exec dies when realtime and survives otherwise
// This behavior is difficult to test in a gtest, because the process is
// wiped away with exec.
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#if IS_NONBLOCKING
# define MAYBE_NONBLOCKING [[clang::nonblocking]]
#else
# define MAYBE_NONBLOCKING
#endif
int main() MAYBE_NONBLOCKING {
const pid_t pid = fork();
if (pid == 0) {
char *args[] = {"/bin/ls", nullptr};
execve(args[0], args, nullptr);
perror("execve failed");
return 1;
} else if (pid > 0) {
int status;
waitpid(pid, &status, 0);
usleep(1);
} else {
perror("fork failed");
return 1;
}
printf("fork/exec succeeded\n");
return 0;
}
// CHECK-NOHALT: Intercepted call to {{.*}} `fork` {{.*}}
// We should also get some other intercepted call. On some systems this
// is `execve`, on others, it's a lock to set up `execve`. In either
// case, just check that we get a second intercepted call, don't sweat
// the name.
// CHECK-NOHALT: Intercepted call to {{.*}}
// usleep checks that rtsan is still enabled in the parent process
// See note in our interceptors file for why we don't look for `wait`
// CHECK-NOHALT: Intercepted call to {{.*}} `usleep` {{.*}}
// CHECK-NOHALT: fork/exec succeeded
// CHECK-HALT: ==ERROR: RealtimeSanitizer: unsafe-library-call
// CHECK-HALT-NEXT: Intercepted call to {{.*}} `fork` {{.*}}
// CHECK-OK: fork/exec succeeded