verification/rvgen: validate the monitor type
Subsystems (2)
v2 cover verification/rvgen: validate the monitor type
rvgen takes the monitor type on the command line and pastes it into the generated monitor as RV_MON_<TYPE>. Nothing validates it, so a typo produces a monitor that cannot build while the tool still exits 0. Monitor.monitor_types already holds the accepted set; pass it to argparse as choices. Patch 2 covers the rejection next to the other error tests.
v2:
- Thread the series; 2/2 replies to this cover letter.
- Tag both patches verification/rvgen: and capitalise the subject.
- Patch content unchanged.
Testing: make check in tools/verification/rvgen -- 31/31 pass.
Chaosheng Qu (2):
verification/rvgen: Validate the monitor type verification/rvgen: Cover an invalid monitor type
tools/verification/rvgen/__main__.py | 1 + tools/verification/rvgen/tests/rvgen_monitor.t | 4 ++++ 2 files changed, 5 insertions(+)
Signature · 1 line
2.43.0
PATCH v2 1/2 verification/rvgen: Validate the monitor type
The monitor type is pasted into the generated monitor as RV_MON_<TYPE>. Nothing checks it, so a typo yields a monitor that cannot build and the tool still exits 0:
$ rvgen monitor -c da -s test_da.dot -t bogus_type -n bm
$ grep RV_MON_TYPE bm/bm.c
#define RV_MON_TYPE RV_MON_BOGUS_TYPEinclude/linux/rv.h defines only RV_MON_GLOBAL, RV_MON_PER_CPU, RV_MON_PER_TASK and RV_MON_PER_OBJ, so that macro never resolves.
The accepted set is already in Monitor.monitor_types, which the help text prints. Pass it to argparse as choices.
--- tools/verification/rvgen/__main__.py | 1 + 1 file changed, 1 insertion(+)
tools/verification/rvgen/__main__.py +1 -0
@@ -38,6 +38,7 @@ if __name__ == '__main__': monitor_parser.add_argument('-s', "--spec", dest="spec", required=True, help="Monitor specification file") monitor_parser.add_argument('-t', "--monitor_type", dest="monitor_type", required=True, + choices=list(Monitor.monitor_types.keys()), help=f"Available options: {', '.join(Monitor.monitor_types.keys())}") container_parser = subparsers.add_parser("container", parents=[parent_parser])
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v2 1/2] verification/rvgen: Validate the monitor type
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] verification/rvgen: missing Fixes: trailer for monitor_type validation --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] verification/rvgen: missing Fixes: trailer for monitor_type validation
--
commit 3e56be70e8ab6364389874866af8ed0012adb35b
Author: Chaosheng Qu <[email protected]>
Quoted 10 lines
verification/rvgen: Validate the monitor type
The monitor type is pasted into the generated monitor as RV_MON_<TYPE>. Nothing checks it, so a typo yields a monitor that cannot build and the tool still exits 0:
$ rvgen monitor -c da -s test_da.dot -t bogus_type -n bm $ grep RV_MON_TYPE bm/bm.c #define RV_MON_TYPE RV_MON_BOGUS_TYPE
Quoted 7 lines
include/linux/rv.hdefines onlyRV_MON_GLOBAL,RV_MON_PER_CPU,RV_MON_PER_TASKandRV_MON_PER_OBJ, so that macro never resolves.The accepted set is already in Monitor.monitor_types, which the help text prints. Pass it to argparse as choices.
Signed-off-by Chaosheng Qu <[email protected]>
[Severity: Low]
Monitor type validation in dot2k.__init__() was removed when monitor_types moved to the Monitor base class in cce86e03a27f ("verification/rvgen: Restructure the classes to prepare for LTL inclusion"). Should this include:
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [PATCH v2 1/2] verification/rvgen: Validate the monitor type
In reply to Chaosheng QuQuoted 8 lines · Chaosheng Qu
The monitor type is pasted into the generated monitor as RV_MON_<TYPE>. Nothing checks it, so a typo yields a monitor that cannot build and the tool still exits 0:
$ rvgen monitor -c da -s test_da.dot -t bogus_type -n bm $ grep RV_MON_TYPE bm/bm.c #define RV_MON_TYPE RV_MON_BOGUS_TYPE
Quoted 8 lines
include/linux/rv.hdefines onlyRV_MON_GLOBAL,RV_MON_PER_CPU,RV_MON_PER_TASKandRV_MON_PER_OBJ, so that macro never resolves.The accepted set is already in Monitor.monitor_types, which the help text prints. Pass it to argparse as choices.
Signed-off-by Chaosheng Qu <[email protected]>---
Looks good now, thanks. I'm taking both.
Quoted 19 lines
tools/verification/rvgen/__main__.py | 1 +
1 file changed, 1 insertion(+)tools/verification/rvgen/__main__.py +1
-0@@ -38,6 +38,7 @@ if __name__ == '__main__': monitor_parser.add_argument('-s', "--spec", dest="spec", required=True, help="Monitor specification file") monitor_parser.add_argument('-t', "--monitor_type", dest="monitor_type", required=True, + choices=list(Monitor.monitor_types.keys()), help=f"Available options: {', '.join(Monitor.monitor_types.keys())}")
container_parser=subparsers.add_parser("container", parents=[parent_parser])
PATCH v2 2/2 verification/rvgen: Cover an invalid monitor type
In reply to Chaosheng QuAdd a rejection test next to the other ones, so the new check is exercised. Without the check the command exits 0 and leaves a generated tree behind, so the test fails on both the exit code and the message.
--- tools/verification/rvgen/tests/rvgen_monitor.t | 4 ++++ 1 file changed, 4 insertions(+)
tools/verification/rvgen/tests/rvgen_monitor.t +4 -0
@@ -64,6 +64,10 @@ check "invalid monitor class" \ "$RVGEN monitor -c invalid -s tests/specs/test_da.dot -t per_cpu" 1 \ "Unknown monitor class" "Traceback (most recent call last)" +check "invalid monitor type" \ + "$RVGEN monitor -c da -s tests/specs/test_da.dot -t invalid" 2 \ + "invalid choice: 'invalid'" "Traceback (most recent call last)" + check "missing dot file" \ "$RVGEN monitor -c da -s tests/specs/nonexistent.dot -t per_cpu" 1 \ "No such file or directory" "Traceback (most recent call last)"
Signature · 1 line
2.43.0