[NFC][Py Reformat] Reformat python files in llvm
[llvm-project.git] / libunwind / test / frameheadercache_test.pass.cpp
blob6b648e72849149ef23f4bf2bbb9142a949b3edd6
1 // -*- C++ -*-
2 //===----------------------------------------------------------------------===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
10 // The other libunwind tests don't test internal interfaces, so the include path
11 // is a little wonky.
12 #include "../src/config.h"
14 // Only run this test under supported configurations.
16 #if defined(_LIBUNWIND_USE_DL_ITERATE_PHDR) && \
17 defined(_LIBUNWIND_USE_FRAME_HEADER_CACHE)
19 #include <link.h>
20 #include <stdio.h>
22 // This file defines several of the data structures needed here,
23 // and includes FrameHeaderCache.hpp as well.
24 #include "../src/AddressSpace.hpp"
26 #define kBaseAddr 0xFFF000
27 #define kTextSegmentLength 0xFF
29 using namespace libunwind;
31 int main(int, char**) {
32 FrameHeaderCache FHC;
33 struct dl_phdr_info PInfo;
34 memset(&PInfo, 0, sizeof(PInfo));
35 // The cache itself should only care about these two fields--they
36 // tell the cache to invalidate or not; everything else is handled
37 // by AddressSpace.hpp.
38 PInfo.dlpi_adds = 6;
39 PInfo.dlpi_subs = 7;
41 UnwindInfoSections UIS;
42 UIS.dso_base = kBaseAddr;
43 UIS.text_segment_length = kTextSegmentLength;
44 dl_iterate_cb_data CBData;
45 // Unused by the cache.
46 CBData.addressSpace = nullptr;
47 CBData.sects = &UIS;
48 CBData.targetAddr = kBaseAddr + 1;
50 // Nothing present, shouldn't find.
51 if (FHC.find(&PInfo, 0, &CBData))
52 abort();
53 FHC.add(&UIS);
54 // Just added. Should find.
55 if (!FHC.find(&PInfo, 0, &CBData))
56 abort();
57 // Cache is invalid. Shouldn't find.
58 PInfo.dlpi_adds++;
59 if (FHC.find(&PInfo, 0, &CBData))
60 abort();
62 FHC.add(&UIS);
63 CBData.targetAddr = kBaseAddr - 1;
64 // Shouldn't find something outside of the addresses.
65 if (FHC.find(&PInfo, 0, &CBData))
66 abort();
67 // Add enough things to the cache that the entry is evicted.
68 for (int i = 0; i < 9; i++) {
69 UIS.dso_base = kBaseAddr + (kTextSegmentLength * i);
70 FHC.add(&UIS);
72 CBData.targetAddr = kBaseAddr;
73 // Should have been evicted.
74 if (FHC.find(&PInfo, 0, &CBData))
75 abort();
76 return 0;
79 #else
80 int main(int, char**) { return 0;}
81 #endif