Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <juri.lelli@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: John Kacur <jkacur@redhat.com>
Link: https://lore.kernel.org/20241227144752.362911-5-gmonaco@redhat.com
Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>

authored by

Gabriele Monaco and committed by
Steven Rostedt (Google)
64b3e5f0 91f3407e

+12 -14
+2 -2
tools/verification/dot2/automata.py
··· 19 19 20 20 invalid_state_str = "INVALID_STATE" 21 21 22 - def __init__(self, file_path): 22 + def __init__(self, file_path, model_name=None): 23 23 self.__dot_path = file_path 24 - self.name = self.__get_model_name() 24 + self.name = model_name or self.__get_model_name() 25 25 self.__dot_lines = self.__open_dot() 26 26 self.states, self.initial_state, self.final_states = self.__get_state_variables() 27 27 self.events = self.__get_event_variables()
+2 -2
tools/verification/dot2/dot2c.py
··· 22 22 struct_automaton_def = "automaton" 23 23 var_automaton_def = "aut" 24 24 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) 27 27 self.line_length = 100 28 28 29 29 def __buff_to_string(self, buff):
+1 -5
tools/verification/dot2/dot2k
··· 25 25 26 26 print("Opening and parsing the dot file %s" % params.dot_file) 27 27 try: 28 - monitor=dot2k(params.dot_file, params.monitor_type) 28 + monitor=dot2k(params.dot_file, params.monitor_type, vars(params)) 29 29 except Exception as e: 30 30 print('Error: '+ str(e)) 31 31 print("Sorry : :-(") 32 32 sys.exit(1) 33 - 34 - # easier than using argparse action. 35 - if params.model_name != None: 36 - print(params.model_name) 37 33 38 34 print("Writing the monitor into the directory %s" % monitor.name) 39 35 monitor.print_files()
+5 -3
tools/verification/dot2/dot2k.py
··· 17 17 monitor_templates_dir = "dot2/dot2k_templates/" 18 18 monitor_type = "per_cpu" 19 19 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")) 22 22 23 23 self.monitor_type = self.monitor_types.get(MonitorType) 24 24 if self.monitor_type is None: 25 - raise Exception("Unknown monitor type: %s" % MonitorType) 25 + raise ValueError("Unknown monitor type: %s" % MonitorType) 26 26 27 27 self.monitor_type = MonitorType 28 28 self.__fill_rv_templates_dir() 29 29 self.main_c = self.__open_file(self.monitor_templates_dir + "main.c") 30 30 self.enum_suffix = "_%s" % self.name 31 + self.description = extra_params.get("description", self.name) or "auto-generated" 31 32 32 33 def __fill_rv_templates_dir(self): 33 34 ··· 115 114 main_c = main_c.replace("%%TRACEPOINT_HANDLERS_SKEL%%", tracepoint_handlers) 116 115 main_c = main_c.replace("%%TRACEPOINT_ATTACH%%", tracepoint_attach) 117 116 main_c = main_c.replace("%%TRACEPOINT_DETACH%%", tracepoint_detach) 117 + main_c = main_c.replace("%%DESCRIPTION%%", self.description) 118 118 119 119 return main_c 120 120
+2 -2
tools/verification/dot2/dot2k_templates/main.c
··· 65 65 */ 66 66 static struct rv_monitor rv_%%MODEL_NAME%% = { 67 67 .name = "%%MODEL_NAME%%", 68 - .description = "auto-generated %%MODEL_NAME%%", 68 + .description = "%%DESCRIPTION%%", 69 69 .enable = enable_%%MODEL_NAME%%, 70 70 .disable = disable_%%MODEL_NAME%%, 71 71 .reset = da_monitor_reset_all_%%MODEL_NAME%%, ··· 88 88 89 89 MODULE_LICENSE("GPL"); 90 90 MODULE_AUTHOR("dot2k: auto-generated"); 91 - MODULE_DESCRIPTION("%%MODEL_NAME%%"); 91 + MODULE_DESCRIPTION("%%MODEL_NAME%%: %%DESCRIPTION%%");