]> git.draconx.ca Git - cdecl99.git/commitdiff
Port random crossparse test to Autotest.
authorNick Bowler <nbowler@draconx.ca>
Fri, 3 Jul 2020 03:16:51 +0000 (23:16 -0400)
committerNick Bowler <nbowler@draconx.ca>
Fri, 3 Jul 2020 03:28:07 +0000 (23:28 -0400)
I don't really know why the existing crossparse testcase is so
complicated.  Sure running the test generation and execution in
parallel may be an interesting approach, but it seems to be total
overkill for this use case.

By enhancing the crossparse application to take a list of test cases
from a file, we can just generate the stimuli in one step and execute
the tests in another which is simple and works fine.

As this is the final test to port to Autotest, we can now retire the
use of the Automake test harness.

Makefile.am
test/crossparse.c
tests/crossparse-c-random.sh [deleted file]
tests/stress.at
testsuite.at

index 8ccdc951e945037ff1b95958db7b0a61b58a3e67..da056d798a288fd75dadb52e5f928409e724fe69 100644 (file)
@@ -4,7 +4,6 @@
 # This is free software: you are free to do what the fuck you want to.
 # There is NO WARRANTY, to the extent permitted by law.
 
-AUTOMAKE_OPTIONS = parallel-tests color-tests
 ACLOCAL_AMFLAGS = -I m4 -I common/m4
 
 # For Gnulib
@@ -72,14 +71,6 @@ $(test_crossparse_OBJECTS): $(gnulib_headers)
 test_randomdecl_LDADD = libcdecl.la libtest.la libgnu.la
 $(test_randomdecl_OBJECTS): $(gnulib_headers)
 
-TESTS_ENVIRONMENT = SHELL='$(SHELL)' LIBTOOL='$(LIBTOOL)' EXEEXT='$(EXEEXT)'
-TEST_EXTENSIONS = .sh
-SH_LOG_COMPILER = $(SHELL)
-
-TESTS = tests/crossparse-c-random.sh
-
-dist_check_SCRIPTS = $(TESTS)
-
 src/parse.lo: src/scan.h
 src/scan.lo: src/parse.h
 src/parse-decl.lo: src/scan.h src/parse.h
index 05c3095a2d1953220e9860b934a1e2f5962b8c51..210714a3a5dada4fcfdaf9ca88a95387f45f6935 100644 (file)
@@ -20,6 +20,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <errno.h>
 #include <stdbool.h>
 #include <getopt.h>
 #include <cdecl.h>
 
 #define PROGNAME "crossparse"
 static const char *progname = PROGNAME;
-static const char sopts[] = "ECVH";
+static const char sopts[] = "f:ECVH";
 static const struct option lopts[] = {
        { "cdecl",   0, NULL, 'C' },
        { "english", 0, NULL, 'E' },
+       { "file",    2, NULL, 'f' },
        { "version", 0, NULL, 'V' },
        { "help",    0, NULL, 'H' },
        { 0 }
@@ -131,13 +133,22 @@ out:
        free(buf1);
        free(buf2);
        free(buf3);
+
+       if (!ret) {
+               fprintf(stderr, "%s: failed cross-parse check of: %s\n",
+                               progname, str);
+       }
+
        return ret;
 }
 
 int main(int argc, char **argv)
 {
        int opt, mode = MODE_CDECL;
-       int ret = EXIT_FAILURE;
+       int ret = EXIT_SUCCESS;
+
+       const char *filename = NULL;
+       FILE *infile = NULL;
 
        if (argc > 0)
                progname = argv[0];
@@ -150,6 +161,10 @@ int main(int argc, char **argv)
                case 'E':
                        mode = MODE_ENGLISH;
                        break;
+               case 'f':
+                       infile = stdin;
+                       filename = optarg;
+                       break;
                case 'V':
                        test_print_version(PROGNAME);
                        return EXIT_SUCCESS;
@@ -162,18 +177,35 @@ int main(int argc, char **argv)
                }
        }
 
