@@ -17,6 +17,13 @@ test_features=y
17
17
test_current=y
18
18
test_msrv=y
19
19
test_code_asm=y
20
+ test_cov=n
21
+
22
+ kcov=kcov
23
+ cov_out=$root_dir /cov-out
24
+ cov_out_rust=$cov_out /rust
25
+ cov_out_rust_tmp=$cov_out_rust /tmp
26
+ cov_out_rust_merged=$cov_out_rust /merged
20
27
21
28
# Minimum supported Rust version
22
29
msrv=" 1.48.0"
@@ -44,22 +51,31 @@ test_valid_invalid_instructions() {
44
51
45
52
# The C# code needs a formatter so add masm feature
46
53
dotnet build -c:$configuration -p:IcedFeatureFlags=" DECODER ENCODER OPCODE_INFO INSTR_INFO MASM" " $root_dir /src/csharp/Intel/IcedFuzzer/IcedFuzzer/IcedFuzzer.csproj"
54
+ if [ " $test_cov " = " y" ]; then
55
+ release_flag=
56
+ fzgt_output_dir=debug
57
+ else
58
+ release_flag=" --release"
59
+ fzgt_output_dir=release
60
+ fi
61
+ cargo build --color always $release_flag --manifest-path " $root_dir /src/rust/iced-x86-fzgt/Cargo.toml"
62
+ fzgt_exe=" $root_dir /src/rust/iced-x86-fzgt/target/$fzgt_output_dir /iced-x86-fzgt"
47
63
for bitness in 16 32 64; do
48
64
echo " ==== ${bitness} -bit: Generating valid/invalid files ===="
49
65
dotnet run -c:$configuration --no-build -p " $root_dir /src/csharp/Intel/IcedFuzzer/IcedFuzzer/IcedFuzzer.csproj" -- -$bitness -oil " $invalid_file " -ovlc " $valid_file "
50
66
echo " ==== ${bitness} -bit: Testing valid instructions ===="
51
- cargo run --color always --release --manifest-path " $root_dir /src/rust/iced-x86-fzgt/Cargo.toml " -- -b $bitness -f " $valid_file "
67
+ cov_test " test_valid_ $bitness " " $fzgt_exe " -b $bitness -f " $valid_file "
52
68
echo " ==== ${bitness} -bit: Testing invalid instructions ===="
53
- cargo run --color always --release --manifest-path " $root_dir /src/rust/iced-x86-fzgt/Cargo.toml " -- -b $bitness -f " $invalid_file " --invalid
69
+ cov_test " test_invalid_ $bitness " " $fzgt_exe " -b $bitness -f " $invalid_file " --invalid
54
70
done
55
71
56
72
for bitness in 16 32 64; do
57
73
echo " ==== ${bitness} -bit (AMD): Generating valid/invalid files ===="
58
74
dotnet run -c:$configuration --no-build -p " $root_dir /src/csharp/Intel/IcedFuzzer/IcedFuzzer/IcedFuzzer.csproj" -- -$bitness -oil " $invalid_file " -ovlc " $valid_file " --amd
59
75
echo " ==== ${bitness} -bit (AMD): Testing valid instructions ===="
60
- cargo run --color always --release --manifest-path " $root_dir /src/rust/iced-x86-fzgt/Cargo.toml " -- -b $bitness -f " $valid_file " --amd
76
+ cov_test " test_amd_valid_ $bitness " " $fzgt_exe " -b $bitness -f " $valid_file " --amd
61
77
echo " ==== ${bitness} -bit (AMD): Testing invalid instructions ===="
62
- cargo run --color always --release --manifest-path " $root_dir /src/rust/iced-x86-fzgt/Cargo.toml " -- -b $bitness -f " $invalid_file " --invalid --amd
78
+ cov_test " test_amd_invalid_ $bitness " " $fzgt_exe " -b $bitness -f " $invalid_file " --invalid --amd
63
79
done
64
80
65
81
rm " $valid_file "
@@ -164,6 +180,33 @@ build_features() {
164
180
cd " $curr_dir "
165
181
}
166
182
183
+ cov_test () {
184
+ cov_test_dir=$1
185
+ shift
186
+ if [ " $test_cov " = " y" ]; then
187
+ $kcov --verify --exclude-pattern=/tests/,/test/,/test_utils/ --include-pattern=/iced-x86/ " $cov_out_rust_tmp /$cov_test_dir " " $@ "
188
+ else
189
+ " $@ "
190
+ fi
191
+ }
192
+
193
+ cargo_test_cov () {
194
+ cov_test_dir=$1
195
+ shift
196
+ if [ " $test_cov " = " y" ]; then
197
+ test_exe=$( cargo test --color always --no-run --message-format=json " $@ " | grep -- ' "name":"iced-x86"' | tail -1 | sed -e ' s/.*"executable":"\([^"]\+\)".*/\1/' )
198
+ if [ ! -x " $test_exe " ]; then
199
+ echo " Couldn't get the test executable name, got '$test_exe '"
200
+ echo " json output:"
201
+ cargo test --color always --no-run --message-format=json " $@ "
202
+ exit 1
203
+ fi
204
+ cov_test " $cov_test_dir " " $test_exe "
205
+ else
206
+ cargo test --color always " $@ "
207
+ fi
208
+ }
209
+
167
210
build_test_current_version () {
168
211
new_func " Build, test (current version)"
169
212
curr_dir=$( pwd)
@@ -194,10 +237,10 @@ build_test_current_version() {
194
237
# Make sure the two read-mem methods behave the same
195
238
# Also test serde code. It needs encoder to also test 'db x,y,z', see serde tests
196
239
echo " ==== TEST DEBUG: std decoder encoder serde __internal_flip ===="
197
- cargo test --color always --tests --no-default-features --features " std decoder encoder serde __internal_flip"
240
+ cargo_test_cov test_internal_flip --tests --no-default-features --features " std decoder encoder serde __internal_flip"
198
241
199
242
echo " ==== TEST DEBUG ===="
200
- cargo test --color always --tests --features " serde $test_code_asm_feat mvex"
243
+ cargo_test_cov test_debug --tests --features " serde $test_code_asm_feat mvex"
201
244
202
245
echo " ==== BUILD RELEASE wasm32-unknown-unknown ===="
203
246
cargo check --color always --target wasm32-unknown-unknown --release --features " serde code_asm mvex"
@@ -269,6 +312,7 @@ while [ "$#" -gt 0 ]; do
269
312
--test-features) test_features=y ;;
270
313
--test-current) test_current=y ;;
271
314
--test-msrv) test_msrv=y ;;
315
+ --coverage) test_cov=y ;;
272
316
273
317
--no-set-rustflags) set_rustflags=n ;;
274
318
* ) echo " Unknown arg: $1 " ; exit 1 ;;
289
333
echo " rustup show"
290
334
rustup show
291
335
336
+ if [ " $test_cov " = " y" ]; then
337
+ mkdir -p " $cov_out "
338
+ rm -rf " $cov_out_rust " " $cov_out_rust_merged "
339
+ mkdir -p " $cov_out_rust_tmp "
340
+ kcov --version
341
+ fi
342
+
292
343
if [ " $test_code_asm " = " y" ]; then
293
344
test_code_asm_feat=" code_asm"
294
345
else
318
369
if [ " $test_msrv " = " y" ]; then
319
370
build_test_msrv
320
371
fi
372
+
373
+ if [ " $test_cov " = " y" ]; then
374
+ $kcov --merge " $cov_out_rust_merged " " $cov_out_rust_tmp /" *
375
+ fi
0 commit comments