using gwp_asan_integration_DeathTest = SilentDeathTest;
// basename is a mess, use gnu basename explicitly to avoid the need for string // mutation. extern"C"constchar* __gnu_basename(constchar* path);
// GWP-ASan tests can run much slower, especially when combined with HWASan. // Triple the deadline to avoid flakes (b/238585984). extern"C"bool GetInitialArgs(constchar*** args, size_t* num_args) { staticconstchar* initial_args[] = {"--deadline_threshold_ms=270000"};
*args = initial_args;
*num_args = 1; returntrue;
}
// This file implements "torture testing" under GWP-ASan, where we sample every // single allocation. The upper limit for the number of GWP-ASan allocations in // the torture mode is is generally 40,000, so that svelte devices don't // explode, as this uses ~163MiB RAM (4KiB per live allocation).
TEST(gwp_asan_integration, malloc_tests_under_torture) { // Do not override HWASan with GWP ASan.
SKIP_WITH_HWASAN;
RunGwpAsanTest("malloc.*:-malloc.mallinfo*");
}
class SyspropRestorer { private:
std::vector<std::pair<std::string, std::string>> props_to_restore_; // System properties are global for a device, so the tests that mutate the // GWP-ASan system properties must be run mutually exclusive. Because // bionic-unit-tests is run in an isolated gtest fashion (each test is run in // its own process), we have to use flocks to synchronise between tests. int flock_fd_;
public:
SyspropRestorer() {
std::string path = testing::internal::GetArgvs()[0];
flock_fd_ = open(path.c_str(), O_RDONLY);
EXPECT_NE(flock_fd_, -1) << "failed to open self for a flock";
EXPECT_NE(flock(flock_fd_, LOCK_EX), -1) << "failed to flock myself";
// A weaker version of the above tests, only checking that GWP-ASan is enabled // for any pointer, not *our* pointer. This allows us to test the system_default // sysprops without potentially OOM-ing other random processes: // b/273904016#comment5
TEST(gwp_asan_integration, DISABLED_assert_gwp_asan_enabled_weaker) {
std::string maps;
EXPECT_TRUE(android::base::ReadFileToString("/proc/self/maps", &maps));
EXPECT_TRUE(maps.find("GWP-ASan") != std::string::npos) << maps;
}
TEST(gwp_asan_integration, sysprops_non_persist_overrides_persist) { // Do not override HWASan with GWP ASan.
SKIP_WITH_HWASAN;
SyspropRestorer restorer;
__system_property_set("libc.debug.gwp_asan.sample_rate.system_default", "1");
__system_property_set("libc.debug.gwp_asan.process_sampling.system_default", "1"); // Note, any processes launched elsewhere on the system right now will have // GWP-ASan enabled. Make sure that we only use a single slot, otherwise we // could end up causing said badly-timed processes to use up to 163MiB extra // penalty that 40,000 allocs would cause. See b/273904016#comment5 for more // context.
__system_property_set("libc.debug.gwp_asan.max_allocs.system_default", "1");
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.