Re: [PATCH v3 13/17] verification/rvgen: Add the rvgen kunit subcommand
From: Nam Cao
Date: Thu Jul 09 2026 - 04:02:17 EST
Gabriele Monaco <gmonaco@xxxxxxxxxx> writes:
> + def print_files(self):
> +
> + handlers = self.__parse_attach_handlers()
> +
> + if not handlers:
> + print(f"No handlers found registered with rv_attach_trace_probe in {self.monitor_path}")
> + return
There is no valid monitor without any handler, right? If so, should we
throw an exception here?
> +
> + print("Found tracepoint handler(s):")
> + for handler in handlers:
> + print(f" - {handler}")
> +
> + prototypes = []
> + assignments = []
> + for handler in handlers:
> + arguments = self.__extract_function_args(handler)
> +
> + prototypes.append(f"void (*{handler})({arguments});")
> + assignments.append(f".{handler} = {handler},")
> +
> + struct_name = f"rv_{self.name}_ops"
> +
> + self.__fill_monitor_handlers(struct_name, assignments)
> +
> + dir_path = os.path.dirname(self.monitor_path)
> +
> + header_file_path = os.path.join(dir_path, f"{self.name}_kunit.h")
> + kunit_c_file_path = os.path.join(dir_path, f"{self.name}_kunit.c")
> +
> + use_backup = True
> + if os.path.exists(header_file_path) or os.path.exists(kunit_c_file_path):
> + try:
> + response = input("KUnit file(s) already exist. Overwrite? [y/N] (N for backup): ")
> + if response.strip().lower() in ("y", "yes"):
> + use_backup = False
> + except EOFError:
> + print("Non-interactive session detected, not overwriting existing files.")
> + else:
> + use_backup = False
> +
> + if use_backup:
> + header_file_path += ".bak"
> + kunit_c_file_path += ".bak"
This is the opposite of what other software do. Usually they copy the
original file to a different name (with a prefix or a suffix), and
overwrite the original file.
I think it's best to follow the usual practice to avoid confusion, maybe
something like this:
if os.path.exists(header_file_path) or os.path.exists(kunit_c_file_path):
try:
response = input("KUnit file(s) already exist. Backup? [Y/n]")
if not response.strip().lower() in ("n", "no"):
...rename the file...
except EOFError:
print("Non-interactive session detected, not overwriting existing files.")
Nam