Skip to content

Commit 5f14b73

Browse files
author
Carolyn Zech
authored
Improve Help Menu (#4109)
1. Group options by category. We already have structs in the source code to do this (e.g. `CommonArgs`), so I just followed that structure. The goal is to make it easier for users to tell what the options do--I don't think it's currently clear that some of these arguments are for Cargo, for example. Open to bikeshedding on the section names--I think "Common Options" is a bit vague but couldn't think of anything better. 2. For each category, put its entries in alphabetical order. New output from `cargo kani -h` below. Note that #4110 will hide some of these options. ``` cmzech@80a9971b5e20 playground % cargo kani -h Verify a Rust crate. For more information, see https://github.com/model-checking/kani Usage: cargo-kani [OPTIONS] [COMMAND] Commands: autoharness Create and run harnesses automatically for eligible functions. Implies -Z function-contracts and -Z loop-contracts. See https://model-checking.github.io/kani/reference/experimental/autoharness.html for documentation list List contracts and harnesses playback Execute concrete playback testcases of a local package help Print this message or the help of the given subcommand(s) Options: -h, --help Print help (see more with '--help') -V, --version Print version Verification Options: --cbmc-args [<CBMC_ARGS>...] Pass through directly to CBMC; must be the last flag. This feature is unstable and it requires `-Z unstable-options` to be used --concrete-playback <CONCRETE_PLAYBACK> Generate concrete playback unit test. If value supplied is 'print', Kani prints the unit test to stdout. If value supplied is 'inplace', Kani automatically adds the unit test to your source code. This option does not work with `--output-format old` [possible values: print, inplace] --default-unwind <DEFAULT_UNWIND> Specify the value used for loop unwinding in CBMC --exact When specified, the harness filter will only match the exact fully qualified name of a harness --fail-fast Stop the verification process as soon as one of the harnesses fails --force-build Force Kani to rebuild all packages before the verification --harness <HARNESS_FILTER> If specified, only run harnesses that match this filter. This option can be provided multiple times, which will run all tests matching any of the filters. If used with --exact, the harness filter will only match the exact fully qualified name of a harness --harness-timeout <HARNESS_TIMEOUT> Timeout for each harness with optional suffix ('s': seconds, 'm': minutes, 'h': hours). Default is seconds. This option is experimental and requires `-Z unstable-options` to be used --no-assertion-reach-checks Turn off assertion reachability checks --output-format <OUTPUT_FORMAT> Toggle between different styles of output [default: regular] [possible values: regular, terse, old] --randomize-layout [<RANDOMIZE_LAYOUT>] Randomize the layout of structures. This option can help catching code that relies on a specific layout chosen by the compiler that is not guaranteed to be stable in the future. If a value is given, it will be used as the seed for randomization See the `-Z randomize-layout` and `-Z layout-seed` arguments of the rust compiler --solver <SOLVER> Specify the CBMC solver to use. Overrides the harness `solver` attribute. If no solver is specified (with --solver or harness attribute), Kani will use CaDiCaL [possible values: cadical, kissat, minisat, bin=<SAT_SOLVER_BINARY>] --target-dir <TARGET_DIR> Directory for all generated artifacts --tests Enable test function verification. Only use this option when the entry point is a test function --unwind <UNWIND> Specify the value used for loop unwinding for the specified harness in CBMC Memory Checks: --default-checks Turn on all default checks --no-default-checks Turn off all default checks --memory-safety-checks Turn on default memory safety checks --no-memory-safety-checks Turn off default memory safety checks --overflow-checks Turn on default overflow checks --no-overflow-checks Turn off default overflow checks --undefined-function-checks Turn on undefined function checks --no-undefined-function-checks Turn off undefined function checks --unwinding-checks Turn on default unwinding checks --no-unwinding-checks Turn off default unwinding checks Common Options: --debug Produce full debug information -q, --quiet Produces no output, just an exit code and requested artifacts; overrides --verbose -v, --verbose Output processing stages and commands, along with minor debug information -Z, --unstable <UNSTABLE_FEATURE> [possible values: async-lib, autoharness, concrete-playback, c-ffi, float-lib, function-contracts, gen-c, ghost-state, lean, list, loop-contracts, mem-predicates, restrict-vtable, source-coverage, stubbing, uninit-checks, unstable-options, valid-value-checks] Cargo Common Options: --all-features Activate all package features -e, --exclude <EXCLUDE>... Exclude the specified packages -F, --features <FEATURES> Comma separated list of package features to activate --manifest-path <PATH> Path to Cargo.toml --no-default-features Do not activate the `default` feature -p, --package <PACKAGE>... Run Kani on the specified packages (see `cargo help pkgid` for the accepted format) --workspace Build all packages in the workspace Cargo Target Options: --bin <BIN> Check only the specified binary target --bins Check all binaries --lib Check only the package's library unit tests ``` Resolves #1951 By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.
1 parent 9d31d52 commit 5f14b73

4 files changed

Lines changed: 152 additions & 138 deletions

File tree

kani-driver/src/args/cargo.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ use std::path::PathBuf;
1212
/// These do not (currently) include cargo args that kani pays special attention to:
1313
/// for instance, we keep `--tests` and `--target-dir` elsewhere.
1414
#[derive(Debug, Default, clap::Args)]
15+
#[clap(next_help_heading = "Cargo Common Options")]
1516
pub struct CargoCommonArgs {
1617
/// Activate all package features
1718
#[arg(long)]
1819
pub all_features: bool,
19-
/// Do not activate the `default` feature
20-
#[arg(long)]
21-
pub no_default_features: bool,
20+
21+
/// Exclude the specified packages
22+
#[arg(long, short, requires("workspace"), conflicts_with("package"), num_args(1..))]
23+
pub exclude: Vec<String>,
2224

2325
// This tolerates spaces too, but we say "comma" only because this is the least error-prone approach...
2426
/// Comma separated list of package features to activate
@@ -29,17 +31,17 @@ pub struct CargoCommonArgs {
2931
#[arg(long, name = "PATH")]
3032
pub manifest_path: Option<PathBuf>,
3133

32-
/// Build all packages in the workspace
34+
/// Do not activate the `default` feature
3335
#[arg(long)]
34-
pub workspace: bool,
36+
pub no_default_features: bool,
3537

3638
/// Run Kani on the specified packages (see `cargo help pkgid` for the accepted format)
3739
#[arg(long, short, conflicts_with("workspace"), num_args(1..))]
3840
pub package: Vec<String>,
3941

40-
/// Exclude the specified packages
41-
#[arg(long, short, requires("workspace"), conflicts_with("package"), num_args(1..))]
42-
pub exclude: Vec<String>,
42+
/// Build all packages in the workspace
43+
#[arg(long)]
44+
pub workspace: bool,
4345
}
4446

4547
impl CargoCommonArgs {
@@ -98,6 +100,7 @@ impl ValidateArgs for CargoCommonArgs {
98100
/// See <https://doc.rust-lang.org/cargo/commands/cargo-test.html#target-selection> for more
99101
/// details.
100102
#[derive(Debug, Default, clap::Args)]
103+
#[clap(next_help_heading = "Cargo Target Options")]
101104
pub struct CargoTargetArgs {
102105
/// Check only the specified binary target.
103106
#[arg(long)]

kani-driver/src/args/common.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub use kani_metadata::{EnabledUnstableFeatures, UnstableFeature};
77

88
/// Common Kani arguments that we expect to be included in most subcommands.
99
#[derive(Debug, clap::Args)]
10+
#[clap(next_help_heading = "Common Options")]
1011
pub struct CommonArgs {
1112
/// Produce full debug information
1213
#[arg(long)]

kani-driver/src/args/mod.rs

Lines changed: 113 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,14 @@ pub struct StandaloneArgs {
141141
/// When no subcommand is provided, there is an implied verification subcommand.
142142
#[derive(Debug, clap::Subcommand)]
143143
pub enum StandaloneSubcommand {
144+
/// Create and run harnesses automatically for eligible functions. Implies -Z function-contracts and -Z loop-contracts.
145+
Autoharness(Box<autoharness_args::StandaloneAutoharnessArgs>),
146+
/// List contracts and harnesses.
147+
List(Box<list_args::StandaloneListArgs>),
144148
/// Execute concrete playback testcases of a local crate.
145149
Playback(Box<playback_args::KaniPlaybackArgs>),
146150
/// Verify the rust standard library.
147151
VerifyStd(Box<std_args::VerifyStdArgs>),
148-
/// List contracts and harnesses.
149-
List(Box<list_args::StandaloneListArgs>),
150-
/// Create and run harnesses automatically for eligible functions. Implies -Z function-contracts and -Z loop-contracts.
151-
Autoharness(Box<autoharness_args::StandaloneAutoharnessArgs>),
152152
}
153153

154154
#[derive(Debug, clap::Parser)]
@@ -172,102 +172,95 @@ pub enum CargoKaniSubcommand {
172172
#[command(hide = true)]
173173
Assess(Box<crate::assess::AssessArgs>),
174174

175-
/// Execute concrete playback testcases of a local package.
176-
Playback(Box<playback_args::CargoPlaybackArgs>),
175+
/// Create and run harnesses automatically for eligible functions. Implies -Z function-contracts and -Z loop-contracts.
176+
/// See https://model-checking.github.io/kani/reference/experimental/autoharness.html for documentation.
177+
Autoharness(Box<autoharness_args::CargoAutoharnessArgs>),
177178

178179
/// List contracts and harnesses.
179180
List(Box<list_args::CargoListArgs>),
180181

181-
/// Create and run harnesses automatically for eligible functions. Implies -Z function-contracts and -Z loop-contracts.
182-
/// See https://model-checking.github.io/kani/reference/experimental/autoharness.html for documentation.
183-
Autoharness(Box<autoharness_args::CargoAutoharnessArgs>),
182+
/// Execute concrete playback testcases of a local package.
183+
Playback(Box<playback_args::CargoPlaybackArgs>),
184184
}
185185

186186
// Common arguments for invoking Kani for verification purpose. This gets put into KaniContext,
187187
// whereas anything above is "local" to "main"'s control flow.
188188
#[derive(Debug, clap::Args)]
189+
#[clap(next_help_heading = "Verification Options")]
189190
pub struct VerificationArgs {
190191
/// Temporary option to trigger assess mode for out test suite
191192
/// where we are able to add options but not subcommands
192193
#[arg(long, hide = true)]
193194
pub assess: bool,
194195

196+
/// Link external C files referenced by Rust code.
197+
/// This is an experimental feature and requires `-Z c-ffi` to be used
198+
#[arg(long, hide = true, num_args(1..))]
199+
pub c_lib: Vec<PathBuf>,
200+
201+
/// Pass through directly to CBMC; must be the last flag.
202+
/// This feature is unstable and it requires `-Z unstable-options` to be used
203+
#[arg(
204+
long,
205+
allow_hyphen_values = true,
206+
num_args(0..)
207+
)]
208+
// consumes everything
209+
pub cbmc_args: Vec<OsString>,
210+
195211
/// Generate concrete playback unit test.
196212
/// If value supplied is 'print', Kani prints the unit test to stdout.
197213
/// If value supplied is 'inplace', Kani automatically adds the unit test to your source code.
198214
/// This option does not work with `--output-format old`.
199215
#[arg(long, ignore_case = true, value_enum)]
200216
pub concrete_playback: Option<ConcretePlaybackMode>,
201-
/// Keep temporary files generated throughout Kani process. This is already the default
202-
/// behavior for `cargo-kani`.
217+
218+
/// Enable Kani coverage output alongside verification result
203219
#[arg(long, hide_short_help = true)]
204-
pub keep_temps: bool,
220+
pub coverage: bool,
205221

206-
/// Generate C file equivalent to inputted program for debug purpose.
207-
/// This feature is unstable, and it requires `-Z unstable-options` to be used
222+
/// Specify the value used for loop unwinding in CBMC
223+
#[arg(long)]
224+
pub default_unwind: Option<u32>,
225+
226+
/// When specified, the harness filter will only match the exact fully qualified name of a harness
227+
#[arg(long, requires("harnesses"))]
228+
pub exact: bool,
229+
230+
/// Enable extra pointer checks such as invalid pointers in relation operations and pointer
231+
/// arithmetic overflow.
232+
/// This feature is unstable and it may yield false counter examples. It requires
233+
/// `-Z unstable-options` to be used
208234
#[arg(long, hide_short_help = true)]
209-
pub gen_c: bool,
235+
pub extra_pointer_checks: bool,
210236

211-
/// Directory for all generated artifacts.
237+
/// Stop the verification process as soon as one of the harnesses fails.
212238
#[arg(long)]
213-
pub target_dir: Option<PathBuf>,
239+
pub fail_fast: bool,
214240

215241
/// Force Kani to rebuild all packages before the verification.
216242
#[arg(long)]
217243
pub force_build: bool,
218244

219-
/// Toggle between different styles of output
220-
#[arg(long, default_value = "regular", ignore_case = true, value_enum)]
221-
pub output_format: OutputFormat,
222-
223-
#[command(flatten)]
224-
pub checks: CheckArgs,
245+
/// Generate C file equivalent to inputted program for debug purpose.
246+
/// This feature is unstable, and it requires `-Z unstable-options` to be used
247+
#[arg(long, hide_short_help = true)]
248+
pub gen_c: bool,
225249

226250
/// If specified, only run harnesses that match this filter. This option can be provided
227251
/// multiple times, which will run all tests matching any of the filters.
228252
/// If used with --exact, the harness filter will only match the exact fully qualified name of a harness.
229253
#[arg(long = "harness", num_args(1), value_name = "HARNESS_FILTER")]
230254
pub harnesses: Vec<String>,
231255

232-
/// When specified, the harness filter will only match the exact fully qualified name of a harness
233-
#[arg(long, requires("harnesses"))]
234-
pub exact: bool,
235-
236-
/// Link external C files referenced by Rust code.
237-
/// This is an experimental feature and requires `-Z c-ffi` to be used
238-
#[arg(long, hide = true, num_args(1..))]
239-
pub c_lib: Vec<PathBuf>,
240-
/// Enable test function verification. Only use this option when the entry point is a test function
256+
/// Timeout for each harness with optional suffix ('s': seconds, 'm': minutes, 'h': hours). Default is seconds. This option is experimental and requires `-Z unstable-options` to be used.
241257
#[arg(long)]
242-
pub tests: bool,
243-
/// Kani will only compile the crate. No verification will be performed
244-
#[arg(long, hide_short_help = true)]
245-
pub only_codegen: bool,
258+
pub harness_timeout: Option<Timeout>,
246259

247-
/// Run Kani without codegen. Useful for quick feedback on whether the code would compile successfully (similar to `cargo check`).
248-
/// This feature is unstable and requires `-Z unstable-options` to be used
260+
/// Do not error out for crates containing `global_asm!`.
261+
/// This option may impact the soundness of the analysis and may cause false proofs and/or counterexamples
249262
#[arg(long, hide_short_help = true)]
250-
pub no_codegen: bool,
251-
252-
/// Specify the value used for loop unwinding in CBMC
253-
#[arg(long)]
254-
pub default_unwind: Option<u32>,
255-
/// Specify the value used for loop unwinding for the specified harness in CBMC
256-
#[arg(long, requires("harnesses"))]
257-
pub unwind: Option<u32>,
258-
/// Specify the CBMC solver to use. Overrides the harness `solver` attribute.
259-
/// If no solver is specified (with --solver or harness attribute), Kani will use CaDiCaL.
260-
#[arg(long, value_parser = CbmcSolverValueParser::new(CbmcSolver::VARIANTS))]
261-
pub solver: Option<CbmcSolver>,
262-
/// Pass through directly to CBMC; must be the last flag.
263-
/// This feature is unstable and it requires `-Z unstable-options` to be used
264-
#[arg(
265-
long,
266-
allow_hyphen_values = true,
267-
num_args(0..)
268-
)]
269-
// consumes everything
270-
pub cbmc_args: Vec<OsString>,
263+
pub ignore_global_asm: bool,
271264

272265
/// Number of threads to spawn to verify harnesses in parallel.
273266
/// Omit the flag entirely to run sequentially (i.e. one thread).
@@ -276,80 +269,99 @@ pub struct VerificationArgs {
276269
#[arg(short, long, hide_short_help = true)]
277270
pub jobs: Option<Option<usize>>,
278271

279-
/// Enable extra pointer checks such as invalid pointers in relation operations and pointer
280-
/// arithmetic overflow.
281-
/// This feature is unstable and it may yield false counter examples. It requires
282-
/// `-Z unstable-options` to be used
272+
/// Keep temporary files generated throughout Kani process. This is already the default
273+
/// behavior for `cargo-kani`.
283274
#[arg(long, hide_short_help = true)]
284-
pub extra_pointer_checks: bool,
275+
pub keep_temps: bool,
285276

286-
/// Restrict the targets of virtual table function pointer calls.
287-
/// This feature is unstable and it requires `-Z restrict-vtable` to be used
288-
#[arg(long, hide = true, conflicts_with = "no_restrict_vtable")]
289-
pub restrict_vtable: bool,
290-
/// Disable restricting the targets of virtual table function pointer calls
277+
/// Do not assert the function contracts of dependencies. Requires -Z function-contracts.
291278
#[arg(long, hide_short_help = true)]
292-
pub no_restrict_vtable: bool,
279+
pub no_assert_contracts: bool,
280+
293281
/// Turn off assertion reachability checks
294282
#[arg(long)]
295283
pub no_assertion_reach_checks: bool,
296284

297-
/// Do not error out for crates containing `global_asm!`.
298-
/// This option may impact the soundness of the analysis and may cause false proofs and/or counterexamples
285+
/// Run Kani without codegen. Useful for quick feedback on whether the code would compile successfully (similar to `cargo check`).
286+
/// This feature is unstable and requires `-Z unstable-options` to be used
299287
#[arg(long, hide_short_help = true)]
300-
pub ignore_global_asm: bool,
301-
302-
/// Write the GotoC symbol table to a file in JSON format instead of goto binary format.
303-
#[arg(long, hide = true)]
304-
pub write_json_symtab: bool,
288+
pub no_codegen: bool,
305289

306-
/// Execute CBMC's sanity checks to ensure the goto-program we generate is correct.
290+
/// Disable restricting the targets of virtual table function pointer calls
307291
#[arg(long, hide_short_help = true)]
308-
pub run_sanity_checks: bool,
292+
pub no_restrict_vtable: bool,
309293

310294
/// Disable CBMC's slice formula which prevents values from being assigned to redundant variables in traces.
311295
#[arg(long, hide_short_help = true)]
312296
pub no_slice_formula: bool,
313297

314-
/// Synthesize loop contracts for all loops.
315-
#[arg(
316-
long,
317-
hide_short_help = true,
318-
conflicts_with("unwind"),
319-
conflicts_with("default_unwind")
320-
)]
321-
pub synthesize_loop_contracts: bool,
322-
323-
/// Do not assert the function contracts of dependencies. Requires -Z function-contracts.
298+
/// Kani will only compile the crate. No verification will be performed
324299
#[arg(long, hide_short_help = true)]
325-
pub no_assert_contracts: bool,
300+
pub only_codegen: bool,
301+
302+
/// Toggle between different styles of output
303+
#[arg(long, default_value = "regular", ignore_case = true, value_enum)]
304+
pub output_format: OutputFormat,
326305

327-
//Harness Output into individual files
306+
/// Write verification results into per-harness files, rather than to stdout
328307
#[arg(long, hide_short_help = true)]
329308
pub output_into_files: bool,
330309

310+
/// Print final LLBC for Lean backend. This requires the `-Z lean` option.
311+
#[arg(long, hide = true)]
312+
pub print_llbc: bool,
313+
331314
/// Randomize the layout of structures. This option can help catching code that relies on
332315
/// a specific layout chosen by the compiler that is not guaranteed to be stable in the future.
333316
/// If a value is given, it will be used as the seed for randomization
334317
/// See the `-Z randomize-layout` and `-Z layout-seed` arguments of the rust compiler.
335318
#[arg(long)]
336319
pub randomize_layout: Option<Option<u64>>,
337320

338-
/// Enable Kani coverage output alongside verification result
321+
/// Restrict the targets of virtual table function pointer calls.
322+
/// This feature is unstable and it requires `-Z restrict-vtable` to be used
323+
#[arg(long, hide = true, conflicts_with = "no_restrict_vtable")]
324+
pub restrict_vtable: bool,
325+
326+
/// Execute CBMC's sanity checks to ensure the goto-program we generate is correct.
339327
#[arg(long, hide_short_help = true)]
340-
pub coverage: bool,
328+
pub run_sanity_checks: bool,
341329

342-
/// Print final LLBC for Lean backend. This requires the `-Z lean` option.
343-
#[arg(long, hide = true)]
344-
pub print_llbc: bool,
330+
/// Specify the CBMC solver to use. Overrides the harness `solver` attribute.
331+
/// If no solver is specified (with --solver or harness attribute), Kani will use CaDiCaL.
332+
#[arg(long, value_parser = CbmcSolverValueParser::new(CbmcSolver::VARIANTS))]
333+
pub solver: Option<CbmcSolver>,
345334

346-
/// Timeout for each harness with optional suffix ('s': seconds, 'm': minutes, 'h': hours). Default is seconds. This option is experimental and requires `-Z unstable-options` to be used.
335+
/// Synthesize loop contracts for all loops.
336+
#[arg(
337+
long,
338+
hide_short_help = true,
339+
conflicts_with("unwind"),
340+
conflicts_with("default_unwind")
341+
)]
342+
pub synthesize_loop_contracts: bool,
343+
344+
/// Directory for all generated artifacts.
347345
#[arg(long)]
348-
pub harness_timeout: Option<Timeout>,
346+
pub target_dir: Option<PathBuf>,
349347

350-
/// Stop the verification process as soon as one of the harnesses fails.
348+
/// Enable test function verification. Only use this option when the entry point is a test function
351349
#[arg(long)]
352-
pub fail_fast: bool,
350+
pub tests: bool,
351+
352+
/// Specify the value used for loop unwinding for the specified harness in CBMC
353+
#[arg(long, requires("harnesses"))]
354+
pub unwind: Option<u32>,
355+
356+
/// Write the GotoC symbol table to a file in JSON format instead of goto binary format.
357+
#[arg(long, hide = true)]
358+
pub write_json_symtab: bool,
359+
360+
#[command(flatten)]
361+
pub checks: CheckArgs,
362+
363+
#[command(flatten)]
364+
pub common_args: CommonArgs,
353365

354366
/// Arguments to pass down to Cargo
355367
#[command(flatten)]
@@ -358,9 +370,6 @@ pub struct VerificationArgs {
358370
/// Arguments used to select Cargo target.
359371
#[command(flatten)]
360372
pub target: CargoTargetArgs,
361-
362-
#[command(flatten)]
363-
pub common_args: CommonArgs,
364373
}
365374

366375
impl VerificationArgs {
@@ -421,6 +430,7 @@ pub enum OutputFormat {
421430
}
422431

423432
#[derive(Debug, clap::Args)]
433+
#[clap(next_help_heading = "Memory Checks")]
424434
pub struct CheckArgs {
425435
// Rust argument parsers (/clap) don't have the convenient '--flag' and '--no-flag' boolean pairs, so approximate
426436
// We're put both here then create helper functions to "intepret"

0 commit comments

Comments
 (0)