Skip to content

Commit

Permalink
Use a memcmp for the expected symbol name. (#100)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
clalancette committed Mar 26, 2024
1 parent 115034b commit 0d720e1
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions test_tracetools/test/test_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,15 @@ 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";

// 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);
std::free(symbol);
}

Expand Down

0 comments on commit 0d720e1

Please sign in to comment.