]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Do some tests based on the type of floating-point arithmetic tcpdump does.
authorGuy Harris <[email protected]>
Wed, 5 Feb 2020 03:08:10 +0000 (19:08 -0800)
committerGuy Harris <[email protected]>
Wed, 5 Feb 2020 03:08:10 +0000 (19:08 -0800)
Add a --fp-type flag to tcpdump, which causes it to do a floating-point
operation and, based on the result of the operation, prints out
"FPTYPE{n}", where {n} is a number indicating the result.

Have tests/TESTrun run "./tcpdump --fp-type" and set a HAVE_ key based
on that.  Run some tests only for FPTYPE1.

Makefile.in
tcpdump.c
tests/TESTrun
tests/isis-seg-fault-1-v.tests
tests/lmp-v.tests

index 694fb18b988f185f31ef45a7d38f79865d73cc0f..2b3b7e3da9a1a7a549ed0ad4d712f641029a9ce3 100644 (file)
@@ -70,7 +70,7 @@ DEPENDENCY_CFLAG = @DEPENDENCY_CFLAG@
        @rm -f $@
        $(CC) $(FULL_CFLAGS) -c $(srcdir)/$*.c
 
-CSRC = tcpdump.c
+CSRC = fptype.c tcpdump.c
 
 LIBNETDISSECT_SRC=\
        addrtoname.c \
index 64aad1603d2a2cc771eb8ec3d77f5a5549375de9..40505b2c28c75a3cbda8c6144920738d4e4efb5f 100644 (file)
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -150,6 +150,8 @@ The Regents of the University of California.  All rights reserved.\n";
 
 #include "print.h"
 
+#include "fptype.h"
+
 #ifndef PATH_MAX
 #define PATH_MAX 1024
 #endif
@@ -687,6 +689,7 @@ show_remote_devices_and_exit(void)
 #define OPTION_LIST_REMOTE_INTERFACES  132
 #define OPTION_TSTAMP_MICRO            133
 #define OPTION_TSTAMP_NANO             134
+#define OPTION_FP_TYPE                 135
 
 static const struct option longopts[] = {
 #if defined(HAVE_PCAP_CREATE) || defined(_WIN32)
@@ -730,6 +733,7 @@ static const struct option longopts[] = {
        { "debug-filter-parser", no_argument, NULL, 'Y' },
 #endif
        { "relinquish-privileges", required_argument, NULL, 'Z' },
+       { "fp-type", no_argument, NULL, OPTION_FP_TYPE },
        { "number", no_argument, NULL, '#' },
        { "print", no_argument, NULL, OPTION_PRINT },
        { "version", no_argument, NULL, OPTION_VERSION },
@@ -1891,6 +1895,26 @@ main(int argc, char **argv)
                        break;
 #endif
 
+               case OPTION_FP_TYPE:
+                       /*
+                        * Print out the type of floating-point arithmetic
+                        * we're doing; it's probably IEEE, unless somebody
+                        * tries to run this on a VAX, but the precision
+                        * may differ (e.g., it might be 32-bit, 64-bit,
+                        * or 80-bit).
+                        */
+                       switch (float_type_check(0x4e93312d)) {
+
+                       case 0x461a5794:
+                               printf("FPTYPE1\n");
+                               break;
+
+                       default:
+                               printf("FPTYPE2\n");
+                               break;
+                       }
+                       return 0;
+
                default:
                        print_usage();
                        exit_tcpdump(S_ERR_HOST_PROGRAM);
index e106057f09571c958fcd121e2add77aaeee6c923..ea1389853392e6294abec7a79f5ffea45b3f64a0 100755 (executable)
@@ -68,17 +68,13 @@ sub loadconfighash {
     close(CONFIG_H);
     #print Dumper($main::confighhash);
 
-    # also grovel Makefile for some things and pretend they are config options.
-    open(MAKEFILE, "Makefile") || die "can not open Makefile: $!\n";
-    while(<MAKEFILE>) {
-        chomp;
-        #print "Processing $_\n";
-        if(/^CC\s*=.*gcc.*/) {
-            #print "GCC FOUND\n";
-            $main::confighhash->{'USING_GCC'} = 1;
-        }
-    }
-    close(MAKEFILE);
+    # also run tcpdump --fp-type to get the type of floating-point
+    # arithmetic we're doing, setting a HAVE_{fptype} key
+    open(FPTYPE_PIPE, "./tcpdump --fp-type |") or die("piping tcpdump --fp-type failed\n");
+    my $have_fptype = "HAVE_" . <FPTYPE_PIPE>;
+    close(FPTYPE_PIPE);
+    $have_fptype =~ s/^\s+|\s+$//g;
+    $main::confighhash->{$have_fptype} = 1;
 
     return $main::confighhash;
 }
index 857f5374aa6d6bdee9a0ebbe7f03920654096938..7d3714efcd4999449102b2de34e271d9d67b0fe7 100644 (file)
@@ -1,11 +1,14 @@
 # -*- perl -*-
 
 # This "verbose" ISIS protocol test involves a float calculation that
-# may produce a slightly different result if the compiler is not GCC.
-# Test only with GCC (similar to GitHub issue #333).
+# may produce a slightly different result depending on the compiler and
+# the version of the instruction set for which it's generating code (see
+# GitHub issue #333 for another example). The test is done only if we have
+# a floating-point type, as reported by "./tcpdump --fp-type", of FPTYPE1.
 
 $testlist = [
     {
+        config_set => 'HAVE_FPTYPE1',
         name => 'isis-seg-fault-1-v',
         input => 'isis-seg-fault-1.pcapng',
         output => 'isis-seg-fault-1-v.out',
index 01c4ede13460ec2a337d98121c30f24fac67bdaf..e2c424ed44428fea2b453bc0d6b9395dd61e3ede 100644 (file)
@@ -1,13 +1,14 @@
 # -*- perl -*-
 
 # The "verbose" Link Management Protocol test involves a float calculation that
-# may produce a slightly different result depending on the architecture and the
-# compiler (see GitHub issue #333). The reference output was produced using a
-# GCC build and must reproduce correctly on any other GCC build regardless of
-# the architecture.
+# may produce a slightly different result depending on the compiler and the
+# version of the instruction set for which it's generating code (see GitHub
+# issue #333). The test is done only if we have a floating-point type, as
+# reported by "./tcpdump --fp-type", of FPTYPE1.
 
 $testlist = [
     {
+        config_set => 'HAVE_FPTYPE1',
         name => 'lmp-v',
         input => 'lmp.pcap',
         output => 'lmp-v.out',