From f4240cc8a4545e4d2e2f926a72aa911d5373ab95 Mon Sep 17 00:00:00 2001 From: Eric Smith Date: Thu, 15 Sep 2016 02:00:29 -0600 Subject: Add optional SEED=n command line option to Makefile, and -S n command line option to test scripts, for deterministic regression tests. --- tests/realmath/generate.py | 12 +++++++++++- tests/realmath/run-test.sh | 16 ++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) (limited to 'tests/realmath') diff --git a/tests/realmath/generate.py b/tests/realmath/generate.py index 19d01c7c6..2bedf38e4 100644 --- a/tests/realmath/generate.py +++ b/tests/realmath/generate.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 +import argparse import sys import random from contextlib import contextmanager @@ -36,7 +37,16 @@ def random_expression(depth = 3, maxparam = 0): return op + '(' + recursion() + ', ' + recursion() + ')' raise -for idx in range(100): +parser = argparse.ArgumentParser(formatter_class = argparse.ArgumentDefaultsHelpFormatter) +parser.add_argument('-S', '--seed', type = int, help = 'seed for PRNG') +parser.add_argument('-c', '--count', type = int, default = 100, help = 'number of test cases to generate') +args = parser.parse_args() + +if args.seed is not None: + print("PRNG seed: %d" % args.seed) + random.seed(args.seed) + +for idx in range(args.count): with open('temp/uut_%05d.v' % idx, 'w') as f: with redirect_stdout(f): print('module uut_%05d(output [63:0] %s);\n' % (idx, ', '.join(['y%02d' % i for i in range(100)]))) diff --git a/tests/realmath/run-test.sh b/tests/realmath/run-test.sh index f1ec5476b..e1a36c694 100755 --- a/tests/realmath/run-test.sh +++ b/tests/realmath/run-test.sh @@ -1,14 +1,26 @@ #!/bin/bash set -e +OPTIND=1 +count=100 +seed="" # default to no seed specified +while getopts "c:S:" opt +do + case "$opt" in + c) count="$OPTARG" ;; + S) seed="-S $OPTARG" ;; + esac +done +shift "$((OPTIND-1))" + rm -rf temp mkdir -p temp echo "generating tests.." -python3 generate.py +python3 generate.py -c $count $seed cd temp echo "running tests.." -for ((i = 0; i < 100; i++)); do +for ((i = 0; i < $count; i++)); do echo -n "[$i]" idx=$( printf "%05d" $i ) ../../../yosys -qq uut_${idx}.ys -- cgit v1.2.3