From e51ac7ec7d3e32e1771c9f824da3dc7e4dcd2bc5 Mon Sep 17 00:00:00 2001 From: lemon Date: Sat, 13 Dec 2025 19:21:04 +0100 Subject: add c-testsuite --- test/external/c-testsuite/scripts/add-single-exec | 78 ++++++++++++++++++++++ test/external/c-testsuite/scripts/htmlescape | 6 ++ test/external/c-testsuite/scripts/lib-exec/mkset | 19 ++++++ .../c-testsuite/scripts/lib-exec/setlookup | 13 ++++ .../external/c-testsuite/scripts/make-search-index | 62 +++++++++++++++++ test/external/c-testsuite/scripts/search-tests | 23 +++++++ test/external/c-testsuite/scripts/tapsummary | 62 +++++++++++++++++ 7 files changed, 263 insertions(+) create mode 100755 test/external/c-testsuite/scripts/add-single-exec create mode 100755 test/external/c-testsuite/scripts/htmlescape create mode 100755 test/external/c-testsuite/scripts/lib-exec/mkset create mode 100755 test/external/c-testsuite/scripts/lib-exec/setlookup create mode 100755 test/external/c-testsuite/scripts/make-search-index create mode 100755 test/external/c-testsuite/scripts/search-tests create mode 100755 test/external/c-testsuite/scripts/tapsummary (limited to 'test/external/c-testsuite/scripts') diff --git a/test/external/c-testsuite/scripts/add-single-exec b/test/external/c-testsuite/scripts/add-single-exec new file mode 100755 index 0000000..3685432 --- /dev/null +++ b/test/external/c-testsuite/scripts/add-single-exec @@ -0,0 +1,78 @@ +#! /usr/bin/env bash + +set -e +set -u +set -x + +if ! test -f README.md +then + echo "run from the base directory." >&2 + exit 1 +fi + +in=$1 + +if ! test -f $in +then + echo "$in does not exist" >&2 + exit 1 +fi + +chosenfile="" +foundname="n" +for n in $(seq 10000) +do + paddedn=$(printf "%05d" "$n") + chosenfile="./tests/single-exec/$paddedn.c" + + if test -f "$chosenfile" + then + continue + fi + + foundname="y" + break +done + +if test "$foundname" = "n" +then + echo "no numbers left." >&2 + exit 1 +fi + + +cat $in > "$chosenfile" +added="y" +tagfile="$chosenfile.tags" + +echo "inferring tags..." 1>&2 + +echo "portable" > $tagfile + +# Check for cstd +if gcc -pedantic --std=c89 -c -o /tmp/ctestsuite-infer.o $in +then + echo "c89" >> $tagfile +elif gcc -pedantic --std=c99 -c -o /tmp/ctestsuite-infer.o $in +then + echo "c99" >> $tagfile +elif gcc -pedantic --std=c11 -c -o /tmp/ctestsuite-infer.o $in +then + echo "c11" >> $tagfile +else + echo "unable to guess c std" +fi + +if grep -q -e "#include" "$in" +then + # Since these are single file tests, the only + # thing we could include would be libc headers. + echo "needs-libc" >> $tagfile +fi + +if grep -q -e "#include" -e "#define" -e "#if" -e "#ifdef" "$in" +then + echo "needs-cpp" >> $tagfile +fi + +echo "$chosenfile" \ No newline at end of file diff --git a/test/external/c-testsuite/scripts/htmlescape b/test/external/c-testsuite/scripts/htmlescape new file mode 100755 index 0000000..04e1f97 --- /dev/null +++ b/test/external/c-testsuite/scripts/htmlescape @@ -0,0 +1,6 @@ +#! /usr/bin/env python3 + +import sys, html + +for l in sys.stdin: + print(html.escape(l), end='') diff --git a/test/external/c-testsuite/scripts/lib-exec/mkset b/test/external/c-testsuite/scripts/lib-exec/mkset new file mode 100755 index 0000000..89ee106 --- /dev/null +++ b/test/external/c-testsuite/scripts/lib-exec/mkset @@ -0,0 +1,19 @@ +#! /usr/bin/env python3 + +import sys +import sqlite3 + +if len(sys.argv) == 3: + inp = open(sys.argv[2]) +elif len(sys.argv) == 2: + inp = sys.stdin +else: + print("bad arguments") + sys.exit(1) + +with sqlite3.connect(sys.argv[1]) as conn: + conn.execute('''CREATE TABLE IF NOT EXISTS LUT (K TEXT UNIQUE);''') + conn.execute('DELETE FROM LUT;') + for l in inp: + conn.execute('INSERT OR IGNORE INTO LUT(K) VALUES (?);', (l[:-1],)) + diff --git a/test/external/c-testsuite/scripts/lib-exec/setlookup b/test/external/c-testsuite/scripts/lib-exec/setlookup new file mode 100755 index 0000000..671a9cb --- /dev/null +++ b/test/external/c-testsuite/scripts/lib-exec/setlookup @@ -0,0 +1,13 @@ +#! /usr/bin/env python3 + +import sys +import sqlite3 + +found=False +with sqlite3.connect(sys.argv[1]) as conn: + c = conn.cursor() + c.execute('''SELECT COUNT(*) FROM LUT WHERE k = ?;''', (sys.argv[2],)) + if c.fetchone()[0] > 0: + found=True +if not found: + sys.exit(1) \ No newline at end of file diff --git a/test/external/c-testsuite/scripts/make-search-index b/test/external/c-testsuite/scripts/make-search-index new file mode 100755 index 0000000..a5658b1 --- /dev/null +++ b/test/external/c-testsuite/scripts/make-search-index @@ -0,0 +1,62 @@ +#! /bin/sh + +set -e +set -u + +if ! test -f README.md +then + echo "run from the base directory." >&2 + exit 1 +fi + +if test -d ./.tmsu/ +then + rm -r ./.tmsu/ +fi + +tmsu init + +tmsu tag -c arch-x86_64 portable \ + needs-cpp needs-libc +tmsu imply c89 c99 +tmsu imply c99 c11 +tmsu imply needs-libc needs-cpp + + +for suite in single-exec +do + for t in ./tests/"$suite"/*.c + do + tmsu tag "$t" "suite=$suite" + + while read -r tagline + do + if test -z "$tagline" + then + continue + fi + tmsu tag --tags="$tagline" "$t" + done < "$t.tags" + done +done + + +# Validation + +q="(not c89) and (not c99) and (not c11)" +n=$(tmsu files "$q" | wc -l) +if test "$n" != "0" +then + echo "Tests without a specified standard, aborting:" + tmsu files "$q" + exit 1 +fi + +q="not portable and not arch-x86_64" +n=$(tmsu files "$q" | wc -l) +if test "$n" != "0" +then + echo "Tests without a specified arch, aborting:" + tmsu files "$q" + exit 1 +fi diff --git a/test/external/c-testsuite/scripts/search-tests b/test/external/c-testsuite/scripts/search-tests new file mode 100755 index 0000000..7d96e77 --- /dev/null +++ b/test/external/c-testsuite/scripts/search-tests @@ -0,0 +1,23 @@ +#! /bin/sh + +set -e +set -u + +if ! test -f README.md +then + echo "please run from the c-test root directory" + exit 1 +fi + +if ! test -d ./.tmsu +then + echo "run regenerate-search-index first" + exit 1 +fi + +if test "$#" -eq "1" +then + tmsu files "$1" +else + tmsu files +fi diff --git a/test/external/c-testsuite/scripts/tapsummary b/test/external/c-testsuite/scripts/tapsummary new file mode 100755 index 0000000..e73520d --- /dev/null +++ b/test/external/c-testsuite/scripts/tapsummary @@ -0,0 +1,62 @@ +#! /usr/bin/env python3 + +import sys +import tempfile + +tfailed=False + +buffered=tempfile.TemporaryFile() +def o(l): + global buffered + buffered.write(l.encode('utf-8')) + +print("Test summary:") +print("") + +ntests=None +passed=0 +failed=0 +skipped=0 + +for l in sys.stdin: + if l.startswith("not ok"): + o(l) + failed += 1 + tfailed=True + elif l.startswith("ok"): + if "# SKIP" in l: + skipped += 1 + else: + passed += 1 + tfailed=False + elif l.startswith('1..'): + ntests = int(l[3:]) + elif l.startswith('#'): + if tfailed: + o(' '+l[1:]) + +if ntests is None: + raise Exception("expected a 1..n line") + +if ntests != passed+failed+skipped: + raise Exception("%s tests did not report results"%(ntests-(passed+failed),)) + +print("pass %d" % passed) +print("fail %d" % failed) +print("skip %d" % skipped) +totalln = "total %d" % ntests +print("-"*len(totalln)) +print(totalln) + +print("") +buffered.seek(0) +try: + while True: + buf = buffered.read(4096) + if len(buf) == 0: + break + sys.stdout.write(buf.decode('utf-8')) +except BrokenPipeError: + pass +sys.stdout.flush() +buffered.close() -- cgit v1.2.3