-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: benchmark_list_tests benchmark-format=json #1647
Open
varshneydevansh
wants to merge
20
commits into
google:main
Choose a base branch
from
varshneydevansh:benchmark_list_tests-work-with-benchmark-format=json-#1642
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
73867c7
feat: benchmark_list_tests benchmark-format=json
varshneydevansh a41e9d6
feat: made method virtual and get rid of errors
varshneydevansh ecb97ff
Merge branch 'main' into benchmark_list_tests-work-with-benchmark-for…
varshneydevansh b83465c
feat: added the missing BENCHMARK_OVERRIDE
varshneydevansh d37b7c3
feat: run the clang-format again
varshneydevansh 644a5fb
feat: removed Out as it's now in console reporter
varshneydevansh 5c5914c
feat: forgot to supress the unused parameter
varshneydevansh 4de740d
feat: deleted test / benchmark.pc
varshneydevansh 550ceca
feat: deleted CMakeLists.txt
varshneydevansh 4132a67
feat: added virtual method to abstract class
varshneydevansh a29702c
feat: modified the List() in output_test_helper
varshneydevansh cd632b2
feat: added List() NullReporter & chnagedback enum
varshneydevansh cb5be7d
feat: removed the extra spaces from the endif
varshneydevansh fa29dab
feat: Corrected if FLAGS_benchmark_list_tests)
varshneydevansh 139e29c
feat: improvement with display_reporter, FormatKV
varshneydevansh e1b21e0
Merge branch 'main' into benchmark_list_tests-work-with-benchmark-for…
dmah42 b8ad5ac
Merge branch 'google:main' into benchmark_list_tests-work-with-benchm…
varshneydevansh f4832c3
Merge branch 'google:main' into benchmark_list_tests-work-with-benchm…
varshneydevansh 3b07ebf
add the test case for List
varshneydevansh 438c8c3
modified the gtest file
varshneydevansh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// Copyright 2015 Google Inc. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include <gtest/gtest.h> | ||
#include <gmock/gmock.h> | ||
#include <sstream> | ||
#include "benchmark/benchmark.h" | ||
|
||
namespace benchmark { | ||
namespace internal { | ||
|
||
// Helper function to register benchmarks | ||
void RegisterBenchmarks() { | ||
benchmark::RegisterBenchmark("BM_simple", [](benchmark::State& state) { | ||
for (auto _ : state) {} | ||
}); | ||
benchmark::RegisterBenchmark("BM_complex", [](benchmark::State& state) { | ||
for (auto _ : state) { | ||
// Simulating a complex operation | ||
for (int i = 0; i < 1000; ++i) { | ||
benchmark::DoNotOptimize(i * i); | ||
} | ||
} | ||
}); | ||
benchmark::RegisterBenchmark("BM_special_chars", [](benchmark::State& state) { | ||
for (auto _ : state) {} | ||
})->Name("BM_special!@#"); | ||
} | ||
|
||
class ReporterListTest : public ::testing::Test { | ||
protected: | ||
std::stringstream ss; | ||
BenchmarkReporter::Context context; | ||
|
||
void SetUp() override { | ||
benchmark::ClearRegisteredBenchmarks(); | ||
ss.str(""); | ||
ss.clear(); | ||
} | ||
|
||
void RunList(BenchmarkReporter& reporter) { | ||
RegisterBenchmarks(); // Register all benchmarks | ||
benchmark::RunSpecifiedBenchmarks(&reporter); | ||
} | ||
}; | ||
|
||
// Tests the behavior of reporters when no benchmarks are registered | ||
TEST_F(ReporterListTest, HandlesEmptyBenchmarkList) { | ||
benchmark::ConsoleReporter console_reporter(&ss); | ||
benchmark::JSONReporter json_reporter(&ss); | ||
benchmark::CSVReporter csv_reporter(&ss); | ||
|
||
// Expect no output as no benchmarks are registered | ||
RunList(console_reporter); | ||
EXPECT_TRUE(ss.str().empty()); | ||
|
||
ss.str(""); | ||
RunList(json_reporter); | ||
EXPECT_TRUE(ss.str().empty()); | ||
|
||
ss.str(""); | ||
RunList(csv_reporter); | ||
EXPECT_TRUE(ss.str().empty()); | ||
} | ||
|
||
// Tests the output of reporters when benchmarks are listed | ||
TEST_F(ReporterListTest, ListsBenchmarksWithDifferentReporters) { | ||
benchmark::ConsoleReporter console_reporter(&ss); | ||
benchmark::JSONReporter json_reporter(&ss); | ||
benchmark::CSVReporter csv_reporter(&ss); | ||
|
||
RegisterBenchmarks(); // Ensure some benchmarks are registered | ||
|
||
RunList(console_reporter); | ||
EXPECT_THAT(ss.str(), ::testing::HasSubstr("BM_simple")); | ||
EXPECT_THAT(ss.str(), ::testing::HasSubstr("BM_complex")); | ||
EXPECT_THAT(ss.str(), ::testing::HasSubstr("BM_special!@#")); | ||
|
||
ss.str(""); | ||
RunList(json_reporter); | ||
EXPECT_THAT(ss.str(), ::testing::HasSubstr("\"name\": \"BM_simple\"")); | ||
EXPECT_THAT(ss.str(), ::testing::HasSubstr("\"name\": \"BM_complex\"")); | ||
EXPECT_THAT(ss.str(), ::testing::HasSubstr("\"name\": \"BM_special!@#\"")); | ||
|
||
// Check JSON structure | ||
std::string json_output = ss.str(); | ||
EXPECT_THAT(json_output.front(), testing::Eq('[')); | ||
EXPECT_THAT(json_output.back(), testing::Eq(']')) | ||
|
||
ss.str(""); | ||
RunList(csv_reporter); | ||
EXPECT_THAT(ss.str(), ::testing::HasSubstr("BM_simple")); | ||
EXPECT_THAT(ss.str(), ::testing::HasSubstr("BM_complex")); | ||
EXPECT_THAT(ss.str(), ::testing::HasSubstr("BM_special!@#")); | ||
} | ||
|
||
} // namespace internal | ||
} // namespace benchmark |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps we could have a gtest for the List function?