-# Copyright © 2012, 2020 Nick Bowler
+# Copyright © 2012, 2020, 2022-2024 Nick Bowler
#
# 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
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
-AT_BANNER([Randomized tests])
+AT_BANNER([Stress tests])
+
+dnl Verify the RNG implementation
+TEST_TAP_SIMPLE([xoshiro256p sanity], [rng-test],
+ [TEST_NEED_PROGRAM([rng-test])])
dnl Verify that randomdecl actually produces all keywords and a variety
dnl of different declarations.
[[^type], [type name]],
[[inline], [inline function specifier]],
[[inline inline], [redundant function specifiers]],
- [[function (@<:@@<:@:alnum:@:>@_@:>@* as], [named function parameter]],
- [[function (void)], [empty prototype declaration]],
+ [[function [(]@<:@]]RE_ALNUM()_[[@:>@* as], [named function parameter]],
+ [[function [(]void[)]], [empty prototype declaration]],
[[function returning], [non-prototype function declaration]],
[[\.\.\.], [variadic function]],
[[const], [const qualifier]],
[[pointer to function], [pointer to a function]],
])
-m4_define([sanity_sed], [/$1/i\
-AS_TR_SH([$2])=:])
-AT_DATA([sanity.sed], [#n
-m4_map_sep([sanity_sed], [m4_newline], [sanity_tests])
+m4_define([sanity_awk], [[/$1/ { found["$2"] = 1; }
+]])AT_DATA([sanity.awk],
+[# We don't need any field splitting, so choose a character that does not
+# appear in C code to avoid tripping over 199-field limit in HP-UX 11 awk.
+BEGIN { FS = "@"; }
+m4_map([sanity_awk], [sanity_tests])dnl
+END { for (k in found) print "FOUND", k; }
])
-printf 'Using seed %d\n' "$random_seed" >&AS_MESSAGE_LOG_FD
-AT_CHECK([randomdecl -En 10000 -s "$random_seed" >decls], [0], [ignore-nolog])
-AT_CHECK([sed -f sanity.sed decls], [0], [stdout-nolog])
-sort -u stdout >decls.chk
+m4_define([sanity_exp], [[FOUND $2
+]])
+LC_ALL=C sort >expout <<'EOF'
+m4_map([sanity_exp], [sanity_tests])dnl
+EOF
+
+AS_ECHO(["Using seed $random_seed"]) >&AS_MESSAGE_LOG_FD
+AT_CHECK([randomdecl -En 10000 -s "$random_seed" >decls], [0])
+AT_CHECK([$AWK -f sanity.awk decls | LC_ALL=C sort], [0], [expout])
+
+AT_CLEANUP
+
+AT_SETUP([Random crossparse])
+
+TEST_NEED_PROGRAM([randomdecl])
+TEST_NEED_PROGRAM([crossparse])
+
+AS_ECHO(["Using seed $random_seed"]) >&AS_MESSAGE_LOG_FD
+AT_CHECK([randomdecl -n "$random_iter" -s "$random_seed"],, [stdout-nolog])
+AT_CHECK([crossparse -f stdout])
+AT_CLEANUP
+
+# Check that we can parse declarations with more than 10000 specifiers.
+AT_SETUP([Excessive specifiers])
+
+s="const"
+for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14; do
+ AS_VAR_APPEND([s], [" $s"])
+done
+
+cat >test.dat <<EOF
+explain $s int
+explain int $s
+type $s int
+type int $s
+EOF
+
+s="inline"
+for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14; do
+ AS_VAR_APPEND([s], [" $s"])
+done
+cat >>test.dat <<EOF
+declare f as $s function returning int
+EOF
+
+AT_CHECK([cdecl99 -f test.dat], [0],
+[[type const int
+type const int
+const int
+const int
+inline int f()
+]])
+
+AT_CLEANUP
+
+# Check that we can parse declarations with more than 10000 declarators.
+AT_SETUP([Excessive declarators])
+
+AT_DATA([check.awk],
+[[# We don't need any field splitting, so choose a character that does not
+# appear in C code to avoid tripping over 199-field limit in HP-UX 11 awk.
+BEGIN { FS = "@"; runstart = 0; }
+END { finish_run(NR); }
+
+gsub(/,[^,)]*/, "~") {
+ while (match($0, /~+/) > 0) {
+ l = substr($0, 1, RSTART-1);
+ r = substr($0, RSTART+RLENGTH);
+ $0 = l ", [plus " RLENGTH " more parameters]" r;
+ }
+}
-exec 3<decls.chk
-while read var <&3; do
- eval "$var"
+$0 != lastline {
+ finish_run(NR-1);
+ lastline = $0;
+ runstart = NR;
+ print;
+}
+
+function finish_run(nr) {
+ count = nr - runstart;
+ if (count > 0)
+ print "[repeated " count " more times]";
+}
+]])
+
+a="a"
+for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14; do
+ AS_VAR_APPEND([a], [",$a"])
done
-exec 3<&-
-m4_define([sanity_check], [AT_CHECK([$AS_TR_SH([$2]) false])])
-m4_map([sanity_check], [sanity_tests])
+cat >test.dat <<EOF
+explain int $a
+explain int ($a)
+type function ($a) returning int
+EOF
+
+AT_CHECK([cdecl99 -f test.dat >test.out; status=$?;
+$AWK -f check.awk test.out
+exit $status], [0],
+[[declare a as int
+[repeated 16383 more times]
+type function (a, [plus 16383 more parameters]) returning int
+int (a, [plus 16383 more parameters])
+]])
AT_CLEANUP