Skip to content

Commit 64b3e5f

Browse files
glemcorostedt
authored andcommitted
verification/dot2k: Add support for name and description options
The dot2k command includes options to set a model name with -n and a description with -D, however those are not used in practice. This patch allows to specify a custom model name (by default the name of the dot file without extension) and a description which overrides the one in the C file. Cc: Juri Lelli <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: John Kacur <[email protected]> Link: https://lore.kernel.org/[email protected] Signed-off-by: Gabriele Monaco <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 91f3407 commit 64b3e5f

File tree

5 files changed

+12
-14
lines changed

5 files changed

+12
-14
lines changed

tools/verification/dot2/automata.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ class Automata:
1919

2020
invalid_state_str = "INVALID_STATE"
2121

22-
def __init__(self, file_path):
22+
def __init__(self, file_path, model_name=None):
2323
self.__dot_path = file_path
24-
self.name = self.__get_model_name()
24+
self.name = model_name or self.__get_model_name()
2525
self.__dot_lines = self.__open_dot()
2626
self.states, self.initial_state, self.final_states = self.__get_state_variables()
2727
self.events = self.__get_event_variables()

tools/verification/dot2/dot2c.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ class Dot2c(Automata):
2222
struct_automaton_def = "automaton"
2323
var_automaton_def = "aut"
2424

25-
def __init__(self, file_path):
26-
super().__init__(file_path)
25+
def __init__(self, file_path, model_name=None):
26+
super().__init__(file_path, model_name)
2727
self.line_length = 100
2828

2929
def __buff_to_string(self, buff):

tools/verification/dot2/dot2k

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,12 @@ if __name__ == '__main__':
2525

2626
print("Opening and parsing the dot file %s" % params.dot_file)
2727
try:
28-
monitor=dot2k(params.dot_file, params.monitor_type)
28+
monitor=dot2k(params.dot_file, params.monitor_type, vars(params))
2929
except Exception as e:
3030
print('Error: '+ str(e))
3131
print("Sorry : :-(")
3232
sys.exit(1)
3333

34-
# easier than using argparse action.
35-
if params.model_name != None:
36-
print(params.model_name)
37-
3834
print("Writing the monitor into the directory %s" % monitor.name)
3935
monitor.print_files()
4036
print("Almost done, checklist")

tools/verification/dot2/dot2k.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,18 @@ class dot2k(Dot2c):
1717
monitor_templates_dir = "dot2/dot2k_templates/"
1818
monitor_type = "per_cpu"
1919

20-
def __init__(self, file_path, MonitorType):
21-
super().__init__(file_path)
20+
def __init__(self, file_path, MonitorType, extra_params={}):
21+
super().__init__(file_path, extra_params.get("model_name"))
2222

2323
self.monitor_type = self.monitor_types.get(MonitorType)
2424
if self.monitor_type is None:
25-
raise Exception("Unknown monitor type: %s" % MonitorType)
25+
raise ValueError("Unknown monitor type: %s" % MonitorType)
2626

2727
self.monitor_type = MonitorType
2828
self.__fill_rv_templates_dir()
2929
self.main_c = self.__open_file(self.monitor_templates_dir + "main.c")
3030
self.enum_suffix = "_%s" % self.name
31+
self.description = extra_params.get("description", self.name) or "auto-generated"
3132

3233
def __fill_rv_templates_dir(self):
3334

@@ -114,6 +115,7 @@ def fill_main_c(self):
114115
main_c = main_c.replace("%%TRACEPOINT_HANDLERS_SKEL%%", tracepoint_handlers)
115116
main_c = main_c.replace("%%TRACEPOINT_ATTACH%%", tracepoint_attach)
116117
main_c = main_c.replace("%%TRACEPOINT_DETACH%%", tracepoint_detach)
118+
main_c = main_c.replace("%%DESCRIPTION%%", self.description)
117119

118120
return main_c
119121

tools/verification/dot2/dot2k_templates/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ static void disable_%%MODEL_NAME%%(void)
6565
*/
6666
static struct rv_monitor rv_%%MODEL_NAME%% = {
6767
.name = "%%MODEL_NAME%%",
68-
.description = "auto-generated %%MODEL_NAME%%",
68+
.description = "%%DESCRIPTION%%",
6969
.enable = enable_%%MODEL_NAME%%,
7070
.disable = disable_%%MODEL_NAME%%,
7171
.reset = da_monitor_reset_all_%%MODEL_NAME%%,
@@ -88,4 +88,4 @@ module_exit(unregister_%%MODEL_NAME%%);
8888

8989
MODULE_LICENSE("GPL");
9090
MODULE_AUTHOR("dot2k: auto-generated");
91-
MODULE_DESCRIPTION("%%MODEL_NAME%%");
91+
MODULE_DESCRIPTION("%%MODEL_NAME%%: %%DESCRIPTION%%");

0 commit comments

Comments
 (0)