13fa38318SNico Weber //===-- scudo_unit_test_main.cpp --------------------------------*- C++ -*-===// 23fa38318SNico Weber // 33fa38318SNico Weber // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 43fa38318SNico Weber // See https://llvm.org/LICENSE.txt for license information. 53fa38318SNico Weber // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 63fa38318SNico Weber // 73fa38318SNico Weber //===----------------------------------------------------------------------===// 83fa38318SNico Weber 94124bca3SVitaly Buka #include "memtag.h" 100d3d4d3bSKostya Kortchinsky #include "tests/scudo_unit_test.h" 110d3d4d3bSKostya Kortchinsky 12c8a2882aSPeter Collingbourne // Match Android's default configuration, which disables Scudo's mismatch 13c8a2882aSPeter Collingbourne // allocation check, as it is being triggered by some third party code. 14c8a2882aSPeter Collingbourne #if SCUDO_ANDROID 15c8a2882aSPeter Collingbourne #define DEALLOC_TYPE_MISMATCH "false" 16c8a2882aSPeter Collingbourne #else 17c8a2882aSPeter Collingbourne #define DEALLOC_TYPE_MISMATCH "true" 18c8a2882aSPeter Collingbourne #endif 19c8a2882aSPeter Collingbourne EnableMemoryTaggingIfSupported()20533abb7eSVitaly Bukastatic void EnableMemoryTaggingIfSupported() { 21533abb7eSVitaly Buka if (!scudo::archSupportsMemoryTagging()) 22533abb7eSVitaly Buka return; 23533abb7eSVitaly Buka static bool Done = []() { 24533abb7eSVitaly Buka if (!scudo::systemDetectsMemoryTagFaultsTestOnly()) 25533abb7eSVitaly Buka scudo::enableSystemMemoryTaggingTestOnly(); 26533abb7eSVitaly Buka return true; 27533abb7eSVitaly Buka }(); 28533abb7eSVitaly Buka (void)Done; 29533abb7eSVitaly Buka } 30533abb7eSVitaly Buka 310d3d4d3bSKostya Kortchinsky // This allows us to turn on/off a Quarantine for specific tests. The Quarantine 320d3d4d3bSKostya Kortchinsky // parameters are on the low end, to avoid having to loop excessively in some 330d3d4d3bSKostya Kortchinsky // tests. 340d3d4d3bSKostya Kortchinsky bool UseQuarantine = true; 350d3d4d3bSKostya Kortchinsky extern "C" __attribute__((visibility("default"))) const char * __scudo_default_options()360d3d4d3bSKostya Kortchinsky__scudo_default_options() { 37533abb7eSVitaly Buka // The wrapper tests initialize the global allocator early, before main(). We 38533abb7eSVitaly Buka // need to have Memory Tagging enabled before that happens or the allocator 39533abb7eSVitaly Buka // will disable the feature entirely. 40533abb7eSVitaly Buka EnableMemoryTaggingIfSupported(); 410d3d4d3bSKostya Kortchinsky if (!UseQuarantine) 42c8a2882aSPeter Collingbourne return "dealloc_type_mismatch=" DEALLOC_TYPE_MISMATCH; 430d3d4d3bSKostya Kortchinsky return "quarantine_size_kb=256:thread_local_quarantine_size_kb=128:" 44c8a2882aSPeter Collingbourne "quarantine_max_chunk_size=512:" 45c8a2882aSPeter Collingbourne "dealloc_type_mismatch=" DEALLOC_TYPE_MISMATCH; 460d3d4d3bSKostya Kortchinsky } 473fa38318SNico Weber 48*8feeba64SChristopher Ferris #if !defined(SCUDO_NO_TEST_MAIN) main(int argc,char ** argv)4927f34540SRoland McGrathint main(int argc, char **argv) { 50533abb7eSVitaly Buka EnableMemoryTaggingIfSupported(); 513fa38318SNico Weber testing::InitGoogleTest(&argc, argv); 523fa38318SNico Weber return RUN_ALL_TESTS(); 533fa38318SNico Weber } 5427f34540SRoland McGrath #endif 55