3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-10-10 17:58:07 +00:00

Testing quoted strings

This commit is contained in:
Krystine Sherwin 2025-09-24 12:07:30 +12:00
parent 5f6819fd76
commit 5c1dd0c5b2
No known key found for this signature in database
7 changed files with 126 additions and 0 deletions

1
tests/scripts/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/plugin.so

View file

@ -0,0 +1,2 @@
module top();
endmodule

View file

@ -0,0 +1 @@
log Hello!

57
tests/scripts/plugin.cc Normal file
View file

@ -0,0 +1,57 @@
#include "kernel/yosys.h"
USING_YOSYS_NAMESPACE
PRIVATE_NAMESPACE_BEGIN
struct TestArgsPass : public Pass {
TestArgsPass() : Pass("test_args", "dummy pass to test arg parsing") {
internal();
}
void execute(std::vector<std::string> args, RTLIL::Design*) override {
int argidx;
for (argidx = 0; argidx < GetSize(args); argidx++)
{
log("%s\n", args[argidx]);
}
}
} TestArgsPass;
struct TestArgsFrontend : public Frontend {
TestArgsFrontend() : Frontend("test_args", "dummy frontend to test arg parsing") {
internal();
}
void execute(std::istream *&f, std::string filename, std::vector<std::string> args, RTLIL::Design *) override {
int argidx;
log("pass: %s\n", args[0]);
for (argidx = 1; argidx < GetSize(args); argidx++) {
if (args[argidx] == "-arg" && argidx+1 < GetSize(args)) {
log("arg: %s\n", args[++argidx]);
continue;
}
break;
}
extra_args(f, filename, args, argidx);
log("filename: %s\n", filename);
}
} TestArgsFrontend;
struct TestArgsBackend : public Backend {
TestArgsBackend() : Backend("test_args", "dummy backend to test arg parsing") {
internal();
}
void execute(std::ostream *&f, std::string filename, std::vector<std::string> args, RTLIL::Design *) override {
int argidx;
log("pass: %s\n", args[0]);
for (argidx = 1; argidx < GetSize(args); argidx++) {
if (args[argidx] == "-arg" && argidx+1 < GetSize(args)) {
log("arg: %s\n", args[++argidx]);
continue;
}
break;
}
extra_args(f, filename, args, argidx);
log("filename: %s\n", filename);
}
} TestArgsBackend;
PRIVATE_NAMESPACE_END

4
tests/scripts/run-test.sh Executable file
View file

@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -eu
source ../gen-tests-makefile.sh
generate_mk --bash

47
tests/scripts/space_in_name.sh Executable file
View file

@ -0,0 +1,47 @@
#!/usr/bin/env bash
set -eu
yosys="$PWD/../../yosys"
# these ones are fine because bash handles it
$yosys "file name.ys"
$yosys file\ name.ys
$yosys "file name.v" -o "file name.out" -b verilog
$yosys file\ name.v -o file\ name.out -b verilog
# these already have special handling in Yosys thanks to `extra_args`
$yosys -p 'read_verilog "file name.v"'
$yosys -p 'write_verilog "file name.out"'
# this one isn't a normal frontend so doesn't
# $yosys -p 'script "file name.ys"'
# these get split by space and treated as two separate filenames
# $yosys -p script\ "file name.ys"
# $yosys -p script\ file\ name.ys
# $yosys -p read_verilog\ "file name.v"
# $yosys -p read_verilog\ file\ name.v
# $yosys -p write_verilog\ file\ name.out
# $yosys -p write_verilog\ "file name.out"
# what does test_args say
rm -f plugin.so
CXXFLAGS=$(../../yosys-config --cxxflags)
DATDIR=$(../../yosys-config --datdir)
DATDIR=${DATDIR//\//\\\/}
CXXFLAGS=${CXXFLAGS//$DATDIR/..\/..\/share}
../../yosys-config --exec --cxx ${CXXFLAGS} --ldflags -shared -o plugin.so plugin.cc
yosys_plugin="$yosys -m ./plugin.so"
$yosys_plugin -p test_args\ "quoted spaces"
$yosys_plugin -p test_args\ escaped\ spaces
$yosys_plugin -p test_args\ \"escaped\ quotes\"
$yosys_plugin -p 'test_args "inner quotes"'
$yosys_plugin -p 'test_args "inner \"escaped quotes\""'
$yosys_plugin -p 'read_test_args "file name.v" "file name.ys"'
$yosys_plugin -p 'write_test_args "file name.out"'
# and as a script
$yosys_plugin space_in_name.ys

14
tests/scripts/space_in_name.ys Executable file
View file

@ -0,0 +1,14 @@
echo on
# pass
test_args "quoted spaces"
test_args escaped\ spaces
test_args \"escaped quotes\"
test_args "inner \"escaped quotes\""
test_args -opt "some value here" -b "some other \"escaped value\""
# frontend/backend
read_test_args -arg "inner \"escaped quotes\"" "file name.v" "file name.ys"
write_test_args -arg "inner \"escaped quotes\"" "file name.out"
read_test_args -arg no_quotes plugin.cc
write_test_args -arg no_quotes