Skip to content

Commit 0d720e1

Browse files
authored
Use a memcmp for the expected symbol name. (#100)
* 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 <[email protected]>
1 parent 115034b commit 0d720e1

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

test_tracetools/test/test_utils.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,15 @@ TEST(TestUtils, valid_symbol_lambda_capture) {
8484

8585
auto m = [&](int other_num) {return num + other_num;};
8686
symbol = tracetools::get_symbol(m);
87-
EXPECT_STREQ(
88-
symbol,
89-
"TestUtils_valid_symbol_lambda_capture_Test::TestBody()::{lambda(int)#2}") <<
90-
"invalid symbol";
87+
88+
// g++ does not guarantee symbol names. Thus in g++ 11.4.0, the symbol for the
89+
// lambda above is "TestUtils_valid_symbol_lambda_capture_Test::TestBody()::{lambda(int)#2}"
90+
// while in g++ 13.2.0 the symbol for the lambda is
91+
// "TestUtils_valid_symbol_lambda_capture_Test::TestBody()::{lambda(int)#1}"
92+
// We only check the first part of the string so we can handle either.
93+
const std::string expected_symbol_name =
94+
"TestUtils_valid_symbol_lambda_capture_Test::TestBody()::{lambda(int)#";
95+
EXPECT_EQ(memcmp(symbol, expected_symbol_name.c_str(), expected_symbol_name.length()), 0);
9196
std::free(symbol);
9297
}
9398

0 commit comments

Comments
 (0)