summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Richardson2020-09-25 12:31:04 +0100
committerAlex Richardson2020-09-25 12:31:04 +0100
commitf22136def93656ebe8c4c6e49214983365ecd6e2 (patch)
treeaf7546afd800b63164ff3acb71be49ea77e2cd94
parent782d3860eb0134c81d4a4204b7caab72cda3bd1d (diff)
Add an initial LaTeX test
This is for a bug I encountered while moving some docs over from the ISA spec into sail documentation comments.
-rw-r--r--test/latex/candperm.commands.tex.exp36
-rw-r--r--test/latex/candperm.sail28
-rwxr-xr-xtest/latex/run_tests.sh57
-rwxr-xr-xtest/run_tests.sh6
4 files changed, 127 insertions, 0 deletions
diff --git a/test/latex/candperm.commands.tex.exp b/test/latex/candperm.commands.tex.exp
new file mode 100644
index 00000000..6c92c681
--- /dev/null
+++ b/test/latex/candperm.commands.tex.exp
@@ -0,0 +1,36 @@
+\providecommand\saildoclabelled[2]{\phantomsection\label{#1}#2}
+
+\newcommand{\sailtypeast}{\saildoclabelled{typezast}{\saildoctype{}{\lstinputlisting[language=sail]{out/typezast6bb070d12e82e4887160cdfd016230c8.tex}}}}
+
+\newcommand{\sailvalexecute}{\saildoclabelled{zexecute}{\saildocval{}{\lstinputlisting[language=sail]{out/valzexecute33a689e3a631b9b905b85461d3814943.tex}}}}
+
+\newcommand{\sailfclCAndPermexecute}{\saildoclabelled{fclCAndPermzexecute}{\saildocfcl{Capability register \emph{cd} is replaced with the contents of capability
+register \emph{cs1} with the \cperms{} field set to the bitwise-AND of
+its previous value and bits 0 .. 10 of integer register \emph{rs2}
+and the \cuperms{} field set to the bitwise and of its previous value
+and bits \hyperref[table:pseudocode-constants]{\emph{first\_uperm}} ..
+\hyperref[table:pseudocode-constants]{\emph{last\_uperm}} of \emph{rd}.
+
+}{\lstinputlisting[language=sail]{out/fclCAndPermzexecute33a689e3a631b9b905b85461d3814943.tex}}}}
+
+\newcommand{\sailfclCSetFlagsexecute}{\saildoclabelled{fclCSetFlagszexecute}{\saildocfcl{}{\lstinputlisting[language=sail]{out/fclCSetFlagszexecute33a689e3a631b9b905b85461d3814943.tex}}}}
+
+
+
+\newcommand{\sailval}[1]{
+ \ifstrequal{#1}{execute}{\sailvalexecute}{}}
+
+\newcommand{\sailrefval}[2]{
+ \ifstrequal{#1}{execute}{\hyperref[zexecute]{#2}}{}}
+
+\newcommand{\sailfn}[1]{
+ }
+
+\newcommand{\sailreffn}[2]{
+ }
+
+\newcommand{\sailtype}[1]{
+ \ifstrequal{#1}{ast}{\sailtypeast}{}}
+
+\newcommand{\sailreftype}[2]{
+ \ifstrequal{#1}{ast}{\hyperref[typezast]{#2}}{}}
diff --git a/test/latex/candperm.sail b/test/latex/candperm.sail
new file mode 100644
index 00000000..4aec545a
--- /dev/null
+++ b/test/latex/candperm.sail
@@ -0,0 +1,28 @@
+/* Test that we can parse the CAndPerm documentation correctly:
+ * Previously the \hyperref expressions were broken. */
+default Order dec
+
+scattered union ast('datasize : Int, 'destsize : Int, 'regsize : Int)
+val execute : forall ('datasize : Int) ('destsize : Int) ('regsize : Int).
+ ast('datasize, 'destsize, 'regsize) -> unit
+scattered function execute
+/*! CAndPerm union clause documentation */
+union clause ast = CAndPerm : (int, int, int)
+/*!
+ * Capability register \emph{cd} is replaced with the contents of capability
+ * register \emph{cs1} with the \cperms{} field set to the bitwise-AND of
+ * its previous value and bits 0 .. 10 of integer register \emph{rs2}
+ * and the \cuperms{} field set to the bitwise and of its previous value
+ * and bits \hyperref[table:pseudocode-constants]{\emph{first\_uperm}} ..
+ * \hyperref[table:pseudocode-constants]{\emph{last\_uperm}} of \emph{rd}.
+ */
+function clause execute(CAndPerm(cd, cs1, rs2)) = {
+ /* Implementation */
+ return ()
+}
+/* Note: need at least two function clauses to generate latex output */
+union clause ast = CSetFlags : (int, int, int)
+function clause execute CSetFlags(cd, cs1, rs2) = return(())
+
+end execute
+end ast
diff --git a/test/latex/run_tests.sh b/test/latex/run_tests.sh
new file mode 100755
index 00000000..6ba3ce6f
--- /dev/null
+++ b/test/latex/run_tests.sh
@@ -0,0 +1,57 @@
+#!/usr/bin/env bash
+set -e
+
+DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+cd "$DIR"
+SAILDIR="$DIR/../.."
+
+rm -f "$DIR/tests.xml"
+
+# shellcheck source=../test_helpers.sh
+source "$SAILDIR/test/test_helpers.sh"
+
+
+printf "<testsuites>\n" >> "$DIR/tests.xml"
+
+find . -name '*.sail' -print0 | while IFS= read -r -d '' line; do
+ echo "$line"
+done
+
+for testfile in *.sail; do
+ temp_dir=$(mktemp -d)
+ trap 'rm -rf $temp_dir' 0 2 3 15
+
+ if (cd "$temp_dir" && "$SAILDIR/sail" -o "out" -latex "$DIR/$testfile"); then
+ # compare with expected files
+ exp_prefix=${testfile//.sail/}
+ errmsg="Missing .exp files for $testfile?"
+ for expected in "${exp_prefix}"*.exp; do
+ echo "expected=$expected"
+ # remove prefix and suffix
+ exp_file_name=${expected//${exp_prefix}./}
+ generated_file="$temp_dir/out/${exp_file_name//.exp/}"
+ if [ ! -f "$generated_file" ]; then
+ errmsg="missing expected output $generated_file"
+ break;
+ elif ! diff -q "$generated_file" "$expected"; then
+ diff -u "$generated_file" "$expected" || true
+ errmsg="output is different"
+ break
+ else
+ errmsg=""
+ fi
+ done
+ if [ -z "$errmsg" ]; then
+ green "LaTeX for $testfile" "ok"
+ else
+ yellow "LaTeX for $testfile" "$errmsg"
+ fi;
+ else
+ red "failed to generate latex for $testfile" "fail"
+ fi
+ rm -rf "$temp_dir"
+done
+
+finish_suite "LaTeX testing"
+
+printf "</testsuites>\n" >> "$DIR/tests.xml"
diff --git a/test/run_tests.sh b/test/run_tests.sh
index 1af340d8..aafdad18 100755
--- a/test/run_tests.sh
+++ b/test/run_tests.sh
@@ -30,6 +30,12 @@ printf "==========================================\n"
./ocaml/run_tests.sh
printf "\n==========================================\n"
+printf "LaTeX tests\n"
+printf "==========================================\n"
+
+./latex/run_tests.sh
+
+printf "\n==========================================\n"
printf "C tests\n"
printf "==========================================\n"