[ASan] Update sanitizer_common and asan test_util headers to support building on...
[blocksruntime.git] / lib / sanitizer_common / tests / sanitizer_procmaps_test.cc
blob335a84ed97dffbc070a61115612848933f1f6c6b
1 //===-- sanitizer_procmaps_test.cc ----------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file is a part of ThreadSanitizer/AddressSanitizer runtime.
12 //===----------------------------------------------------------------------===//
13 #include "sanitizer_common/sanitizer_procmaps.h"
14 #include "gtest/gtest.h"
16 #include <stdlib.h>
18 static void noop() {}
19 extern const char *argv0;
21 namespace __sanitizer {
23 #if SANITIZER_LINUX && !SANITIZER_ANDROID
24 TEST(MemoryMappingLayout, CodeRange) {
25 uptr start, end;
26 bool res = GetCodeRangeForFile("[vdso]", &start, &end);
27 EXPECT_EQ(res, true);
28 EXPECT_GT(start, 0U);
29 EXPECT_LT(start, end);
31 #endif
33 TEST(MemoryMappingLayout, DumpListOfModules) {
34 const char *last_slash = strrchr(argv0, '/');
35 const char *binary_name = last_slash ? last_slash + 1 : argv0;
36 MemoryMappingLayout memory_mapping(false);
37 const uptr kMaxModules = 100;
38 LoadedModule *modules =
39 (LoadedModule *)malloc(kMaxModules * sizeof(LoadedModule));
40 uptr n_modules = memory_mapping.DumpListOfModules(modules, kMaxModules, 0);
41 EXPECT_GT(n_modules, 0U);
42 bool found = false;
43 for (uptr i = 0; i < n_modules; ++i) {
44 if (modules[i].containsAddress((uptr)&noop)) {
45 // Verify that the module name is sane.
46 if (strstr(modules[i].full_name(), binary_name) != 0)
47 found = true;
50 EXPECT_TRUE(found);
51 free(modules);
54 } // namespace __sanitizer