From e44d69908b19dc9d9778169e315f0b97d0051f03 Mon Sep 17 00:00:00 2001 From: Krystine Sherwin <93062060+KrystalDelusion@users.noreply.github.com> Date: Sat, 17 Aug 2024 11:33:28 +1200 Subject: [PATCH 1/7] tests: Add script tests Currently provides tests for logging quoted strings. --- Makefile | 1 + tests/scripts/.gitignore | 3 +++ tests/scripts/run-test.sh | 4 ++++ tests/scripts/test_logging.sh | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 40 insertions(+) create mode 100644 tests/scripts/.gitignore create mode 100755 tests/scripts/run-test.sh create mode 100755 tests/scripts/test_logging.sh diff --git a/Makefile b/Makefile index 5594a605a1b..d598cbcbd9f 100644 --- a/Makefile +++ b/Makefile @@ -861,6 +861,7 @@ endif +cd tests/various && bash run-test.sh +cd tests/select && bash run-test.sh +cd tests/sat && bash run-test.sh + +cd tests/scripts && bash run-test.sh +cd tests/sim && bash run-test.sh +cd tests/svinterfaces && bash run-test.sh $(SEEDOPT) +cd tests/svtypes && bash run-test.sh $(SEEDOPT) diff --git a/tests/scripts/.gitignore b/tests/scripts/.gitignore new file mode 100644 index 00000000000..102700103b2 --- /dev/null +++ b/tests/scripts/.gitignore @@ -0,0 +1,3 @@ +*.err +*.log +run-test.mk diff --git a/tests/scripts/run-test.sh b/tests/scripts/run-test.sh new file mode 100755 index 00000000000..4fb3eb83d46 --- /dev/null +++ b/tests/scripts/run-test.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +set -eu +source ../gen-tests-makefile.sh +run_tests --bash diff --git a/tests/scripts/test_logging.sh b/tests/scripts/test_logging.sh new file mode 100755 index 00000000000..9910d86222d --- /dev/null +++ b/tests/scripts/test_logging.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +var=0 +rm -f quotes-*.log quotes-*.err + +test_log() +{ + # Usage: test_log + var=$((var + 1)) + log_str="$1" + grep_str="$2" + log_file="quotes-$var.log" + ../../yosys -QTq -l $log_file -p "log $log_str" + if ! grep -qx "$grep_str" $log_file; then + echo "ERROR: Expected 'yosys> log $log_str' to log '$grep_str'." > "quotes-$var.err" + cat "quotes-$var.err" + fi +} + +test_log "test" "test" +test_log "test;" "test" +test_log "test;;" "test" +test_log "\"test" "\"test" +test_log "test\"" "test\"" +test_log "\"test\"" "test" +test_log "\"test;\"" "test;" +test_log "\"test;;\"" "test;;" +test_log "\"test\" abc" "\"test\" abc" + +if [ -f quotes-*.err ] ; then + exit 1 +fi From 48f358bb09b18fe44d99ded610fd889341472088 Mon Sep 17 00:00:00 2001 From: Krystine Sherwin <93062060+KrystalDelusion@users.noreply.github.com> Date: Sat, 17 Aug 2024 11:33:28 +1200 Subject: [PATCH 2/7] Docs: Update example_synth We can now fake the `yosys> flatten;;` line, so we no longer need to explain the split flatten/clean. --- docs/source/code_examples/fifo/fifo.out | 7 ++++--- docs/source/code_examples/fifo/fifo.ys | 3 +++ docs/source/getting_started/example_synth.rst | 11 ++--------- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/docs/source/code_examples/fifo/fifo.out b/docs/source/code_examples/fifo/fifo.out index ac132ee6c3d..31907a74147 100644 --- a/docs/source/code_examples/fifo/fifo.out +++ b/docs/source/code_examples/fifo/fifo.out @@ -306,14 +306,15 @@ yosys> show -color maroon3 c:fifo_reader -color cornflowerblue @new_cells -notit Writing dot description to `rdata_proc.dot'. Dumping selected parts of module fifo to page 1. -yosys> flatten +yosys> echo off +echo off +yosys> flatten;; 15. Executing FLATTEN pass (flatten design). Deleting now unused module $paramod\addr_gen\MAX_DATA=s32'00000000000000000000000100000000. - -yosys> clean Removed 3 unused cells and 25 unused wires. +echo on yosys> select -set rdata_path o:rdata %ci* diff --git a/docs/source/code_examples/fifo/fifo.ys b/docs/source/code_examples/fifo/fifo.ys index 57a28e63e8e..c4ea9f9bd6d 100644 --- a/docs/source/code_examples/fifo/fifo.ys +++ b/docs/source/code_examples/fifo/fifo.ys @@ -39,7 +39,10 @@ show -color maroon3 c:fifo_reader -color cornflowerblue @new_cells -notitle -for # ======================================================== +echo off +log "yosys> flatten;;" flatten;; +echo on select -set rdata_path o:rdata %ci* select -set new_cells @rdata_path o:rdata %ci3 %d i:* %d show -color maroon3 @new_cells -notitle -format dot -prefix rdata_flat @rdata_path diff --git a/docs/source/getting_started/example_synth.rst b/docs/source/getting_started/example_synth.rst index ae0a9a36620..04133f9a99b 100644 --- a/docs/source/getting_started/example_synth.rst +++ b/docs/source/getting_started/example_synth.rst @@ -292,8 +292,8 @@ optimizations between modules which would otherwise be missed. Let's run .. literalinclude:: /code_examples/fifo/fifo.out :language: doscon - :start-at: yosys> flatten - :end-before: yosys> select + :start-at: yosys> flatten;; + :end-before: echo on :name: flat_clean :caption: output of :yoscrypt:`flatten;;` @@ -313,13 +313,6 @@ and merged with the ``raddr`` wire feeding into the ``$memrd`` cell. This wire merging happened during the call to :cmd:ref:`clean` which we can see in the :ref:`flat_clean`. -.. note:: - - :cmd:ref:`flatten` and :cmd:ref:`clean` would normally be combined into a - single :yoterm:`yosys> flatten;;` output, but they appear separately here as - a side effect of using :cmd:ref:`echo` for generating the terminal style - output. - Depending on the target architecture, this stage of synthesis might also see commands such as :cmd:ref:`tribuf` with the ``-logic`` option and :cmd:ref:`deminout`. These remove tristate and inout constructs respectively, From b78725f772489e925b618baf72fbedf69d42ac8e Mon Sep 17 00:00:00 2001 From: Krystine Sherwin <93062060+KrystalDelusion@users.noreply.github.com> Date: Sat, 17 Aug 2024 11:33:28 +1200 Subject: [PATCH 3/7] logcmd.cc: Quote stripping If a command has a single argument, and that argument is quoted, strip the quotes. --- passes/cmds/logcmd.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/passes/cmds/logcmd.cc b/passes/cmds/logcmd.cc index 3b82ac48c0c..52f6b1e311c 100644 --- a/passes/cmds/logcmd.cc +++ b/passes/cmds/logcmd.cc @@ -97,6 +97,9 @@ struct LogPass : public Pass { text += args[argidx] + ' '; if (!text.empty()) text.resize(text.size()-1); + if (text[0] == '"' && text[text.size()-1] == '"') + text = text.substr(1, text.size()-2); + const char *fmtline = newline ? "%s\n" : "%s"; if (to_stdout) fprintf(stdout, fmtline, text.c_str()); From c87b4782a887c7a5b9e318dc6b4ac1f0ba7b1be9 Mon Sep 17 00:00:00 2001 From: Krystine Sherwin <93062060+KrystalDelusion@users.noreply.github.com> Date: Sat, 17 Aug 2024 11:33:29 +1200 Subject: [PATCH 4/7] More quoted log tests --- tests/scripts/test_logging.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/scripts/test_logging.sh b/tests/scripts/test_logging.sh index 9910d86222d..d69fcc75289 100755 --- a/tests/scripts/test_logging.sh +++ b/tests/scripts/test_logging.sh @@ -26,6 +26,11 @@ test_log "\"test\"" "test" test_log "\"test;\"" "test;" test_log "\"test;;\"" "test;;" test_log "\"test\" abc" "\"test\" abc" +test_log "\"#comments\" #123" "#comments" +test_log "\"!bang\"" "!bang" +test_log "\"spaces are cool too\"" "spaces are cool too" +test_log "\"log a\"; log b" "log a" +test_log "\"log a\"; log b" "b" if [ -f quotes-*.err ] ; then exit 1 From db90d1a4c2260d1604d32778705c5b8a52808449 Mon Sep 17 00:00:00 2001 From: Krystine Sherwin <93062060+KrystalDelusion@users.noreply.github.com> Date: Sat, 17 Aug 2024 11:33:29 +1200 Subject: [PATCH 5/7] logcmd.cc: Check length before unquoting `log "` should log `"`. Also fix test script to correctly fail when more than one test fails. --- passes/cmds/logcmd.cc | 2 +- tests/scripts/test_logging.sh | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/passes/cmds/logcmd.cc b/passes/cmds/logcmd.cc index 52f6b1e311c..c6cba1115df 100644 --- a/passes/cmds/logcmd.cc +++ b/passes/cmds/logcmd.cc @@ -97,7 +97,7 @@ struct LogPass : public Pass { text += args[argidx] + ' '; if (!text.empty()) text.resize(text.size()-1); - if (text[0] == '"' && text[text.size()-1] == '"') + if (text.size() > 1 && text[0] == '"' && text[text.size()-1] == '"') text = text.substr(1, text.size()-2); const char *fmtline = newline ? "%s\n" : "%s"; diff --git a/tests/scripts/test_logging.sh b/tests/scripts/test_logging.sh index d69fcc75289..d2f635f7656 100755 --- a/tests/scripts/test_logging.sh +++ b/tests/scripts/test_logging.sh @@ -31,7 +31,10 @@ test_log "\"!bang\"" "!bang" test_log "\"spaces are cool too\"" "spaces are cool too" test_log "\"log a\"; log b" "log a" test_log "\"log a\"; log b" "b" +test_log "\"" "\"" +test_log "\\\"" "\\\\\"" #\" == \" -if [ -f quotes-*.err ] ; then +errors=( quotes-*.err ) +if [ -f $errors ] ; then exit 1 fi From 398588ebb7dcd4579b869233b6638f2ba160b5b4 Mon Sep 17 00:00:00 2001 From: Krystine Sherwin <93062060+KrystalDelusion@users.noreply.github.com> Date: Sat, 17 Aug 2024 12:01:17 +1200 Subject: [PATCH 6/7] logcmd: Only strip quotes on single arg --- passes/cmds/logcmd.cc | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/passes/cmds/logcmd.cc b/passes/cmds/logcmd.cc index c6cba1115df..d3325b001bd 100644 --- a/passes/cmds/logcmd.cc +++ b/passes/cmds/logcmd.cc @@ -93,12 +93,15 @@ struct LogPass : public Pass { if (push) { log_push(); return; } if (pop) { log_pop(); return; } - for (; argidx < args.size(); argidx++) - text += args[argidx] + ' '; - if (!text.empty()) text.resize(text.size()-1); - - if (text.size() > 1 && text[0] == '"' && text[text.size()-1] == '"') - text = text.substr(1, text.size()-2); + text = args[argidx++]; + if (argidx < args.size()) { + for (; argidx < args.size(); argidx++) { + text += ' ' + args[argidx]; + } + } else { + if (text.size() > 1 && text[0] == '"' && text[text.size()-1] == '"') + text = text.substr(1, text.size()-2); + } const char *fmtline = newline ? "%s\n" : "%s"; From 7d3c69edd55c2fef9027c9b8ae78f92a202ca9d1 Mon Sep 17 00:00:00 2001 From: Krystine Sherwin <93062060+KrystalDelusion@users.noreply.github.com> Date: Sat, 17 Aug 2024 12:34:42 +1200 Subject: [PATCH 7/7] tests: Quote stripping edge case --- tests/scripts/test_logging.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/scripts/test_logging.sh b/tests/scripts/test_logging.sh index d2f635f7656..66d5a4b7b50 100755 --- a/tests/scripts/test_logging.sh +++ b/tests/scripts/test_logging.sh @@ -33,6 +33,7 @@ test_log "\"log a\"; log b" "log a" test_log "\"log a\"; log b" "b" test_log "\"" "\"" test_log "\\\"" "\\\\\"" #\" == \" +test_log "\"abc\" \"def\"" "\"abc\" \"def\"" # don't abbreviate to abc" "def errors=( quotes-*.err ) if [ -f $errors ] ; then