add seed capability to CSR test generation
@@ -318,9 +318,12 @@ def gen_csr_instr(original_csr_map, csr_instructions, xlen,
gen_csr_test_fail(csr_test_file, end_signature_addr)
-"""
-Define command line arguments.
-"""
+def main():
+ """Main entry point of CSR test generation script.
+ Will set up a list of all supported CSR instructions,
+ and seed the RNG."""
+
+ # define command line arguments
parser = argparse.ArgumentParser()
parser.add_argument("--csr_file", type=str, default="yaml/csr_template.yaml",
help="The YAML file contating descriptions of all processor supported CSRs")
@@ -332,14 +335,25 @@ parser.add_argument("--out", type=str, default="./",
help="Specify output directory")
parser.add_argument("--end_signature_addr", type=str, default="0",
help="Address that should be written to at end of this test")
+ parser.add_argument("--seed", type=int, default=None,
+ help="""Value used to seed the random number generator. If no value is passed in,
+ the RNG will be seeded from an internal source of randomness.""")
args = parser.parse_args()
+ """All supported CSR operations"""
+ csr_ops = ['csrrw', 'csrrs', 'csrrc', 'csrrwi', 'csrrsi', 'csrrci']
"""
-A list containing all supported CSR instructions.
+ Seed the RNG.
+ If args.seed is None, seed will be drawn from some internal random source.
+ If args.seed is defined, this will be used to seed the RNG for user reproducibility.
"""
-csr_ops = ['csrrw', 'csrrs', 'csrrc', 'csrrwi', 'csrrsi', 'csrrci']
+ random.seed(args.seed)
gen_csr_instr(get_csr_map(args.csr_file, args.xlen),
csr_ops, args.xlen, args.iterations, args.out,
args.end_signature_addr)
+
+
+if __name__ == "__main__":
+ main()
