Skip to content
This repository has been archived by the owner on Nov 6, 2022. It is now read-only.

Commit

Permalink
codecov.io support and coverage tooling for mini
Browse files Browse the repository at this point in the history
  • Loading branch information
Rachel Franks committed Jun 30, 2021
1 parent 34d2c29 commit 21dfcc5
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 17 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ jobs:
if: matrix.rust == 'nightly'
run: |
grcov . --binary-path ./target/release/ -s . -t lcov --branch --ignore-not-existing -o lcov.info
make coverage
- name: Upload to codecov.io
uses: codecov/codecov-action@v1
Expand Down
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ arb_os/contractTemplates.mini
.idea
evm-tests/.travis.yml
evm-test-logs/*
*.cov
*/*.cov
**.cov
**~
lcov.info

# Files generated by Hardhat
contracts/artifacts
Expand Down
12 changes: 4 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ TESTCONTRACTSPURE = $(TCBUILDDIR)/Add.sol/Add.json $(TCBUILDDIR)/Fibonacci.sol/F
TESTCONTRACTS = $(ACBUILDDIR)/ArbSys.sol/ArbSys.json $(TESTCONTRACTSPURE)
UPGRADEFILES = $(UPGRADETESTDIR)/regcopy_old.mexe $(UPGRADETESTDIR)/regcopy_new.mexe $(UPGRADETESTDIR)/upgrade1_old.mexe $(UPGRADETESTDIR)/upgrade1_new.mexe $(UPGRADETESTDIR)/upgrade2_new.mexe
ARBOSCONTRACTS = $(ACBUILDDIR)/ArbAddressTable.sol/ArbAddressTable.json $(ACBUILDDIR)/ArbBLS.sol/ArbBLS.json $(ACBUILDDIR)/ArbFunctionTable.sol/ArbFunctionTable.json $(ACBUILDDIR)/ArbInfo.sol/ArbInfo.json $(ACBUILDDIR)/ArbOwner.sol/ArbOwner.json $(ACBUILDDIR)/ArbSys.sol/ArbSys.json $(ACBUILDDIR)/ArbosTest.sol/ArbosTest.json $(ACBUILDDIR)/ArbRetryable.sol/ArbRetryable.json
COVERAGES = $(BUILTINDIR)/arraytest.cov $(BUILTINDIR)/globaltest.cov $(BUILTINDIR)/kvstest.cov $(BUILTINDIR)/maptest.cov $(STDDIR)/biguinttest.cov $(STDDIR)/blstest.cov $(STDDIR)/bytearraytest.cov $(STDDIR)/fixedpointtest.cov $(STDDIR)/keccaktest.cov $(STDDIR)/priorityqtest.cov $(STDDIR)/queuetest.cov $(STDDIR)/ripemd160test.cov $(STDDIR)/sha256test.cov $(STDDIR)/storageMapTest.cov

COMPILEFLAGS = -c "arb_os/constants.json" -i "none"
COMPILEFLAGSNOINLINE = -c "arb_os/constants.json"
Expand Down Expand Up @@ -138,12 +137,9 @@ test:

coverage: alltests.cov

alltests.cov: compiler contracts $(COVERAGES) $(STDDIR)/rlptest.mexe
cargo test --release -- minitests::test_rlp
cat $(BUILTINDIR)/*.cov $(STDDIR)/*.cov | sort | uniq | grep -v test | grep -v Test >alltests.cov

$(COVERAGES): %.cov: %.mexe
$(CARGORUN) run $< -c $@
alltests.cov: compiler contracts
cat coverage/*/*.cov | sort -r | uniq | sort | uniq -f 1 | sort -k2,2 -k3,3n | grep -v test | grep -v Test > coverage/alltests.cov
./coverage/mini-coverage.sh ./coverage/alltests.cov >> lcov.info

evmtest: $(ARBOS)
$(CARGORUN) evm-tests
Expand All @@ -165,5 +161,5 @@ benchmark: compiler $(TEMPLATES) $(ARBOS)
$(CARGORUN) make-benchmarks

clean:
rm -f $(BUILTINDIR)/*.mexe $(STDDIR)/*.mexe *.cov $(BUILTINDIR)/*.cov $(STDDIR)/*.cov $(UPGRADETESTDIR)/*.mexe $(ARBOSDIR)/arbos.mexe $(ARBOSDIR)/arbos-upgrade.mexe $(ARBOSDIR)/upgrade.json minitests/*.mexe $(ARBOSDIR)/contractTemplates.mini
rm -f $(BUILTINDIR)/*.mexe $(STDDIR)/*.mexe *.cov coverage/*/*.cov $(BUILTINDIR)/*.cov $(STDDIR)/*.cov $(UPGRADETESTDIR)/*.mexe $(ARBOSDIR)/arbos.mexe $(ARBOSDIR)/arbos-upgrade.mexe $(ARBOSDIR)/upgrade.json minitests/*.mexe $(ARBOSDIR)/contractTemplates.mini lcov.info
rm -rf contracts/artifacts contracts/cache
30 changes: 30 additions & 0 deletions coverage/mini-coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

LINES=$(cat $1 | awk '{$3="DA:"$3","$1; $1=""; sub(/\+/, 1); sub(/\-/, 0); sub(/^ /, ""); sub(/^std::/, "stdlib/"); sub(/^core::/, "builtin/"); print $0}')

CURR_FILE=""
CURR_COUNT=0

while read -r line; do

FILE=${line%% *}

if [[ "$FILE" != "$CURR_FILE" ]]; then
if [[ "$CURR_FILE" != "" ]]; then
echo "LF:$CURR_COUNT"
echo "LH:0"
echo "end_of_record"
fi
CURR_FILE=$FILE
CURR_COUNT=0
echo "SF:$FILE.mini"
fi

((CURR_COUNT += 1))

echo $line | cut -d" " -f2-

done <<< "$LINES"

echo "LF:$CURR_COUNT"
echo "LH:0"
echo "end_of_record"
20 changes: 17 additions & 3 deletions src/minitests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,21 @@ fn test_from_file_with_args_and_return(
}

fn test_from_file(path: &Path) {
test_from_file_with_args_and_return(path, vec![], Value::Int(Uint256::zero()), None);
test_from_file_with_args_and_return(
path,
vec![],
Value::Int(Uint256::zero()),
Some({
let mut file = Path::new("coverage")
.join(path)
.to_str()
.unwrap()
.to_string();
let length = file.len();
file.truncate(length - 4);
file + "cov"
}),
);
}

#[test]
Expand Down Expand Up @@ -138,7 +152,7 @@ fn test_rlp() {
test_rlp_bytearray(
testvec.to_vec(),
res,
Some(format!("stdlib/rlptest_bv_{}.cov", i)),
Some(format!("coverage/stdlib/rlptest_bv_{}.cov", i)),
);
}

Expand All @@ -160,7 +174,7 @@ fn test_rlp() {
test_rlp_list3(
testvec.clone(),
res,
Some(format!("stdlib/rlptest_ls_{}.cov", i)),
Some(format!("coverage/stdlib/rlptest_ls_{}.cov", i)),
);
}
}
Expand Down
12 changes: 8 additions & 4 deletions src/run/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,14 @@ fn write_coverage_data_to_file(
let mut coverage_file = File::create(coverage_filename).unwrap();
let mut coverage_lines: Vec<usize> = coverage_data.iter().map(|r| *r).collect();
coverage_lines.sort();
for i in coverage_lines {
if let Some(loc) = instructions[i].debug_info.location {
if let Some(finfo) = file_info_table.get(&loc.file_id) {
writeln!(coverage_file, "{} {}", finfo.name, loc.line).unwrap();

for (index, insn) in instructions.into_iter().enumerate() {
if let Some(loc) = insn.debug_info.location {
if let Some(info) = file_info_table.get(&loc.file_id) {
match coverage_data.contains(&index) {
true => drop(writeln!(coverage_file, "+ {} {}", info.name, loc.line)),
false => drop(writeln!(coverage_file, "- {} {}", info.name, loc.line)),
}
}
}
}
Expand Down

0 comments on commit 21dfcc5

Please sign in to comment.