Skip to content

Commit de228ce

Browse files
committed
config related fixes after aptos deps version bump
1 parent 3880c5a commit de228ce

File tree

3 files changed

+60
-41
lines changed

3 files changed

+60
-41
lines changed

move-mutation-test/src/cli.rs

Lines changed: 44 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
// Copyright © Aptos Foundation
33
// SPDX-License-Identifier: Apache-2.0
44

5-
use aptos::{common::types::MovePackageDir, move_tool::experiments_from_opt_level};
5+
use aptos::common::types::MovePackageOptions;
66
use aptos_framework::extended_checks;
77
use clap::Parser;
8-
use move_model::metadata::LanguageVersion;
8+
use move_model::metadata::{CompilerVersion, LanguageVersion};
99
use move_mutator::cli::{FunctionFilter, ModuleFilter};
1010
use move_package::CompilerConfig;
1111
use std::path::PathBuf;
@@ -65,27 +65,30 @@ pub fn create_mutator_options(
6565
// Info: this set struct is based on TestPackage in `aptos-core/crates/aptos/src/move_tool/mod.rs`.
6666
#[derive(Parser, Debug, Clone)]
6767
pub struct TestBuildConfig {
68-
/// Options for compiling a move package dir.
69-
// We might move some options out and have our own option struct here - not all options are
70-
// needed for mutation testing.
71-
#[clap(flatten)]
72-
pub move_pkg: MovePackageDir,
73-
74-
/// Dump storage state on failure.
75-
#[clap(long = "dump")]
76-
pub dump_state: bool,
77-
78-
/// A filter string to determine which unit tests to run.
79-
#[clap(long)]
68+
/// A filter string to determine which unit tests to run
69+
#[clap(long, short)]
8070
pub filter: Option<String>,
8171

8272
/// A boolean value to skip warnings.
8373
#[clap(long)]
8474
pub ignore_compile_warnings: bool,
8575

86-
/// Compute and then use unit test computed coverage to generate mutants only for covered code.
87-
#[clap(long = "coverage", conflicts_with = "use_generated_mutants")]
88-
pub apply_coverage: bool,
76+
#[clap(flatten)]
77+
pub(crate) move_options: MovePackageOptions,
78+
79+
/// The maximum number of instructions that can be executed by a test
80+
///
81+
/// If set, the number of instructions executed by one test will be bounded
82+
#[clap(long = "instructions", default_value_t = 100000)]
83+
pub instruction_execution_bound: u64,
84+
85+
/// Collect coverage information for later use with the various `aptos move coverage` subcommands
86+
#[clap(long = "coverage")]
87+
pub compute_coverage: bool,
88+
89+
/// Dump storage state on failure.
90+
#[clap(long = "dump")]
91+
pub dump_state: bool,
8992

9093
/// The maximum gas limit for each test.
9194
///
@@ -100,25 +103,38 @@ impl TestBuildConfig {
100103
pub fn compiler_config(&self) -> CompilerConfig {
101104
let known_attributes = extended_checks::get_all_attribute_names().clone();
102105
CompilerConfig {
103-
known_attributes,
104-
skip_attribute_checks: self.move_pkg.skip_attribute_checks,
105-
bytecode_version: get_bytecode_version(
106-
self.move_pkg.bytecode_version,
107-
self.move_pkg.language_version,
106+
known_attributes: known_attributes.clone(),
107+
skip_attribute_checks: self.move_options.skip_attribute_checks,
108+
bytecode_version: fix_bytecode_version(
109+
self.move_options.bytecode_version,
110+
self.move_options.language_version,
108111
),
109-
compiler_version: self.move_pkg.compiler_version,
110-
language_version: self.move_pkg.language_version,
111-
experiments: experiments_from_opt_level(&self.move_pkg.optimize),
112+
compiler_version: self
113+
.move_options
114+
.compiler_version
115+
.or_else(|| Some(CompilerVersion::latest_stable())),
116+
language_version: self
117+
.move_options
118+
.language_version
119+
.or_else(|| Some(LanguageVersion::latest_stable())),
120+
experiments: self.move_options.compute_experiments(),
112121
}
113122
}
114123
}
115124

116-
/// Get bytecode version.
117-
fn get_bytecode_version(
125+
fn fix_bytecode_version(
118126
bytecode_version_in: Option<u32>,
119127
language_version: Option<LanguageVersion>,
120128
) -> Option<u32> {
121-
bytecode_version_in.or_else(|| language_version.map(|lv| lv.infer_bytecode_version(None)))
129+
if bytecode_version_in.is_none() {
130+
if let Some(language_version) = language_version {
131+
Some(language_version.infer_bytecode_version(bytecode_version_in))
132+
} else {
133+
bytecode_version_in
134+
}
135+
} else {
136+
bytecode_version_in
137+
}
122138
}
123139

124140
#[cfg(test)]

move-mutation-test/src/lib.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ pub fn run_mutation_test(
5252
let _ = pretty_env_logger::try_init();
5353

5454
// Setup output dir and clone package path there.
55-
let original_package_path = test_config.move_pkg.get_package_path()?.canonicalize()?;
55+
let original_package_path = test_config
56+
.move_options
57+
.get_package_path()?
58+
.canonicalize()?;
5659
let (outdir, package_path) = setup_outdir_and_package_path(&original_package_path)?;
5760

5861
info!("Running tool the following options: {options:?} and test config: {test_config:?}");
@@ -74,17 +77,17 @@ pub fn run_mutation_test(
7477
} else {
7578
benchmarks.mutator.start();
7679
let mutator_config = BuildConfig {
77-
dev_mode: test_config.move_pkg.dev,
78-
additional_named_addresses: test_config.move_pkg.named_addresses(),
79-
full_model_generation: test_config.move_pkg.check_test_code,
80+
dev_mode: test_config.move_options.dev,
81+
additional_named_addresses: test_config.move_options.named_addresses(),
82+
full_model_generation: test_config.move_options.skip_checks_on_test_code,
8083
// No need to fetch latest deps again.
8184
skip_fetch_latest_git_deps: true,
8285
compiler_config: test_config.compiler_config(),
8386
..Default::default()
8487
};
8588
let outdir_mutant = run_mutator(
8689
options,
87-
test_config.apply_coverage,
90+
test_config.compute_coverage,
8891
&mutator_config,
8992
&package_path,
9093
&outdir,

move-mutation-test/src/mutation_test.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ pub(crate) fn run_tests_on_mutated_code(
8888

8989
// Do not calculate the coverage on mutants.
9090
let mut test_config = cfg.clone();
91-
test_config.apply_coverage = false;
91+
test_config.compute_coverage = false;
9292
test_config.ignore_compile_warnings = true;
93-
test_config.move_pkg.skip_attribute_checks = true;
93+
test_config.move_options.skip_attribute_checks = true;
9494

9595
// Rayon pool will utilize all CPU threads anyway, so one test thread per the bigger rayon
9696
// thread should be more than enough. Using more threads here slows the overall time.
@@ -118,11 +118,11 @@ fn run_tests<W: WriteColor + Send>(
118118
mut error_writer: &mut W,
119119
) -> anyhow::Result<()> {
120120
let config = BuildConfig {
121-
dev_mode: cfg.move_pkg.dev,
122-
additional_named_addresses: cfg.move_pkg.named_addresses(),
121+
dev_mode: cfg.move_options.dev,
122+
additional_named_addresses: cfg.move_options.named_addresses(),
123123
test_mode: true,
124-
full_model_generation: cfg.move_pkg.check_test_code,
125-
install_dir: cfg.move_pkg.output_dir.clone(),
124+
full_model_generation: cfg.move_options.skip_checks_on_test_code,
125+
install_dir: cfg.move_options.output_dir.clone(),
126126
skip_fetch_latest_git_deps,
127127
compiler_config: cfg.compiler_config(),
128128
..Default::default()
@@ -144,7 +144,7 @@ fn run_tests<W: WriteColor + Send>(
144144
report_statistics,
145145
num_threads,
146146
named_address_values: cfg
147-
.move_pkg
147+
.move_options
148148
.named_addresses()
149149
.iter()
150150
.map(|(name, account_address)| {
@@ -173,7 +173,7 @@ fn run_tests<W: WriteColor + Send>(
173173
)
174174
.map_err(|err| Error::msg(format!("failed to run unit tests: {err:#}")))?;
175175

176-
if cfg.apply_coverage {
176+
if cfg.compute_coverage {
177177
// Disk space optimization:
178178
let trace_path = package_path.join(".trace");
179179
// Our tool doesn't use the .trace file at all, only the .coverage_map.mvcov file, and

0 commit comments

Comments
 (0)