[compiler-rt] r253342 - [asan] Enable halt_on_error tests on OS X.
Yury Gribov via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 17 08:34:39 PST 2015
Author: ygribov
Date: Tue Nov 17 10:34:39 2015
New Revision: 253342
URL: http://llvm.org/viewvc/llvm-project?rev=253342&view=rev
Log:
[asan] Enable halt_on_error tests on OS X.
Added:
compiler-rt/trunk/test/asan/TestCases/Posix/halt_on_error-signals.c
- copied unchanged from r253340, compiler-rt/trunk/test/asan/TestCases/Linux/halt_on_error-signals.c
compiler-rt/trunk/test/asan/TestCases/Posix/halt_on_error-torture.cc
- copied unchanged from r253340, compiler-rt/trunk/test/asan/TestCases/Linux/halt_on_error-torture.cc
Removed:
compiler-rt/trunk/test/asan/TestCases/Linux/halt_on_error-signals.c
compiler-rt/trunk/test/asan/TestCases/Linux/halt_on_error-torture.cc
Removed: compiler-rt/trunk/test/asan/TestCases/Linux/halt_on_error-signals.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Linux/halt_on_error-signals.c?rev=253341&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Linux/halt_on_error-signals.c (original)
+++ compiler-rt/trunk/test/asan/TestCases/Linux/halt_on_error-signals.c (removed)
@@ -1,104 +0,0 @@
-// Test interaction of Asan recovery mode with asynch signals.
-//
-// RUN: %clang_asan -fsanitize-recover=address -pthread %s -o %t
-//
-// RUN: rm -f %t.log
-// RUN: env ASAN_OPTIONS=halt_on_error=false %run %t 100 >%t.log 2>&1 || true
-// Collision will almost always get triggered but we still need to check the unlikely case:
-// RUN: FileCheck --check-prefix=CHECK-COLLISION %s < %t.log || FileCheck --check-prefix=CHECK-NO-COLLISION %s < %t.log
-//
-// REQUIRES: stable-runtime
-
-#define _SVID_SOURCE 1 // SA_NODEFER
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <pthread.h>
-#include <time.h>
-#include <signal.h>
-
-#include <sanitizer/asan_interface.h>
-
-void random_delay(unsigned *seed) {
- *seed = 1664525 * *seed + 1013904223;
- struct timespec delay = { 0, (*seed % 1000) * 1000 };
- nanosleep(&delay, 0);
-}
-
-volatile char bad[2] = {1, };
-
-void error() {
- // CHECK-COLLISION: AddressSanitizer: nested bug in the same thread, aborting
- // CHECK-NO-COLLISION: AddressSanitizer: use-after-poison
- volatile int idx = 0;
- bad[idx] = 0;
-}
-
-#define CHECK_CALL(e, msg) do { \
- if (0 != (e)) { \
- fprintf(stderr, "Failed to " msg "\n"); \
- exit(1); \
- } \
-} while (0)
-
-size_t niter = 10;
-pthread_t sender_tid, receiver_tid;
-
-pthread_mutex_t keep_alive_mu = PTHREAD_MUTEX_INITIALIZER;
-
-void *sender(void *arg) {
- unsigned seed = 0;
- for (size_t i = 0; i < niter; ++i) {
- random_delay(&seed);
- CHECK_CALL(pthread_kill(receiver_tid, SIGUSR1), "send signal");
- }
- return 0;
-}
-
-void handler(int sig) {
- // Expect error collisions here
- error();
-}
-
-void *receiver(void *arg) {
- unsigned seed = 1;
- for (size_t i = 0; i < niter; ++i) {
- random_delay(&seed);
- // And here
- error();
- }
- // Parent will release this when it's ok to terminate
- CHECK_CALL(pthread_mutex_lock(&keep_alive_mu), "unlock mutex");
- return 0;
-}
-
-int main(int argc, char **argv) {
- if (argc != 2) {
- fprintf(stderr, "Syntax: %s niter\n", argv[0]);
- exit(1);
- }
-
- niter = (size_t)strtoul(argv[1], 0, 0);
-
- struct sigaction sa;
- memset(&sa, 0, sizeof(sa));
- sa.sa_handler = handler;
- sa.sa_flags = SA_NODEFER; // Enable nested handlers to add more stress
- CHECK_CALL(sigaction(SIGUSR1, &sa, 0), "set sighandler");
-
- __asan_poison_memory_region(&bad, sizeof(bad));
-
- CHECK_CALL(pthread_mutex_lock(&keep_alive_mu), "lock mutex");
- CHECK_CALL(pthread_create(&receiver_tid, 0, receiver, 0), "start thread");
- CHECK_CALL(pthread_create(&sender_tid, 0, sender, 0), "start thread");
- CHECK_CALL(pthread_join(sender_tid, 0), "join thread");
- // Now allow receiver to die
- CHECK_CALL(pthread_mutex_unlock(&keep_alive_mu), "unlock mutex");
- CHECK_CALL(pthread_join(receiver_tid, 0), "join thread");
-
- // CHECK-NO-COLLISION: All threads terminated
- printf("All threads terminated\n");
-
- return 0;
-}
Removed: compiler-rt/trunk/test/asan/TestCases/Linux/halt_on_error-torture.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Linux/halt_on_error-torture.cc?rev=253341&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Linux/halt_on_error-torture.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/Linux/halt_on_error-torture.cc (removed)
@@ -1,83 +0,0 @@
-// Stress test recovery mode with many threads.
-//
-// RUN: %clangxx_asan -fsanitize-recover=address -pthread %s -o %t
-//
-// RUN: env ASAN_OPTIONS=halt_on_error=false %run %t 1 10 >1.txt 2>&1
-// RUN: FileCheck %s < 1.txt
-// RUN: [ $(grep -c 'ERROR: AddressSanitizer: use-after-poison' 1.txt) -eq 10 ]
-// RUN: FileCheck --check-prefix=CHECK-NO-COLLISION %s < 1.txt
-//
-// Collisions are unlikely but still possible so we need the ||.
-// RUN: env ASAN_OPTIONS=halt_on_error=false %run %t 10 20 >10.txt 2>&1 || true
-// This one is racy although _very_ unlikely to fail:
-// RUN: FileCheck %s < 10.txt
-// RUN: FileCheck --check-prefix=CHECK-COLLISION %s < 1.txt || FileCheck --check-prefix=CHECK-NO-COLLISION %s < 1.txt
-//
-// REQUIRES: stable-runtime
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <pthread.h>
-#include <time.h>
-
-#include <sanitizer/asan_interface.h>
-
-size_t nthreads = 10;
-size_t niter = 10;
-
-void random_delay(unsigned *seed) {
- *seed = 1664525 * *seed + 1013904223;
- struct timespec delay = { 0, (*seed % 1000) * 1000 };
- nanosleep(&delay, 0);
-}
-
-void *run(void *arg) {
- unsigned seed = (unsigned)(size_t)arg;
-
- volatile char tmp[2];
- __asan_poison_memory_region(&tmp, sizeof(tmp));
-
- for (size_t i = 0; i < niter; ++i) {
- random_delay(&seed);
- // Expect error collisions here
- // CHECK: ERROR: AddressSanitizer: use-after-poison
- volatile int idx = 0;
- tmp[idx] = 0;
- }
-
- return 0;
-}
-
-int main(int argc, char **argv) {
- if (argc != 3) {
- fprintf(stderr, "Syntax: %s nthreads niter\n", argv[0]);
- exit(1);
- }
-
- nthreads = (size_t)strtoul(argv[1], 0, 0);
- niter = (size_t)strtoul(argv[2], 0, 0);
-
- pthread_t *tids = new pthread_t[nthreads];
-
- for (size_t i = 0; i < nthreads; ++i) {
- if (0 != pthread_create(&tids[i], 0, run, (void *)i)) {
- fprintf(stderr, "Failed to create thread\n");
- exit(1);
- }
- }
-
- for (size_t i = 0; i < nthreads; ++i) {
- if (0 != pthread_join(tids[i], 0)) {
- fprintf(stderr, "Failed to join thread\n");
- exit(1);
- }
- }
-
- // CHECK-COLLISION: AddressSanitizer: nested bug in the same thread, aborting
- // CHECK-NO-COLLISION: All threads terminated
- printf("All threads terminated\n");
-
- delete [] tids;
-
- return 0;
-}
More information about the llvm-commits
mailing list