Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions libc/cmake/modules/LLVMLibCTestRules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ function(create_libc_unittest fq_target_name)
if(NOT LIBC_UNITTEST_NO_RUN_POSTBUILD)
add_custom_target(
${fq_target_name}
COMMAND ${fq_build_target_name}
COMMAND ${fq_build_target_name} "--gtest_brief=\$\${BRIEF:-1}"
COMMENT "Running unit test ${fq_target_name}"
)
endif()
Expand Down Expand Up @@ -526,7 +526,7 @@ function(add_integration_test test_name)
$<TARGET_FILE:${fq_build_target_name}> ${INTEGRATION_TEST_ARGS})
add_custom_target(
${fq_target_name}
COMMAND ${test_cmd}
COMMAND ${test_cmd} "--gtest_brief=\$\${BRIEF:-1}"
COMMAND_EXPAND_LISTS
COMMENT "Running integration test ${fq_target_name}"
)
Expand Down Expand Up @@ -719,7 +719,7 @@ function(add_libc_hermetic test_name)

add_custom_command(
OUTPUT ${fq_target_name}-cmd
COMMAND ${test_cmd}
COMMAND ${test_cmd} "--gtest_brief=\$\${BRIEF:-1}"
COMMAND_EXPAND_LISTS
COMMENT "Running hermetic test ${fq_target_name}"
${LIBC_HERMETIC_TEST_JOB_POOL}
Expand Down
20 changes: 14 additions & 6 deletions libc/test/UnitTest/LibcTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ int Test::runTests(const TestOptions &Options) {
const char *reset = Options.PrintColor ? "\033[0m" : "";

int TestCount = getNumTests();
if (TestCount) {
if (TestCount && !Options.Brief) {
tlog << green << "[==========] " << reset << "Running " << TestCount
<< " test";
if (TestCount > 1)
Expand All @@ -157,7 +157,8 @@ int Test::runTests(const TestOptions &Options) {
continue;
}

tlog << green << "[ RUN ] " << reset << TestName << '\n';
if (!Options.Brief)
tlog << green << "[ RUN ] " << reset << TestName << '\n';
[[maybe_unused]] const uint64_t start_time = clock();
RunContext Ctx;
T->SetUp();
Expand All @@ -171,7 +172,12 @@ int Test::runTests(const TestOptions &Options) {
++FailCount;
break;
case RunContext::RunResult::Pass:
tlog << green << "[ OK ] " << reset << TestName;
if (!Options.Brief)
tlog << green << "[ OK ] " << reset << TestName;

if (Options.Brief)
break;

#ifdef LIBC_TEST_USE_CLOCK
tlog << " (";
if (start_time > end_time) {
Expand All @@ -197,9 +203,11 @@ int Test::runTests(const TestOptions &Options) {
}

if (TestCount > 0) {
tlog << "Ran " << TestCount << " tests. "
<< " PASS: " << TestCount - FailCount << ' ' << " FAIL: " << FailCount
<< '\n';
if (!Options.Brief) {
tlog << "Ran " << TestCount << " tests. "
<< " PASS: " << TestCount - FailCount << ' '
<< " FAIL: " << FailCount << '\n';
}
} else {
tlog << "No tests run.\n";
if (Options.TestFilter) {
Expand Down
2 changes: 2 additions & 0 deletions libc/test/UnitTest/LibcTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ struct TestOptions {
bool PrintColor = true;
// Should the test results print timing only in milliseconds, as GTest does?
bool TimeInMs = false;
// Should passing tests be suppressed?
bool Brief = false;
};

// NOTE: One should not create instances and call methods on them directly. One
Expand Down
2 changes: 2 additions & 0 deletions libc/test/UnitTest/LibcTestMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ TestOptions parseOptions(int argc, char **argv) {
Options.PrintColor = false;
else if (arg == "--gtest_print_time")
Options.TimeInMs = true;
else if (arg == "--gtest_brief=1")
Options.Brief = true;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: gtest also support the GTEST_BRIEF env var. To make this cleaner in the Cmake files, perhaps I should only support the env var, and not the command line flag?

// Ignore other unsupported gtest specific flags.
else if (arg.starts_with("--gtest_"))
continue;
Expand Down
3 changes: 3 additions & 0 deletions libc/test/utils/UnitTest/testfilter_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ TEST(LlvmLibcTestFilterTest, NoFilter) {}

TEST(LlvmLibcTestFilterTest, CheckCorrectFilter) {
TestOptions Options;

Options.Brief = true;

Options.TestFilter = "LlvmLibcTestFilterTest.NoFilter";
ASSERT_EQ(LIBC_NAMESPACE::testing::Test::runTests(Options), 0);

Expand Down
Loading