blob: 16a71431afd8ab93d8edbac8a98e8f8f4d4c487b [file] [log] [blame]
Kevin Penga127b452021-02-23 10:02:55 +08001#-------------------------------------------------------------------------------
2# Copyright (c) 2020, Arm Limited. All rights reserved.
3#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6#-------------------------------------------------------------------------------
7
8""" This module is the entry point of the IRQ testing tool.
9"""
10
11import argparse
12import json
13import logging
14import os
15import sys
16
17# Workaround for GDB: Add current directory to the module search path
18sys.path.insert(0, os.getcwd())
19from irq_test_abstract_debugger import Location
20from irq_test_dummy_debugger import DummyDebugger
21from irq_test_executor import TestExecutor
22
23def create_argparser():
24 """ Create an argument parser for the script
25
26 This parser enumerates the arguments that are necessary for all the
27 debuggers. Debugger implementations might add other arguments to this
28 parser.
29 """
30 parser = argparse.ArgumentParser()
31 parser.add_argument("-w", "--sw-break",
32 help="use sw breakpoint (the default is HW breakpoint)",
33 action="store_true")
34 parser.add_argument("-q", "--irqs",
35 type=str,
36 help="the name of the irqs json",
37 required=True)
38 parser.add_argument("-b", "--breakpoints",
39 type=str,
40 help="the name of the breakpoints json",
41 required=True)
42 parser.add_argument("-t", "--testcase",
43 type=str,
44 help="The testcase to execute",
45 required=True)
46 return parser
47
48def main():
49 """ The main function of the script
50
51 Detects the debugger that it is started in, creates the debugger
52 implementation instance, and either executes the test, or registers a
53 command in the debugger. For details see the README.rst
54 """
55 try:
56 # TODO: evironment checking should be refactored to the debugger
57 # implementations
58 from arm_ds.debugger_v1 import Debugger
59 debugger_type = 'Arm-DS'
60 except ImportError:
61 logging.debug('Failed to import Arm-DS scripting env, try GDB')
62 try:
63 # TODO: evironment checking should be refactored to the debugger
64 # implementations
65 import gdb
66 debugger_type = 'GDB'
67 except ImportError:
68 logging.debug("Failed to import GDB scripting env, fall back do "
69 "dummy")
70 debugger_type = 'dummy'
71
72 logging.info("The debugger type selected is: %s", debugger_type)
73
74 # create a debugger controller instance
75 if debugger_type == 'Arm-DS':
76 from irq_test_Arm_DS_debugger import ArmDSDebugger
77 logging.debug("initialising debugger object...")
78 arg_parser = create_argparser()
79 try:
80 args = arg_parser.parse_args()
81 except:
82 logging.error("Failed to parse command line parameters")
83 return
84 # TODO: Fail gracefully in case of an argparse error
85 debugger = ArmDSDebugger(args.sw_break)
86 executor = TestExecutor(debugger)
87 executor.execute(args.irqs, args.breakpoints, args.testcase)
88 elif debugger_type == 'GDB':
89 from irq_test_gdb_debugger import GDBDebugger
90 from irq_test_gdb_debugger import TestIRQsCommand
91 logging.debug("initialising debugger object...")
92 arg_parser = create_argparser()
93
94 # register the 'test_irqs' custom command
95 TestIRQsCommand(arg_parser)
96 logging.info("Command 'test_irqs' is successfully registered")
97 elif debugger_type == 'dummy':
98 arg_parser = create_argparser()
99 args = arg_parser.parse_args()
100 debugger = DummyDebugger(args.sw_break)
101 executor = TestExecutor(debugger)
102 executor.execute(args.irqs, args.breakpoints, args.testcase)
103
104if __name__ == "__main__":
105 logging.basicConfig(format='===== %(levelname)s: %(message)s',
106 level=logging.DEBUG, stream=sys.stdout)
107 main()