Home | History | Annotate | Download | only in tests
      1 //===-- sanitizer_symbolizer_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 // Tests for sanitizer_symbolizer.h and sanitizer_symbolizer_internal.h
     11 //
     12 //===----------------------------------------------------------------------===//
     13 
     14 #include "sanitizer_common/sanitizer_allocator_internal.h"
     15 #include "sanitizer_common/sanitizer_symbolizer_internal.h"
     16 #include "gtest/gtest.h"
     17 
     18 namespace __sanitizer {
     19 
     20 TEST(Symbolizer, ExtractToken) {
     21   char *token;
     22   const char *rest;
     23 
     24   rest = ExtractToken("a;b;c", ";", &token);
     25   EXPECT_STREQ("a", token);
     26   EXPECT_STREQ("b;c", rest);
     27   InternalFree(token);
     28 
     29   rest = ExtractToken("aaa-bbb.ccc", ";.-*", &token);
     30   EXPECT_STREQ("aaa", token);
     31   EXPECT_STREQ("bbb.ccc", rest);
     32   InternalFree(token);
     33 }
     34 
     35 TEST(Symbolizer, ExtractInt) {
     36   int token;
     37   const char *rest = ExtractInt("123,456;789", ";,", &token);
     38   EXPECT_EQ(123, token);
     39   EXPECT_STREQ("456;789", rest);
     40 }
     41 
     42 TEST(Symbolizer, ExtractUptr) {
     43   uptr token;
     44   const char *rest = ExtractUptr("123,456;789", ";,", &token);
     45   EXPECT_EQ(123U, token);
     46   EXPECT_STREQ("456;789", rest);
     47 }
     48 
     49 TEST(Symbolizer, ExtractTokenUpToDelimiter) {
     50   char *token;
     51   const char *rest =
     52       ExtractTokenUpToDelimiter("aaa-+-bbb-+-ccc", "-+-", &token);
     53   EXPECT_STREQ("aaa", token);
     54   EXPECT_STREQ("bbb-+-ccc", rest);
     55   InternalFree(token);
     56 }
     57 
     58 #if !SANITIZER_WINDOWS
     59 TEST(Symbolizer, DemangleSwiftAndCXX) {
     60   // Swift names are not demangled in default llvm build because Swift
     61   // runtime is not linked in.
     62   EXPECT_STREQ("_TtSd", DemangleSwiftAndCXX("_TtSd"));
     63   // Check that the rest demangles properly.
     64   EXPECT_STREQ("f1(char*, int)", DemangleSwiftAndCXX("_Z2f1Pci"));
     65   EXPECT_STREQ("foo", DemangleSwiftAndCXX("foo"));
     66   EXPECT_STREQ("", DemangleSwiftAndCXX(""));
     67 }
     68 #endif
     69 
     70 }  // namespace __sanitizer
     71