Added "test_autotb -seed" (and "autotest.sh -S")
authorClifford Wolf <clifford@clifford.at>
Sat, 6 Aug 2016 11:32:29 +0000 (13:32 +0200)
committerClifford Wolf <clifford@clifford.at>
Sat, 6 Aug 2016 11:32:29 +0000 (13:32 +0200)
passes/tests/test_autotb.cc
tests/tools/autotest.sh

index 59de111c264abcab95b8418711cdaf5652179324..607bc476165294496f69ea281f897bd34de93085 100644 (file)
@@ -71,7 +71,7 @@ static std::string idy(std::string str1, std::string str2 = std::string(), std::
        return id(str1);
 }
 
-static void autotest(std::ostream &f, RTLIL::Design *design, int num_iter)
+static void autotest(std::ostream &f, RTLIL::Design *design, int num_iter, int seed)
 {
        f << stringf("`ifndef outfile\n");
        f << stringf("\t`define outfile \"/dev/stdout\"\n");
@@ -85,7 +85,7 @@ static void autotest(std::ostream &f, RTLIL::Design *design, int num_iter)
        f << stringf("reg [31:0] xorshift128_x = 123456789;\n");
        f << stringf("reg [31:0] xorshift128_y = 362436069;\n");
        f << stringf("reg [31:0] xorshift128_z = 521288629;\n");
-       f << stringf("reg [31:0] xorshift128_w = %u; // <-- seed value\n", int(time(NULL)));
+       f << stringf("reg [31:0] xorshift128_w = %u; // <-- seed value\n", seed ? seed : int(time(NULL)));
        f << stringf("reg [31:0] xorshift128_t;\n\n");
        f << stringf("task xorshift128;\n");
        f << stringf("begin\n");
@@ -342,6 +342,7 @@ struct TestAutotbBackend : public Backend {
        virtual void execute(std::ostream *&f, std::string filename, std::vector<std::string> args, RTLIL::Design *design)
        {
                int num_iter = 1000;
+               int seed = 0;
 
                log_header(design, "Executing TEST_AUTOTB backend (auto-generate pseudo-random test benches).\n");
 
@@ -352,11 +353,15 @@ struct TestAutotbBackend : public Backend {
                                num_iter = atoi(args[++argidx].c_str());
                                continue;
                        }
+                       if (args[argidx] == "-seed" && argidx+1 < GetSize(args)) {
+                               seed = atoi(args[++argidx].c_str());
+                               continue;
+                       }
                        break;
                }
 
                extra_args(f, filename, args, argidx);
-               autotest(*f, design, num_iter);
+               autotest(*f, design, num_iter, seed);
        }
 } TestAutotbBackend;
 
index 82fecfd8077db462d00a13271a4b9049c533d18e..a0ed976fd60a441ce9d5af0318d5ebfe214678eb 100755 (executable)
@@ -19,7 +19,7 @@ if [ ! -f $toolsdir/cmp_tbdata -o $toolsdir/cmp_tbdata.c -nt $toolsdir/cmp_tbdat
        ( set -ex; ${CC:-gcc} -Wall -o $toolsdir/cmp_tbdata $toolsdir/cmp_tbdata.c; ) || exit 1
 fi
 
-while getopts xmGl:wkjvref:s:p:n: opt; do
+while getopts xmGl:wkjvref:s:p:n:S: opt; do
        case "$opt" in
                x)
                        use_xsim=true ;;
@@ -50,8 +50,10 @@ while getopts xmGl:wkjvref:s:p:n: opt; do
                        scriptopt="$OPTARG" ;;
                n)
                        autotb_opts="$autotb_opts -n $OPTARG" ;;
+               S)
+                       autotb_opts="$autotb_opts -seed $OPTARG" ;;
                *)
-                       echo "Usage: $0 [-x|-m] [-w] [-k] [-j] [-v] [-r] [-e] [-l libs] [-f frontend] [-s script] [-p cmdstring] verilog-files\n" >&2
+                       echo "Usage: $0 [-x|-m] [-G] [-w] [-k] [-j] [-v] [-r] [-e] [-l libs] [-f frontend] [-s script] [-p cmdstring] [-n iters] [-S seed] verilog-files\n" >&2
                        exit 1
        esac
 done