[clang][extract-api] Emit "navigator" property of "name" in SymbolGraph
[llvm-project.git] / compiler-rt / lib / sanitizer_common / tests / sanitizer_chained_origin_depot_test.cpp
blob8e3021f613778d51aa7fa87b29db95e58c95aeda
1 //===-- sanitizer_chained_origin_depot_test.cpp ---------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file is a part of Sanitizer runtime.
10 // Tests for sanitizer_chained_origin_depot.h.
12 //===----------------------------------------------------------------------===//
14 #include "sanitizer_common/sanitizer_chained_origin_depot.h"
16 #include "gtest/gtest.h"
17 #include "sanitizer_common/sanitizer_internal_defs.h"
18 #include "sanitizer_common/sanitizer_libc.h"
20 namespace __sanitizer {
22 static ChainedOriginDepot chainedOriginDepot;
24 TEST(SanitizerCommon, ChainedOriginDepotBasic) {
25 u32 new_id;
26 EXPECT_TRUE(chainedOriginDepot.Put(1, 2, &new_id));
27 u32 prev_id;
28 EXPECT_EQ(chainedOriginDepot.Get(new_id, &prev_id), 1U);
29 EXPECT_EQ(prev_id, 2U);
32 TEST(SanitizerCommon, ChainedOriginDepotAbsent) {
33 u32 prev_id;
34 EXPECT_EQ(0U, chainedOriginDepot.Get(99, &prev_id));
35 EXPECT_EQ(0U, prev_id);
38 TEST(SanitizerCommon, ChainedOriginDepotZeroId) {
39 u32 prev_id;
40 EXPECT_EQ(0U, chainedOriginDepot.Get(0, &prev_id));
41 EXPECT_EQ(0U, prev_id);
44 TEST(SanitizerCommon, ChainedOriginDepotSame) {
45 u32 new_id1;
46 EXPECT_TRUE(chainedOriginDepot.Put(11, 12, &new_id1));
47 u32 new_id2;
48 EXPECT_FALSE(chainedOriginDepot.Put(11, 12, &new_id2));
49 EXPECT_EQ(new_id1, new_id2);
51 u32 prev_id;
52 EXPECT_EQ(chainedOriginDepot.Get(new_id1, &prev_id), 11U);
53 EXPECT_EQ(prev_id, 12U);
56 TEST(SanitizerCommon, ChainedOriginDepotDifferent) {
57 u32 new_id1;
58 EXPECT_TRUE(chainedOriginDepot.Put(21, 22, &new_id1));
59 u32 new_id2;
60 EXPECT_TRUE(chainedOriginDepot.Put(21, 23, &new_id2));
61 EXPECT_NE(new_id1, new_id2);
63 u32 prev_id;
64 EXPECT_EQ(chainedOriginDepot.Get(new_id1, &prev_id), 21U);
65 EXPECT_EQ(prev_id, 22U);
66 EXPECT_EQ(chainedOriginDepot.Get(new_id2, &prev_id), 21U);
67 EXPECT_EQ(prev_id, 23U);
70 TEST(SanitizerCommon, ChainedOriginDepotStats) {
71 StackDepotStats stats0 = chainedOriginDepot.GetStats();
73 u32 new_id;
74 EXPECT_TRUE(chainedOriginDepot.Put(33, 34, &new_id));
75 StackDepotStats stats1 = chainedOriginDepot.GetStats();
76 EXPECT_EQ(stats1.n_uniq_ids, stats0.n_uniq_ids + 1);
77 EXPECT_GT(stats1.allocated, stats0.allocated);
79 EXPECT_FALSE(chainedOriginDepot.Put(33, 34, &new_id));
80 StackDepotStats stats2 = chainedOriginDepot.GetStats();
81 EXPECT_EQ(stats2.n_uniq_ids, stats1.n_uniq_ids);
82 EXPECT_EQ(stats2.allocated, stats1.allocated);
84 for (int i = 0; i < 100000; ++i) {
85 ASSERT_TRUE(chainedOriginDepot.Put(35, i, &new_id));
86 StackDepotStats stats3 = chainedOriginDepot.GetStats();
87 ASSERT_EQ(stats3.n_uniq_ids, stats2.n_uniq_ids + 1 + i);
89 EXPECT_GT(chainedOriginDepot.GetStats().allocated, stats2.allocated);
92 } // namespace __sanitizer