Skip to content

Commit

Permalink
fmt: add tests for Yosys evaluation of format expressions.
Browse files Browse the repository at this point in the history
  • Loading branch information
whitequark committed Dec 5, 2020
1 parent e02788c commit e386e11
Show file tree
Hide file tree
Showing 4 changed files with 254 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,7 @@ test: $(TARGETS) $(EXTRA_TARGETS)
+cd tests/rpc && bash run-test.sh
+cd tests/memfile && bash run-test.sh
+cd tests/verilog && bash run-test.sh
+cd tests/fmt && bash run-test.sh
@echo ""
@echo " Passed \"make test\"."
@echo ""
Expand Down
2 changes: 2 additions & 0 deletions tests/fmt/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.log
iverilog-initial_display*
245 changes: 245 additions & 0 deletions tests/fmt/initial_display.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,245 @@
module m;
initial $display("<<<BEGIN>>>");

initial $display("==> small unsigned %%d");
initial $display(":%d:", 16'haa);
initial $display(":%-d:", 16'haa);
initial $display(":%+d:", 16'haa);
initial $display(":%+-d:", 16'haa);
initial $display(":%0d:", 16'haa);
initial $display(":%-0d:", 16'haa);
initial $display(":%+0d:", 16'haa);
initial $display(":%+-0d:", 16'haa);
initial $display(":%20d:", 16'haa);
initial $display(":%-20d:", 16'haa);
initial $display(":%+20d:", 16'haa);
initial $display(":%+-20d:", 16'haa);
initial $display(":%020d:", 16'haa);
initial $display(":%-020d:", 16'haa);
initial $display(":%+020d:", 16'haa);
initial $display(":%+-020d:", 16'haa);

initial $display("==> big unsigned %%d");
initial $display(":%d:", 16'haaaa);
initial $display(":%-d:", 16'haaaa);
initial $display(":%+d:", 16'haaaa);
initial $display(":%+-d:", 16'haaaa);
initial $display(":%0d:", 16'haaaa);
initial $display(":%-0d:", 16'haaaa);
initial $display(":%+0d:", 16'haaaa);
initial $display(":%+-0d:", 16'haaaa);
initial $display(":%20d:", 16'haaaa);
initial $display(":%-20d:", 16'haaaa);
initial $display(":%+20d:", 16'haaaa);
initial $display(":%+-20d:", 16'haaaa);
initial $display(":%020d:", 16'haaaa);
initial $display(":%-020d:", 16'haaaa);
initial $display(":%+020d:", 16'haaaa);
initial $display(":%+-020d:", 16'haaaa);

initial $display("==> small signed %%d");
initial $display(":%d:", 16'shaa);
initial $display(":%-d:", 16'shaa);
initial $display(":%+d:", 16'shaa);
initial $display(":%+-d:", 16'shaa);
initial $display(":%0d:", 16'shaa);
initial $display(":%-0d:", 16'shaa);
initial $display(":%+0d:", 16'shaa);
initial $display(":%+-0d:", 16'shaa);
initial $display(":%20d:", 16'shaa);
initial $display(":%-20d:", 16'shaa);
initial $display(":%+20d:", 16'shaa);
initial $display(":%+-20d:", 16'shaa);
initial $display(":%020d:", 16'shaa);
initial $display(":%-020d:", 16'shaa);
initial $display(":%+020d:", 16'shaa);
initial $display(":%+-020d:", 16'shaa);

initial $display("==> big signed %%d");
initial $display(":%d:", 16'shaaaa);
initial $display(":%-d:", 16'shaaaa);
initial $display(":%+d:", 16'shaaaa);
initial $display(":%+-d:", 16'shaaaa);
initial $display(":%0d:", 16'shaaaa);
initial $display(":%-0d:", 16'shaaaa);
initial $display(":%+0d:", 16'shaaaa);
initial $display(":%+-0d:", 16'shaaaa);
initial $display(":%20d:", 16'shaaaa);
initial $display(":%-20d:", 16'shaaaa);
initial $display(":%+20d:", 16'shaaaa);
initial $display(":%+-20d:", 16'shaaaa);
initial $display(":%020d:", 16'shaaaa);
initial $display(":%-020d:", 16'shaaaa);
initial $display(":%+020d:", 16'shaaaa);
initial $display(":%+-020d:", 16'shaaaa);

initial $display("==> small unsigned %%h");
initial $display(":%h:", 16'haa);
initial $display(":%-h:", 16'haa);
initial $display(":%0h:", 16'haa);
initial $display(":%-0h:", 16'haa);
initial $display(":%20h:", 16'haa);
initial $display(":%-20h:", 16'haa);
initial $display(":%020h:", 16'haa);
initial $display(":%-020h:", 16'haa);

initial $display("==> big unsigned %%h");
initial $display(":%h:", 16'haaaa);
initial $display(":%-h:", 16'haaaa);
initial $display(":%0h:", 16'haaaa);
initial $display(":%-0h:", 16'haaaa);
initial $display(":%20h:", 16'haaaa);
initial $display(":%-20h:", 16'haaaa);
initial $display(":%020h:", 16'haaaa);
initial $display(":%-020h:", 16'haaaa);

initial $display("==> small signed %%h");
initial $display(":%h:", 16'shaa);
initial $display(":%-h:", 16'shaa);
initial $display(":%0h:", 16'shaa);
initial $display(":%-0h:", 16'shaa);
initial $display(":%20h:", 16'shaa);
initial $display(":%-20h:", 16'shaa);
initial $display(":%020h:", 16'shaa);
initial $display(":%-020h:", 16'shaa);

initial $display("==> big signed %%h");
initial $display(":%h:", 16'shaaaa);
initial $display(":%-h:", 16'shaaaa);
initial $display(":%0h:", 16'shaaaa);
initial $display(":%-0h:", 16'shaaaa);
initial $display(":%20h:", 16'shaaaa);
initial $display(":%-20h:", 16'shaaaa);
initial $display(":%020h:", 16'shaaaa);
initial $display(":%-020h:", 16'shaaaa);

initial $display("==> small unsigned %%o");
initial $display(":%o:", 16'haa);
initial $display(":%-o:", 16'haa);
initial $display(":%0o:", 16'haa);
initial $display(":%-0o:", 16'haa);
initial $display(":%20o:", 16'haa);
initial $display(":%-20o:", 16'haa);
initial $display(":%020o:", 16'haa);
initial $display(":%-020o:", 16'haa);

initial $display("==> big unsigned %%o");
initial $display(":%o:", 16'haaaa);
initial $display(":%-o:", 16'haaaa);
initial $display(":%0o:", 16'haaaa);
initial $display(":%-0o:", 16'haaaa);
initial $display(":%20o:", 16'haaaa);
initial $display(":%-20o:", 16'haaaa);
initial $display(":%020o:", 16'haaaa);
initial $display(":%-020o:", 16'haaaa);

initial $display("==> small signed %%o");
initial $display(":%o:", 16'shaa);
initial $display(":%-o:", 16'shaa);
initial $display(":%0o:", 16'shaa);
initial $display(":%-0o:", 16'shaa);
initial $display(":%20o:", 16'shaa);
initial $display(":%-20o:", 16'shaa);
initial $display(":%020o:", 16'shaa);
initial $display(":%-020o:", 16'shaa);

initial $display("==> big signed %%o");
initial $display(":%o:", 16'shaaaa);
initial $display(":%-o:", 16'shaaaa);
initial $display(":%0o:", 16'shaaaa);
initial $display(":%-0o:", 16'shaaaa);
initial $display(":%20o:", 16'shaaaa);
initial $display(":%-20o:", 16'shaaaa);
initial $display(":%020o:", 16'shaaaa);
initial $display(":%-020o:", 16'shaaaa);

initial $display("==> small unsigned %%b");
initial $display(":%b:", 16'haa);
initial $display(":%-b:", 16'haa);
initial $display(":%0b:", 16'haa);
initial $display(":%-0b:", 16'haa);
initial $display(":%20b:", 16'haa);
initial $display(":%-20b:", 16'haa);
initial $display(":%020b:", 16'haa);
initial $display(":%-020b:", 16'haa);

initial $display("==> big unsigned %%b");
initial $display(":%b:", 16'haaaa);
initial $display(":%-b:", 16'haaaa);
initial $display(":%0b:", 16'haaaa);
initial $display(":%-0b:", 16'haaaa);
initial $display(":%20b:", 16'haaaa);
initial $display(":%-20b:", 16'haaaa);
initial $display(":%020b:", 16'haaaa);
initial $display(":%-020b:", 16'haaaa);

initial $display("==> small signed %%b");
initial $display(":%b:", 16'shaa);
initial $display(":%-b:", 16'shaa);
initial $display(":%0b:", 16'shaa);
initial $display(":%-0b:", 16'shaa);
initial $display(":%20b:", 16'shaa);
initial $display(":%-20b:", 16'shaa);
initial $display(":%020b:", 16'shaa);
initial $display(":%-020b:", 16'shaa);

initial $display("==> big signed %%b");
initial $display(":%b:", 16'shaaaa);
initial $display(":%-b:", 16'shaaaa);
initial $display(":%0b:", 16'shaaaa);
initial $display(":%-0b:", 16'shaaaa);
initial $display(":%20b:", 16'shaaaa);
initial $display(":%-20b:", 16'shaaaa);
initial $display(":%020b:", 16'shaaaa);
initial $display(":%-020b:", 16'shaaaa);

initial $display("===> %%s");
initial $display(":%10s:", "foo");
initial $display(":%010s:", "foo");
initial $display(":%-10s:", "foo");
initial $display(":%-010s:", "foo");

initial $display("===> %%c");
initial $display(":%10c:", "foo");
initial $display(":%010c:", "foo");
initial $display(":%-10c:", "foo");
initial $display(":%-010c:", "foo");

initial $display("==> aliases");
initial $display(":%x:", 16'shaa);
initial $display(":%X:", 16'shaa);
initial $display(":%H:", 16'shaa);
initial $display(":%O:", 16'shaa);
initial $display(":%B:", 16'shaa);

initial $display("==> x/z");
initial $display(":%d:", 16'b1010101010101010);
initial $display(":%d:", 16'b101010101010101x);
initial $display(":%d:", 16'b101010101010101z);
initial $display(":%x:", 16'b1010101010101010);
initial $display(":%x:", 16'b101010101010101x);
initial $display(":%x:", 16'b101010101010101z);
initial $display(":%x:", 16'b101010101010xxxx);
initial $display(":%x:", 16'b101010101010zzzz);
initial $display(":%o:", 16'b1010101010101010);
initial $display(":%o:", 16'b101010101010101x);
initial $display(":%o:", 16'b101010101010101z);
initial $display(":%o:", 16'b1010101010101xxx);
initial $display(":%o:", 16'b1010101010101zzz);
initial $display(":%b:", 16'b1010101010101010);
initial $display(":%b:", 16'b101010101010101x);
initial $display(":%b:", 16'b101010101010101z);

initial $display("==> default base");
initial $displayh(16'haa);
initial $displayo(16'haa);
initial $displayb(16'haa);

initial $display("==> write/format");
initial $display("%d", 1, "%d", 1);
// this one hits a bug in iverilog:
// initial $display("%s", $sformatf("%d", 1, "%d", 1));

initial $display("<<<END>>>");

endmodule
6 changes: 6 additions & 0 deletions tests/fmt/run-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash -eu

../../yosys initial_display.v | awk '/<<<BEGIN>>>/,/<<<END>>>/ {print $0}' >yosys-initial_display.log
iverilog -o iverilog-initial_display initial_display.v
./iverilog-initial_display >iverilog-initial_display.log
diff yosys-initial_display.log iverilog-initial_display.log

0 comments on commit e386e11

Please sign in to comment.