chiark / gitweb /
regress: Introduce hnonfuzz.c and Ttestinputfd
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 19 Nov 2016 18:19:10 +0000 (18:19 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 11 Jun 2020 15:13:02 +0000 (16:13 +0100)
We are going to want to build a fuzzer target binary which will be
very like a playback binary, but provides a bit more wrapping.

For now we introduce hnonfuzz.o and link it into all the
currently-generated executables.

To make it not be an empty translation unit, combine this with:

Break out Ttestinputfd from hplayback.c.m4.

Neither of these changes produce any functional change.  (Ttestinputfd
ends up linked into *_record as well as *_playback but this is of no
consequence.)

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
regress/Makefile.in
regress/harness.h.m4
regress/hnonfuzz.c [new file with mode: 0644]
regress/hplayback.c.m4

index a6df8bb016df685843992a0714d8dc51bdd3351e..67f867c3b78e2b5ed6de4fab3d69ab04c989e088 100644 (file)
@@ -40,7 +40,7 @@ HARNLOBJS=    hcommon.o $(REDIRLIBOBJS)
 TARGETS=       $(addsuffix _record, $(CLIENTS)) \
                $(addsuffix _playback, $(CLIENTS))
 ADH_OBJS=      adh-main_c.o adh-opts_c.o adh-query_c.o
-ALL_OBJS=      $(HARNLOBJS) dtest.o hrecord.o hplayback.o
+ALL_OBJS=      $(HARNLOBJS) dtest.o hrecord.o hplayback.o hnonfuzz.o
 
 .PRECIOUS:     $(AUTOCSRCS) $(AUTOCHDRS)
 
@@ -57,10 +57,10 @@ check-%:    case-%.sys
 
 LINK_CMD=      $(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
 
-%_record:      %_c.o hrecord.o $(HARNLOBJS)
+%_record:      %_c.o hrecord.o hnonfuzz.o $(HARNLOBJS)
                $(LINK_CMD)
 
-%_playback:    %_c.o hplayback.o $(HARNLOBJS)
+%_playback:    %_c.o hplayback.o hnonfuzz.o $(HARNLOBJS)
                $(LINK_CMD)
 
 .SECONDARY: $(addsuffix _c.o, $(filter-out adnshost, $(CLIENTS)))
@@ -73,7 +73,7 @@ LINK_CMD=     $(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
 #
 # See also Savannah #29620, http://savannah.gnu.org/bugs/index.php?29620
 
-adnshost_%:    $(ADH_OBJS) h%.o $(HARNLOBJS)
+adnshost_%:    $(ADH_OBJS) h%.o hnonfuzz.o $(HARNLOBJS)
                $(LINK_CMD)
 
 %_d.o:         $(srcdir)/../src/%.c hredirect.h
index cc589a540a408252ee3e95454c3b790ebfa45058..1c602d988e14d15ad4ed71b6abc6a3048c0b75d5 100644 (file)
@@ -73,5 +73,6 @@ extern const struct Terrno { const char *n; int v; } Terrnos[];
 void Texit(int rv) NONRETURNING;
 
 void Tallocshutdown(void);
+int Ttestinputfd(void);
 
 #endif
diff --git a/regress/hnonfuzz.c b/regress/hnonfuzz.c
new file mode 100644 (file)
index 0000000..89876a9
--- /dev/null
@@ -0,0 +1,34 @@
+/* nhonfuzz.c
+ * (part of complex test harness, not of the library)
+ * - routines used for record and playback but not for fuzzing
+ *
+ *  This file is part of adns, which is
+ *    Copyright (C) 1997-2000,2003,2006,2014-2016  Ian Jackson
+ *    Copyright (C) 2014  Mark Wooding
+ *    Copyright (C) 1999-2000,2003,2006  Tony Finch
+ *    Copyright (C) 1991 Massachusetts Institute of Technology
+ *  (See the file INSTALL for full details.)
+ *  
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 3, or (at your option)
+ *  any later version.
+ *  
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *  
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software Foundation.
+ */
+
+#include <stdio.h>
+
+#include "harness.h"
+
+int Ttestinputfd(void) {
+  const char *fdstr= getenv("ADNS_TEST_IN_FD");
+  if (!fdstr) return -1;
+  return atoi(fdstr);
+}
index b3c45c6c7eed1548c12a6d8df9bff9e3324ae3a0..fb4295cca0dc31e6bb86bc6ce3969871712dc40b 100644 (file)
@@ -69,16 +69,14 @@ static void Pcheckinput(void) {
 }
 
 void Tensurerecordfile(void) {
-  const char *fdstr;
   int fd;
   int chars;
   unsigned long sec, usec;
 
   if (Tinputfile) return;
   Tinputfile= stdin;
-  fdstr= getenv("ADNS_TEST_IN_FD");
-  if (fdstr) {
-    fd= atoi(fdstr);
+  fd = Ttestinputfd();
+  if (fd >= 0) {
     Tinputfile= fdopen(fd,"r"); if (!Tinputfile) Tfailed("fdopen ADNS_TEST_IN_FD");
   }
   setvbuf(Tinputfile,0,_IONBF,0);