diff options
Diffstat (limited to 'test/scudo')
-rw-r--r-- | test/scudo/aligned-new.cpp | 86 | ||||
-rw-r--r-- | test/scudo/alignment.c | 2 | ||||
-rw-r--r-- | test/scudo/double-free.cpp | 8 | ||||
-rw-r--r-- | test/scudo/fsanitize.c | 28 | ||||
-rw-r--r-- | test/scudo/interface.cpp | 15 | ||||
-rw-r--r-- | test/scudo/lit.cfg | 23 | ||||
-rw-r--r-- | test/scudo/memalign.c | 28 | ||||
-rw-r--r-- | test/scudo/mismatch.cpp | 24 | ||||
-rw-r--r-- | test/scudo/preload.cpp | 3 | ||||
-rw-r--r-- | test/scudo/random_shuffle.cpp | 16 | ||||
-rw-r--r-- | test/scudo/realloc.cpp | 10 | ||||
-rw-r--r-- | test/scudo/sized-delete.cpp | 2 | ||||
-rw-r--r-- | test/scudo/sizes.cpp | 32 | ||||
-rw-r--r-- | test/scudo/stats.c | 21 | ||||
-rw-r--r-- | test/scudo/symbols.test | 8 | ||||
-rw-r--r-- | test/scudo/valloc.c | 5 |
16 files changed, 231 insertions, 80 deletions
diff --git a/test/scudo/aligned-new.cpp b/test/scudo/aligned-new.cpp new file mode 100644 index 000000000000..0a10ae188c92 --- /dev/null +++ b/test/scudo/aligned-new.cpp @@ -0,0 +1,86 @@ +// RUN: %clangxx_scudo -std=c++1z -faligned-allocation %s -o %t +// RUN: %run %t valid 2>&1 +// RUN: %env_scudo_opts=allocator_may_return_null=1 %run %t invalid 2>&1 +// RUN: %env_scudo_opts=allocator_may_return_null=0 not %run %t invalid 2>&1 | FileCheck %s + +// Tests that the C++17 aligned new/delete operators are working as expected. +// Currently we do not check the consistency of the alignment on deallocation, +// so this just tests that the APIs work. + +#include <assert.h> +#include <stdio.h> +#include <stdint.h> +#include <string.h> + +// Define all new/delete to not depend on the version provided by the platform. + +namespace std { +struct nothrow_t {}; +static const nothrow_t nothrow; +enum class align_val_t : size_t {}; +} // namespace std + +void *operator new(size_t); +void *operator new[](size_t); +void *operator new(size_t, std::nothrow_t const&); +void *operator new[](size_t, std::nothrow_t const&); +void *operator new(size_t, std::align_val_t); +void *operator new[](size_t, std::align_val_t); +void *operator new(size_t, std::align_val_t, std::nothrow_t const&); +void *operator new[](size_t, std::align_val_t, std::nothrow_t const&); + +void operator delete(void*) throw(); +void operator delete[](void*) throw(); +void operator delete(void*, std::nothrow_t const&); +void operator delete[](void*, std::nothrow_t const&); +void operator delete(void*, size_t) throw(); +void operator delete[](void*, size_t) throw(); +void operator delete(void*, std::align_val_t) throw(); +void operator delete[](void*, std::align_val_t) throw(); +void operator delete(void*, std::align_val_t, std::nothrow_t const&); +void operator delete[](void*, std::align_val_t, std::nothrow_t const&); +void operator delete(void*, size_t, std::align_val_t) throw(); +void operator delete[](void*, size_t, std::align_val_t) throw(); + +template<typename T> +inline T* break_optimization(T *arg) { + __asm__ __volatile__("" : : "r" (arg) : "memory"); + return arg; +} + +struct S12 { int a, b, c; }; +struct alignas(128) S12_128 { int a, b, c; }; +struct alignas(256) S12_256 { int a, b, c; }; +struct alignas(512) S1024_512 { char a[1024]; }; +struct alignas(1024) S1024_1024 { char a[1024]; }; + +int main(int argc, char **argv) { + assert(argc == 2); + + if (!strcmp(argv[1], "valid")) { + // Standard use case. + delete break_optimization(new S12); + delete break_optimization(new S12_128); + delete[] break_optimization(new S12_128[4]); + delete break_optimization(new S12_256); + delete break_optimization(new S1024_512); + delete[] break_optimization(new S1024_512[4]); + delete break_optimization(new S1024_1024); + + // Call directly the aligned versions of the operators. + const size_t alignment = 1U << 8; + void *p = operator new(1, static_cast<std::align_val_t>(alignment)); + assert((reinterpret_cast<uintptr_t>(p) & (alignment - 1)) == 0); + operator delete(p, static_cast<std::align_val_t>(alignment)); + } + if (!strcmp(argv[1], "invalid")) { + // Alignment must be a power of 2. + const size_t alignment = (1U << 8) - 1; + void *p = operator new(1, static_cast<std::align_val_t>(alignment), + std::nothrow); + // CHECK: Scudo ERROR: invalid allocation alignment + assert(!p); + } + + return 0; +} diff --git a/test/scudo/alignment.c b/test/scudo/alignment.c index 6235d50608db..4e2dc1af03b1 100644 --- a/test/scudo/alignment.c +++ b/test/scudo/alignment.c @@ -20,4 +20,4 @@ int main(int argc, char **argv) return 0; } -// CHECK: ERROR: attempted to deallocate a chunk not properly aligned +// CHECK: ERROR: misaligned pointer when deallocating address diff --git a/test/scudo/double-free.cpp b/test/scudo/double-free.cpp index 56118038cf1f..de6c90f1cced 100644 --- a/test/scudo/double-free.cpp +++ b/test/scudo/double-free.cpp @@ -2,7 +2,6 @@ // RUN: not %run %t malloc 2>&1 | FileCheck %s // RUN: not %run %t new 2>&1 | FileCheck %s // RUN: not %run %t newarray 2>&1 | FileCheck %s -// RUN: not %run %t memalign 2>&1 | FileCheck %s // Tests double-free error on pointers allocated with different allocation // functions. @@ -32,13 +31,6 @@ int main(int argc, char **argv) delete[] p; delete[] p; } - if (!strcmp(argv[1], "memalign")) { - void *p = nullptr; - posix_memalign(&p, 0x100, sizeof(int)); - assert(p); - free(p); - free(p); - } return 0; } diff --git a/test/scudo/fsanitize.c b/test/scudo/fsanitize.c new file mode 100644 index 000000000000..7e5d5451f726 --- /dev/null +++ b/test/scudo/fsanitize.c @@ -0,0 +1,28 @@ +// Test various -fsanitize= additional flags combinations. + +// RUN: %clang_scudo %s -o %t +// RUN: not %run %t 2>&1 | FileCheck %s + +// RUN: %clang_scudo -shared-libsan %s -o %t +// RUN: env LD_LIBRARY_PATH=`dirname %shared_libscudo`:$LD_LIBRARY_PATH not %run %t 2>&1 | FileCheck %s +// RUN: %clang_scudo -shared-libsan -fsanitize-minimal-runtime %s -o %t +// RUN: env LD_LIBRARY_PATH=`dirname %shared_minlibscudo`:$LD_LIBRARY_PATH not %run %t 2>&1 | FileCheck %s + +// RUN: %clang_scudo -static-libsan %s -o %t +// RUN: not %run %t 2>&1 | FileCheck %s +// RUN: %clang_scudo -static-libsan -fsanitize-minimal-runtime %s -o %t +// RUN: not %run %t 2>&1 | FileCheck %s + +#include <assert.h> +#include <stdlib.h> + +int main(int argc, char *argv[]) { + unsigned long *p = (unsigned long *)malloc(sizeof(unsigned long)); + assert(p); + *p = 0; + free(p); + free(p); + return 0; +} + +// CHECK: ERROR: invalid chunk state diff --git a/test/scudo/interface.cpp b/test/scudo/interface.cpp index 73ea0a738e43..ec7375193e12 100644 --- a/test/scudo/interface.cpp +++ b/test/scudo/interface.cpp @@ -4,7 +4,6 @@ // RUN: %run %t heap-size 2>&1 // RUN: %env_scudo_opts="allocator_may_return_null=1" %run %t soft-limit 2>&1 // RUN: %env_scudo_opts="allocator_may_return_null=1" not %run %t hard-limit 2>&1 -// UNSUPPORTED: armhf-linux // Tests that the sanitizer interface functions behave appropriately. @@ -51,8 +50,11 @@ int main(int argc, char **argv) // Verifies that setting the soft RSS limit at runtime works as expected. std::vector<void *> pointers; size_t size = 1 << 19; // 512Kb - for (int i = 0; i < 5; i++) - pointers.push_back(malloc(size)); + for (int i = 0; i < 5; i++) { + void *p = malloc(size); + memset(p, 0, size); + pointers.push_back(p); + } // Set the soft RSS limit to 1Mb. __scudo_set_rss_limit(1, 0); usleep(20000); @@ -74,8 +76,11 @@ int main(int argc, char **argv) // Verifies that setting the hard RSS limit at runtime works as expected. std::vector<void *> pointers; size_t size = 1 << 19; // 512Kb - for (int i = 0; i < 5; i++) - pointers.push_back(malloc(size)); + for (int i = 0; i < 5; i++) { + void *p = malloc(size); + memset(p, 0, size); + pointers.push_back(p); + } // Set the hard RSS limit to 1Mb __scudo_set_rss_limit(1, 1); usleep(20000); diff --git a/test/scudo/lit.cfg b/test/scudo/lit.cfg index 028bf721b89e..df78d5f9d6ad 100644 --- a/test/scudo/lit.cfg +++ b/test/scudo/lit.cfg @@ -8,16 +8,12 @@ config.name = 'Scudo' + config.name_suffix # Setup source root. config.test_source_root = os.path.dirname(__file__) -# Path to the shared & static libraries -shared_libscudo = os.path.join(config.compiler_rt_libdir, "libclang_rt.scudo-%s.so" % config.target_arch) -static_libscudo = os.path.join(config.compiler_rt_libdir, "libclang_rt.scudo-%s.a" % config.target_arch) -static_libscudo_cxx = os.path.join(config.compiler_rt_libdir, "libclang_rt.scudo_cxx-%s.a" % config.target_arch) - -whole_archive = "-Wl,-whole-archive %s -Wl,-no-whole-archive " % static_libscudo -whole_archive_cxx = "-Wl,-whole-archive %s -Wl,-no-whole-archive " % static_libscudo_cxx +# Path to the shared library +shared_libscudo = os.path.join(config.compiler_rt_libdir, "libclang_rt.scudo%s.so" % config.target_suffix) +shared_minlibscudo = os.path.join(config.compiler_rt_libdir, "libclang_rt.scudo_minimal-%s.so" % config.target_arch) # Test suffixes. -config.suffixes = ['.c', '.cc', '.cpp'] +config.suffixes = ['.c', '.cc', '.cpp', '.test'] # C & CXX flags. c_flags = ([config.target_cflags] + @@ -35,14 +31,17 @@ if not config.android: cxx_flags = (c_flags + config.cxx_mode_flags + ["-std=c++11"]) -def build_invocation(compile_flags): +scudo_flags = ["-fsanitize=scudo"] + +def build_invocation(compile_flags): return " " + " ".join([config.clang] + compile_flags) + " " -# Add clang substitutions. +# Add substitutions. config.substitutions.append(("%clang ", build_invocation(c_flags))) -config.substitutions.append(("%clang_scudo ", build_invocation(c_flags) + whole_archive)) -config.substitutions.append(("%clangxx_scudo ", build_invocation(cxx_flags) + whole_archive + whole_archive_cxx)) +config.substitutions.append(("%clang_scudo ", build_invocation(c_flags + scudo_flags))) +config.substitutions.append(("%clangxx_scudo ", build_invocation(cxx_flags + scudo_flags))) config.substitutions.append(("%shared_libscudo", shared_libscudo)) +config.substitutions.append(("%shared_minlibscudo", shared_minlibscudo)) # Platform-specific default SCUDO_OPTIONS for lit tests. default_scudo_opts = '' diff --git a/test/scudo/memalign.c b/test/scudo/memalign.c index 1fe6e3ec7eed..675f53415193 100644 --- a/test/scudo/memalign.c +++ b/test/scudo/memalign.c @@ -1,7 +1,10 @@ // RUN: %clang_scudo %s -o %t -// RUN: %run %t valid 2>&1 -// RUN: not %run %t invalid 2>&1 -// RUN: %env_scudo_opts=allocator_may_return_null=1 %run %t invalid 2>&1 +// RUN: %run %t valid 2>&1 +// RUN: not %run %t invalid 2>&1 | FileCheck --check-prefix=CHECK-align %s +// RUN: %env_scudo_opts=allocator_may_return_null=1 %run %t invalid 2>&1 +// RUN: not %run %t double-free 2>&1 | FileCheck --check-prefix=CHECK-double-free %s +// RUN: %env_scudo_opts=DeallocationTypeMismatch=1 not %run %t realloc 2>&1 | FileCheck --check-prefix=CHECK-realloc %s +// RUN: %env_scudo_opts=DeallocationTypeMismatch=0 %run %t realloc 2>&1 // Tests that the various aligned allocation functions work as intended. Also // tests for the condition where the alignment is not a power of 2. @@ -51,6 +54,7 @@ int main(int argc, char **argv) // For larger alignment, reduce the number of allocations to avoid running // out of potential addresses (on 32-bit). for (int i = 19; i <= 24; i++) { + alignment = 1U << i; for (int k = 0; k < 3; k++) { p = memalign(alignment, 0x1000 - (2 * sizeof(void *) * k)); assert(p); @@ -62,6 +66,7 @@ int main(int argc, char **argv) if (!strcmp(argv[1], "invalid")) { // Alignment is not a power of 2. p = memalign(alignment - 1, size); + // CHECK-align: Scudo ERROR: invalid allocation alignment assert(!p); // Size is not a multiple of alignment. p = aligned_alloc(alignment, size >> 1); @@ -77,5 +82,22 @@ int main(int argc, char **argv) assert(p == p_unchanged); assert(err == EINVAL); } + if (!strcmp(argv[1], "double-free")) { + void *p = NULL; + posix_memalign(&p, 0x100, sizeof(int)); + assert(p); + free(p); + free(p); + } + if (!strcmp(argv[1], "realloc")) { + // We cannot reallocate a memalign'd chunk. + void *p = memalign(16, 16); + assert(p); + p = realloc(p, 32); + free(p); + } return 0; } + +// CHECK-double-free: ERROR: invalid chunk state +// CHECK-realloc: ERROR: allocation type mismatch when reallocating address diff --git a/test/scudo/mismatch.cpp b/test/scudo/mismatch.cpp index b49e0ea46f12..b794f66d8a4e 100644 --- a/test/scudo/mismatch.cpp +++ b/test/scudo/mismatch.cpp @@ -1,18 +1,13 @@ // RUN: %clangxx_scudo %s -o %t -// RUN: %env_scudo_opts=DeallocationTypeMismatch=1 not %run %t mallocdel 2>&1 | FileCheck --check-prefix=CHECK-dealloc %s -// RUN: %env_scudo_opts=DeallocationTypeMismatch=0 %run %t mallocdel 2>&1 -// RUN: %env_scudo_opts=DeallocationTypeMismatch=1 not %run %t newfree 2>&1 | FileCheck --check-prefix=CHECK-dealloc %s -// RUN: %env_scudo_opts=DeallocationTypeMismatch=0 %run %t newfree 2>&1 -// RUN: %env_scudo_opts=DeallocationTypeMismatch=1 not %run %t memaligndel 2>&1 | FileCheck --check-prefix=CHECK-dealloc %s -// RUN: %env_scudo_opts=DeallocationTypeMismatch=0 %run %t memaligndel 2>&1 -// RUN: %env_scudo_opts=DeallocationTypeMismatch=1 not %run %t memalignrealloc 2>&1 | FileCheck --check-prefix=CHECK-realloc %s -// RUN: %env_scudo_opts=DeallocationTypeMismatch=0 %run %t memalignrealloc 2>&1 +// RUN: %env_scudo_opts=DeallocationTypeMismatch=1 not %run %t mallocdel 2>&1 | FileCheck --check-prefix=CHECK-dealloc %s +// RUN: %env_scudo_opts=DeallocationTypeMismatch=0 %run %t mallocdel 2>&1 +// RUN: %env_scudo_opts=DeallocationTypeMismatch=1 not %run %t newfree 2>&1 | FileCheck --check-prefix=CHECK-dealloc %s +// RUN: %env_scudo_opts=DeallocationTypeMismatch=0 %run %t newfree 2>&1 // Tests that type mismatches between allocation and deallocation functions are // caught when the related option is set. #include <assert.h> -#include <malloc.h> #include <stdlib.h> #include <string.h> @@ -29,17 +24,6 @@ int main(int argc, char **argv) assert(p); free((void *)p); } - if (!strcmp(argv[1], "memaligndel")) { - int *p = (int *)memalign(16, 16); - assert(p); - delete p; - } - if (!strcmp(argv[1], "memalignrealloc")) { - void *p = memalign(16, 16); - assert(p); - p = realloc(p, 32); - free(p); - } return 0; } diff --git a/test/scudo/preload.cpp b/test/scudo/preload.cpp index b41a70e472b3..7fa8df4c6931 100644 --- a/test/scudo/preload.cpp +++ b/test/scudo/preload.cpp @@ -1,7 +1,8 @@ // Test that the preloaded runtime works without linking the static library. // RUN: %clang %s -lstdc++ -o %t -// RUN: env LD_PRELOAD=%shared_libscudo not %run %t 2>&1 | FileCheck %s +// RUN: env LD_PRELOAD=%shared_libscudo not %run %t 2>&1 | FileCheck %s +// RUN: env LD_PRELOAD=%shared_minlibscudo not %run %t 2>&1 | FileCheck %s // This way of setting LD_PRELOAD does not work with Android test runner. // REQUIRES: !android diff --git a/test/scudo/random_shuffle.cpp b/test/scudo/random_shuffle.cpp index f886cb1504e1..b493a292944c 100644 --- a/test/scudo/random_shuffle.cpp +++ b/test/scudo/random_shuffle.cpp @@ -1,12 +1,12 @@ // RUN: %clangxx_scudo %s -o %t -// RUN: rm -rf %T/random_shuffle_tmp_dir -// RUN: mkdir %T/random_shuffle_tmp_dir -// RUN: %run %t 100 > %T/random_shuffle_tmp_dir/out1 -// RUN: %run %t 100 > %T/random_shuffle_tmp_dir/out2 -// RUN: %run %t 10000 > %T/random_shuffle_tmp_dir/out1 -// RUN: %run %t 10000 > %T/random_shuffle_tmp_dir/out2 -// RUN: not diff %T/random_shuffle_tmp_dir/out? -// RUN: rm -rf %T/random_shuffle_tmp_dir +// RUN: rm -rf %t-dir/random_shuffle_tmp_dir +// RUN: mkdir -p %t-dir/random_shuffle_tmp_dir +// RUN: %run %t 100 > %t-dir/random_shuffle_tmp_dir/out1 +// RUN: %run %t 100 > %t-dir/random_shuffle_tmp_dir/out2 +// RUN: %run %t 10000 > %t-dir/random_shuffle_tmp_dir/out1 +// RUN: %run %t 10000 > %t-dir/random_shuffle_tmp_dir/out2 +// RUN: not diff %t-dir/random_shuffle_tmp_dir/out? +// RUN: rm -rf %t-dir/random_shuffle_tmp_dir // Tests that the allocator shuffles the chunks before returning to the user. diff --git a/test/scudo/realloc.cpp b/test/scudo/realloc.cpp index 254c67a2cca4..26f6373b918e 100644 --- a/test/scudo/realloc.cpp +++ b/test/scudo/realloc.cpp @@ -1,6 +1,6 @@ // RUN: %clangxx_scudo %s -lstdc++ -o %t -// RUN: %run %t pointers 2>&1 -// RUN: %run %t contents 2>&1 +// RUN: %run %t pointers 2>&1 +// RUN: %run %t contents 2>&1 // RUN: %run %t usablesize 2>&1 // Tests that our reallocation function returns the same pointer when the @@ -15,6 +15,8 @@ #include <vector> +#include <sanitizer/allocator_interface.h> + int main(int argc, char **argv) { void *p, *old_p; @@ -35,7 +37,7 @@ int main(int argc, char **argv) if (p) free(p); size += 16; p = malloc(size); - usable_size = malloc_usable_size(p); + usable_size = __sanitizer_get_allocated_size(p); assert(usable_size >= size); } while (usable_size == size); for (int i = 0; i < usable_size; i++) @@ -56,7 +58,7 @@ int main(int argc, char **argv) if (!strcmp(argv[1], "pointers")) { old_p = p = realloc(nullptr, size); assert(p); - size = malloc_usable_size(p); + size = __sanitizer_get_allocated_size(p); // Our realloc implementation will return the same pointer if the size // requested is lower than or equal to the usable size of the associated // chunk. diff --git a/test/scudo/sized-delete.cpp b/test/scudo/sized-delete.cpp index 85df05e2f809..81151b097481 100644 --- a/test/scudo/sized-delete.cpp +++ b/test/scudo/sized-delete.cpp @@ -38,4 +38,4 @@ int main(int argc, char **argv) return 0; } -// CHECK: ERROR: invalid sized delete on chunk at address +// CHECK: ERROR: invalid sized delete when deallocating address diff --git a/test/scudo/sizes.cpp b/test/scudo/sizes.cpp index 73fc71f25c54..f7ccbebedc30 100644 --- a/test/scudo/sizes.cpp +++ b/test/scudo/sizes.cpp @@ -1,11 +1,11 @@ // RUN: %clangxx_scudo %s -lstdc++ -o %t -// RUN: %env_scudo_opts=allocator_may_return_null=0 not %run %t malloc 2>&1 | FileCheck %s +// RUN: %env_scudo_opts=allocator_may_return_null=0 not %run %t malloc 2>&1 | FileCheck %s --check-prefix=CHECK-max // RUN: %env_scudo_opts=allocator_may_return_null=1 %run %t malloc 2>&1 -// RUN: %env_scudo_opts=allocator_may_return_null=0 not %run %t calloc 2>&1 | FileCheck %s +// RUN: %env_scudo_opts=allocator_may_return_null=0 not %run %t calloc 2>&1 | FileCheck %s --check-prefix=CHECK-calloc // RUN: %env_scudo_opts=allocator_may_return_null=1 %run %t calloc 2>&1 -// RUN: %env_scudo_opts=allocator_may_return_null=0 not %run %t new 2>&1 | FileCheck %s -// RUN: %env_scudo_opts=allocator_may_return_null=1 not %run %t new 2>&1 | FileCheck %s -// RUN: %env_scudo_opts=allocator_may_return_null=0 not %run %t new-nothrow 2>&1 | FileCheck %s +// RUN: %env_scudo_opts=allocator_may_return_null=0 not %run %t new 2>&1 | FileCheck %s --check-prefix=CHECK-max +// RUN: %env_scudo_opts=allocator_may_return_null=1 not %run %t new 2>&1 | FileCheck %s --check-prefix=CHECK-oom +// RUN: %env_scudo_opts=allocator_may_return_null=0 not %run %t new-nothrow 2>&1 | FileCheck %s --check-prefix=CHECK-max // RUN: %env_scudo_opts=allocator_may_return_null=1 %run %t new-nothrow 2>&1 // RUN: %run %t usable 2>&1 @@ -21,10 +21,10 @@ #include <limits> #include <new> +#include <sanitizer/allocator_interface.h> + int main(int argc, char **argv) { assert(argc == 2); - const char *action = argv[1]; - fprintf(stderr, "%s:\n", action); #if __LP64__ || defined(_WIN64) static const size_t kMaxAllowedMallocSize = 1ULL << 40; @@ -34,32 +34,32 @@ int main(int argc, char **argv) { static const size_t kChunkHeaderSize = 8; #endif - if (!strcmp(action, "malloc")) { + if (!strcmp(argv[1], "malloc")) { void *p = malloc(kMaxAllowedMallocSize); assert(!p); p = malloc(kMaxAllowedMallocSize - kChunkHeaderSize); assert(!p); - } else if (!strcmp(action, "calloc")) { + } else if (!strcmp(argv[1], "calloc")) { // Trigger an overflow in calloc. size_t size = std::numeric_limits<size_t>::max(); void *p = calloc((size / 0x1000) + 1, 0x1000); assert(!p); - } else if (!strcmp(action, "new")) { + } else if (!strcmp(argv[1], "new")) { void *p = operator new(kMaxAllowedMallocSize); assert(!p); - } else if (!strcmp(action, "new-nothrow")) { + } else if (!strcmp(argv[1], "new-nothrow")) { void *p = operator new(kMaxAllowedMallocSize, std::nothrow); assert(!p); - } else if (!strcmp(action, "usable")) { + } else if (!strcmp(argv[1], "usable")) { // Playing with the actual usable size of a chunk. void *p = malloc(1007); assert(p); - size_t size = malloc_usable_size(p); + size_t size = __sanitizer_get_allocated_size(p); assert(size >= 1007); memset(p, 'A', size); p = realloc(p, 2014); assert(p); - size = malloc_usable_size(p); + size = __sanitizer_get_allocated_size(p); assert(size >= 2014); memset(p, 'B', size); free(p); @@ -70,4 +70,6 @@ int main(int argc, char **argv) { return 0; } -// CHECK: allocator is terminating the process +// CHECK-max: {{Scudo ERROR: requested allocation size .* exceeds maximum supported size}} +// CHECK-oom: Scudo ERROR: allocator is out of memory +// CHECK-calloc: Scudo ERROR: calloc parameters overflow diff --git a/test/scudo/stats.c b/test/scudo/stats.c new file mode 100644 index 000000000000..e7cc78ff0d49 --- /dev/null +++ b/test/scudo/stats.c @@ -0,0 +1,21 @@ +// RUN: %clang_scudo %s -o %t +// RUN: %run %t 2>&1 | FileCheck %s + +// Tests that the allocator stats printing function exists and outputs +// "something". Currently that "something" is fairly nebulous, as the 32-bit +// primary doesn't output anything, and for the 64-bit one it's highly dependent +// on the size class map and potential library allocations. So keep it very +// generic for now. + +#include <stdlib.h> + +#include <sanitizer/scudo_interface.h> + +int main(int argc, char **argv) +{ + free(malloc(1U)); + __scudo_print_stats(); + return 0; +} + +// CHECK: Stats: diff --git a/test/scudo/symbols.test b/test/scudo/symbols.test new file mode 100644 index 000000000000..0425e62ba6af --- /dev/null +++ b/test/scudo/symbols.test @@ -0,0 +1,8 @@ +UNSUPPORTED: android + +Verify that various functions are *not* present in the minimal binary. Presence +of those symbols in the minimal runtime would mean that the split code made it +back into the core Sanitizer runtime library. + +RUN: nm %shared_minlibscudo | not grep Symbolizer +RUN: nm %shared_minlibscudo | not grep Coverage diff --git a/test/scudo/valloc.c b/test/scudo/valloc.c index 132c4f280220..605b9c4d4b9d 100644 --- a/test/scudo/valloc.c +++ b/test/scudo/valloc.c @@ -1,8 +1,8 @@ // RUN: %clang_scudo %s -o %t // RUN: %run %t valid 2>&1 -// RUN: not %run %t invalid 2>&1 +// RUN: not %run %t invalid 2>&1 | FileCheck %s // RUN: %env_scudo_opts=allocator_may_return_null=1 %run %t invalid 2>&1 -// UNSUPPORTED: android, armhf-linux +// UNSUPPORTED: android // Tests that valloc and pvalloc work as intended. @@ -54,6 +54,7 @@ int main(int argc, char **argv) if (!strcmp(argv[1], "invalid")) { // Size passed to pvalloc overflows when rounded up. p = pvalloc((size_t)-1); + // CHECK: Scudo ERROR: pvalloc parameters overflow assert(!p); assert(errno == ENOMEM); errno = 0; |