1414# Store testdir for safe switch back to directory:
1515testdir = os .path .dirname (os .path .abspath (__file__ ))
1616test_path = Path (testdir )
17+ examples_path = test_path .parent / "examples"
1718logger = logging .getLogger ("util" )
1819
1920
@@ -84,13 +85,15 @@ def has_qemu():
8485 return False
8586
8687
87- def run_qemu (kernel , machine = "lm3s811evb" , dump_file = None , dump_range = None ):
88+ def run_qemu (
89+ kernel : Path , machine = "lm3s811evb" , dump_file = None , dump_range = None
90+ ):
8891 """Runs qemu on a given kernel file"""
8992
9093 if not has_qemu ():
9194 return ""
9295 # Check bin file exists:
93- assert os . path . isfile ( kernel )
96+ assert kernel . is_file ( )
9497
9598 logger .debug ("Running qemu with machine=%s and image %s" , machine , kernel )
9699
@@ -107,7 +110,7 @@ def run_qemu(kernel, machine="lm3s811evb", dump_file=None, dump_range=None):
107110 return qemu (args )
108111
109112
110- def create_qemu_launch_script (filename , qemu_cmd ):
113+ def create_qemu_launch_script (filename : Path , qemu_cmd ):
111114 """Create a shell script for a qemu command.
112115
113116 This can be used to launch qemu manually for a specific test example.
@@ -129,7 +132,7 @@ def create_qemu_launch_script(filename, qemu_cmd):
129132 if "-nographic" in qemu_cmd :
130133 qemu_cmd .remove ("-nographic" )
131134
132- with open (filename , "w" ) as f :
135+ with filename . open ("w" ) as f :
133136 print ("#!/bin/bash" , file = f )
134137 print ("" , file = f )
135138 print ("# *** automatically generated QEMU launch file! ***" , file = f )
@@ -141,8 +144,8 @@ def create_qemu_launch_script(filename, qemu_cmd):
141144 # chmod +x:
142145 import stat
143146
144- st = os .stat (filename )
145- os .chmod (filename , st .st_mode | stat .S_IEXEC )
147+ st = filename .stat ()
148+ filename .chmod (st .st_mode | stat .S_IEXEC )
146149
147150
148151def qemu (args ):
@@ -264,22 +267,20 @@ def has_iverilog():
264267 return hasattr (shutil , "which" ) and bool (shutil .which (iverilog_app ))
265268
266269
267- def run_msp430 (pmem ):
270+ def run_msp430 (pmem : Path ):
268271 """Run the given memory file in the openmsp430 iverilog project."""
269272
270273 # Make a run file with the same name as the mem file:
271- simv = pmem [: - 4 ] + ".run"
274+ simv = pmem . with_suffix ( ".run" )
272275
273- if not os . path . exists (simv ):
276+ if not simv . exists ():
274277 print ()
275278 print ("======" )
276279 print ("Compiling verilog!" )
277280 print ("======" )
278281
279282 # compile msp430 bench for this pmem:
280- workdir = relpath (
281- ".." , "examples" , "msp430" , "test_system" , "iverilog"
282- )
283+ workdir = examples_path / "msp430" / "test_system" / "iverilog"
283284 cmd = [
284285 "iverilog" ,
285286 "-o" ,
@@ -313,20 +314,20 @@ def run_msp430(pmem):
313314 return data
314315
315316
316- def run_picorv32 (pmem ):
317+ def run_picorv32 (pmem : Path ):
317318 """Run the given memory file in the riscvpicorv32 iverilog project."""
318319
319320 # Make a run file with the same name as the mem file:
320- simv = pmem [: - 4 ] + ".run"
321+ simv = pmem . with_suffix ( ".run" )
321322
322- if not os . path . exists (simv ):
323+ if not simv . exists ():
323324 print ()
324325 print ("======" )
325326 print ("Compiling verilog!" )
326327 print ("======" )
327328
328329 # compile picorv32 bench for this pmem:
329- workdir = relpath ( ".." , "examples" , "riscvpicorv32" , "iverilog" )
330+ workdir = examples_path / "riscvpicorv32" / "iverilog"
330331 cmd = [
331332 "iverilog" ,
332333 "-o" ,
@@ -353,11 +354,11 @@ def run_picorv32(pmem):
353354 return outs
354355
355356
356- avr_emu1 = relpath ( ".." , "examples" , "avr" , "emu" , "build" , "emu1" )
357+ avr_emu1 = examples_path / "avr" / "emu" / "build" / "emu1"
357358
358359
359360def has_avr_emulator ():
360- return os . path . exists (avr_emu1 )
361+ return avr_emu1 . exists ()
361362
362363
363364def run_avr (hexfile ):
0 commit comments