mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
test-fuzz: Port to LibMain
Also use StringView in place of raw C strings and String.
This commit is contained in:
parent
b47a9ab4dc
commit
4994718d8d
Notes:
sideshowbarker
2024-07-17 23:07:41 +09:00
Author: https://github.com/kennethmyhra Commit: https://github.com/SerenityOS/serenity/commit/4994718d8d Pull-request: https://github.com/SerenityOS/serenity/pull/13341 Issue: https://github.com/SerenityOS/serenity/issues/11609 Reviewed-by: https://github.com/kleinesfilmroellchen ✅
2 changed files with 10 additions and 15 deletions
|
@ -197,7 +197,7 @@ target_link_libraries(tar LibMain LibArchive LibCompress)
|
|||
target_link_libraries(tee LibMain)
|
||||
target_link_libraries(telws LibProtocol LibLine LibMain)
|
||||
target_link_libraries(test-bindtodevice LibMain)
|
||||
target_link_libraries(test-fuzz LibCore LibGemini LibGfx LibHTTP LibIPC LibJS LibMarkdown LibShell)
|
||||
target_link_libraries(test-fuzz LibCore LibGemini LibGfx LibHTTP LibIPC LibJS LibMarkdown LibShell LibMain)
|
||||
target_link_libraries(test-imap LibIMAP LibMain)
|
||||
target_link_libraries(test-pthread LibThreading)
|
||||
target_link_libraries(timezone LibMain)
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include <AK/String.h>
|
||||
#include <LibCore/ArgsParser.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <stdio.h>
|
||||
#include <LibMain/Main.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define ENUMERATE_TARGETS(T) \
|
||||
|
@ -112,9 +112,9 @@ ENUMERATE_TARGETS(__ENUMERATE_TARGET)
|
|||
#include <Meta/Lagom/Fuzzers/FuzzURL.cpp>
|
||||
#undef LLVMFuzzerTestOneInput
|
||||
|
||||
static auto parse_target_name(const String& name)
|
||||
static auto parse_target_name(StringView name)
|
||||
{
|
||||
if (name == "list") {
|
||||
if (name == "list"sv) {
|
||||
outln("The following targets are included:");
|
||||
#undef __ENUMERATE_TARGET
|
||||
#define __ENUMERATE_TARGET(x) outln(#x);
|
||||
|
@ -134,25 +134,20 @@ static auto parse_target_name(const String& name)
|
|||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
{
|
||||
const char* type;
|
||||
const char* filename;
|
||||
StringView type;
|
||||
StringView filename;
|
||||
|
||||
Core::ArgsParser args_parser;
|
||||
args_parser.add_positional_argument(type, "Type of fuzzing target to run (use \"list\" to list all existing)", "target-kind");
|
||||
args_parser.add_positional_argument(filename, "Input file", "filename");
|
||||
args_parser.parse(argc, argv);
|
||||
args_parser.parse(arguments);
|
||||
|
||||
auto fn = parse_target_name(type);
|
||||
|
||||
auto file = Core::File::open(filename, Core::OpenMode::ReadOnly);
|
||||
if (file.is_error()) {
|
||||
warnln("Cannot read from file: {}", file.error());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
auto input = file.value()->read_all();
|
||||
auto file = TRY(Core::File::open(filename, Core::OpenMode::ReadOnly));
|
||||
auto input = file->read_all();
|
||||
|
||||
return fn(input.data(), input.size());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue