1//===-- sanitizer_symbolizer_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// Tests for sanitizer_symbolizer.h and sanitizer_symbolizer_internal.h
10//
11//===----------------------------------------------------------------------===//
12
13#include "sanitizer_common/sanitizer_allocator_internal.h"
14#include "sanitizer_common/sanitizer_symbolizer_internal.h"
15#include "gtest/gtest.h"
16
17namespace __sanitizer {
18
19TEST(Symbolizer, ExtractToken) {
20 char *token;
21 const char *rest;
22
23 rest = ExtractToken(str: "a;b;c", delims: ";", result: &token);
24 EXPECT_STREQ("a", token);
25 EXPECT_STREQ("b;c", rest);
26 InternalFree(p: token);
27
28 rest = ExtractToken(str: "aaa-bbb.ccc", delims: ";.-*", result: &token);
29 EXPECT_STREQ("aaa", token);
30 EXPECT_STREQ("bbb.ccc", rest);
31 InternalFree(p: token);
32}
33
34TEST(Symbolizer, ExtractInt) {
35 int token;
36 const char *rest = ExtractInt(str: "123,456;789", delims: ";,", result: &token);
37 EXPECT_EQ(123, token);
38 EXPECT_STREQ("456;789", rest);
39}
40
41TEST(Symbolizer, ExtractUptr) {
42 uptr token;
43 const char *rest = ExtractUptr(str: "123,456;789", delims: ";,", result: &token);
44 EXPECT_EQ(123U, token);
45 EXPECT_STREQ("456;789", rest);
46}
47
48TEST(Symbolizer, ExtractTokenUpToDelimiter) {
49 char *token;
50 const char *rest =
51 ExtractTokenUpToDelimiter(str: "aaa-+-bbb-+-ccc", delimiter: "-+-", result: &token);
52 EXPECT_STREQ("aaa", token);
53 EXPECT_STREQ("bbb-+-ccc", rest);
54 InternalFree(p: token);
55}
56
57#if !SANITIZER_WINDOWS
58TEST(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(name: "_TtSd"));
62 // Check that the rest demangles properly.
63 EXPECT_STREQ("f1(char*, int)", DemangleSwiftAndCXX(name: "_Z2f1Pci"));
64#if !SANITIZER_FREEBSD // QoI issue with libcxxrt on FreeBSD
65 EXPECT_STREQ(nullptr, DemangleSwiftAndCXX(name: "foo"));
66#endif
67 EXPECT_STREQ(nullptr, DemangleSwiftAndCXX(name: ""));
68}
69#endif
70
71} // namespace __sanitizer
72

source code of compiler-rt/lib/sanitizer_common/tests/sanitizer_symbolizer_test.cpp