Skip to content

Commit

Permalink
Switch back to libFuzzer style
Browse files Browse the repository at this point in the history
Signed-off-by: Geoff Hutchison <[email protected]>
  • Loading branch information
ghutchis committed Jan 20, 2025
1 parent 07a67f6 commit 820d90c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 27 deletions.
16 changes: 6 additions & 10 deletions tests/io/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,11 @@ endforeach()

option(ENABLE_FUZZ "Enable fuzz testing." OFF)

if(ENABLE_FUZZ)
add_definitions(-DFUZZTEST_FUZZING_MODE=on)
# fuzztest uses abseil-cpp
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_VISIBILITY_PRESET default)
add_subdirectory(fuzztest)
if(ENABLE_FUZZ OR DEFINED ENV{LIB_FUZZING_ENGINE})
add_executable(fuzz_cjson fuzztest.cpp)
target_compile_options(fuzz_cjson PRIVATE -g -fsanitize=fuzzer)
target_link_libraries(fuzz_cjson PRIVATE Avogadro::IO $ENV{LIB_FUZZING_ENGINE})

fuzztest_setup_fuzzing_flags()
add_executable(AvogadroFuzzTests fuzztest.cpp)
target_link_libraries(AvogadroFuzzTests PRIVATE Avogadro::IO)
link_fuzztest(AvogadroFuzzTests)
# todo use a modular input format
# target_compile_definitions(fuzz_cjson PRIVATE -DFUZZ_INPUT_FORMAT="cjson")
endif()
23 changes: 6 additions & 17 deletions tests/io/fuzztest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,19 @@
This source code is released under the 3-Clause BSD License, (see "LICENSE").
******************************************************************************/

#include "fuzztest/fuzztest.h"
#include "iotests.h"

#include <gtest/gtest.h>

#include <avogadro/core/matrix.h>
#include <avogadro/core/molecule.h>
#include <avogadro/core/unitcell.h>

#include <avogadro/io/cjsonformat.h>

using Avogadro::Core::Molecule;
using Avogadro::Io::CjsonFormat;

static const std::string cjsonDir = std::string(AVOGADRO_DATA) + "/data/cjson/";

void readCjson(const std::string& data)
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size)
{
std::string input(reinterpret_cast<const char*>(Data), Size);

CjsonFormat cjson;
Molecule molecule;
bool success = cjson.readString(data, molecule);
EXPECT_TRUE(success);
EXPECT_EQ(cjson.error(), "");
}
bool success = cjson.readString(input, molecule);

Check notice on line 18 in tests/io/fuzztest.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

tests/io/fuzztest.cpp#L18

Variable 'success' is assigned a value that is never used.

FUZZ_TEST(AvogadroFuzzTests, readCjson)
.WithSeeds(fuzztest::ReadFilesFromDirectory(cjsonDir));
return 0;
}

0 comments on commit 820d90c

Please sign in to comment.