-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcommand_line_interface.py
108 lines (84 loc) · 4.08 KB
/
command_line_interface.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
"""Command-line interface.
Following arguments are neccessary when calling the main-method of the traditional-SA package:
db_path path to the database file.
Additional there are optional arguments:
-h, --help show a help message and exit
--test_all run all available schedulability analysis methods
-s, --simulate run simulation
-u, --utilization run all utilization based schedulability analysis methods
-rta, --response_time_analysis run all response time analyses
-w, --workload run all workload based schedulability analysis methods
The full call looks like the following:
main.py [-h] [--test_all] [-s] [-u] [-rta] [-w] db_path
"""
import argparse
import logging
import os
import rta
import simulation
import utilization
import workload
from main import VALID_SA
def read_input():
"""Read arguments from the command line.
This methods reads the arguments of the script-call from the command line.
Return:
db_dir -- directory of the database file
db_name -- name of the database file
tests_todo -- list with schedulability tests that should be done
"""
# create logger
logger = logging.getLogger('traditional-SA.command_line_interface.read_input')
# create argument parser
parser = _create_argparser()
# parse arguments
args = parser.parse_args()
# extract directory and name of the database file
(db_dir, db_name) = os.path.split(args.db_path)
# create empty list: schedulability analysis methods that should be done
tests_todo = []
# add the selected test to the to-do list
if args.test_all: # run all available schedulability analysis methods
logger.info("Doing all available schedulability tests...\n")
tests_todo = VALID_SA
else:
if args.simulation: # run simulation
tests_todo.append(simulation.simulate)
if args.utilization: # run all utilization based schedulability analysis methods
tests_todo.append(utilization.basic_utilization_test)
tests_todo.append(utilization.rm_utilization_test)
tests_todo.append(utilization.hb_utilization_test)
if args.response_time_analysis: # run all response time analyses
tests_todo.append(rta.rta_audsley)
tests_todo.append(rta.rta_buttazzo)
if args.workload: # run all workload based schedulability analysis methods
tests_todo.append(workload.rm_workload_test)
tests_todo.append(workload.het_workload_test)
if not tests_todo: # no schedulability method selected
logger.info("No schedulability test selected! Doing nothing...\n")
return None
return db_dir, db_name, tests_todo
def _create_argparser():
"""Create a parser for command-line options, arguments and sub-commands.
This method creates an argument parser and adds the neccessary arguments.
Return:
parser -- the created argument parser
"""
# create argument parser
parser = argparse.ArgumentParser(description="traditional schedulability analysis methods")
# add positional arguments arguments to the parser
parser.add_argument("db_path", help="path to the database file")
# add optional arguments to the parser
parser.add_argument("--test_all", help="run all available schedulability analysis methods",
action="store_true")
parser.add_argument("-s", "--simulation", help="run simulation", action="store_true")
parser.add_argument("-u", "--utilization",
help="run all utilization based schedulability analysis methods",
action="store_true")
parser.add_argument("-rta", "--response_time_analysis", help="run all response time analyses",
action="store_true")
parser.add_argument("-w", "--workload",
help="run all workload based schedulability analysis methods",
action="store_true")
# return argument parser
return parser