-       if (!argv[optind]) {
-               print_usage(stderr);
-               return EXIT_FAILURE;
-       }
+       if (infile) {
+               char *line = NULL;
+               size_t n;
+
+               if (filename) {
+                       infile = fopen(filename, "r");
+                       if (!infile) {
+                               fprintf(stderr, "%s: %s: %s\n", progname,
+                                               filename, strerror(errno));
+                               return EXIT_FAILURE;
+                       }
+               }
 
-       for (int i = optind; i < argc; i++) {
-               if (!test_crossparse(argv[i], mode)) {
-                       fprintf(stderr, "%s: failed cross-parse check of: %s\n",
-                                       progname, argv[i]);
-                       return EXIT_FAILURE;
+               while (getline(&line, &n, infile) >= 0) {
+                       char *c = strchr(line, '\n');
+                       if (c)
+                               *c = '\0';
+                       if (!test_crossparse(line, mode))
+                               ret = EXIT_FAILURE;
                }
+       } else if (argv[optind]) {
+               for (int i = optind; i < argc; i++) {
+                       if (!test_crossparse(argv[i], mode))
+                               ret = EXIT_FAILURE;
+               }
+       } else {
+               print_usage(stderr);
+               return EXIT_FAILURE;
        }
 
-       return EXIT_SUCCESS;
+       return ret;
 }
diff --git a/tests/crossparse-c-random.sh b/tests/crossparse-c-random.sh
deleted file mode 100755 (executable)
index a800f3f..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-#!/bin/sh
-#
-# Copyright © 2012 Nick Bowler
-#
-# Randomized tests that libcdecl can parse its own output.
-#
-# License WTFPL2: Do What The Fuck You Want To Public License, version 2.
-# This is free software: you are free to do what the fuck you want to.
-# There is NO WARRANTY, to the extent permitted by law.
-
-: "${RANDOMSEED=$RANDOM}" "${TESTITER=500}"
-
-randomdecl=test/randomdecl$EXEEXT
-crossparse=test/crossparse$EXEEXT
-test -x $randomdecl || exit 77
-
-# Slow case: run tests one at a time to determine exactly which one failed.
-first_failed() {
-       ff_count=0
-
-       while test $# -gt 0
-       do
-               $crossparse "$1" 2>/dev/null || break
-               ff_count=`expr $ff_count + 1`
-               shift
-       done
-
-       echo "$ff_count"
-}
-
-proc() {
-       result=pass
-       count=0
-
-       set x
-       while read decl
-       do
-               set "$@" "$decl"
-
-               # Accumulate tests in $@ and run them in batches to avoid
-               # significant startup costs.
-               if test $# -gt 25; then
-                       shift
-                       $crossparse "$@" || { result=fail
-                               tmp_count=`first_failed "$@"`
-                               count=`expr $count + $tmp_count`
-                               break
-                       }
-                       count=`expr $count + $#`
-                       set x
-               fi
-       done
-
-       shift
-       if test $# -gt 0 && test x"$result" = x"pass"; then
-               tmp_count=$#
-               $crossparse "$@" || { result=fail
-                       tmp_count=`first_failed "$@"`
-               }
-               count=`expr $count + $tmp_count`
-       fi
-
-       echo "result=$result"
-       echo "count=$count"
-}
-
-printf '%s: randomized test using RANDOMSEED=%d\n' "$0" "$RANDOMSEED"
-
-eval_cmd=`exec 3>&1
-       { $randomdecl -s "$RANDOMSEED" -n "$TESTITER" 3>&-
-               echo gen_status=$? >&3
-       } | proc >&3`
-eval "$eval_cmd"
-
-if test x"$gen_status" != x"0"; then
-       printf '%s: %s failed with status=%d\n' \
-               "$0" "$randomdecl" "$gen_status" 1>&2
-       exit 1
-fi
-
-expected_count=`expr "$TESTITER" + 0`
-if test x"$count" != x"$expected_count"; then
-       printf '%s: failed after %d successful tests (out of %d)\n' \
-               "$0" "$count" "$expected_count" 1>&2
-       exit 1
-fi
-
-test x"$result" = x"pass" && exit 0
-exit 1
index 9b45cea46f7da3981a30b64eee80f28b64e5c4d4..77c0d20a1250646aab6c121c100b5930c9126f3c 100644 (file)
@@ -79,3 +79,13 @@ m4_define([sanity_check], [AT_CHECK([$AS_TR_SH([$2]) false])])
 m4_map([sanity_check], [sanity_tests])
 
 AT_CLEANUP
+
+AT_SETUP([random cross-parse])
+
+TEST_NEED_PROGRAM([randomdecl])
+TEST_NEED_PROGRAM([crossparse])
+
+printf 'Using seed %d\n' "$random_seed" >&AS_MESSAGE_LOG_FD
+AT_CHECK([randomdecl -n "$random_iter" -s "$random_seed"],, [stdout-nolog])
+AT_CHECK([crossparse -f stdout])
+AT_CLEANUP
index 930ff2ceaf4102d11b72d3deaf36b4a63cdbf0a8..2fb25be017b84e7f0a5a3391e3c22d2c14f2c2be 100644 (file)
@@ -23,10 +23,17 @@ AT_ARG_OPTION_ARG([random-seed],
     [Integer seed for randomized testing (default: auto)])],
   [random_seed=$at_optarg], [random_seed=$RANDOM$$])
 
+AT_ARG_OPTION_ARG([random-iterations],
+  [AS_HELP_STRING([--random-iterations=N],
+    [Number of randomized testcases to perform (default: 500)])],
+  [random_iter=$at_optarg], [random_iter=])
+
 m4_divert_push([PREPARE_TESTS])dnl
 : ${LIBTOOL="$SHELL $builddir/libtool"}
 random_seed=`printf '%s' "$random_seed" | tr -cd '@<:@:digit:@:>@'`
 random_seed=${random_seed:-0}
+random_iter=`printf '%s' "$random_iter" | tr -cd '@<:@:digit:@:>@'`
+random_iter=`expr "$random_iter" '|' 500`
 m4_divert_pop([PREPARE_TESTS])
 
 m4_define([TEST_NEED_PROGRAM], [AT_KEYWORDS([$1])dnl