Skip to content

Commit e324310

Browse files
[RFC][libc] shut up passing tests
When a test fails, you have to scroll quite a bit to find which test failed. This gets worst over time as we add more tests. gtest has the option --gtest_brief=1 to silence passing tests from the output. Add this to our pseudo-gtest framework. With this change, only failing tests are printed. Example: $ ninja libc-unit-tests [1206/1357] Running unit test libc.test.src.string.memchr_test.__unit__ FAILED: libc/test/src/string/CMakeFiles/libc.test.src.string.memchr_test.__unit__ /android0/llvm-project/build/libc/test/src/string/CMakeFiles/libc.test.src.string.memchr_test.__unit__ cd /android0/llvm-project/build/libc/test/src/string && /android0/llvm-project/build/libc/test/src/string/libc.test.src.string.memchr_test.__unit__.__build__ --gtest_brief=${BRIEF:-1} /android0/llvm-project/libc/test/src/string/memchr_test.cpp:24: FAILURE Expected: call_memchr(src, 'b', size) Which is: bc To be equal to: "b" Which is: b [ FAILED ] LlvmLibcMemChrTest.FindsCharacterAfterNullTerminator There are currently two tests that do print output which can probably also get cleaned up (they are kind of like expected failures): - stack_chk_guard_test - LlvmLibcTestFilterTest.IncorrFilter To get the old behavior, one can do: $ BRIEF=0 ninja libc-unit-tests Longer term, I'd like to move to use of llvm-lit, as is used throughout most of the rest of llvm. Link: https://google.github.io/googletest/advanced.html#suppressing-test-passes
1 parent 8663b87 commit e324310

File tree

6 files changed

+25
-10
lines changed

6 files changed

+25
-10
lines changed

libc/cmake/modules/LLVMLibCTestRules.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ function(create_libc_unittest fq_target_name)
235235
if(NOT LIBC_UNITTEST_NO_RUN_POSTBUILD)
236236
add_custom_target(
237237
${fq_target_name}
238-
COMMAND ${fq_build_target_name}
238+
COMMAND ${fq_build_target_name} "--gtest_brief=\$\${BRIEF:-1}"
239239
COMMENT "Running unit test ${fq_target_name}"
240240
)
241241
endif()
@@ -526,7 +526,7 @@ function(add_integration_test test_name)
526526
$<TARGET_FILE:${fq_build_target_name}> ${INTEGRATION_TEST_ARGS})
527527
add_custom_target(
528528
${fq_target_name}
529-
COMMAND ${test_cmd}
529+
COMMAND ${test_cmd} "--gtest_brief=\$\${BRIEF:-1}"
530530
COMMAND_EXPAND_LISTS
531531
COMMENT "Running integration test ${fq_target_name}"
532532
)
@@ -719,7 +719,7 @@ function(add_libc_hermetic test_name)
719719

720720
add_custom_command(
721721
OUTPUT ${fq_target_name}-cmd
722-
COMMAND ${test_cmd}
722+
COMMAND ${test_cmd} "--gtest_brief=\$\${BRIEF:-1}"
723723
COMMAND_EXPAND_LISTS
724724
COMMENT "Running hermetic test ${fq_target_name}"
725725
${LIBC_HERMETIC_TEST_JOB_POOL}

libc/test/UnitTest/LibcTest.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ int Test::runTests(const TestOptions &Options) {
140140
const char *reset = Options.PrintColor ? "\033[0m" : "";
141141

142142
int TestCount = getNumTests();
143-
if (TestCount) {
143+
if (TestCount && !Options.Brief) {
144144
tlog << green << "[==========] " << reset << "Running " << TestCount
145145
<< " test";
146146
if (TestCount > 1)
@@ -157,7 +157,8 @@ int Test::runTests(const TestOptions &Options) {
157157
continue;
158158
}
159159

160-
tlog << green << "[ RUN ] " << reset << TestName << '\n';
160+
if (!Options.Brief)
161+
tlog << green << "[ RUN ] " << reset << TestName << '\n';
161162
[[maybe_unused]] const uint64_t start_time = clock();
162163
RunContext Ctx;
163164
T->SetUp();
@@ -171,7 +172,12 @@ int Test::runTests(const TestOptions &Options) {
171172
++FailCount;
172173
break;
173174
case RunContext::RunResult::Pass:
174-
tlog << green << "[ OK ] " << reset << TestName;
175+
if (!Options.Brief)
176+
tlog << green << "[ OK ] " << reset << TestName;
177+
178+
if (Options.Brief)
179+
break;
180+
175181
#ifdef LIBC_TEST_USE_CLOCK
176182
tlog << " (";
177183
if (start_time > end_time) {
@@ -197,9 +203,11 @@ int Test::runTests(const TestOptions &Options) {
197203
}
198204

199205
if (TestCount > 0) {
200-
tlog << "Ran " << TestCount << " tests. "
201-
<< " PASS: " << TestCount - FailCount << ' ' << " FAIL: " << FailCount
202-
<< '\n';
206+
if (!Options.Brief) {
207+
tlog << "Ran " << TestCount << " tests. "
208+
<< " PASS: " << TestCount - FailCount << ' ' << " FAIL: " << FailCount
209+
<< '\n';
210+
}
203211
} else {
204212
tlog << "No tests run.\n";
205213
if (Options.TestFilter) {

libc/test/UnitTest/LibcTest.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ struct TestOptions {
108108
bool PrintColor = true;
109109
// Should the test results print timing only in milliseconds, as GTest does?
110110
bool TimeInMs = false;
111+
// Should passing tests be suppressed?
112+
bool Brief = false;
111113
};
112114

113115
// NOTE: One should not create instances and call methods on them directly. One

libc/test/UnitTest/LibcTestMain.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ TestOptions parseOptions(int argc, char **argv) {
3131
Options.PrintColor = false;
3232
else if (arg == "--gtest_print_time")
3333
Options.TimeInMs = true;
34+
else if (arg == "--gtest_brief=1")
35+
Options.Brief = true;
3436
// Ignore other unsupported gtest specific flags.
3537
else if (arg.starts_with("--gtest_"))
3638
continue;

libc/test/src/string/memchr_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ TEST(LlvmLibcMemChrTest, FindsCharacterAfterNullTerminator) {
2121
const size_t size = 5;
2222
const unsigned char src[size] = {'a', '\0', 'b', 'c', '\0'};
2323
// Should return 'b', 'c', '\0' even when after null terminator.
24-
ASSERT_STREQ(call_memchr(src, 'b', size), "bc");
24+
ASSERT_STREQ(call_memchr(src, 'b', size), "b");
2525
}
2626

2727
TEST(LlvmLibcMemChrTest, FindsCharacterInNonNullTerminatedCollection) {

libc/test/utils/UnitTest/testfilter_test.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ TEST(LlvmLibcTestFilterTest, NoFilter) {}
2020

2121
TEST(LlvmLibcTestFilterTest, CheckCorrectFilter) {
2222
TestOptions Options;
23+
24+
Options.Brief = true;
25+
2326
Options.TestFilter = "LlvmLibcTestFilterTest.NoFilter";
2427
ASSERT_EQ(LIBC_NAMESPACE::testing::Test::runTests(Options), 0);
2528

0 commit comments

Comments
 (0)