xref: /aosp_15_r20/bionic/tests/gwp_asan_test.cpp (revision 8d67ca893c1523eb926b9080dbe4e2ffd2a27ba1)
1*8d67ca89SAndroid Build Coastguard Worker /*
2*8d67ca89SAndroid Build Coastguard Worker  * Copyright (C) 2021 The Android Open Source Project
3*8d67ca89SAndroid Build Coastguard Worker  * All rights reserved.
4*8d67ca89SAndroid Build Coastguard Worker  *
5*8d67ca89SAndroid Build Coastguard Worker  * Redistribution and use in source and binary forms, with or without
6*8d67ca89SAndroid Build Coastguard Worker  * modification, are permitted provided that the following conditions
7*8d67ca89SAndroid Build Coastguard Worker  * are met:
8*8d67ca89SAndroid Build Coastguard Worker  *  * Redistributions of source code must retain the above copyright
9*8d67ca89SAndroid Build Coastguard Worker  *    notice, this list of conditions and the following disclaimer.
10*8d67ca89SAndroid Build Coastguard Worker  *  * Redistributions in binary form must reproduce the above copyright
11*8d67ca89SAndroid Build Coastguard Worker  *    notice, this list of conditions and the following disclaimer in
12*8d67ca89SAndroid Build Coastguard Worker  *    the documentation and/or other materials provided with the
13*8d67ca89SAndroid Build Coastguard Worker  *    distribution.
14*8d67ca89SAndroid Build Coastguard Worker  *
15*8d67ca89SAndroid Build Coastguard Worker  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16*8d67ca89SAndroid Build Coastguard Worker  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17*8d67ca89SAndroid Build Coastguard Worker  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18*8d67ca89SAndroid Build Coastguard Worker  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19*8d67ca89SAndroid Build Coastguard Worker  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20*8d67ca89SAndroid Build Coastguard Worker  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21*8d67ca89SAndroid Build Coastguard Worker  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22*8d67ca89SAndroid Build Coastguard Worker  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23*8d67ca89SAndroid Build Coastguard Worker  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24*8d67ca89SAndroid Build Coastguard Worker  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25*8d67ca89SAndroid Build Coastguard Worker  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26*8d67ca89SAndroid Build Coastguard Worker  * SUCH DAMAGE.
27*8d67ca89SAndroid Build Coastguard Worker  */
28*8d67ca89SAndroid Build Coastguard Worker 
29*8d67ca89SAndroid Build Coastguard Worker #include <gtest/gtest.h>
30*8d67ca89SAndroid Build Coastguard Worker #include <stdio.h>
31*8d67ca89SAndroid Build Coastguard Worker #include <sys/file.h>
32*8d67ca89SAndroid Build Coastguard Worker #include <string>
33*8d67ca89SAndroid Build Coastguard Worker 
34*8d67ca89SAndroid Build Coastguard Worker #if defined(__BIONIC__)
35*8d67ca89SAndroid Build Coastguard Worker 
36*8d67ca89SAndroid Build Coastguard Worker #include "android-base/file.h"
37*8d67ca89SAndroid Build Coastguard Worker #include "android-base/silent_death_test.h"
38*8d67ca89SAndroid Build Coastguard Worker #include "android-base/test_utils.h"
39*8d67ca89SAndroid Build Coastguard Worker #include "gwp_asan/options.h"
40*8d67ca89SAndroid Build Coastguard Worker #include "platform/bionic/malloc.h"
41*8d67ca89SAndroid Build Coastguard Worker #include "sys/system_properties.h"
42*8d67ca89SAndroid Build Coastguard Worker #include "utils.h"
43*8d67ca89SAndroid Build Coastguard Worker 
44*8d67ca89SAndroid Build Coastguard Worker using gwp_asan_integration_DeathTest = SilentDeathTest;
45*8d67ca89SAndroid Build Coastguard Worker 
46*8d67ca89SAndroid Build Coastguard Worker // basename is a mess, use gnu basename explicitly to avoid the need for string
47*8d67ca89SAndroid Build Coastguard Worker // mutation.
48*8d67ca89SAndroid Build Coastguard Worker extern "C" const char* __gnu_basename(const char* path);
49*8d67ca89SAndroid Build Coastguard Worker 
50*8d67ca89SAndroid Build Coastguard Worker // GWP-ASan tests can run much slower, especially when combined with HWASan.
51*8d67ca89SAndroid Build Coastguard Worker // Triple the deadline to avoid flakes (b/238585984).
GetInitialArgs(const char *** args,size_t * num_args)52*8d67ca89SAndroid Build Coastguard Worker extern "C" bool GetInitialArgs(const char*** args, size_t* num_args) {
53*8d67ca89SAndroid Build Coastguard Worker   static const char* initial_args[] = {"--deadline_threshold_ms=270000"};
54*8d67ca89SAndroid Build Coastguard Worker   *args = initial_args;
55*8d67ca89SAndroid Build Coastguard Worker   *num_args = 1;
56*8d67ca89SAndroid Build Coastguard Worker   return true;
57*8d67ca89SAndroid Build Coastguard Worker }
58*8d67ca89SAndroid Build Coastguard Worker 
59*8d67ca89SAndroid Build Coastguard Worker // This file implements "torture testing" under GWP-ASan, where we sample every
60*8d67ca89SAndroid Build Coastguard Worker // single allocation. The upper limit for the number of GWP-ASan allocations in
61*8d67ca89SAndroid Build Coastguard Worker // the torture mode is is generally 40,000, so that svelte devices don't
62*8d67ca89SAndroid Build Coastguard Worker // explode, as this uses ~163MiB RAM (4KiB per live allocation).
TEST(gwp_asan_integration,malloc_tests_under_torture)63*8d67ca89SAndroid Build Coastguard Worker TEST(gwp_asan_integration, malloc_tests_under_torture) {
64*8d67ca89SAndroid Build Coastguard Worker   // Do not override HWASan with GWP ASan.
65*8d67ca89SAndroid Build Coastguard Worker   SKIP_WITH_HWASAN;
66*8d67ca89SAndroid Build Coastguard Worker 
67*8d67ca89SAndroid Build Coastguard Worker   RunGwpAsanTest("malloc.*:-malloc.mallinfo*");
68*8d67ca89SAndroid Build Coastguard Worker }
69*8d67ca89SAndroid Build Coastguard Worker 
70*8d67ca89SAndroid Build Coastguard Worker class SyspropRestorer {
71*8d67ca89SAndroid Build Coastguard Worker  private:
72*8d67ca89SAndroid Build Coastguard Worker   std::vector<std::pair<std::string, std::string>> props_to_restore_;
73*8d67ca89SAndroid Build Coastguard Worker   // System properties are global for a device, so the tests that mutate the
74*8d67ca89SAndroid Build Coastguard Worker   // GWP-ASan system properties must be run mutually exclusive. Because
75*8d67ca89SAndroid Build Coastguard Worker   // bionic-unit-tests is run in an isolated gtest fashion (each test is run in
76*8d67ca89SAndroid Build Coastguard Worker   // its own process), we have to use flocks to synchronise between tests.
77*8d67ca89SAndroid Build Coastguard Worker   int flock_fd_;
78*8d67ca89SAndroid Build Coastguard Worker 
79*8d67ca89SAndroid Build Coastguard Worker  public:
SyspropRestorer()80*8d67ca89SAndroid Build Coastguard Worker   SyspropRestorer() {
81*8d67ca89SAndroid Build Coastguard Worker     std::string path = testing::internal::GetArgvs()[0];
82*8d67ca89SAndroid Build Coastguard Worker     flock_fd_ = open(path.c_str(), O_RDONLY);
83*8d67ca89SAndroid Build Coastguard Worker     EXPECT_NE(flock_fd_, -1) << "failed to open self for a flock";
84*8d67ca89SAndroid Build Coastguard Worker     EXPECT_NE(flock(flock_fd_, LOCK_EX), -1) << "failed to flock myself";
85*8d67ca89SAndroid Build Coastguard Worker 
86*8d67ca89SAndroid Build Coastguard Worker     const char* basename = __gnu_basename(path.c_str());
87*8d67ca89SAndroid Build Coastguard Worker     std::vector<std::string> props = {
88*8d67ca89SAndroid Build Coastguard Worker         std::string("libc.debug.gwp_asan.sample_rate.") + basename,
89*8d67ca89SAndroid Build Coastguard Worker         std::string("libc.debug.gwp_asan.process_sampling.") + basename,
90*8d67ca89SAndroid Build Coastguard Worker         std::string("libc.debug.gwp_asan.max_allocs.") + basename,
91*8d67ca89SAndroid Build Coastguard Worker         "libc.debug.gwp_asan.sample_rate.system_default",
92*8d67ca89SAndroid Build Coastguard Worker         "libc.debug.gwp_asan.sample_rate.app_default",
93*8d67ca89SAndroid Build Coastguard Worker         "libc.debug.gwp_asan.process_sampling.system_default",
94*8d67ca89SAndroid Build Coastguard Worker         "libc.debug.gwp_asan.process_sampling.app_default",
95*8d67ca89SAndroid Build Coastguard Worker         "libc.debug.gwp_asan.max_allocs.system_default",
96*8d67ca89SAndroid Build Coastguard Worker         "libc.debug.gwp_asan.max_allocs.app_default",
97*8d67ca89SAndroid Build Coastguard Worker     };
98*8d67ca89SAndroid Build Coastguard Worker 
99*8d67ca89SAndroid Build Coastguard Worker     size_t base_props_size = props.size();
100*8d67ca89SAndroid Build Coastguard Worker     for (size_t i = 0; i < base_props_size; ++i) {
101*8d67ca89SAndroid Build Coastguard Worker       props.push_back("persist." + props[i]);
102*8d67ca89SAndroid Build Coastguard Worker     }
103*8d67ca89SAndroid Build Coastguard Worker 
104*8d67ca89SAndroid Build Coastguard Worker     std::string reset_log;
105*8d67ca89SAndroid Build Coastguard Worker 
106*8d67ca89SAndroid Build Coastguard Worker     for (const std::string& prop : props) {
107*8d67ca89SAndroid Build Coastguard Worker       std::string value = GetSysprop(prop);
108*8d67ca89SAndroid Build Coastguard Worker       props_to_restore_.emplace_back(prop, value);
109*8d67ca89SAndroid Build Coastguard Worker       if (!value.empty()) {
110*8d67ca89SAndroid Build Coastguard Worker         __system_property_set(prop.c_str(), "");
111*8d67ca89SAndroid Build Coastguard Worker       }
112*8d67ca89SAndroid Build Coastguard Worker     }
113*8d67ca89SAndroid Build Coastguard Worker   }
114*8d67ca89SAndroid Build Coastguard Worker 
~SyspropRestorer()115*8d67ca89SAndroid Build Coastguard Worker   ~SyspropRestorer() {
116*8d67ca89SAndroid Build Coastguard Worker     for (const auto& kv : props_to_restore_) {
117*8d67ca89SAndroid Build Coastguard Worker       if (kv.second != GetSysprop(kv.first)) {
118*8d67ca89SAndroid Build Coastguard Worker         __system_property_set(kv.first.c_str(), kv.second.c_str());
119*8d67ca89SAndroid Build Coastguard Worker       }
120*8d67ca89SAndroid Build Coastguard Worker     }
121*8d67ca89SAndroid Build Coastguard Worker     close(flock_fd_);
122*8d67ca89SAndroid Build Coastguard Worker   }
123*8d67ca89SAndroid Build Coastguard Worker 
GetSysprop(const std::string & name)124*8d67ca89SAndroid Build Coastguard Worker   static std::string GetSysprop(const std::string& name) {
125*8d67ca89SAndroid Build Coastguard Worker     std::string value;
126*8d67ca89SAndroid Build Coastguard Worker     const prop_info* pi = __system_property_find(name.c_str());
127*8d67ca89SAndroid Build Coastguard Worker     if (pi == nullptr) return value;
128*8d67ca89SAndroid Build Coastguard Worker     __system_property_read_callback(
129*8d67ca89SAndroid Build Coastguard Worker         pi,
130*8d67ca89SAndroid Build Coastguard Worker         [](void* cookie, const char* /* name */, const char* value, uint32_t /* serial */) {
131*8d67ca89SAndroid Build Coastguard Worker           std::string* v = static_cast<std::string*>(cookie);
132*8d67ca89SAndroid Build Coastguard Worker           *v = value;
133*8d67ca89SAndroid Build Coastguard Worker         },
134*8d67ca89SAndroid Build Coastguard Worker         &value);
135*8d67ca89SAndroid Build Coastguard Worker     return value;
136*8d67ca89SAndroid Build Coastguard Worker   }
137*8d67ca89SAndroid Build Coastguard Worker };
138*8d67ca89SAndroid Build Coastguard Worker 
TEST_F(gwp_asan_integration_DeathTest,DISABLED_assert_gwp_asan_enabled)139*8d67ca89SAndroid Build Coastguard Worker TEST_F(gwp_asan_integration_DeathTest, DISABLED_assert_gwp_asan_enabled) {
140*8d67ca89SAndroid Build Coastguard Worker   std::string maps;
141*8d67ca89SAndroid Build Coastguard Worker   EXPECT_TRUE(android::base::ReadFileToString("/proc/self/maps", &maps));
142*8d67ca89SAndroid Build Coastguard Worker   EXPECT_TRUE(maps.find("GWP-ASan") != std::string::npos) << maps;
143*8d67ca89SAndroid Build Coastguard Worker 
144*8d67ca89SAndroid Build Coastguard Worker   volatile int* x = new int;
145*8d67ca89SAndroid Build Coastguard Worker   delete x;
146*8d67ca89SAndroid Build Coastguard Worker   EXPECT_DEATH({ *x = 7; }, "");
147*8d67ca89SAndroid Build Coastguard Worker }
148*8d67ca89SAndroid Build Coastguard Worker 
149*8d67ca89SAndroid Build Coastguard Worker // A weaker version of the above tests, only checking that GWP-ASan is enabled
150*8d67ca89SAndroid Build Coastguard Worker // for any pointer, not *our* pointer. This allows us to test the system_default
151*8d67ca89SAndroid Build Coastguard Worker // sysprops without potentially OOM-ing other random processes:
152*8d67ca89SAndroid Build Coastguard Worker // b/273904016#comment5
TEST(gwp_asan_integration,DISABLED_assert_gwp_asan_enabled_weaker)153*8d67ca89SAndroid Build Coastguard Worker TEST(gwp_asan_integration, DISABLED_assert_gwp_asan_enabled_weaker) {
154*8d67ca89SAndroid Build Coastguard Worker   std::string maps;
155*8d67ca89SAndroid Build Coastguard Worker   EXPECT_TRUE(android::base::ReadFileToString("/proc/self/maps", &maps));
156*8d67ca89SAndroid Build Coastguard Worker   EXPECT_TRUE(maps.find("GWP-ASan") != std::string::npos) << maps;
157*8d67ca89SAndroid Build Coastguard Worker }
158*8d67ca89SAndroid Build Coastguard Worker 
TEST(gwp_asan_integration,DISABLED_assert_gwp_asan_disabled)159*8d67ca89SAndroid Build Coastguard Worker TEST(gwp_asan_integration, DISABLED_assert_gwp_asan_disabled) {
160*8d67ca89SAndroid Build Coastguard Worker   std::string maps;
161*8d67ca89SAndroid Build Coastguard Worker   EXPECT_TRUE(android::base::ReadFileToString("/proc/self/maps", &maps));
162*8d67ca89SAndroid Build Coastguard Worker   EXPECT_TRUE(maps.find("GWP-ASan") == std::string::npos);
163*8d67ca89SAndroid Build Coastguard Worker }
164*8d67ca89SAndroid Build Coastguard Worker 
TEST(gwp_asan_integration,sysprops_program_specific)165*8d67ca89SAndroid Build Coastguard Worker TEST(gwp_asan_integration, sysprops_program_specific) {
166*8d67ca89SAndroid Build Coastguard Worker   // Do not override HWASan with GWP ASan.
167*8d67ca89SAndroid Build Coastguard Worker   SKIP_WITH_HWASAN;
168*8d67ca89SAndroid Build Coastguard Worker 
169*8d67ca89SAndroid Build Coastguard Worker   SyspropRestorer restorer;
170*8d67ca89SAndroid Build Coastguard Worker 
171*8d67ca89SAndroid Build Coastguard Worker   std::string path = testing::internal::GetArgvs()[0];
172*8d67ca89SAndroid Build Coastguard Worker   const char* basename = __gnu_basename(path.c_str());
173*8d67ca89SAndroid Build Coastguard Worker   __system_property_set((std::string("libc.debug.gwp_asan.sample_rate.") + basename).c_str(), "1");
174*8d67ca89SAndroid Build Coastguard Worker   __system_property_set((std::string("libc.debug.gwp_asan.process_sampling.") + basename).c_str(),
175*8d67ca89SAndroid Build Coastguard Worker                         "1");
176*8d67ca89SAndroid Build Coastguard Worker   __system_property_set((std::string("libc.debug.gwp_asan.max_allocs.") + basename).c_str(),
177*8d67ca89SAndroid Build Coastguard Worker                         "40000");
178*8d67ca89SAndroid Build Coastguard Worker 
179*8d67ca89SAndroid Build Coastguard Worker   RunSubtestNoEnv("gwp_asan_integration_DeathTest.DISABLED_assert_gwp_asan_enabled");
180*8d67ca89SAndroid Build Coastguard Worker }
181*8d67ca89SAndroid Build Coastguard Worker 
TEST(gwp_asan_integration,sysprops_persist_program_specific)182*8d67ca89SAndroid Build Coastguard Worker TEST(gwp_asan_integration, sysprops_persist_program_specific) {
183*8d67ca89SAndroid Build Coastguard Worker   // Do not override HWASan with GWP ASan.
184*8d67ca89SAndroid Build Coastguard Worker   SKIP_WITH_HWASAN;
185*8d67ca89SAndroid Build Coastguard Worker 
186*8d67ca89SAndroid Build Coastguard Worker   SyspropRestorer restorer;
187*8d67ca89SAndroid Build Coastguard Worker 
188*8d67ca89SAndroid Build Coastguard Worker   std::string path = testing::internal::GetArgvs()[0];
189*8d67ca89SAndroid Build Coastguard Worker   const char* basename = __gnu_basename(path.c_str());
190*8d67ca89SAndroid Build Coastguard Worker   __system_property_set(
191*8d67ca89SAndroid Build Coastguard Worker       (std::string("persist.libc.debug.gwp_asan.sample_rate.") + basename).c_str(), "1");
192*8d67ca89SAndroid Build Coastguard Worker   __system_property_set(
193*8d67ca89SAndroid Build Coastguard Worker       (std::string("persist.libc.debug.gwp_asan.process_sampling.") + basename).c_str(), "1");
194*8d67ca89SAndroid Build Coastguard Worker   __system_property_set((std::string("persist.libc.debug.gwp_asan.max_allocs.") + basename).c_str(),
195*8d67ca89SAndroid Build Coastguard Worker                         "40000");
196*8d67ca89SAndroid Build Coastguard Worker 
197*8d67ca89SAndroid Build Coastguard Worker   RunSubtestNoEnv("gwp_asan_integration_DeathTest.DISABLED_assert_gwp_asan_enabled");
198*8d67ca89SAndroid Build Coastguard Worker }
199*8d67ca89SAndroid Build Coastguard Worker 
TEST(gwp_asan_integration,sysprops_non_persist_overrides_persist)200*8d67ca89SAndroid Build Coastguard Worker TEST(gwp_asan_integration, sysprops_non_persist_overrides_persist) {
201*8d67ca89SAndroid Build Coastguard Worker   // Do not override HWASan with GWP ASan.
202*8d67ca89SAndroid Build Coastguard Worker   SKIP_WITH_HWASAN;
203*8d67ca89SAndroid Build Coastguard Worker 
204*8d67ca89SAndroid Build Coastguard Worker   SyspropRestorer restorer;
205*8d67ca89SAndroid Build Coastguard Worker 
206*8d67ca89SAndroid Build Coastguard Worker   __system_property_set("libc.debug.gwp_asan.sample_rate.system_default", "1");
207*8d67ca89SAndroid Build Coastguard Worker   __system_property_set("libc.debug.gwp_asan.process_sampling.system_default", "1");
208*8d67ca89SAndroid Build Coastguard Worker   // Note, any processes launched elsewhere on the system right now will have
209*8d67ca89SAndroid Build Coastguard Worker   // GWP-ASan enabled. Make sure that we only use a single slot, otherwise we
210*8d67ca89SAndroid Build Coastguard Worker   // could end up causing said badly-timed processes to use up to 163MiB extra
211*8d67ca89SAndroid Build Coastguard Worker   // penalty that 40,000 allocs would cause. See b/273904016#comment5 for more
212*8d67ca89SAndroid Build Coastguard Worker   // context.
213*8d67ca89SAndroid Build Coastguard Worker   __system_property_set("libc.debug.gwp_asan.max_allocs.system_default", "1");
214*8d67ca89SAndroid Build Coastguard Worker 
215*8d67ca89SAndroid Build Coastguard Worker   __system_property_set("persist.libc.debug.gwp_asan.sample_rate.system_default", "0");
216*8d67ca89SAndroid Build Coastguard Worker   __system_property_set("persist.libc.debug.gwp_asan.process_sampling.system_default", "0");
217*8d67ca89SAndroid Build Coastguard Worker   __system_property_set("persist.libc.debug.gwp_asan.max_allocs.system_default", "0");
218*8d67ca89SAndroid Build Coastguard Worker 
219*8d67ca89SAndroid Build Coastguard Worker   RunSubtestNoEnv("gwp_asan_integration.DISABLED_assert_gwp_asan_enabled_weaker");
220*8d67ca89SAndroid Build Coastguard Worker }
221*8d67ca89SAndroid Build Coastguard Worker 
TEST(gwp_asan_integration,sysprops_program_specific_overrides_default)222*8d67ca89SAndroid Build Coastguard Worker TEST(gwp_asan_integration, sysprops_program_specific_overrides_default) {
223*8d67ca89SAndroid Build Coastguard Worker   // Do not override HWASan with GWP ASan.
224*8d67ca89SAndroid Build Coastguard Worker   SKIP_WITH_HWASAN;
225*8d67ca89SAndroid Build Coastguard Worker 
226*8d67ca89SAndroid Build Coastguard Worker   SyspropRestorer restorer;
227*8d67ca89SAndroid Build Coastguard Worker 
228*8d67ca89SAndroid Build Coastguard Worker   std::string path = testing::internal::GetArgvs()[0];
229*8d67ca89SAndroid Build Coastguard Worker   const char* basename = __gnu_basename(path.c_str());
230*8d67ca89SAndroid Build Coastguard Worker   __system_property_set(
231*8d67ca89SAndroid Build Coastguard Worker       (std::string("persist.libc.debug.gwp_asan.sample_rate.") + basename).c_str(), "1");
232*8d67ca89SAndroid Build Coastguard Worker   __system_property_set(
233*8d67ca89SAndroid Build Coastguard Worker       (std::string("persist.libc.debug.gwp_asan.process_sampling.") + basename).c_str(), "1");
234*8d67ca89SAndroid Build Coastguard Worker   __system_property_set((std::string("persist.libc.debug.gwp_asan.max_allocs.") + basename).c_str(),
235*8d67ca89SAndroid Build Coastguard Worker                         "40000");
236*8d67ca89SAndroid Build Coastguard Worker 
237*8d67ca89SAndroid Build Coastguard Worker   __system_property_set("libc.debug.gwp_asan.sample_rate.system_default", "0");
238*8d67ca89SAndroid Build Coastguard Worker   __system_property_set("libc.debug.gwp_asan.process_sampling.system_default", "0");
239*8d67ca89SAndroid Build Coastguard Worker   __system_property_set("libc.debug.gwp_asan.max_allocs.system_default", "0");
240*8d67ca89SAndroid Build Coastguard Worker 
241*8d67ca89SAndroid Build Coastguard Worker   RunSubtestNoEnv("gwp_asan_integration_DeathTest.DISABLED_assert_gwp_asan_enabled");
242*8d67ca89SAndroid Build Coastguard Worker }
243*8d67ca89SAndroid Build Coastguard Worker 
TEST(gwp_asan_integration,sysprops_can_disable)244*8d67ca89SAndroid Build Coastguard Worker TEST(gwp_asan_integration, sysprops_can_disable) {
245*8d67ca89SAndroid Build Coastguard Worker   // Do not override HWASan with GWP ASan.
246*8d67ca89SAndroid Build Coastguard Worker   SKIP_WITH_HWASAN;
247*8d67ca89SAndroid Build Coastguard Worker 
248*8d67ca89SAndroid Build Coastguard Worker   SyspropRestorer restorer;
249*8d67ca89SAndroid Build Coastguard Worker 
250*8d67ca89SAndroid Build Coastguard Worker   __system_property_set("libc.debug.gwp_asan.sample_rate.system_default", "0");
251*8d67ca89SAndroid Build Coastguard Worker   __system_property_set("libc.debug.gwp_asan.process_sampling.system_default", "0");
252*8d67ca89SAndroid Build Coastguard Worker   __system_property_set("libc.debug.gwp_asan.max_allocs.system_default", "0");
253*8d67ca89SAndroid Build Coastguard Worker 
254*8d67ca89SAndroid Build Coastguard Worker   RunSubtestNoEnv("gwp_asan_integration.DISABLED_assert_gwp_asan_disabled");
255*8d67ca89SAndroid Build Coastguard Worker }
256*8d67ca89SAndroid Build Coastguard Worker 
TEST(gwp_asan_integration,env_overrides_sysprop)257*8d67ca89SAndroid Build Coastguard Worker TEST(gwp_asan_integration, env_overrides_sysprop) {
258*8d67ca89SAndroid Build Coastguard Worker   // Do not override HWASan with GWP ASan.
259*8d67ca89SAndroid Build Coastguard Worker   SKIP_WITH_HWASAN;
260*8d67ca89SAndroid Build Coastguard Worker 
261*8d67ca89SAndroid Build Coastguard Worker   SyspropRestorer restorer;
262*8d67ca89SAndroid Build Coastguard Worker 
263*8d67ca89SAndroid Build Coastguard Worker   __system_property_set("libc.debug.gwp_asan.sample_rate.system_default", "0");
264*8d67ca89SAndroid Build Coastguard Worker   __system_property_set("libc.debug.gwp_asan.process_sampling.system_default", "0");
265*8d67ca89SAndroid Build Coastguard Worker   __system_property_set("libc.debug.gwp_asan.max_allocs.system_default", "0");
266*8d67ca89SAndroid Build Coastguard Worker 
267*8d67ca89SAndroid Build Coastguard Worker   RunGwpAsanTest("gwp_asan_integration_DeathTest.DISABLED_assert_gwp_asan_enabled");
268*8d67ca89SAndroid Build Coastguard Worker }
269*8d67ca89SAndroid Build Coastguard Worker 
270*8d67ca89SAndroid Build Coastguard Worker #endif  // defined(__BIONIC__)
271