Skip to content

Commit

Permalink
Change the grouping of the rflx validate -v and -i arguments
Browse files Browse the repository at this point in the history
Ref. eng/recordflux/RecordFlux#1441
  • Loading branch information
andrestt committed Nov 2, 2023
1 parent 8945f7d commit f4b1bce
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 27 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Support for SPARK Pro 24.0 (eng/recordflux/RecordFlux#1409)
- Support for GNAT Pro 24.0 (eng/recordflux/RecordFlux#1443)

### Changed

- Syntax for passing repeated `-i` and `-v` options to `rflx validate` (eng/recordflux/RecordFlux#1441)

### Fixed

- User defined `GNATCOLL_ICONV_OPT` environment variable is ignored (AdaCore/RecordFlux#1289, eng/recordflux/RecordFlux#1437)
Expand Down
12 changes: 6 additions & 6 deletions doc/user_guide/20-overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ The result can be included in the list of source directories and analyzed by `gn

The Validator is available through the `rflx validate` subcommand on the command line.
It can be used to check whether a message specification correctly formalizes real-world data, or vice versa, whether a given data sample corresponds to the specification.
Two types of samples can be used: valid samples (which must be accepted by a specification) and invalid samples (which must be rejected).
Valid samples are passed as a list of values for the `-v` argument and invalid samples as a list of values for the `-i` argument.
Two types of samples can be used: valid samples which must be accepted by a specification (passed with the `-v` option) and invalid samples which must be rejected (passed with the `-i` option).
All samples must be raw binary files without any metadata.
There are two ways how samples can be provided to the tool and the same rules apply for both the `-v` and `-i` argument.
If all of the samples are in the same directory and have a `.raw` file extension, then it is sufficient to just provide this directory (or several such directories).
Otherwise, the paths of the individual sample files must be provided.
There are two ways how samples can be provided to the tool and the same rules apply for both `-v` and `-i`.
If there are several samples of the same kind in one directory and the samples have a `.raw` file extension, then it is sufficient to just provide this directory.
Otherwise, the paths of the individual sample files must be provided one by one.
In the latter case the sample file can have any extension or even have no extension.
However, if it has an extension, then it must be included in the path as well.
The list of paths can contain any combination of files and directories.
There can be as many `-v` and `-i` options given to the tool as needed.
However, each of those options must have exactly one argument.
Raw packets can, e.g., be exported from packet analyzers like Wireshark or extracted from a PCAP file using `this script <https://github.com/AdaCore/RecordFlux/blob/main/tools/extract_packets.py>`__.
To facilitate execution within a CI/CD pipeline, the `--abort-on-error` switch causes the tool to exit with an error code if any samples are rejected.
Upon completion, the Validator will produce a report, with an option to display how much of a message has been covered:
Expand Down
16 changes: 7 additions & 9 deletions doc/user_guide/90-rflx-validate--help.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
usage: rflx validate [-h] [--split-disjunctions]
[-v VALID_SAMPLES_PATHS [VALID_SAMPLES_PATHS ...]]
[-i INVALID_SAMPLES_PATHS [INVALID_SAMPLES_PATHS ...]]
[-c CHECKSUM_MODULE] [-o OUTPUT_FILE] [--abort-on-error]
[--coverage] [--target-coverage PERCENTAGE]
usage: rflx validate [-h] [--split-disjunctions] [-v VALID_SAMPLE_PATH]
[-i INVALID_SAMPLE_PATH] [-c CHECKSUM_MODULE]
[-o OUTPUT_FILE] [--abort-on-error] [--coverage]
[--target-coverage PERCENTAGE]
SPECIFICATION_FILE MESSAGE_IDENTIFIER

positional arguments:
SPECIFICATION_FILE specification file
MESSAGE_IDENTIFIER identifier of the top-level message (e.g.,
Package::Message)

options:
optional arguments:
-h, --help show this help message and exit
--split-disjunctions split disjunctions before model validation (may have
severe performance impact)
-v VALID_SAMPLES_PATHS [VALID_SAMPLES_PATHS ...]
known valid sample files or directories
-i INVALID_SAMPLES_PATHS [INVALID_SAMPLES_PATHS ...]
-v VALID_SAMPLE_PATH known valid sample files or directories
-i INVALID_SAMPLE_PATH
known invalid sample files or directories
-c CHECKSUM_MODULE name of the module containing the checksum functions
-o OUTPUT_FILE path to output file for validation report in JSON
Expand Down
18 changes: 8 additions & 10 deletions rflx/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,20 +287,18 @@ def main( # noqa: PLR0915
)
parser_validate.add_argument(
"-v",
action=UniqueStore,
dest="valid_samples_paths",
nargs="+",
action="append",
dest="valid_sample_path",
type=Path,
help="known valid sample files or directories",
help="known valid sample file or directory",
default=None,
)
parser_validate.add_argument(
"-i",
action=UniqueStore,
nargs="+",
dest="invalid_samples_paths",
action="append",
dest="invalid_sample_path",
type=Path,
help="known invalid sample files or directories",
help="known invalid sample file or directory",
default=None,
)
parser_validate.add_argument(
Expand Down Expand Up @@ -596,8 +594,8 @@ def validate(args: argparse.Namespace) -> None:
args.split_disjunctions,
).validate(
identifier,
args.invalid_samples_paths,
args.valid_samples_paths,
args.invalid_sample_path,
args.valid_sample_path,
args.output_file,
args.abort_on_error,
args.coverage,
Expand Down
61 changes: 59 additions & 2 deletions tests/unit/cli_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,65 @@ def test_main_validate_required_arg_not_provided(tmp_path: Path) -> None:
)


def test_main_validate(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
monkeypatch.setattr(validator.Validator, "__init__", lambda _a, _b, _c, _d, _e: None)
monkeypatch.setattr(
validator.Validator,
"validate",
lambda _a, _b, _c, _d, _e, _f, _g, _h: None,
)
assert (
cli.main(
# The positional and optional arguments are intentionally mixed
# below so that a positional argument appears after the "-i" and its
# value. '-i' and '-v' occur intentionally multiple times.
[
"rflx",
"validate",
"-v",
str(tmp_path),
"-i",
str(tmp_path),
"-v",
str(tmp_path),
"-i",
str(tmp_path),
str(tmp_path / "test.rflx"),
"Test::Message",
"--split-disjunctions",
"--abort-on-error",
"--coverage",
"-c",
"CHECKSUM_MODULE",
"-o",
str(tmp_path),
"--target-coverage",
"99",
],
)
== 0
)
assert (
cli.main(
# The positional and optional arguments are intentionally mixed
# below so that a positional argument appears after the "-v" and its
# value.
[
"rflx",
"validate",
"-v",
str(tmp_path),
str(tmp_path / "test.rflx"),
"Test::Message",
"--split-disjunctions",
"-i",
str(tmp_path),
],
)
== 0
)


def test_main_validate_invalid_identifier(tmp_path: Path) -> None:
assert (
cli.main(
Expand Down Expand Up @@ -652,8 +711,6 @@ def raise_argparse_error(self, message: str) -> None:
(call_generate, "--integration-files-dir", "OTHER_STR", []),
(call_graph, "-f", "png", []),
(call_graph, "-d", "OTHER_STR", []),
(call_validate, "-v", "OTHER_STR", []),
(call_validate, "-i", "OTHER_STR", []),
(call_validate, "-c", "OTHER_STR", []),
(call_validate, "-o", "OTHER_STR", []),
(call_validate, "--target-coverage", "75", []),
Expand Down

0 comments on commit f4b1bce

Please sign in to comment.