Bug 1530773 - Add log module and macro for fuzzing. r=froydnj
authorChristian Holler <choller@mozilla.com>
Mon, 04 Mar 2019 14:13:28 +0000
changeset 520105 3702a10f9758ce8e45350a24789c6e2d3a15b743
parent 520104 0ece01da444e26fd8ccb16028e95b4ac6ff03d94
child 520106 77b7364aabec18d52b6f520c14ef4ec21c614600
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1530773
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1530773 - Add log module and macro for fuzzing. r=froydnj Differential Revision: https://phabricator.services.mozilla.com/D21251
tools/fuzzing/interface/FuzzingInterface.cpp
tools/fuzzing/interface/FuzzingInterface.h
tools/fuzzing/interface/moz.build
new file mode 100644
--- /dev/null
+++ b/tools/fuzzing/interface/FuzzingInterface.cpp
@@ -0,0 +1,29 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+ * Common code for the unified fuzzing interface
+ */
+
+#include <stdlib.h>
+#include "FuzzingInterface.h"
+
+namespace mozilla {
+
+#ifdef JS_STANDALONE
+static bool fuzzing_verbose = !!getenv("MOZ_FUZZ_LOG");
+void fuzzing_log(const char* aFmt, ...) {
+  if (fuzzing_verbose) {
+    va_list ap;
+    va_start(ap, aFmt);
+    vfprintf(stderr, aFmt, ap);
+    va_end(ap);
+  }
+}
+#else
+LazyLogModule gFuzzingLog("nsFuzzing");
+#endif
+
+}  // namespace mozilla
--- a/tools/fuzzing/interface/FuzzingInterface.h
+++ b/tools/fuzzing/interface/FuzzingInterface.h
@@ -10,18 +10,35 @@
 #ifndef FuzzingInterface_h__
 #define FuzzingInterface_h__
 
 #include <fstream>
 
 #include "FuzzerRegistry.h"
 #include "mozilla/Assertions.h"
 
+#ifndef JS_STANDALONE
+#include "mozilla/Logging.h"
+#endif
+
 namespace mozilla {
 
+#ifdef JS_STANDALONE
+void fuzzing_log(const char* aFmt, ...);
+#define MOZ_LOG_EXPAND_ARGS(...) __VA_ARGS__
+
+#define FUZZING_LOG(args) \
+  fuzzing_log(MOZ_LOG_EXPAND_ARGS args);
+#else
+extern LazyLogModule gFuzzingLog;
+
+#define FUZZING_LOG(args) \
+  MOZ_LOG(mozilla::gFuzzingLog, mozilla::LogLevel::Verbose, args)
+#endif  // JS_STANDALONE
+
 typedef int (*FuzzingTestFuncRaw)(const uint8_t*, size_t);
 
 #ifdef __AFL_COMPILER
 
 static int afl_interface_raw(const char* testFile,
                              FuzzingTestFuncRaw testFunc) {
   char* buf = NULL;
 
--- a/tools/fuzzing/interface/moz.build
+++ b/tools/fuzzing/interface/moz.build
@@ -5,16 +5,20 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 Library('fuzzer-interface')
 
 EXPORTS += [
     'FuzzingInterface.h',
 ]
 
+SOURCES += [
+    'FuzzingInterface.cpp',
+]
+
 if CONFIG['JS_STANDALONE']:
     FINAL_LIBRARY = "js"
 else:
     EXPORTS += [
         'FuzzingInterfaceStream.h',
     ]
 
     SOURCES += [