mirror of
https://github.com/YosysHQ/yosys
synced 2025-10-10 09:48:06 +00:00
Testing quoted strings
This commit is contained in:
parent
5f6819fd76
commit
5c1dd0c5b2
7 changed files with 126 additions and 0 deletions
1
tests/scripts/.gitignore
vendored
Normal file
1
tests/scripts/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/plugin.so
|
2
tests/scripts/file name.v
Normal file
2
tests/scripts/file name.v
Normal file
|
@ -0,0 +1,2 @@
|
|||
module top();
|
||||
endmodule
|
1
tests/scripts/file name.ys
Normal file
1
tests/scripts/file name.ys
Normal file
|
@ -0,0 +1 @@
|
|||
log Hello!
|
57
tests/scripts/plugin.cc
Normal file
57
tests/scripts/plugin.cc
Normal 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
4
tests/scripts/run-test.sh
Executable 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
47
tests/scripts/space_in_name.sh
Executable 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
14
tests/scripts/space_in_name.ys
Executable 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
|
Loading…
Add table
Add a link
Reference in a new issue