Skip to content
This repository has been archived by the owner on Jul 5, 2023. It is now read-only.

Commit

Permalink
This make the integration tests also use the Clang version of the test
Browse files Browse the repository at this point in the history
DLL.

None of the tests has been modified.

Review-Url: https://codereview.chromium.org/2983783002
  • Loading branch information
sebmarchand authored and Commit Bot committed Aug 31, 2017
1 parent 7b2e197 commit 9de882b
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 105 deletions.
3 changes: 3 additions & 0 deletions syzygy/integration_tests/asan_interceptors_tests.cc
Expand Up @@ -1145,6 +1145,9 @@ size_t AsanCorruptBlock() {
}

size_t AsanCorruptBlockInQuarantine() {
// This test requires the HeapCreate/HeapDestroy functions to be intercepted
// and so doesn't work with a Clang-instrumented binary.
// TODO(sebmarchand): Find another way to flush the quarantine.
HANDLE heap = ::HeapCreate(NULL, 0, 0);
size_t* mem =
static_cast<size_t*>(::HeapAlloc(heap, NULL, 10 * sizeof(size_t)));
Expand Down
17 changes: 15 additions & 2 deletions syzygy/integration_tests/asan_interceptors_tests.h
Expand Up @@ -31,7 +31,12 @@ namespace testing {
// @tparam type The type of the value to be read.
// @param location The location where to read from.
// @returns the value at |location|
template<typename type>
template <typename type>
#if defined(__clang__)
type __attribute__((no_sanitize_address)) NonInterceptedRead(type* location) {
return *location;
}
#else
type NonInterceptedRead(type* location) {
// The try-except statement prevents the function from being instrumented.
__try {
Expand All @@ -41,6 +46,7 @@ type NonInterceptedRead(type* location) {
}
return static_cast<type>(0);
}
#endif

// Helper function to do non instrumented reads from an array.
// @tparam type The type of the values to be read.
Expand All @@ -58,7 +64,13 @@ void NonInterceptedReads(type* src, size_t size, type* dst) {
// @tparam type The type of the value to be written.
// @param location The location where to write to.
// @param val The value to write.
template<typename type>
template <typename type>
#if defined(__clang__)
void __attribute__((no_sanitize_address))
NonInterceptedWrite(type* location, type val) {
*location = val;
}
#else
void NonInterceptedWrite(type* location, type val) {
// The try-except statement prevents the function from being instrumented.
__try {
Expand All @@ -67,6 +79,7 @@ void NonInterceptedWrite(type* location, type val) {
// Nothing to do here.
}
}
#endif

// Helper function to do non instrumented writes from an array.
// @tparam type The type of the values to be written.
Expand Down
209 changes: 106 additions & 103 deletions syzygy/integration_tests/instrument_integration_test.cc
Expand Up @@ -1313,6 +1313,11 @@ class ParametrizedLenientInstrumentAppIntegrationTest
void EndToEndTest(const std::string& mode) override {
if (GetParam() == SYZYGY) {
LenientInstrumentAppIntegrationTest::EndToEndTest(mode);
} else if (GetParam() == CLANG) {
test_dll_path_ =
testing::GetExeRelativePath(testing::kIntegrationTestsClangDllName);
// Validates that the test dll loads post instrumentation.
ASSERT_NO_FATAL_FAILURE(LoadTestDll(test_dll_path_, &module_));
}
}

Expand Down Expand Up @@ -1459,44 +1464,9 @@ TEST_P(ParametrizedInstrumentAppIntegrationTest, AsanEndToEnd) {
ASSERT_NO_FATAL_FAILURE(CheckTestDllImportsRedirected());
}

TEST_P(ParametrizedInstrumentAppIntegrationTest, AsanEndToEndNoLiveness) {
// Disable the heap checking as this is implies touching all the shadow bytes
// and this make those tests really slow.
AddEnvironmentChange(::common::kSyzyAsanOptionsEnvVar,
"--no_check_heap_on_failure");
cmd_line_.AppendSwitch("no-liveness-analysis");
ASSERT_NO_FATAL_FAILURE(EndToEndTest("asan"));
ASSERT_NO_FATAL_FAILURE(EndToEndCheckTestDll());
ASSERT_NO_FATAL_FAILURE(AsanErrorCheckTestDll());
}

TEST_P(ParametrizedInstrumentAppIntegrationTest,
AsanEndToEndNoRedundancyAnalysis) {
// Disable the heap checking as this is implies touching all the shadow bytes
// and this make those tests really slow.
AddEnvironmentChange(::common::kSyzyAsanOptionsEnvVar,
"--no_check_heap_on_failure");
cmd_line_.AppendSwitch("no-redundancy-analysis");
ASSERT_NO_FATAL_FAILURE(EndToEndTest("asan"));
ASSERT_NO_FATAL_FAILURE(EndToEndCheckTestDll());
ASSERT_NO_FATAL_FAILURE(AsanErrorCheckTestDll());
}

TEST_P(ParametrizedInstrumentAppIntegrationTest,
AsanEndToEndNoFunctionInterceptors) {
// Disable the heap checking as this is implies touching all the shadow bytes
// and this make those tests really slow.
AddEnvironmentChange(::common::kSyzyAsanOptionsEnvVar,
"--no_check_heap_on_failure");
cmd_line_.AppendSwitch("no-interceptors");
ASSERT_NO_FATAL_FAILURE(EndToEndTest("asan"));
ASSERT_NO_FATAL_FAILURE(EndToEndCheckTestDll());
ASSERT_NO_FATAL_FAILURE(AsanErrorCheckTestDll());
}

TEST_P(ParametrizedInstrumentAppIntegrationTest, AsanEndToEndWithRtlOptions) {
cmd_line_.AppendSwitchASCII(
common::kAsanRtlOptions,
AddEnvironmentChange(
::common::kSyzyAsanOptionsEnvVar,
"--quarantine_size=20000000 --quarantine_block_size=1000000 "
"--no_check_heap_on_failure");
ASSERT_NO_FATAL_FAILURE(EndToEndTest("asan"));
Expand All @@ -1510,47 +1480,11 @@ TEST_P(ParametrizedInstrumentAppIntegrationTest, AsanEndToEndWithRtlOptions) {
ASSERT_EQ(1000000u, runtime->params().quarantine_block_size);
}

TEST_P(ParametrizedInstrumentAppIntegrationTest,
AsanEndToEndWithRtlOptionsOverrideWithEnvironment) {
std::unique_ptr<base::Environment> env(base::Environment::Create());
ASSERT_NE(env.get(), nullptr);
env->SetVar(::common::kSyzyAsanOptionsEnvVar,
"--quarantine_block_size=800000 --ignored_stack_ids=0x1 "
"--no_check_heap_on_failure");
cmd_line_.AppendSwitchASCII(
common::kAsanRtlOptions,
"--quarantine_size=20000000 --quarantine_block_size=1000000 "
"--ignored_stack_ids=0x2");
ASSERT_NO_FATAL_FAILURE(EndToEndTest("asan"));
ASSERT_NO_FATAL_FAILURE(EndToEndCheckTestDll());
ASSERT_NO_FATAL_FAILURE(AsanErrorCheckTestDll());

// Get the active runtime and validate its parameters.
agent::asan::AsanRuntime* runtime = GetActiveAsanRuntime();
ASSERT_TRUE(runtime != NULL);
ASSERT_EQ(20000000u, runtime->params().quarantine_size);
ASSERT_EQ(800000u, runtime->params().quarantine_block_size);
ASSERT_THAT(runtime->params().ignored_stack_ids_set,
testing::ElementsAre(0x1, 0x2));

env->UnSetVar(::common::kSyzyAsanOptionsEnvVar);
}

TEST_P(ParametrizedInstrumentAppIntegrationTest, FullOptimizedAsanEndToEnd) {
// Disable the heap checking as this implies touching all the shadow bytes
// and this make these tests really slow.
AddEnvironmentChange(::common::kSyzyAsanOptionsEnvVar,
"--no_check_heap_on_failure");
ASSERT_NO_FATAL_FAILURE(EndToEndTest("asan"));
ASSERT_NO_FATAL_FAILURE(EndToEndCheckTestDll());
ASSERT_NO_FATAL_FAILURE(AsanErrorCheckTestDll());
ASSERT_NO_FATAL_FAILURE(AsanErrorCheckInterceptedFunctions());
}

TEST_P(ParametrizedInstrumentAppIntegrationTest,
AsanInvalidAccessWithCorruptAllocatedBlockHeader) {
ASSERT_NO_FATAL_FAILURE(EndToEndTest("asan"));
ASSERT_NO_FATAL_FAILURE(EndToEndCheckTestDll());
ASSERT_NO_FATAL_FAILURE(AsanErrorCheckTestDll());
OutOfProcessAsanErrorCheckAndValidateLog(
testing::kAsanInvalidAccessWithCorruptAllocatedBlockHeader, true,
kAsanCorruptHeap, NULL);
Expand Down Expand Up @@ -1596,43 +1530,35 @@ TEST_P(ParametrizedInstrumentAppIntegrationTest,

TEST_P(ParametrizedInstrumentAppIntegrationTest,
SampledAllocationsAsanEndToEnd) {
cmd_line_.AppendSwitchASCII("asan-rtl-options",
"--allocation_guard_rate=0.5 "
"--no_check_heap_on_failure");
AddEnvironmentChange(::common::kSyzyAsanOptionsEnvVar,
"--allocation_guard_rate=0.5 "
"--no_check_heap_on_failure");
ASSERT_NO_FATAL_FAILURE(EndToEndTest("asan"));
ASSERT_NO_FATAL_FAILURE(EndToEndCheckTestDll());
ASSERT_NO_FATAL_FAILURE(AsanErrorCheckSampledAllocations());
}

TEST_P(ParametrizedInstrumentAppIntegrationTest,
AsanLargeBlockHeapEnabledTest) {
cmd_line_.AppendSwitchASCII("asan-rtl-options",
"--no_check_heap_on_failure "
"--quarantine_size=4000000 "
"--quarantine_block_size=2000000");
AddEnvironmentChange(::common::kSyzyAsanOptionsEnvVar,
"--no_check_heap_on_failure "
"--quarantine_size=4000000 "
"--quarantine_block_size=2000000");
ASSERT_NO_FATAL_FAILURE(EndToEndTest("asan"));
ASSERT_NO_FATAL_FAILURE(EndToEndCheckTestDll());
ASSERT_NO_FATAL_FAILURE(AsanLargeBlockHeapTests(true));
}

TEST_P(ParametrizedInstrumentAppIntegrationTest,
AsanLargeBlockHeapDisabledTest) {
cmd_line_.AppendSwitchASCII("asan-rtl-options",
"--no_check_heap_on_failure "
"--disable_large_block_heap");
AddEnvironmentChange(::common::kSyzyAsanOptionsEnvVar,
"--no_check_heap_on_failure "
"--disable_large_block_heap");
ASSERT_NO_FATAL_FAILURE(EndToEndTest("asan"));
ASSERT_NO_FATAL_FAILURE(EndToEndCheckTestDll());
ASSERT_NO_FATAL_FAILURE(AsanLargeBlockHeapTests(false));
}

TEST_P(ParametrizedInstrumentAppIntegrationTest, AsanZebraHeapDisabledTest) {
AsanZebraHeapTest(false);
}

TEST_P(ParametrizedInstrumentAppIntegrationTest, AsanZebraHeapEnabledTest) {
AsanZebraHeapTest(true);
}

TEST_P(ParametrizedInstrumentAppIntegrationTest,
AsanSymbolizerTestAsanBufferOverflow) {
AsanSymbolizerTest(testing::kAsanRead8BufferOverflow,
Expand Down Expand Up @@ -1669,15 +1595,6 @@ TEST_P(ParametrizedInstrumentAppIntegrationTest,
false);
}

TEST_P(ParametrizedInstrumentAppIntegrationTest,
AsanSymbolizerTestAsanCorruptBlockInQuarantine) {
AsanSymbolizerTest(testing::kAsanCorruptBlockInQuarantine,
STRINGIFY(CORRUPT_BLOCK),
STRINGIFY(ASAN_UNKNOWN_ACCESS),
0,
true);
}

// These tests require corrupt heap checking to be enabled.
TEST_P(ParametrizedInstrumentAppIntegrationTest, AsanNearNullptrAccess) {
ASSERT_NO_FATAL_FAILURE(EndToEndTest("asan"));
Expand All @@ -1699,10 +1616,96 @@ TEST_P(ParametrizedInstrumentAppIntegrationTest, AsanNearNullptrAccess) {
kAsanHandlingException, kAsanNearNullptrAccessNoHeapCorruption);
}

// Instantiate the test cases only with SYZYGY until some problems are fixed.
INSTANTIATE_TEST_CASE_P(InstantiationName,
ParametrizedInstrumentAppIntegrationTest,
testing::Values(SYZYGY));
testing::Values(SYZYGY, CLANG));

TEST_F(InstrumentAppIntegrationTest, AsanEndToEndNoLiveness) {
// Disable the heap checking as this is implies touching all the shadow bytes
// and this make those tests really slow.
AddEnvironmentChange(::common::kSyzyAsanOptionsEnvVar,
"--no_check_heap_on_failure");
cmd_line_.AppendSwitch("no-liveness-analysis");
ASSERT_NO_FATAL_FAILURE(EndToEndTest("asan"));
ASSERT_NO_FATAL_FAILURE(EndToEndCheckTestDll());
ASSERT_NO_FATAL_FAILURE(AsanErrorCheckTestDll());
}

TEST_F(InstrumentAppIntegrationTest, AsanEndToEndNoRedundancyAnalysis) {
// Disable the heap checking as this is implies touching all the shadow bytes
// and this make those tests really slow.
AddEnvironmentChange(::common::kSyzyAsanOptionsEnvVar,
"--no_check_heap_on_failure");
cmd_line_.AppendSwitch("no-redundancy-analysis");
ASSERT_NO_FATAL_FAILURE(EndToEndTest("asan"));
ASSERT_NO_FATAL_FAILURE(EndToEndCheckTestDll());
ASSERT_NO_FATAL_FAILURE(AsanErrorCheckTestDll());
}

TEST_F(InstrumentAppIntegrationTest, AsanEndToEndNoFunctionInterceptors) {
// Disable the heap checking as this is implies touching all the shadow bytes
// and this make those tests really slow.
AddEnvironmentChange(::common::kSyzyAsanOptionsEnvVar,
"--no_check_heap_on_failure");
cmd_line_.AppendSwitch("no-interceptors");
ASSERT_NO_FATAL_FAILURE(EndToEndTest("asan"));
ASSERT_NO_FATAL_FAILURE(EndToEndCheckTestDll());
ASSERT_NO_FATAL_FAILURE(AsanErrorCheckTestDll());
}

TEST_F(InstrumentAppIntegrationTest,
AsanEndToEndWithRtlOptionsOverrideWithEnvironment) {
std::unique_ptr<base::Environment> env(base::Environment::Create());
ASSERT_NE(env.get(), nullptr);
env->SetVar(::common::kSyzyAsanOptionsEnvVar,
"--quarantine_block_size=800000 --ignored_stack_ids=0x1 "
"--no_check_heap_on_failure");
cmd_line_.AppendSwitchASCII(
common::kAsanRtlOptions,
"--quarantine_size=20000000 --quarantine_block_size=1000000 "
"--ignored_stack_ids=0x2");
ASSERT_NO_FATAL_FAILURE(EndToEndTest("asan"));
ASSERT_NO_FATAL_FAILURE(EndToEndCheckTestDll());
ASSERT_NO_FATAL_FAILURE(AsanErrorCheckTestDll());

// Get the active runtime and validate its parameters.
agent::asan::AsanRuntime* runtime = GetActiveAsanRuntime();
ASSERT_TRUE(runtime != NULL);
ASSERT_EQ(20000000u, runtime->params().quarantine_size);
ASSERT_EQ(800000u, runtime->params().quarantine_block_size);
ASSERT_THAT(runtime->params().ignored_stack_ids_set,
testing::ElementsAre(0x1, 0x2));

env->UnSetVar(::common::kSyzyAsanOptionsEnvVar);
}

TEST_F(InstrumentAppIntegrationTest, FullOptimizedAsanEndToEnd) {
// Disable the heap checking as this implies touching all the shadow bytes
// and this make these tests really slow.
AddEnvironmentChange(::common::kSyzyAsanOptionsEnvVar,
"--no_check_heap_on_failure");
ASSERT_NO_FATAL_FAILURE(EndToEndTest("asan"));
ASSERT_NO_FATAL_FAILURE(EndToEndCheckTestDll());
ASSERT_NO_FATAL_FAILURE(AsanErrorCheckTestDll());
ASSERT_NO_FATAL_FAILURE(AsanErrorCheckInterceptedFunctions());
}

TEST_F(InstrumentAppIntegrationTest,
AsanSymbolizerTestAsanCorruptBlockInQuarantine) {
// This test requires the HeapCreate/HeapDestroy functions to be intercepted
// and thus doesn't work on a Clang instrumented binary.
AsanSymbolizerTest(testing::kAsanCorruptBlockInQuarantine,
STRINGIFY(CORRUPT_BLOCK), STRINGIFY(ASAN_UNKNOWN_ACCESS),
0, true);
}

TEST_F(InstrumentAppIntegrationTest, AsanZebraHeapDisabledTest) {
AsanZebraHeapTest(false);
}

TEST_F(InstrumentAppIntegrationTest, AsanZebraHeapEnabledTest) {
AsanZebraHeapTest(true);
}

TEST_F(InstrumentAppIntegrationTest, BBEntryEndToEnd) {
ASSERT_NO_FATAL_FAILURE(StartService());
Expand Down
2 changes: 2 additions & 0 deletions syzygy/pe/unittest_util.cc
Expand Up @@ -159,6 +159,8 @@ const wchar_t testing::kIntegrationTestsDllName[] =
L"integration_tests_dll.dll";
const wchar_t testing::kIntegrationTestsDllPdbName[] =
L"integration_tests_dll.dll.pdb";
const wchar_t testing::kIntegrationTestsClangDllName[] =
L"integration_tests_clang_dll.dll";

const wchar_t kNoExportsDllName[] = L"no_exports_dll.dll";
const wchar_t kNoExportsDllPdbName[] = L"no_exports_dll.dll.pdb";
Expand Down
1 change: 1 addition & 0 deletions syzygy/pe/unittest_util.h
Expand Up @@ -41,6 +41,7 @@ extern const wchar_t kTestDllPdbName64[];
// Name of the integrations tests DLLs and PDBs.
extern const wchar_t kIntegrationTestsDllName[];
extern const wchar_t kIntegrationTestsDllPdbName[];
extern const wchar_t kIntegrationTestsClangDllName[];

// Name of the DLL containing an empty exports directory.
extern const wchar_t kNoExportsDllName[];
Expand Down

0 comments on commit 9de882b

Please sign in to comment.