From fa69a0798b9ab54805b17e6b5d090004a3230f4a Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Mon, 22 May 2023 12:39:08 +0100 Subject: [PATCH] add getopt for test and help to inorder.py --- src/openpower/cyclemodel/inorder.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/openpower/cyclemodel/inorder.py b/src/openpower/cyclemodel/inorder.py index 5d719da4..03ca65dd 100644 --- a/src/openpower/cyclemodel/inorder.py +++ b/src/openpower/cyclemodel/inorder.py @@ -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") -- 2.30.2