tmp creation/string formatting
authorklehman <klehman9@comcast.net>
Mon, 25 Oct 2021 14:13:39 +0000 (10:13 -0400)
committerklehman <klehman9@comcast.net>
Mon, 25 Oct 2021 14:13:39 +0000 (10:13 -0400)
src/openpower/test/state.py

index f1eb8ef2398efea7e189695d02a47a91f38fb988..2b00fbd10cdcd1eb1d416ebb670d85f206c30cae 100644 (file)
@@ -24,6 +24,7 @@ methods, the use of yield from/yield is required.
 
 from openpower.decoder.power_enums import XER_bits
 from openpower.util import log
+import os
 
 global staterunner_factory
 staterunner_factory = {}
@@ -221,29 +222,27 @@ class ExpectedState(State):
         to set an expected state object
         """
         lindent = ' '*8 # indent for code
-        with open("/tmp/{0}.py".format(testname), "w") as sout:
+        path = "/tmp/expected/"  # temp for now
+        os.makedirs(path, exist_ok=True)
+        with open("%s%s.py" % (path, testname), "w") as sout:
             # pc and intregs
-            sout.write(f"{lindent}e = ExpectedState(pc={state.pc})\n")
-            for i in range(32):
-                if(state.intregs[i] != 0):
-                    sout.write("{0}e.intregs[{1}] = 0x{2:x}\n".format(
-                               lindent,
-                               i,
-                               state.intregs[i]))
+            sout.write("%se = ExpectedState(pc=%d)\n" % (lindent, state.pc))
+            for i, reg in enumerate(state.intregs):
+                if(reg != 0):
+                    msg = "%se.intregs[%d] = 0x%x\n"
+                    sout.write( msg % (lindent, i, reg))
             # cr
-            for i in range(8):
-                if(state.crregs[i] != 0):
-                    sout.write("{0}e.crregs[{1}] = 0x{2:x}\n".format(
-                               lindent,
-                               i,
-                               state.crregs[i]))
+            for i, reg in enumerate(state.crregs):
+                if(reg != 0):
+                    msg = "%se.crregs[%d] = 0x%x\n"
+                    sout.write( msg % (lindent, i, reg))
             # XER
             if(state.so != 0):
-                sout.write(f"{lindent}e.so = 0x{state.so}\n")
+                sout.write("%se.so = 0x%x\n" % (lindent, state.so))
             if(state.ov != 0):
-                sout.write(f"{lindent}e.sv = 0x{state.ov}\n")
+                sout.write("%se.ov = 0x%x\n" % (lindent, state.ov))
             if(state.ca != 0):
-                sout.write(f"{lindent}e.ca = 0x{state.ca}\n")
+                sout.write("%se.ca = 0x%x\n" % (lindent, state.ca))
 
 
 global state_factory