tf_fuzz: add --seed option to suitegen

Add the --seed option to tfz-suitegen, allowing reproducable test suite
builds.

To keep individual tests random, the seed given is not directly used by
TF-Fuzz, but is instead used to randomly generate a seed for TF-Fuzz.

Change-Id: Ia7d3d228619fbbbae05012343b0078c3287cbd77
Signed-off-by: Nik Dewally <Nik.Dewally@arm.com>
diff --git a/tf_fuzz/tfz-suitegen/src/tfz-suitegen/__main__.py b/tf_fuzz/tfz-suitegen/src/tfz-suitegen/__main__.py
index dded491..49340f4 100644
--- a/tf_fuzz/tfz-suitegen/src/tfz-suitegen/__main__.py
+++ b/tf_fuzz/tfz-suitegen/src/tfz-suitegen/__main__.py
@@ -11,7 +11,7 @@
 from dataclasses import dataclass, field, asdict
 import subprocess as sp
 import re
-from IPython import embed
+import random
 
 
 @dataclass
@@ -59,8 +59,16 @@
         type=Path,
     )
 
+    parser.add_argument(
+        "--seed", help="Random seed used during test generation", type=int
+    )
+
     args = parser.parse_args()
 
+    SEED: int = args.seed
+    if not SEED:
+        SEED = random.randint(0, 0xFFFFFFFF)
+
     TFZ_DIR: Path = args.tfz_dir
     LIB_DIR: Path = TFZ_DIR / "lib"
     TFZ_EXECUTABLE: Path = args.tfz_dir / "bin" / "tfz"
@@ -106,7 +114,13 @@
 
     test_suite: TestSuite = TestSuite()
 
+    print(f"Using random seed: {SEED}")
+    random.seed(SEED)
+
     for i, test_input_path in enumerate(sorted(INPUT_DIR.glob("*.test"))):
+        # use different random seeds based on a known seed so the tests have
+        # different random values, but still can be ran deterministically
+        seed = random.randint(0, 0xFFFFFFFF)
 
         print(f"* Found test file {test_input_path}")
 
@@ -114,7 +128,7 @@
         generated_test_path: Path = TARGET_DIR / f"{c_file_name}"
 
         process = sp.run(
-            f"{TFZ_EXECUTABLE.absolute()} {test_input_path.absolute()} {generated_test_path.absolute()}",
+            f"{TFZ_EXECUTABLE.absolute()} {test_input_path.absolute()} {generated_test_path.absolute()} {seed}",
             shell=True,
             text=True,
             stderr=sp.STDOUT,