1 //===-- sanitizer_symbolizer_test.cpp -------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // Tests for sanitizer_symbolizer.h and sanitizer_symbolizer_internal.h
11 //===----------------------------------------------------------------------===//
13 #include "sanitizer_common/sanitizer_allocator_internal.h"
14 #include "sanitizer_common/sanitizer_symbolizer_internal.h"
15 #include "gtest/gtest.h"
17 namespace __sanitizer
{
19 TEST(Symbolizer
, ExtractToken
) {
23 rest
= ExtractToken("a;b;c", ";", &token
);
24 EXPECT_STREQ("a", token
);
25 EXPECT_STREQ("b;c", rest
);
28 rest
= ExtractToken("aaa-bbb.ccc", ";.-*", &token
);
29 EXPECT_STREQ("aaa", token
);
30 EXPECT_STREQ("bbb.ccc", rest
);
34 TEST(Symbolizer
, ExtractInt
) {
36 const char *rest
= ExtractInt("123,456;789", ";,", &token
);
37 EXPECT_EQ(123, token
);
38 EXPECT_STREQ("456;789", rest
);
41 TEST(Symbolizer
, ExtractUptr
) {
43 const char *rest
= ExtractUptr("123,456;789", ";,", &token
);
44 EXPECT_EQ(123U, token
);
45 EXPECT_STREQ("456;789", rest
);
48 TEST(Symbolizer
, ExtractTokenUpToDelimiter
) {
51 ExtractTokenUpToDelimiter("aaa-+-bbb-+-ccc", "-+-", &token
);
52 EXPECT_STREQ("aaa", token
);
53 EXPECT_STREQ("bbb-+-ccc", rest
);
57 #if !SANITIZER_WINDOWS
58 TEST(Symbolizer
, DemangleSwiftAndCXX
) {
59 // Swift names are not demangled in default llvm build because Swift
60 // runtime is not linked in.
61 EXPECT_STREQ(nullptr, DemangleSwiftAndCXX("_TtSd"));
62 // Check that the rest demangles properly.
63 EXPECT_STREQ("f1(char*, int)", DemangleSwiftAndCXX("_Z2f1Pci"));
64 #if !SANITIZER_FREEBSD // QoI issue with libcxxrt on FreeBSD
65 EXPECT_STREQ(nullptr, DemangleSwiftAndCXX("foo"));
67 EXPECT_STREQ(nullptr, DemangleSwiftAndCXX(""));
71 } // namespace __sanitizer