[ASan] Split interception-in-shared-lib-test.cc into two tests with platform-specific RUN commands.

Get rid of a TestCases/SharedLibs/shared-lib-test-so.cc dependency in these tests.

llvm-svn: 202267
This commit is contained in:
Alexander Potapenko 2014-02-26 14:05:57 +00:00
parent 78443cfda6
commit 4b1a7fe33a
3 changed files with 41 additions and 7 deletions

View File

@ -0,0 +1,30 @@
// Check that memset() call from a shared library gets intercepted.
// RUN: %clangxx_asan -O0 %s -DSHARED_LIB \
// RUN: -shared -o %T/libinterception-in-shared-lib-test.so \
// RUN: -fPIC
// TODO(glider): figure out how to set rpath in a more portable way and unite
// this test with ../Linux/interception-in-shared-lib-test.cc.
// RUN: %clangxx_asan -O0 %s -o %t -Wl,-rpath,@executable-path -L%T -linterception-in-shared-lib-test && \
// RUN: not %t 2>&1 | FileCheck %s
#include <stdio.h>
#include <string.h>
#if defined(SHARED_LIB)
extern "C"
void my_memset(void *p, size_t sz) {
memset(p, 0, sz);
}
#else
extern "C" void my_memset(void *p, size_t sz);
int main(int argc, char *argv[]) {
char buf[10];
my_memset(buf, 11);
// CHECK: {{.*ERROR: AddressSanitizer: stack-buffer-overflow}}
// CHECK: {{WRITE of size 11 at 0x.* thread T0}}
// CHECK: {{ #0 0x.* in my_memset .*interception-in-shared-lib-test.cc:17}}
return 0;
}
#endif

View File

@ -1,14 +1,22 @@
// Check that memset() call from a shared library gets intercepted.
// RUN: %clangxx_asan -O0 %p/SharedLibs/shared-lib-test-so.cc \
// RUN: %clangxx_asan -O0 %s -DSHARED_LIB \
// RUN: -shared -o %T/libinterception-in-shared-lib-test.so \
// RUN: -fPIC
// TODO(glider): figure out how to set rpath in a more portable way and unite
// this test with ../Darwin/interception-in-shared-lib-test.cc.
// RUN: %clangxx_asan -O0 %s -o %t -Wl,-R,\$ORIGIN -L%T -linterception-in-shared-lib-test && \
// RUN: not %t 2>&1 | FileCheck %s
#include <stdio.h>
#include <string.h>
#if defined(SHARED_LIB)
extern "C"
void my_memset(void *p, size_t sz) {
memset(p, 0, sz);
}
#else
extern "C" void my_memset(void *p, size_t sz);
int main(int argc, char *argv[]) {
@ -16,6 +24,7 @@ int main(int argc, char *argv[]) {
my_memset(buf, 11);
// CHECK: {{.*ERROR: AddressSanitizer: stack-buffer-overflow}}
// CHECK: {{WRITE of size 11 at 0x.* thread T0}}
// CHECK: {{ #0 0x.* in my_memset .*shared-lib-test-so.cc:31}}
// CHECK: {{ #0 0x.* in my_memset .*interception-in-shared-lib-test.cc:17}}
return 0;
}
#endif

View File

@ -25,8 +25,3 @@ extern "C"
void inc2(int *a, int index) {
a[index]++;
}
extern "C"
void my_memset(void *p, size_t sz) {
memset(p, 0, sz);
}