Skip to content

Commit

Permalink
coverage support #8
Browse files Browse the repository at this point in the history
  • Loading branch information
izlatkin committed Jun 24, 2022
1 parent 25df3d5 commit 6399955
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 119 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ docker build -f Dockerfile-solcmc . --rm -t leoalt/cav
npm install -g solc
sudo snap install solc
```

* Foundry (source https://github.com/foundry-rs/foundry)
```
git clone https://github.com/foundry-rs/foundry
cd foundry
cargo install --path ./cli --bins --locked --force
cargo install --path ./anvil --locked --force
```

* LCov
```brew install lcov```
* GenHtml (part or lcov)

used for
`solc a.sol --ast-compact-json`
example of command
Expand Down
41 changes: 38 additions & 3 deletions scripts/ReportBuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def get_extra_info_from_log(cls, dir):
"Done with TG",
"array operation requires one sort parameter",
"ALL Branches are covered: DONE",
"FOUND", 'unrolling sat', 'unrolling unsat', 'WOW!']
"FOUND", 'unrolling sat', 'unrolling unsat']
filein = open(log[0], "r", encoding='ISO-8859-1')
lines = filein.readlines()
for w in what_to_check:
Expand Down Expand Up @@ -126,9 +126,44 @@ def get_tests_info(cls, dir):
else:
return "No info"


@classmethod
def read_lcov_html_report(cls, file_name):
file = open(file_name, "r")
lines = file.readlines()
brench_lines = []
flag = False
i = 0
for line in lines:
if flag:
brench_lines.append(re.sub('<[^<]+?>', '', line))
i += 1
if 'Branches:' in line:
brench_lines.append(re.sub('<[^<]+?>', '', line))
flag = True
if i == 3:
break
return '{}<br/>\nHit: {}<br/>\nTotal: {}<br/>\nCoverage: {}\n'.format(brench_lines[0], brench_lines[1],
brench_lines[2], brench_lines[3])



@classmethod
def get_coverage_data(cls, line):
return "No info"
def get_coverage_data(cls, dir):
sub_dirs = [f.path for f in os.scandir(dir) if f.is_dir() and os.path.basename(f) in 'generated-coverage']
if len(sub_dirs) != 1:
return "<font color=\"red\">{}</font>\n".format('no data')
else:
report_dir = [f.path for f in os.scandir(sub_dirs[0]) if f.is_dir()]
exclude = ['usr']
report_dir = [d for d in report_dir if os.path.basename(d) not in exclude]
if len(report_dir) != 1:
return "<font color=\"red\">{}</font>\n".format('no report')
else:
file_name = report_dir[0] + '/' + os.path.basename(dir) +'.sol.gcov.html'
out = "<a href=\"{0}\">{1} </a>\n".format(file_name, "coverage_c_file_TG") + '<br/>\n'
out += html_report.read_lcov_html_report(file_name) + '<br/>'
return out


@classmethod
Expand Down
1 change: 1 addition & 0 deletions scripts/RunAll.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def main_pipeline(files):
for i, f in enumerate(sorted(files)):
start_time = time.time()
print("{:.2f}".format(100 * i / len(files)), "%", f)
print(i)
basename = os.path.basename(f)
dirname = os.path.dirname(f)
print("basename: {}".format(basename))
Expand Down
18 changes: 15 additions & 3 deletions scripts/SolidityTestGen.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def init():
SOLCMC = "/home/fmfsu/Dev/blockchain/cav_2022_artifact"
ADT_DIR = "/home/fmfsu/Dev/blockchain/adt_transform/target/debug/adt_transform"
TG_PATH = "/home/fmfsu/Dev/blockchain/aeval/build/tools/nonlin/tgnonlin"
FORGE_PATH = "/home/fmfsu/.foundry/bin/forge"
FORGE_PATH = "/home/fmfsu/.cargo/bin/forge" # "/home/fmfsu/.foundry/bin/forge"
DOCKER_SOLCMC = SOLCMC + "/docker_solcmc"
TIMEOUT = 900
TG_TIMEOUT = 100
Expand Down Expand Up @@ -397,15 +397,27 @@ def run_test(file, signature):
# copy source file to "scr"
shutil.copyfile(file, "../src/" + basename)
#run command: forge test --match name
command = [FORGE_PATH, 'test', '--match', str(os.path.splitext(basename)[0])]
SANDBOX_DIR = os.path.abspath(SANDBOX_DIR)
logger(SANDBOX_DIR + "/log.txt", "new signature" + str(signature))
os.chdir("../")
command_executer([FORGE_PATH, 'clean'], 60, SANDBOX_DIR + "/log.txt", SANDBOX_DIR + "/log.txt")
command = [FORGE_PATH, 'test', '--match', str(os.path.splitext(basename)[0])]
command_executer(command, 60, SANDBOX_DIR + "/log.txt", SANDBOX_DIR + "/test_results.txt")
command = [FORGE_PATH, 'coverage', '--match', str(os.path.splitext(basename)[0]), '--report', 'lcov']
command_executer(command, 60, SANDBOX_DIR + "/log.txt", SANDBOX_DIR + "/test_results.txt")
command = [FORGE_PATH, 'coverage', '--match', str(os.path.splitext(basename)[0]), '--report', 'summary']
command_executer(command, 60, SANDBOX_DIR + "/log.txt", SANDBOX_DIR + "/test_results.txt")
#copy lcov file
if os.path.isfile("lcov.info"):
shutil.move("lcov.info", SANDBOX_DIR + "/lcov.info")
genhtml_report_command = ['genhtml', '--branch-coverage', '--output', SANDBOX_DIR + '/generated-coverage', SANDBOX_DIR + "/lcov.info"]
command_executer(genhtml_report_command, 60, SANDBOX_DIR + "/log.txt", SANDBOX_DIR + "/log.txt")
os.chdir(save)
os.remove("../src/" + basename)
#os.remove("../src/" + basename)
clean_dir("../src")
shutil.move("../test/" + os.path.splitext(basename)[0] + ".t.sol",
SANDBOX_DIR + "/" + os.path.splitext(basename)[0] + ".t.sol")
clean_dir("../test")



Expand Down
4 changes: 0 additions & 4 deletions src/Contract.sol

This file was deleted.

43 changes: 0 additions & 43 deletions src/Loop_1.sol

This file was deleted.

12 changes: 0 additions & 12 deletions test/Contract.t.sol

This file was deleted.

30 changes: 0 additions & 30 deletions test/Loop_1.t.sol

This file was deleted.

24 changes: 0 additions & 24 deletions test/Test.t.sol

This file was deleted.

0 comments on commit 6399955

Please sign in to comment.