Open marvi3 opened 1 year ago
can you paste the command that is failing? you mentioned your project is in C, which makes me think that you are compiling with clang and not clang++.
Hello Markus, thanks for the quick reply. That is utterly stupid of me. I did not even think about c not having strings and was just all the time wondering what was going on and what I did wrong.
I run the following commands:
CC=clang-16 CXX=clang++-16 cmake -DCMAKE_BUILD_TYPE=RelWithDebug -DFUZZTEST_FUZZING_MODE=on ..
cmake --build .
Does that mean I can not test c programms with fuzztest out of the box?
Best wishes, marvi3
You should be able to FuzzTest C code. C++ is largely a superset of C so you should be OK. Maybe you could put the FuzzTests in a C++ file and link in your C code when you build everything with clang++.
On Mon, Oct 23, 2023, 13:43 marvi3 @.***> wrote:
Hello Markus, thanks for the quick reply. That is utterly stupid of me. I did not even think about c not having strings and was just all the time wondering what was going on and what I did wrong.
I run the following commands:
CC=clang-16 CXX=clang++-16 cmake -DCMAKE_BUILD_TYPE=RelWithDebug -DFUZZTEST_FUZZING_MODE=on .. cmake --build .
Does that mean I can not test c programms with fuzztest out of the box?
Best wishes, marvi3
— Reply to this email directly, view it on GitHub https://github.com/google/fuzztest/issues/657#issuecomment-1775701435, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABDETCPN5POCNLYDYR6YSIDYA2UCJAVCNFSM6AAAAAA6MMJ4SGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONZVG4YDCNBTGU . You are receiving this because you commented.Message ID: @.***>
As Markus suggested, put your fuzz tests in a C++ file. Include your C header file with C language linkage:
extern "C" {
#include "my/c/header.h"
}
// Call your C functions from fuzz tests.
Then you should be good!
Thank you a lot for your reply and help. I have tried to get it working with what you have provided but I am still failing. I have tried both, to include my c program with the extern keyword and just changing the .c to a .cc ending and then adding the cpp code of fuzztest. However I had no success with this.
By the way I think I forgot to tell which SUT I want to build with FuzzTest: It is mjs, a javascript interpreter.
I am getting a lot of error code that I do not get when building the program originally. Some errors seem to be connected with makros that try to get expanded:
./mjs.c:1650:3: error: expected identifier
LL_NONE = -1,
^
/usr/include/elf.h:2056:20: note: expanded from macro 'LL_NONE'
#define LL_NONE 0
^
In file included from /home/kali/SUT/mjsFuzzTest/mjs_fuzz/fuzztest.cc:4:
./mjs.c:3847:19: error: cannot initialize a variable of type 'enum cs_log_level' with an rvalue of type 'int'
enum cs_log_level cs_log_cur_msg_level WEAK = LL_NONE;
But even when I have fixed them I get this error that I can't seem to fix without breaking other things:
In file included from /home/kali/SUT/mjsFuzzTest/mjs_fuzz/fuzztest.cc:1:
In file included from /home/kali/SUT/mjsFuzzTest/fuzztest/fuzztest/fuzztest.h:23:
In file included from /home/kali/SUT/mjsFuzzTest/fuzztest/./fuzztest/domain.h:18:
In file included from /home/kali/SUT/mjsFuzzTest/fuzztest/./fuzztest/domain_core.h:47:
/home/kali/SUT/mjsFuzzTest/fuzztest/./fuzztest/internal/domains/arbitrary_impl.h:63:3: error: static assertion failed
due to requirement 'foobar<char *>::value': => Type not supported yet. Consider filing an issue.
static_assert(foobar<T>::value,
^ ~~~~~~~~~~~~~~~~
This assertion fail also does not happen when I build the program on it's own.
When I fix all other problems I am left with an error:
fuzztest/./fuzztest/internal/domains/arbitrary_impl.h:63:3: error: static assertion failed due to requirement 'foobar<char *>::value': => Type not supported yet. Consider filing an issue.
static_assert(foobar<T>::value,
So I simply commented this assertion out and then it throws the following error. So it seems like there is a problem with the value_type. I looked a bit in issues and found issue #176 where it is talked about no longer explicitly defining value_type and the change removed the value_type from InRegexImpl::DomainBase. Could the problem I am facing be related to this ?
fuzztest/./fuzztest/internal/type_support.h:42:1: error: no type named 'value_type' in 'fuzztest::internal::ArbitraryImpl<char *>' using value_type_t = typename Domain::value_type;
I am sorry to bother you guys with my problems but I really do not know how to continue anymore.
Looks like you're trying to instantiate fuzztest::Arbitrary<T>()
with a type T
that's not supported (which is what the static assert says).
Can you paste the fuzz test somewhere and share a link?
Hello,
I am sorry, but I am running into a problem when building a project with cmake and fuzztest. My project is a make c project but I have changed it to a simple cmake project using the provided guide about cmake projects. I basically have a .c and a .h file and would like to build them with fuzztest.
CMakeLists.txt
``` cmake_minimum_required(VERSION 3.19) project(fuzztest) set(CMAKE_CXX_STANDARD 17) add_subdirectory(fuzztest) enable_testing() include(GoogleTest) fuzztest_setup_fuzzing_flags() add_compile_definitions(-DMJS_MAIN -DMJS_EXPOSE_PRIVATE -DCS_ENABLE_STDIO -DMJS_ENABLE_DEBUG -DCS_MMAP -DMJS_MODULE_LINES) add_executable( mjs_fuzztest mjs_fuzz/mjs.c mjs_fuzz/mjs.h ) link_fuzztest(mjs_fuzztest) gtest_discover_tests(mjs_fuzztest) ```
However when I run
cmake --build .
as described I get the following error:However when I run the example from the cmake file, the first_fuzz_test.cc, everything works like a charme.
How is it possible, that clang can not find the string header?
I hope to get some suggestion, what I might be doing wrong.