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

tools/dot2c: Fix generated files going over 100 column limit

The dot2c.py script generates all states in a single line. This breaks the
100 column limit when the state machines are non-trivial.

Change dot2c.py to generate the states in separate lines in case the
generated line is going to be too long.

Also adapt existing monitors with line length over the limit.

Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Tomas Glozar <tglozar@redhat.com>
Cc: Juri Lelli <jlelli@redhat.com>
Cc: Clark Williams <williams@redhat.com>
Cc: John Kacur <jkacur@redhat.com>
Link: https://lore.kernel.org/20250723161240.194860-4-gmonaco@redhat.com
Suggested-by: Nam Cao <namcao@linutronix.de>
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)
9efcf590 1160ccaf

+24 -12
+12 -2
kernel/trace/rv/monitors/snep/snep.h
··· 41 41 "schedule_exit" 42 42 }, 43 43 .function = { 44 - { non_scheduling_context_snep, non_scheduling_context_snep, scheduling_contex_snep, INVALID_STATE }, 45 - { INVALID_STATE, INVALID_STATE, INVALID_STATE, non_scheduling_context_snep }, 44 + { 45 + non_scheduling_context_snep, 46 + non_scheduling_context_snep, 47 + scheduling_contex_snep, 48 + INVALID_STATE 49 + }, 50 + { 51 + INVALID_STATE, 52 + INVALID_STATE, 53 + INVALID_STATE, 54 + non_scheduling_context_snep 55 + }, 46 56 }, 47 57 .initial_state = non_scheduling_context_snep, 48 58 .final_states = { 1, 0 },
+12 -10
tools/verification/rvgen/rvgen/dot2c.py
··· 152 152 max_state_name = max(self.states, key = len).__len__() 153 153 return max(max_state_name, self.invalid_state_str.__len__()) 154 154 155 - def __get_state_string_length(self): 156 - maxlen = self.__get_max_strlen_of_states() + self.enum_suffix.__len__() 157 - return "%" + str(maxlen) + "s" 158 - 159 155 def get_aut_init_function(self): 160 156 nr_states = self.states.__len__() 161 157 nr_events = self.events.__len__() 162 158 buff = [] 163 159 164 - strformat = self.__get_state_string_length() 165 - 160 + maxlen = self.__get_max_strlen_of_states() + len(self.enum_suffix) 161 + tab_braces = 2 * 8 + 2 + 1 # "\t\t{ " ... "}" 162 + comma_space = 2 # ", " count last comma here 163 + linetoolong = tab_braces + (maxlen + comma_space) * nr_events > self.line_length 166 164 for x in range(nr_states): 167 - line = "\t\t{ " 165 + line = "\t\t{\n" if linetoolong else "\t\t{ " 168 166 for y in range(nr_events): 169 167 next_state = self.function[x][y] 170 168 if next_state != self.invalid_state_str: 171 169 next_state = self.function[x][y] + self.enum_suffix 172 170 173 - if y != nr_events-1: 174 - line = line + strformat % next_state + ", " 171 + if linetoolong: 172 + line += "\t\t\t%s" % next_state 175 173 else: 176 - line = line + strformat % next_state + " }," 174 + line += "%*s" % (maxlen, next_state) 175 + if y != nr_events-1: 176 + line += ",\n" if linetoolong else ", " 177 + else: 178 + line += "\n\t\t}," if linetoolong else " }," 177 179 buff.append(line) 178 180 179 181 return self.__buff_to_string(buff)