sanitizer_stackdepot_test.cc revision 1b37017f0216d0b8f3ae3a7dea8b3cc20d74db25
1//===-- sanitizer_stackdepot_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.
11//
12//===----------------------------------------------------------------------===//
13#include "sanitizer_common/sanitizer_stackdepot.h"
14#include "sanitizer_common/sanitizer_internal_defs.h"
15#include "sanitizer_common/sanitizer_libc.h"
16#include "gtest/gtest.h"
17
18namespace __sanitizer {
19
20TEST(SanitizerCommon, StackDepotBasic) {
21  uptr s1[] = {1, 2, 3, 4, 5};
22  u32 i1 = StackDepotPut(s1, ARRAY_SIZE(s1));
23  uptr sz1 = 0;
24  uptr *sp1 = StackDepotGet(i1, &sz1);
25  EXPECT_NE(sp1, (uptr*)0);
26  EXPECT_EQ(sz1, ARRAY_SIZE(s1));
27  EXPECT_EQ(internal_memcmp(sp1?:s1, s1, sizeof(s1)), 0);
28}
29
30TEST(SanitizerCommon, StackDepotAbsent) {
31  uptr sz1 = 0;
32  uptr *sp1 = StackDepotGet(-10, &sz1);
33  EXPECT_EQ(sp1, (uptr*)0);
34}
35
36TEST(SanitizerCommon, StackDepotZero) {
37  u32 i1 = StackDepotPut(0, 0);
38  uptr sz1 = 0;
39  uptr *sp1 = StackDepotGet(i1, &sz1);
40  EXPECT_EQ(sp1, (uptr*)0);
41}
42
43TEST(SanitizerCommon, StackDepotSame) {
44  uptr s1[] = {1, 2, 3, 4, 6};
45  u32 i1 = StackDepotPut(s1, ARRAY_SIZE(s1));
46  u32 i2 = StackDepotPut(s1, ARRAY_SIZE(s1));
47  EXPECT_EQ(i1, i2);
48  uptr sz1 = 0;
49  uptr *sp1 = StackDepotGet(i1, &sz1);
50  EXPECT_NE(sp1, (uptr*)0);
51  EXPECT_EQ(sz1, ARRAY_SIZE(s1));
52  EXPECT_EQ(internal_memcmp(sp1?:s1, s1, sizeof(s1)), 0);
53}
54
55TEST(SanitizerCommon, StackDepotSeveral) {
56  uptr s1[] = {1, 2, 3, 4, 7};
57  u32 i1 = StackDepotPut(s1, ARRAY_SIZE(s1));
58  uptr s2[] = {1, 2, 3, 4, 8, 9};
59  u32 i2 = StackDepotPut(s2, ARRAY_SIZE(s2));
60  EXPECT_NE(i1, i2);
61}
62
63}  // namespace __sanitizer
64