[otbnsim] Factor out test compile into shared lib

The otbnsim pytests typically need to assemble/compile source code for
testing. Factor this functionality out into a separate module to make it
easier to reuse in other test files.

Signed-off-by: Philipp Wagner <phw@lowrisc.org>
diff --git a/hw/ip/otbn/dv/otbnsim/test/conftest.py b/hw/ip/otbn/dv/otbnsim/test/conftest.py
new file mode 100644
index 0000000..3e63f98
--- /dev/null
+++ b/hw/ip/otbn/dv/otbnsim/test/conftest.py
@@ -0,0 +1,9 @@
+# Copyright lowRISC contributors.
+# Licensed under the Apache License, Version 2.0, see LICENSE for details.
+# SPDX-License-Identifier: Apache-2.0
+
+import os
+import sys
+
+# Make tested code available for import
+sys.path.append(os.path.join(os.path.dirname(__file__), '../'))
diff --git a/hw/ip/otbn/dv/otbnsim/test/simple_test.py b/hw/ip/otbn/dv/otbnsim/test/simple_test.py
index 5807347..e6621b9 100644
--- a/hw/ip/otbn/dv/otbnsim/test/simple_test.py
+++ b/hw/ip/otbn/dv/otbnsim/test/simple_test.py
@@ -16,10 +16,7 @@
 import subprocess
 from typing import Any, Dict, List, Tuple
 
-
-_OTBN_DIR = os.path.join(os.path.dirname(__file__), '../../..')
-_UTIL_DIR = os.path.join(_OTBN_DIR, 'util')
-_SIM_DIR = os.path.join(os.path.dirname(__file__), '..')
+from testutil import asm_and_link_one_file, SIM_DIR
 
 _REG_RE = re.compile(r'\s*([xw][0-9]+)\s*=\s*((:?0x[0-9a-f]+)|([0-9]+))$')
 
@@ -80,22 +77,6 @@
     return ret
 
 
-def asm_and_link_one_file(asm_path: str, work_dir: str) -> str:
-    '''Assemble and link file at asm_path in work_dir.
-
-    Returns the path to the resulting ELF
-
-    '''
-    otbn_as = os.path.join(_UTIL_DIR, 'otbn-as')
-    otbn_ld = os.path.join(_UTIL_DIR, 'otbn-ld')
-    obj_path = os.path.join(work_dir, 'tst.o')
-    elf_path = os.path.join(work_dir, 'tst')
-
-    subprocess.run([otbn_as, '-o', obj_path, asm_path], check=True)
-    subprocess.run([otbn_ld, '-o', elf_path, obj_path], check=True)
-    return elf_path
-
-
 def get_reg_dump(stdout: str) -> Dict[str, int]:
     '''Parse the output from a simple test ending in print_regs
 
@@ -165,7 +146,7 @@
 
     # Run the simulation. We can just pass a list of commands to stdin, and
     # don't need to do anything clever to track what's going on.
-    stepped_py = os.path.join(_SIM_DIR, 'stepped.py')
+    stepped_py = os.path.join(SIM_DIR, 'stepped.py')
     commands = 'load_elf {}\nstart 0\nrun\nprint_regs\n'.format(elf_file)
     sim_proc = subprocess.run([stepped_py], check=True, input=commands,
                               stdout=subprocess.PIPE, universal_newlines=True)
diff --git a/hw/ip/otbn/dv/otbnsim/test/testutil.py b/hw/ip/otbn/dv/otbnsim/test/testutil.py
new file mode 100644
index 0000000..7900e89
--- /dev/null
+++ b/hw/ip/otbn/dv/otbnsim/test/testutil.py
@@ -0,0 +1,27 @@
+# Copyright lowRISC contributors.
+# Licensed under the Apache License, Version 2.0, see LICENSE for details.
+# SPDX-License-Identifier: Apache-2.0
+
+import os
+import subprocess
+
+
+OTBN_DIR = os.path.join(os.path.dirname(__file__), '../../..')
+UTIL_DIR = os.path.join(OTBN_DIR, 'util')
+SIM_DIR = os.path.join(os.path.dirname(__file__), '..')
+
+
+def asm_and_link_one_file(asm_path: str, work_dir: str) -> str:
+    '''Assemble and link file at asm_path in work_dir.
+
+    Returns the path to the resulting ELF
+
+    '''
+    otbn_as = os.path.join(UTIL_DIR, 'otbn-as')
+    otbn_ld = os.path.join(UTIL_DIR, 'otbn-ld')
+    obj_path = os.path.join(work_dir, 'tst.o')
+    elf_path = os.path.join(work_dir, 'tst')
+
+    subprocess.run([otbn_as, '-o', obj_path, asm_path], check=True)
+    subprocess.run([otbn_ld, '-o', elf_path, obj_path], check=True)
+    return elf_path