add getopt for test and help to inorder.py
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 22 May 2023 11:39:08 +0000 (12:39 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 22 May 2023 11:39:08 +0000 (12:39 +0100)
src/openpower/cyclemodel/inorder.py

index 5d719da449a75fa50dbc8de07c72c67eba74fca5..03ca65ddd93dbc8b47597a2a9ddc65b6435b5f86 100644 (file)
@@ -43,6 +43,8 @@
 from collections import namedtuple
 import io
 import unittest
+import getopt
+import sys
 
 # trace file entries are lists of these.
 Hazard = namedtuple("Hazard", ["action", "target", "ident", "offs", "elwid"])
@@ -292,6 +294,31 @@ class TestTrace(unittest.TestCase):
         for trace in lines:
             print(trace)
 
+def help():
+    print ("-t             runs unit tests")
+    print ("-h --help      prints this message")
+    exit(-1)
+
 
 if __name__ == "__main__":
-    unittest.main()
+    opts, args = getopt.getopt(sys.argv[1:], "thi:o:",
+                                             ["help",])
+
+    # default files are stdin/stdout.
+    in_file = sys.stdin
+    out_file = sys.stdout
+
+    for opt, arg in opts:
+        if opt in ['-h', '--help']:
+            help()
+        if opt in ['-t']:
+            unittest.main(argv=[sys.argv[0]]+sys.argv[2:])
+        if opt in ['-i']:
+            in_file = arg
+        if opt in ['-o']:
+            out_file = arg
+
+    # TODO: run model
+    lines = read_file(in_file)
+    for trace in lines:
+        out_file.write("|" + "|".join(map(str, trace)) + "|\n")