| 1 | //===-- scudo_unit_test_main.cpp --------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "memtag.h" |
| 10 | #include "tests/scudo_unit_test.h" |
| 11 | |
| 12 | // Match Android's default configuration, which disables Scudo's mismatch |
| 13 | // allocation check, as it is being triggered by some third party code. |
| 14 | #if SCUDO_ANDROID |
| 15 | #define DEALLOC_TYPE_MISMATCH "false" |
| 16 | #else |
| 17 | #define DEALLOC_TYPE_MISMATCH "true" |
| 18 | #endif |
| 19 | |
| 20 | static void EnableMemoryTaggingIfSupported() { |
| 21 | if (!scudo::archSupportsMemoryTagging()) |
| 22 | return; |
| 23 | static bool Done = []() { |
| 24 | if (!scudo::systemDetectsMemoryTagFaultsTestOnly()) |
| 25 | scudo::enableSystemMemoryTaggingTestOnly(); |
| 26 | return true; |
| 27 | }(); |
| 28 | (void)Done; |
| 29 | } |
| 30 | |
| 31 | // This allows us to turn on/off a Quarantine for specific tests. The Quarantine |
| 32 | // parameters are on the low end, to avoid having to loop excessively in some |
| 33 | // tests. |
| 34 | bool UseQuarantine = true; |
| 35 | extern "C" __attribute__((visibility("default" ))) const char * |
| 36 | __scudo_default_options() { |
| 37 | // The wrapper tests initialize the global allocator early, before main(). We |
| 38 | // need to have Memory Tagging enabled before that happens or the allocator |
| 39 | // will disable the feature entirely. |
| 40 | EnableMemoryTaggingIfSupported(); |
| 41 | if (!UseQuarantine) |
| 42 | return "dealloc_type_mismatch=" DEALLOC_TYPE_MISMATCH; |
| 43 | return "quarantine_size_kb=256:thread_local_quarantine_size_kb=128:" |
| 44 | "quarantine_max_chunk_size=512:" |
| 45 | "dealloc_type_mismatch=" DEALLOC_TYPE_MISMATCH; |
| 46 | } |
| 47 | |
| 48 | #if !defined(SCUDO_NO_TEST_MAIN) |
| 49 | int main(int argc, char **argv) { |
| 50 | EnableMemoryTaggingIfSupported(); |
| 51 | testing::InitGoogleTest(&argc, argv); |
| 52 | return RUN_ALL_TESTS(); |
| 53 | } |
| 54 | #endif |
| 55 | |