Commit b90ec7d3 authored by Thomas Guillem's avatar Thomas Guillem

test: input: change args handling

vlc arguments are passed by environment variable in order to don't mess
libfuzzer arguments handling:

- "VLC_TARGET" to pass the target name (or demux name).
- "V" to specify the verbose level.
parent e25fefce
......@@ -26,7 +26,23 @@
#include "common.h"
libvlc_instance_t *libvlc_create(void)
static inline int getenv_atoi(const char *name)
{
char *env = getenv(name);
return env ? atoi(env) : 0;
}
void vlc_run_args_init(struct vlc_run_args *args)
{
memset(args, 0, sizeof(struct vlc_run_args));
args->verbose = getenv_atoi("V");
if (args->verbose >= 10)
args->verbose = 9;
args->name = getenv("VLC_TARGET");
}
libvlc_instance_t *libvlc_create(const struct vlc_run_args *args)
{
#ifdef TOP_BUILDDIR
# ifndef HAVE_STATIC_MODULES
......@@ -35,8 +51,24 @@ libvlc_instance_t *libvlc_create(void)
setenv("VLC_DATA_PATH", TOP_SRCDIR"/share", 1);
#endif
libvlc_instance_t *vlc = libvlc_new(0, NULL);
/* Override argc/argv with "--verbose lvl" or "--quiet" depending on the V
* environment variable */
const char *argv[2];
char verbose[2];
int argc = args->verbose == 0 ? 1 : 2;
if (args->verbose > 0)
{
argv[0] = "--verbose";
sprintf(verbose, "%u", args->verbose);
argv[1] = verbose;
}
else
argv[0] = "--quiet";
libvlc_instance_t *vlc = libvlc_new(argc, argv);
if (vlc == NULL)
fprintf(stderr, "Error: cannot initialize LibVLC.\n");
return vlc;
}
......@@ -26,4 +26,16 @@
#define debug(...) (void)0
#endif
libvlc_instance_t *libvlc_create(void);
struct vlc_run_args
{
/* force specific target name (demux or decoder name). NULL to don't force
* any */
const char *name;
/* vlc verbose level */
unsigned verbose;
};
void vlc_run_args_init(struct vlc_run_args *args);
libvlc_instance_t *libvlc_create(const struct vlc_run_args *args);
......@@ -189,8 +189,9 @@ static es_out_t *test_es_out_create(vlc_object_t *parent)
return out;
}
static int demux_process_stream(const char *name, stream_t *s)
static int demux_process_stream(const struct vlc_run_args *args, stream_t *s)
{
const char *name = args->name;
if (name == NULL)
name = "any";
......@@ -224,9 +225,9 @@ static int demux_process_stream(const char *name, stream_t *s)
return val == VLC_DEMUXER_EOF ? 0 : -1;
}
int vlc_demux_process_url(const char *demux, const char *url)
int vlc_demux_process_url(const struct vlc_run_args *args, const char *url)
{
libvlc_instance_t *vlc = libvlc_create();
libvlc_instance_t *vlc = libvlc_create(args);
if (vlc == NULL)
return -1;
......@@ -234,12 +235,12 @@ int vlc_demux_process_url(const char *demux, const char *url)
if (s == NULL)
fprintf(stderr, "Error: cannot create input stream: %s\n", url);
int ret = demux_process_stream(demux, s);
int ret = demux_process_stream(args, s);
libvlc_release(vlc);
return ret;
}
int vlc_demux_process_path(const char *demux, const char *path)
int vlc_demux_process_path(const struct vlc_run_args *args, const char *path)
{
char *url = vlc_path2uri(path, NULL);
if (url == NULL)
......@@ -248,15 +249,15 @@ int vlc_demux_process_path(const char *demux, const char *path)
return -1;
}
int ret = vlc_demux_process_url(demux, url);
int ret = vlc_demux_process_url(args, url);
free(url);
return ret;
}
int vlc_demux_process_memory(const char *demux,
int vlc_demux_process_memory(const struct vlc_run_args *args,
const unsigned char *buf, size_t length)
{
libvlc_instance_t *vlc = libvlc_create();
libvlc_instance_t *vlc = libvlc_create(args);
if (vlc == NULL)
return -1;
......@@ -265,7 +266,7 @@ int vlc_demux_process_memory(const char *demux,
if (s == NULL)
fprintf(stderr, "Error: cannot create input stream\n");
int ret = demux_process_stream(demux, s);
int ret = demux_process_stream(args, s);
libvlc_release(vlc);
return ret;
}
......
......@@ -26,7 +26,7 @@
#include "common.h"
int vlc_demux_process_url(const char *demux, const char *url);
int vlc_demux_process_path(const char *demux, const char *path);
int vlc_demux_process_memory(const char *demux,
int vlc_demux_process_url(const struct vlc_run_args *, const char *url);
int vlc_demux_process_path(const struct vlc_run_args *, const char *path);
int vlc_demux_process_memory(const struct vlc_run_args *,
const unsigned char *buf, size_t length);
......@@ -30,12 +30,25 @@
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "src/input/demux-run.h"
int LLVMFuzzerInitialize(int *argc, char ***argv);
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
static struct vlc_run_args args;
int LLVMFuzzerInitialize(int *argc, char ***argv)
{
(void) argc; (void) argv;
vlc_run_args_init(&args);
return 0;
}
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
vlc_demux_process_memory(getenv("VLC_DEMUX"), data, size);
vlc_demux_process_memory(&args, data, size);
return 0;
}
......@@ -33,13 +33,12 @@
int main(int argc, char *argv[])
{
const char *demux = NULL, *filename;
const char *filename;
struct vlc_run_args args;
vlc_run_args_init(&args);
switch (argc)
{
case 3:
demux = argv[argc - 2];
/* fall through */
case 2:
filename = argv[argc - 1];
break;
......@@ -48,5 +47,5 @@ int main(int argc, char *argv[])
return 1;
}
return -vlc_demux_process_path(demux, filename);
return -vlc_demux_process_path(&args, filename);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment