Skip to content

Commit 6413277

Browse files
authored
Dev m3 (#138)
* feat: remove verify_mutants (#136) * feat: remove verify_mutants * fix: remove this test that is now obsolete * fix: tests * Feat/fail fast (#137) * feat: make work on aptos main branch * feat: fail-fast * chore: switch to aptos 1.38 release branch * chore: update lock file * fix: improve doc comment * bump to aptos v1.38.2
1 parent 81c5980 commit 6413277

File tree

13 files changed

+558
-608
lines changed

13 files changed

+558
-608
lines changed

Cargo.lock

Lines changed: 482 additions & 441 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ rust-version = "1.86.0"
2222
[workspace.dependencies]
2323
ahash = "0.8"
2424
anyhow = "1.0"
25-
aptos = { git = "https://github.com/aptos-labs/aptos-core.git", branch = "aptos-release-v1.35" }
26-
aptos-framework = { git = "https://github.com/aptos-labs/aptos-core.git", branch = "aptos-release-v1.35" }
27-
aptos-gas-schedule = { git = "https://github.com/aptos-labs/aptos-core.git", branch = "aptos-release-v1.35" }
28-
aptos-types = { git = "https://github.com/aptos-labs/aptos-core.git", branch = "aptos-release-v1.35" }
29-
aptos-vm = { git = "https://github.com/aptos-labs/aptos-core.git", branch = "aptos-release-v1.35" }
25+
aptos = { git = "https://github.com/aptos-labs/aptos-core.git", branch = "aptos-release-v1.38" }
26+
aptos-framework = { git = "https://github.com/aptos-labs/aptos-core.git", branch = "aptos-release-v1.38" }
27+
aptos-gas-schedule = { git = "https://github.com/aptos-labs/aptos-core.git", branch = "aptos-release-v1.38" }
28+
aptos-types = { git = "https://github.com/aptos-labs/aptos-core.git", branch = "aptos-release-v1.38" }
29+
aptos-vm = { git = "https://github.com/aptos-labs/aptos-core.git", branch = "aptos-release-v1.38" }
3030
clap = { version = "4.5", features = ["derive"] }
3131
codespan = "0.11"
3232
codespan-reporting = "0.11"
@@ -36,21 +36,21 @@ either = "1.9"
3636
fs_extra = "1.3"
3737
itertools = "0.13"
3838
log = "0.4"
39-
move-binary-format = { git = "https://github.com/aptos-labs/aptos-core.git", branch = "aptos-release-v1.35" }
40-
move-bytecode-source-map = { git = "https://github.com/aptos-labs/aptos-core.git", branch = "aptos-release-v1.35" }
41-
move-cli = { git = "https://github.com/aptos-labs/aptos-core.git", branch = "aptos-release-v1.35" }
42-
move-command-line-common = { git = "https://github.com/aptos-labs/aptos-core.git", branch = "aptos-release-v1.35" }
43-
legacy-move-compiler = { git = "https://github.com/aptos-labs/aptos-core.git", branch = "aptos-release-v1.35" }
44-
move-compiler-v2 = { git = "https://github.com/aptos-labs/aptos-core.git", branch = "aptos-release-v1.35" }
45-
move-coverage = { git = "https://github.com/aptos-labs/aptos-core.git", branch = "aptos-release-v1.35" }
46-
move-ir-types = { git = "https://github.com/aptos-labs/aptos-core.git", branch = "aptos-release-v1.35" }
47-
move-model = { git = "https://github.com/aptos-labs/aptos-core.git", branch = "aptos-release-v1.35" }
39+
move-binary-format = { git = "https://github.com/aptos-labs/aptos-core.git", branch = "aptos-release-v1.38" }
40+
move-bytecode-source-map = { git = "https://github.com/aptos-labs/aptos-core.git", branch = "aptos-release-v1.38" }
41+
move-cli = { git = "https://github.com/aptos-labs/aptos-core.git", branch = "aptos-release-v1.38" }
42+
move-command-line-common = { git = "https://github.com/aptos-labs/aptos-core.git", branch = "aptos-release-v1.38" }
43+
legacy-move-compiler = { git = "https://github.com/aptos-labs/aptos-core.git", branch = "aptos-release-v1.38" }
44+
move-compiler-v2 = { git = "https://github.com/aptos-labs/aptos-core.git", branch = "aptos-release-v1.38" }
45+
move-coverage = { git = "https://github.com/aptos-labs/aptos-core.git", branch = "aptos-release-v1.38" }
46+
move-ir-types = { git = "https://github.com/aptos-labs/aptos-core.git", branch = "aptos-release-v1.38" }
47+
move-model = { git = "https://github.com/aptos-labs/aptos-core.git", branch = "aptos-release-v1.38" }
4848
move-mutator = { path = "move-mutator" }
49-
move-package = { git = "https://github.com/aptos-labs/aptos-core.git", branch = "aptos-release-v1.35" }
50-
move-prover = { git = "https://github.com/aptos-labs/aptos-core.git", branch = "aptos-release-v1.35" }
51-
move-symbol-pool = { git = "https://github.com/aptos-labs/aptos-core.git", branch = "aptos-release-v1.35" }
52-
move-unit-test = { git = "https://github.com/aptos-labs/aptos-core.git", branch = "aptos-release-v1.35" }
53-
move-vm-runtime = { git = "https://github.com/aptos-labs/aptos-core.git", branch = "aptos-release-v1.35" }
49+
move-package = { git = "https://github.com/aptos-labs/aptos-core.git", branch = "aptos-release-v1.38" }
50+
move-prover = { git = "https://github.com/aptos-labs/aptos-core.git", branch = "aptos-release-v1.38" }
51+
move-symbol-pool = { git = "https://github.com/aptos-labs/aptos-core.git", branch = "aptos-release-v1.38" }
52+
move-unit-test = { git = "https://github.com/aptos-labs/aptos-core.git", branch = "aptos-release-v1.38" }
53+
move-vm-runtime = { git = "https://github.com/aptos-labs/aptos-core.git", branch = "aptos-release-v1.38" }
5454
mutator-common = { path = "mutator-common" }
5555
num = "0.4"
5656
num-traits = "0.2"
@@ -63,11 +63,12 @@ serde_json = "1"
6363
stacker = "0.1"
6464
tabled = "0.16"
6565
tempfile = "3.12"
66-
termcolor = "1.1" # aptos deps require 1.1 here
66+
termcolor = "1.1" # aptos deps require 1.1 here
6767

6868
# These below are necessary for some aptos deps
6969
[patch.crates-io]
7070
merlin = { git = "https://github.com/aptos-labs/merlin" }
71+
jemalloc-sys = { git = "https://github.com/aptos-labs/jemalloc-sys-shim", rev = "e0920246dd74303fab9a14b990768c6ac990a59b" }
7172

7273
[patch."https://github.com/aptos-labs/aptos-core.git"]
7374
poem = "=3.1.3"

move-mutation-test/src/cli.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ pub fn create_mutator_options(
8282
mutate_modules: options.mutate_modules.clone(),
8383
downsampling_ratio_percentage: options.downsampling_ratio_percentage,
8484
apply_coverage,
85-
// To run tests, compilation must succeed
86-
verify_mutants: true,
8785
mode: options.mode,
8886
operators: options.operators.clone(),
8987
..Default::default()
@@ -119,6 +117,10 @@ pub struct TestBuildConfig {
119117
/// The default value is large enough for all normal tests in most projects.
120118
#[clap(long, default_value_t = 1_000_000)]
121119
pub gas_limit: u64,
120+
121+
/// Whether to stop running test for the current mutant upon the first test failure for the mutant.
122+
#[clap(long, default_value_t = true, action = clap::ArgAction::Set)]
123+
pub fail_fast: bool,
122124
}
123125

124126
impl TestBuildConfig {
@@ -141,6 +143,7 @@ impl TestBuildConfig {
141143
.language_version
142144
.or_else(|| Some(LanguageVersion::latest_stable())),
143145
experiments: self.move_options.compute_experiments(),
146+
print_errors: false,
144147
}
145148
}
146149
}

move-mutation-test/src/mutation_test.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ fn run_tests<W: WriteColor + Send>(
154154
)
155155
})
156156
.collect(),
157+
fail_fast: cfg.fail_fast,
157158
..UnitTestingConfig::default()
158159
},
159160
natives,
@@ -170,6 +171,7 @@ fn run_tests<W: WriteColor + Send>(
170171
// once_cell value above and then we can't change it back anymore.
171172
false,
172173
&mut error_writer,
174+
true,
173175
)
174176
.map_err(|err| Error::msg(format!("failed to run unit tests: {err:#}")))?;
175177

