[vlc-commits] test: input: change args handling

Thomas Guillem git at videolan.org
Sat Nov 11 15:46:54 CET 2017


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Fri Oct 13 14:01:30 2017 +0200| [b90ec7d343504985649bfc144c9cb5830850ab34] | committer: 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.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=b90ec7d343504985649bfc144c9cb5830850ab34
---

 test/src/input/common.c    | 36 ++++++++++++++++++++++++++++++++++--
 test/src/input/common.h    | 14 +++++++++++++-
 test/src/input/demux-run.c | 19 ++++++++++---------
 test/src/input/demux-run.h |  6 +++---
 test/vlc-demux-libfuzzer.c | 15 ++++++++++++++-
 test/vlc-demux-run.c       |  9 ++++-----
 6 files changed, 78 insertions(+), 21 deletions(-)

diff --git a/test/src/input/common.c b/test/src/input/common.c
index 4f9d3d0aaa..81539ce60c 100644
--- a/test/src/input/common.c
+++ b/test/src/input/common.c
@@ -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;
 }
diff --git a/test/src/input/common.h b/test/src/input/common.h
index 79e3378a4a..ef81a3ff9b 100644
--- a/test/src/input/common.h
+++ b/test/src/input/common.h
@@ -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);
diff --git a/test/src/input/demux-run.c b/test/src/input/demux-run.c
index 691e9c98c4..f748302346 100644
--- a/test/src/input/demux-run.c
+++ b/test/src/input/demux-run.c
@@ -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;
 }
diff --git a/test/src/input/demux-run.h b/test/src/input/demux-run.h
index b9b8bac4d4..01ae245891 100644
--- a/test/src/input/demux-run.h
+++ b/test/src/input/demux-run.h
@@ -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);
diff --git a/test/vlc-demux-libfuzzer.c b/test/vlc-demux-libfuzzer.c
index b9774ebad2..c7ec2a9b05 100644
--- a/test/vlc-demux-libfuzzer.c
+++ b/test/vlc-demux-libfuzzer.c
@@ -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;
 }
diff --git a/test/vlc-demux-run.c b/test/vlc-demux-run.c
index 334dbc618f..92ee61d4cc 100644
--- a/test/vlc-demux-run.c
+++ b/test/vlc-demux-run.c
@@ -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);
 }



More information about the vlc-commits mailing list