From 32aff54e832f1d249f655e6c76d6b1ba30adbd83 Mon Sep 17 00:00:00 2001 From: Chris Lalancette Date: Tue, 26 Mar 2024 16:12:30 +0000 Subject: [PATCH 1/2] Use a memcmp for the expected symbol name. I believe that g++ does not guarantee what a particular symbol name will be. Thus, in g++ 11.4.0 (what is in Ubuntu 22.04), the symbol name here ended with "#2", while in g++ 13.2.0 (what is in Ubuntu 24.04), the symbol name ends with "#1". Given that we can't guarantee this, just search for the first part of the name up to the number, which should be good enough for this test. Signed-off-by: Chris Lalancette --- test_tracetools/test/test_utils.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test_tracetools/test/test_utils.cpp b/test_tracetools/test/test_utils.cpp index 163c18db..36a5548a 100644 --- a/test_tracetools/test/test_utils.cpp +++ b/test_tracetools/test/test_utils.cpp @@ -84,10 +84,9 @@ TEST(TestUtils, valid_symbol_lambda_capture) { auto m = [&](int other_num) {return num + other_num;}; symbol = tracetools::get_symbol(m); - EXPECT_STREQ( - symbol, - "TestUtils_valid_symbol_lambda_capture_Test::TestBody()::{lambda(int)#2}") << - "invalid symbol"; + const std::string expected_symbol_name = + "TestUtils_valid_symbol_lambda_capture_Test::TestBody()::{lambda(int)#"; + EXPECT_EQ(memcmp(symbol, expected_symbol_name.c_str(), expected_symbol_name.length()), 0); std::free(symbol); } From 84b93a5a2cf501fea0911e481d693a01f94c7c99 Mon Sep 17 00:00:00 2001 From: Chris Lalancette Date: Tue, 26 Mar 2024 16:49:49 +0000 Subject: [PATCH 2/2] Add in a comment. Signed-off-by: Chris Lalancette --- test_tracetools/test/test_utils.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test_tracetools/test/test_utils.cpp b/test_tracetools/test/test_utils.cpp index 36a5548a..67935f21 100644 --- a/test_tracetools/test/test_utils.cpp +++ b/test_tracetools/test/test_utils.cpp @@ -84,6 +84,12 @@ TEST(TestUtils, valid_symbol_lambda_capture) { auto m = [&](int other_num) {return num + other_num;}; symbol = tracetools::get_symbol(m); + + // g++ does not guarantee symbol names. Thus in g++ 11.4.0, the symbol for the + // lambda above is "TestUtils_valid_symbol_lambda_capture_Test::TestBody()::{lambda(int)#2}" + // while in g++ 13.2.0 the symbol for the lambda is + // "TestUtils_valid_symbol_lambda_capture_Test::TestBody()::{lambda(int)#1}" + // We only check the first part of the string so we can handle either. const std::string expected_symbol_name = "TestUtils_valid_symbol_lambda_capture_Test::TestBody()::{lambda(int)#"; EXPECT_EQ(memcmp(symbol, expected_symbol_name.c_str(), expected_symbol_name.length()), 0);