72 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8//9// Tests for sanitizer_symbolizer.h and sanitizer_symbolizer_internal.h10//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("a;b;c", ";", &token);24 EXPECT_STREQ("a", token);25 EXPECT_STREQ("b;c", rest);26 InternalFree(token);27 28 rest = ExtractToken("aaa-bbb.ccc", ";.-*", &token);29 EXPECT_STREQ("aaa", token);30 EXPECT_STREQ("bbb.ccc", rest);31 InternalFree(token);32}33 34TEST(Symbolizer, ExtractInt) {35 int token;36 const char *rest = ExtractInt("123,456;789", ";,", &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("123,456;789", ";,", &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("aaa-+-bbb-+-ccc", "-+-", &token);52 EXPECT_STREQ("aaa", token);53 EXPECT_STREQ("bbb-+-ccc", rest);54 InternalFree(token);55}56 57#if !SANITIZER_WINDOWS58TEST(Symbolizer, DemangleSwiftAndCXX) {59 // Swift names are not demangled in default llvm build because Swift60 // 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 FreeBSD65 EXPECT_STREQ(nullptr, DemangleSwiftAndCXX("foo"));66#endif67 EXPECT_STREQ(nullptr, DemangleSwiftAndCXX(""));68}69#endif70 71} // namespace __sanitizer72