move-mutation-test/tests/integration_tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ fn test_run_mutation_test(path: &Path, expected_report: String) -> datatest_stab
3434
ignore_compile_warnings: false,
3535
compute_coverage: false,
3636
gas_limit: 2000,
37+
fail_fast: true,
3738
};
3839

3940
let report_file = PathBuf::from("report.txt");

move-mutator/src/cli.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ pub struct CLIOptions {
3636
#[clap(long, value_parser)]
3737
pub out_mutant_dir: Option<PathBuf>,
3838

39-
/// Indicates if mutants should be verified and made sure mutants can compile.
40-
#[clap(long, default_value = "false", conflicts_with = "move_sources")]
41-
pub verify_mutants: bool,
42-
4339
/// Indicates if the output files should be overwritten.
4440
#[clap(long, default_value = "false")]
4541
pub no_overwrite: bool,
@@ -104,7 +100,6 @@ impl Default for CLIOptions {
104100
mutate_modules: ModuleFilter::All,
105101
mutate_functions: FunctionFilter::All,
106102
out_mutant_dir: Some(PathBuf::from(DEFAULT_OUTPUT_DIR)),
107-
verify_mutants: false,
108103
no_overwrite: false,
109104
apply_coverage: false,
110105
downsampling_ratio_percentage: None,

move-mutator/src/compiler.rs

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use crate::configuration::Configuration;
66
use codespan_reporting::diagnostic::Severity;
77
use either::Either;
8-
use fs_extra::dir::CopyOptions;
98
use itertools::Itertools;
109
use legacy_move_compiler::shared::{
1110
known_attributes::{AttributeKind, KnownAttribute},
@@ -17,7 +16,6 @@ use move_model::model::GlobalEnv;
1716
use move_package::{
1817
compilation::compiled_package::{make_source_and_deps_for_compiler, CompiledPackage},
1918
resolution::resolution_graph::ResolvedTable,
20-
source_package::layout::SourcePackageLayout,
2119
BuildConfig,
2220
};
2321
use move_symbol_pool::Symbol;
@@ -275,70 +273,6 @@ fn prepare_compiler_for_files(
275273
}
276274
}
277275

278-
/// Verify the mutant.
279-
/// This function compiles the mutated source and checks if the compilation is successful.
280-
/// If the compilation is successful, the mutant is valid.
281-
///
282-
/// This function uses the Move compiler to compile the mutated source. To do so, it copies the whole package
283-
/// to a temporary directory and replaces the original file with the mutated source. It may introduce problems
284-
/// with dependencies that are specified as relative paths to the package root.
285-
///
286-
/// # Arguments
287-
///
288-
/// * `config` - the build configuration.
289-
/// * `mutated_source` - the mutated source code as a string.
290-
/// * `original_file` - the path to the original file.
291-
///
292-
/// # Errors
293-
///
294-
/// * If any error occurs during the verification, the string with the cause is returned.
295-
///
296-
/// # Returns
297-
///
298-
/// * `Result<(), anyhow::Error>` - Ok if the mutant is valid, or an error if any error occurs.
299-
pub fn verify_mutant(
300-
config: &BuildConfig,
301-
mutated_source: &str,
302-
original_file: &Path,
303-
) -> Result<(), anyhow::Error> {
304-
// Find the root for the package.
305-
let root = SourcePackageLayout::try_find_root(&original_file.canonicalize()?)?;
306-
307-
debug!("Package path found: {root:?}");
308-
309-
// Get the relative path to the original file.
310-
let relative_path = original_file.canonicalize()?;
311-
let relative_path = relative_path.strip_prefix(&root)?;
312-
313-
debug!("Relative path: {relative_path:?}");
314-
315-
let tempdir = tempfile::tempdir()?;
316-
317-
debug!("Temporary directory: {:?}", tempdir.path());
318-
319-
// Copy the whole package to the tempdir.
320-
// We need to copy the whole package because the Move compiler needs to find the Move.toml file and all the dependencies
321-
// as we don't know which files are needed for the compilation.
322-
let options = CopyOptions::new().content_only(true);
323-
fs_extra::dir::copy(&root, &tempdir, &options)?;
324-
325-
// Write the mutated source to the tempdir in place of the original file.
326-
std::fs::write(tempdir.path().join(relative_path), mutated_source)?;
327-
328-
debug!(
329-
"Mutated source written to {:?}",
330-
tempdir.path().join(relative_path)
331-
);
332-
333-
// Create a working config, making sure that the test mode is disabled.
334-
// We want just check if the compilation is successful.
335-
let mut working_config = config.clone();
336-
working_config.test_mode = false;
337-
let _ = compile_package(working_config, tempdir.path())?;
338-
339-
Ok(())
340-
}
341-
342276
pub(crate) fn compile_package(
343277
build_config: BuildConfig,
344278
package_path: &Path,

move-mutator/src/lib.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ mod output;
2121
pub mod report;
2222

2323
use crate::{
24-
compiler::{generate_ast, verify_mutant},
24+
compiler::generate_ast,
2525
configuration::Configuration,
2626
report::{MutationReport, Report},
2727
};
@@ -169,16 +169,6 @@ pub fn run_move_mutator(
169169
let rayon_tid = rayon::current_thread_index().unwrap_or(0);
170170
info!("job_{rayon_tid}: Checking mutant {mutant}");
171171

172-
if mutator_configuration.project.verify_mutants {
173-
let res = verify_mutant(&config, &mutated_info.mutated_source, &path);
174-
175-
// In case the mutant is not a valid Move file, skip the mutant (do not save it).
176-
if let Err(e) = res {
177-
info!("job_{rayon_tid}: Mutant {mutant} is invalid and will not be generated: {e:?}");
178-
return None;
179-
}
180-
}
181-
182172
let mutant_id = mutated_info.unique_id();
183173
let Ok(mutant_path) = output::setup_mutant_path(&output_dir, &path, mutant_id) else {
184174
// If we cannot set up the mutant path, we skip the mutant.

move-mutator/tests/basic_tests.rs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ fn check_mutator_verify_mutants_correctly() {
7878

7979
let options = CLIOptions {
8080
out_mutant_dir: Some(outdir.clone()),
81-
verify_mutants: true,
8281
..Default::default()
8382
};
8483

@@ -177,33 +176,6 @@ fn check_mutator_properly_fails_with_single_files_that_require_dep_or_addr_resol
177176
fs::remove_dir_all(package_path).unwrap();
178177
}
179178

180-
// Check if the mutator produce zero mutants if verification is enabled for
181-
// files without any package (we're unable to verify such files successfully).
182-
#[test]
183-
fn check_mutator_fails_verify_file_without_package() {
184-
let package_path = clone_project("tests/move-assets/file_without_package");
185-
let outdir = package_path.join("outdir");
186-
187-
let options = CLIOptions {
188-
move_sources: vec![package_path.join("Sub.move")],
189-
out_mutant_dir: Some(outdir.clone()),
190-
verify_mutants: true,
191-
..Default::default()
192-
};
193-
194-
let config = quick_build_config();
195-
196-
let result = move_mutator::run_move_mutator(options.clone(), &config, &package_path);
197-
assert!(result.is_ok());
198-
199-
let report_path = outdir.join("report.json");
200-
assert!(report_path.exists());
201-
202-
let report = move_mutator::report::Report::load_from_json_file(&report_path).unwrap();
203-
assert!(report.get_mutants().is_empty());
204-
fs::remove_dir_all(package_path).unwrap();
205-
}
206-
207179
// Check that the mutator will apply function-filters correctly and generate mutants only for
208180
// specified functions.
209181
#[test]

move-mutator/tests/move-assets/breakcontinue/report.txt.mutation-exp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@
162162
},
163163
{
164164
"module_func": "Continue::sum_intermediate_in_for",
165-
"tested": 50,
166-
"killed": 49,
165+
"tested": 55,
166+
"killed": 54,
167167
"mutants_alive_diffs": [
168168
"--- original\n+++ modified\n@@ -18,7 +18,7 @@\n fun sum_intermediate_in_for(n: u64): u64 {\n let sum = 0;\n\n- for (i in 0..(n + 1)) {\n+ for (i in 1..(n + 1)) {\n if (i % 10 == 0) continue;\n sum = sum + i\n };\n"
169169
],
@@ -183,16 +183,21 @@
183183
"--- original\n+++ modified\n@@ -18,7 +18,7 @@\n fun sum_intermediate_in_for(n: u64): u64 {\n let sum = 0;\n\n- for (i in 0..(n + 1)) {\n+ for (i in 0..(n + 0)) {\n if (i % 10 == 0) continue;\n sum = sum + i\n };\n",
184184
"--- original\n+++ modified\n@@ -18,10 +18,7 @@\n fun sum_intermediate_in_for(n: u64): u64 {\n let sum = 0;\n\n- for (i in 0..(n + 1)) {\n- if (i % 10 == 0) continue;\n- sum = sum + i\n- };\n+ true;\n\n sum\n }\n",
185185
"--- original\n+++ modified\n@@ -18,10 +18,7 @@\n fun sum_intermediate_in_for(n: u64): u64 {\n let sum = 0;\n\n- for (i in 0..(n + 1)) {\n- if (i % 10 == 0) continue;\n- sum = sum + i\n- };\n+ false;\n\n sum\n }\n",
186+
"--- original\n+++ modified\n@@ -18,10 +18,10 @@\n fun sum_intermediate_in_for(n: u64): u64 {\n let sum = 0;\n\n- for (i in 0..(n + 1)) {\n+ !(for (i in 0..(n + 1)) {\n if (i % 10 == 0) continue;\n sum = sum + i\n- };\n+ });\n\n sum\n }\n",
186187
"--- original\n+++ modified\n@@ -18,10 +18,7 @@\n fun sum_intermediate_in_for(n: u64): u64 {\n let sum = 0;\n\n- for (i in 0..(n + 1)) {\n- if (i % 10 == 0) continue;\n- sum = sum + i\n- };\n+ true;\n\n sum\n }\n",
187188
"--- original\n+++ modified\n@@ -18,10 +18,7 @@\n fun sum_intermediate_in_for(n: u64): u64 {\n let sum = 0;\n\n- for (i in 0..(n + 1)) {\n- if (i % 10 == 0) continue;\n- sum = sum + i\n- };\n+ false;\n\n sum\n }\n",
188189
"--- original\n+++ modified\n@@ -18,10 +18,7 @@\n fun sum_intermediate_in_for(n: u64): u64 {\n let sum = 0;\n\n- for (i in 0..(n + 1)) {\n- if (i % 10 == 0) continue;\n- sum = sum + i\n- };\n+ true;\n\n sum\n }\n",
189190
"--- original\n+++ modified\n@@ -18,10 +18,7 @@\n fun sum_intermediate_in_for(n: u64): u64 {\n let sum = 0;\n\n- for (i in 0..(n + 1)) {\n- if (i % 10 == 0) continue;\n- sum = sum + i\n- };\n+ false;\n\n sum\n }\n",
191+
"--- original\n+++ modified\n@@ -18,10 +18,10 @@\n fun sum_intermediate_in_for(n: u64): u64 {\n let sum = 0;\n\n- for (i in 0..(n + 1)) {\n+ !(for (i in 0..(n + 1)) {\n if (i % 10 == 0) continue;\n sum = sum + i\n- };\n+ });\n\n sum\n }\n",
190192
"--- original\n+++ modified\n@@ -18,10 +18,7 @@\n fun sum_intermediate_in_for(n: u64): u64 {\n let sum = 0;\n\n- for (i in 0..(n + 1)) {\n- if (i % 10 == 0) continue;\n- sum = sum + i\n- };\n+ 0;\n\n sum\n }\n",
191193
"--- original\n+++ modified\n@@ -18,10 +18,7 @@\n fun sum_intermediate_in_for(n: u64): u64 {\n let sum = 0;\n\n- for (i in 0..(n + 1)) {\n- if (i % 10 == 0) continue;\n- sum = sum + i\n- };\n+ 18446744073709551615;\n\n sum\n }\n",
192194
"--- original\n+++ modified\n@@ -18,10 +18,7 @@\n fun sum_intermediate_in_for(n: u64): u64 {\n let sum = 0;\n\n- for (i in 0..(n + 1)) {\n- if (i % 10 == 0) continue;\n- sum = sum + i\n- };\n+ 2;\n\n sum\n }\n",
193195
"--- original\n+++ modified\n@@ -18,10 +18,7 @@\n fun sum_intermediate_in_for(n: u64): u64 {\n let sum = 0;\n\n- for (i in 0..(n + 1)) {\n- if (i % 10 == 0) continue;\n- sum = sum + i\n- };\n+ 0;\n\n sum\n }\n",
194196
"--- original\n+++ modified\n@@ -18,10 +18,7 @@\n fun sum_intermediate_in_for(n: u64): u64 {\n let sum = 0;\n\n- for (i in 0..(n + 1)) {\n- if (i % 10 == 0) continue;\n- sum = sum + i\n- };\n+ true;\n\n sum\n }\n",
195197
"--- original\n+++ modified\n@@ -18,10 +18,7 @@\n fun sum_intermediate_in_for(n: u64): u64 {\n let sum = 0;\n\n- for (i in 0..(n + 1)) {\n- if (i % 10 == 0) continue;\n- sum = sum + i\n- };\n+ false;\n\n sum\n }\n",
198+
"--- original\n+++ modified\n@@ -18,7 +18,7 @@\n fun sum_intermediate_in_for(n: u64): u64 {\n let sum = 0;\n\n- for (i in 0..(n + 1)) {\n+ for (true in 0..(n + 1)) {\n if (i % 10 == 0) continue;\n sum = sum + i\n };\n",
199+
"--- original\n+++ modified\n@@ -18,7 +18,7 @@\n fun sum_intermediate_in_for(n: u64): u64 {\n let sum = 0;\n\n- for (i in 0..(n + 1)) {\n+ for (false in 0..(n + 1)) {\n if (i % 10 == 0) continue;\n sum = sum + i\n };\n",
200+
"--- original\n+++ modified\n@@ -18,7 +18,7 @@\n fun sum_intermediate_in_for(n: u64): u64 {\n let sum = 0;\n\n- for (i in 0..(n + 1)) {\n+ for (!(i) in 0..(n + 1)) {\n if (i % 10 == 0) continue;\n sum = sum + i\n };\n",
196201
"--- original\n+++ modified\n@@ -19,7 +19,7 @@\n let sum = 0;\n\n for (i in 0..(n + 1)) {\n- if (i % 10 == 0) continue;\n+ if (true) continue;\n sum = sum + i\n };\n\n",
197202
"--- original\n+++ modified\n@@ -19,7 +19,7 @@\n let sum = 0;\n\n for (i in 0..(n + 1)) {\n- if (i % 10 == 0) continue;\n+ if (false) continue;\n sum = sum + i\n };\n\n",
198203
"--- original\n+++ modified\n@@ -19,7 +19,7 @@\n let sum = 0;\n\n for (i in 0..(n + 1)) {\n- if (i % 10 == 0) continue;\n+ if (!(i % 10 == 0)) continue;\n sum = sum + i\n };\n\n",

0 commit comments

Comments
 (0)