-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathv2_only.rs
95 lines (81 loc) · 2.75 KB
/
v2_only.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright (c) Aptos Foundation
// SPDX-License-Identifier: Apache-2.0
#![no_main]
use libfuzzer_sys::fuzz_target;
use msmith::{
execution::{
transactional::{
CommonRunConfig, TransactionalExecutor, TransactionalInputBuilder, TransactionalResult,
},
ExecutionManager,
},
MoveSmith,
};
use once_cell::sync::Lazy;
use std::{env, fs::OpenOptions, io::Write, sync::Mutex, time::Instant};
static FILE_MUTEX: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(()));
static RUNNER: Lazy<Mutex<ExecutionManager<TransactionalResult, TransactionalExecutor>>> =
Lazy::new(|| {
Mutex::new(ExecutionManager::<TransactionalResult, TransactionalExecutor>::default())
});
fuzz_target!(|data: &[u8]| {
let smith = MoveSmith::new();
let do_profile = match env::var("MOVE_SMITH_PROFILING") {
Ok(v) => v == "1",
Err(_) => false,
};
if do_profile {
let mut profile_s = String::new();
let start = Instant::now();
let code = match smith.generate(data) {
Ok(code) => code,
Err(_) => return,
};
let elapsed = start.elapsed();
profile_s.push_str(&format!(
"move-smith-profile::time::generation::{}ms\n",
elapsed.as_millis()
));
let start = Instant::now();
let mut input_builder = TransactionalInputBuilder::new();
let input = input_builder
.set_code(&code)
.with_common_runs(&CommonRunConfig::V2Only)
.build();
let bug = RUNNER.lock().unwrap().execute_check_new_bug(&input);
let elapsed = start.elapsed();
profile_s.push_str(&format!(
"move-smith-profile::time::transactional::{}ms\n",
elapsed.as_millis()
));
let status = match &bug {
Ok(_) => "success",
Err(_) => "error",
};
profile_s.push_str(&format!("move-smith-profile::status::{}\n", status));
let _lock = FILE_MUTEX.lock().unwrap();
let mut file = OpenOptions::new()
.create(true)
.append(true)
.open("move-smith-profile.txt")
.unwrap();
file.write_all(profile_s.as_bytes()).unwrap();
if bug.unwrap() {
panic!("Found bug")
}
} else {
let code = match smith.generate(data) {
Ok(code) => code,
Err(_) => return,
};
let mut input_builder = TransactionalInputBuilder::new();
let input = input_builder
.set_code(&code)
.with_common_runs(&CommonRunConfig::V2Only)
.build();
let bug = RUNNER.lock().unwrap().execute_check_new_bug(&input);
if bug.unwrap() {
panic!("Found bug")
}
}
});