Skip to content

chore: use latest cifuzz.h file #7

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
76 changes: 21 additions & 55 deletions include/cifuzz/cifuzz.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,48 +10,8 @@
#include <stdint.h>
#endif

#if defined(__CLION_IDE__) && defined(__cplusplus)
/* This code will only be seen by CLion's static analysis/preprocessing engine
* and thus doesn't have to contain any definitions, declarations are
* sufficient. It mocks enough of the Doctest classes to make CLion's test
* framework support treat it as the full Doctest library. */
namespace doctest {
namespace detail {
struct TestSuite {};
typedef int (*funcType)(const uint8_t *data, std::size_t size);
struct TestCase
{
TestCase(funcType test, const char* file, unsigned line, const TestSuite& test_suite,
const char* type = "", int template_id = -1);
TestCase& operator*(const char* in);
};
int regTest(const TestCase& tc);
}
}

/* This macro has to be defined or CLion will not show a play button, but the
* value doesn't matter. */
#define DOCTEST_TEST_CASE

#define CLION_TEST_PLAY_BUTTON \
/* Silence a CLion warning about a static
* initializer with static storage duration */ \
/* NOLINTBEGIN(cert-err58-cpp) */ \
static const int DOCTEST_ANON_VAR_15771531 = \
doctest::detail::regTest( \
doctest::detail::TestCase( \
&LLVMFuzzerTestOneInput, \
"", \
1, \
doctest::detail::TestSuite() \
/* This string is used as the test name and has
* to be globally unique so that CLion
* generates a unique run configuration per
* test. */ \
) * CIFUZZ_TEST_NAME); \
/* NOLINTEND(cert-err58-cpp) */
#else
#define CLION_TEST_PLAY_BUTTON
#ifdef CI_FUZZ_TEST_FRAMEWORK_GTEST
#include <cifuzz/cifuzz_gtest.h>
#endif

#ifdef __cplusplus
Expand All @@ -63,22 +23,28 @@ static const int DOCTEST_ANON_VAR_15771531 = \
static void LLVMFuzzerTestOneInputNoReturn(const uint8_t *data, size_t size);

#ifdef CIFUZZ_GCOV
CIFUZZ_C_LINKAGE void __gcov_dump();
CIFUZZ_C_LINKAGE void __gcov_reset();
CIFUZZ_C_LINKAGE int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
LLVMFuzzerTestOneInputNoReturn(data, size);
__gcov_dump();
__gcov_reset();
return 0;
}
#define DEFINE_LLVM_FUZZER_TEST_ONE_INPUT \
CIFUZZ_C_LINKAGE void __gcov_dump(); \
CIFUZZ_C_LINKAGE void __gcov_reset(); \
CIFUZZ_C_LINKAGE int LLVMFuzzerTestOneInput(const uint8_t *data, \
size_t size) { \
LLVMFuzzerTestOneInputNoReturn(data, size); \
__gcov_dump(); \
__gcov_reset(); \
return 0; \
}
#else
CIFUZZ_C_LINKAGE int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
LLVMFuzzerTestOneInputNoReturn(data, size);
return 0;
}
#define DEFINE_LLVM_FUZZER_TEST_ONE_INPUT \
CIFUZZ_C_LINKAGE int LLVMFuzzerTestOneInput(const uint8_t *data, \
size_t size) { \
LLVMFuzzerTestOneInputNoReturn(data, size); \
return 0; \
}
#endif

#define FUZZ_TEST void LLVMFuzzerTestOneInputNoReturn
#define FUZZ_TEST \
DEFINE_LLVM_FUZZER_TEST_ONE_INPUT; \
void LLVMFuzzerTestOneInputNoReturn

#ifdef __APPLE__
#define DECLARE_LLVM_FUZZER_INITIALIZE_NO_RETURN \
Expand Down