Skip to content

Commit

Permalink
Reorganization around InitFuzzTest for internal purposes.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 650653482
  • Loading branch information
fniksic authored and copybara-github committed Jul 9, 2024
1 parent dbbd750 commit fb8df81
Show file tree
Hide file tree
Showing 14 changed files with 22 additions and 31 deletions.
12 changes: 5 additions & 7 deletions e2e_tests/testdata/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,10 @@ cc_binary(
"@com_google_absl//absl/strings:str_format",
"@com_google_absl//absl/time",
"@com_google_fuzztest//fuzztest",
"@com_google_fuzztest//fuzztest:fuzztest_gtest_main",
"@com_google_fuzztest//fuzztest:googletest_fixture_adapter",
"@com_google_fuzztest//fuzztest:init_fuzztest",
"@com_google_fuzztest//fuzztest:io",
"@com_google_fuzztest//fuzztest:logging",
"@com_google_fuzztest//fuzztest:test_protobuf_cc_proto",
"@com_google_googletest//:gtest",
"@com_google_protobuf//:protobuf",
],
)
Expand All @@ -98,7 +96,7 @@ cc_binary(
testonly = 1,
srcs = ["fuzz_tests_with_invalid_seeds.cc"],
deps = [
"@com_google_fuzztest//fuzztest:fuzztest_core",
"@com_google_fuzztest//fuzztest",
"@com_google_fuzztest//fuzztest:fuzztest_gtest_main",
],
)
Expand All @@ -108,7 +106,7 @@ cc_binary(
testonly = 1,
srcs = ["dynamically_registered_fuzz_tests.cc"],
deps = [
"@com_google_fuzztest//fuzztest:fuzztest_core",
"@com_google_fuzztest//fuzztest",
"@com_google_fuzztest//fuzztest:fuzztest_gtest_main",
],
)
Expand All @@ -119,7 +117,7 @@ cc_binary(
srcs = ["domain_tests.cc"],
deps = [
"@com_google_absl//absl/strings:str_format",
"@com_google_fuzztest//fuzztest:fuzztest_core",
"@com_google_fuzztest//fuzztest",
"@com_google_fuzztest//fuzztest:fuzztest_gtest_main",
],
)
Expand All @@ -129,7 +127,7 @@ cc_binary(
testonly = 1,
srcs = ["unit_test_and_fuzz_tests.cc"],
deps = [
"@com_google_fuzztest//fuzztest:fuzztest_core",
"@com_google_fuzztest//fuzztest",
"@com_google_fuzztest//fuzztest:fuzztest_gtest_main",
],
)
3 changes: 2 additions & 1 deletion e2e_tests/testdata/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ target_link_libraries(
PUBLIC
protobuf::libprotobuf
test_protobuf
absl::algorithm_container
absl::function_ref
absl::str_format
absl::strings
absl::time
fuzztest_googletest_fixture_adapter
fuzztest_logging
fuzztest_status
)
link_fuzztest(fuzz_tests_for_functional_testing.stripped)
set_target_properties(
Expand Down
2 changes: 1 addition & 1 deletion e2e_tests/testdata/domain_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#include <random>

#include "gtest/gtest.h"
#include "./fuzztest/fuzztest.h"
#include "absl/strings/str_format.h"
#include "./fuzztest/fuzztest_core.h"

namespace {

Expand Down
2 changes: 1 addition & 1 deletion e2e_tests/testdata/dynamically_registered_fuzz_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "./fuzztest/fuzztest_core.h"
#include "./fuzztest/fuzztest.h"

namespace {

Expand Down
11 changes: 1 addition & 10 deletions e2e_tests/testdata/fuzz_tests_for_functional_testing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,14 @@
#include <utility>
#include <vector>

#include "gtest/gtest.h"
#include "./fuzztest/fuzztest.h"
#include "absl/algorithm/container.h"
#include "absl/functional/function_ref.h"
#include "absl/strings/match.h"
#include "absl/strings/str_format.h"
#include "absl/strings/string_view.h"
#include "absl/time/clock.h"
#include "absl/time/time.h"
#include "./fuzztest/fuzztest.h"
#include "./fuzztest/init_fuzztest.h"
#include "./fuzztest/internal/io.h"
#include "./fuzztest/internal/logging.h"
#include "./fuzztest/internal/test_protobuf.pb.h"
#include "google/protobuf/descriptor.h"
Expand Down Expand Up @@ -818,9 +815,3 @@ void SkipInputs(uint32_t input) {
FUZZ_TEST(MySuite, SkipInputs).WithSeeds({1});

} // namespace

int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
fuzztest::InitFuzzTest(&argc, &argv, fuzztest::internal::Basename(argv[0]));
return RUN_ALL_TESTS();
}
5 changes: 2 additions & 3 deletions e2e_tests/testdata/fuzz_tests_for_microbenchmarking.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,16 @@
#include <array>
#include <cmath>
#include <cstdlib>
#include <limits>
#include <optional>
#include <string>
#include <string_view>
#include <tuple>
#include <utility>
#include <vector>

#include "./fuzztest/fuzztest.h"
#include "absl/strings/str_format.h"
#include "absl/strings/string_view.h"
#include "./fuzztest/fuzztest.h"
#include "./fuzztest/internal/test_protobuf.pb.h"

volatile int googlefuzz_force_write;
Expand Down Expand Up @@ -370,7 +369,7 @@ auto SwitchTest(unsigned int x) {
FUZZ_TEST(MySuite, SwitchTest);

// Enabled by including absolute distance in the CMP coverage score.
// Path-dependends-on-states could be somehow explored by a fair
// Path-dependent-on-states could be somehow explored by a fair
// scoring of the state data. With Absolute distance, this test will be
// captured.
auto PathDependentState(char a, char b, char c, char d) {
Expand Down
3 changes: 1 addition & 2 deletions e2e_tests/testdata/fuzz_tests_using_googletest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@

#include <cstdio>
#include <cstdlib>
#include <limits>

#include "gtest/gtest.h"
#include "absl/strings/match.h"
#include "./fuzztest/fuzztest.h"
#include "absl/strings/match.h"
#include "./fuzztest/googletest_fixture_adapter.h"
#include "./fuzztest/internal/test_protobuf.pb.h"

Expand Down
2 changes: 1 addition & 1 deletion e2e_tests/testdata/fuzz_tests_with_invalid_seeds.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

// Fuzz test examples to be used by `functional_test` only.

#include "./fuzztest/fuzztest_core.h"
#include "./fuzztest/fuzztest.h"

namespace {

Expand Down
6 changes: 3 additions & 3 deletions e2e_tests/testdata/fuzz_tests_with_proto_inputs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <vector>

#include "gtest/gtest.h"
#include "./fuzztest/fuzztest.h"
#include "absl/algorithm/container.h"
#include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h"
Expand All @@ -34,7 +35,6 @@
#include "absl/time/clock.h"
#include "absl/time/time.h"
#include "absl/types/span.h"
#include "./fuzztest/fuzztest.h"
#include "./fuzztest/internal/test_protobuf.pb.h"
#include "google/protobuf/text_format.h"
#include "re2/re2.h"
Expand Down Expand Up @@ -579,7 +579,7 @@ void MathFunctions(const TestProtobuf& input) {
if (
// Basic operations.
d[0] < 0 // Negative.
&& i[0] > 0 // Postive.
&& i[0] > 0 // Positive.
&& std::fabs(d[0]) == i[0] // |x|.

// Remainder and qoutient functions.
Expand Down Expand Up @@ -1045,7 +1045,7 @@ bool CanSupervise(const Person& person1, const Person& person2) {
return false;
}

// Determine wether `input` has at least two direct or indirect legal
// Determine whether `input` has at least two direct or indirect legal
// supervisor (18 <= supervisor.age <= 80), one of which is local.
void HasLegalSupervisors(const Person& input) {
if (!NeedsValidSupervisor(input)) return;
Expand Down
2 changes: 1 addition & 1 deletion e2e_tests/testdata/unit_test_and_fuzz_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

#include "gtest/gtest.h"
#include "./fuzztest/fuzztest_core.h"
#include "./fuzztest/fuzztest.h"

namespace {

Expand Down
1 change: 1 addition & 0 deletions fuzztest/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ cc_library(
":configuration",
":flag_name",
":googletest_adaptor",
":io",
":logging",
":registry",
":runtime",
Expand Down
1 change: 1 addition & 0 deletions fuzztest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ fuzztest_cc_library(
DEPS
fuzztest::configuration
fuzztest::googletest_adaptor
fuzztest::io
fuzztest::logging
fuzztest::registry
fuzztest::runtime
Expand Down
1 change: 1 addition & 0 deletions fuzztest/init_fuzztest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "./fuzztest/internal/configuration.h"
#include "./fuzztest/internal/flag_name.h"
#include "./fuzztest/internal/googletest_adaptor.h"
#include "./fuzztest/internal/io.h"
#include "./fuzztest/internal/logging.h"
#include "./fuzztest/internal/registry.h"
#include "./fuzztest/internal/runtime.h"
Expand Down
2 changes: 1 addition & 1 deletion fuzztest/init_fuzztest.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include <string>
#include <string_view>
#include <tuple>
#include <vector>

namespace fuzztest {
Expand Down Expand Up @@ -36,6 +35,7 @@ void ParseAbslFlags(int argc, char** argv);
// REQUIRES: `main()` has started before calling this function.
// REQUIRES: Abseil flags have been inited, either using
// ParseAbslFlags or some other means
//
void InitFuzzTest(int* argc, char*** argv, std::string_view binary_id = {});

// Returns a list of all registered fuzz test names in the form of
Expand Down

0 comments on commit fb8df81

Please sign in to comment.