-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updating the original files in libraries to Dafny 4 (#2) #97
Changes from all commits
7486acd
f7f2ff2
fe7b9cf
b99f202
9d58c03
4164986
2fd07c6
85b4714
c66ee31
063d5ef
e4b76c2
84fbf36
cb5c412
629a2cf
7be722c
6bd5d9d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#! /usr/bin/env bash | ||
|
||
FAIL=0 | ||
for f in `find $1 -name '*.dfy'`; do \ | ||
echo $f ;\ | ||
dafny format --check $f || ( dafny format --print $f | diff $f - ) ;\ | ||
if [ "$?" != 0 ] ; then FAIL=1 ; fi; \ | ||
done | ||
exit $FAIL |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# This workflow does static verification of the legacy modules | ||
name: Check formatting | ||
|
||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
branches: [ master ] | ||
|
||
jobs: | ||
formatting: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: switch branch | ||
run: | | ||
git fetch | ||
git checkout cok-code | ||
|
||
- name: Install Dafny | ||
uses: dafny-lang/setup-dafny-action@v1 | ||
with: | ||
dafny-version: "nightly-2023-02-15-567a5ba" | ||
|
||
- name: Install lit | ||
run: pip install lit OutputCheck | ||
|
||
- name: Set up JS dependencies | ||
run: npm install bignumber.js | ||
|
||
- name: Check exe | ||
run: | | ||
dafny --version | ||
|
||
- name: Check formatting | ||
run: | | ||
chmod +x ./.github/workflows/check-format | ||
./.github/workflows/check-format src |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,66 @@ | ||
# This workflow performs static analysis checks. | ||
name: tests | ||
# This workflow does static verification of the DafnyCore library | ||
name: Dafny Core verification | ||
|
||
on: | ||
# Scheduled to be run sometime after the nightly build of dafny | ||
schedule: | ||
- cron: "7 10 * * *" | ||
workflow_dispatch: | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
branches: [ master ] | ||
|
||
jobs: | ||
verification: | ||
runs-on: ubuntu-latest | ||
continue-on-error: true | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
# nightly-latest to catch anything that breaks these tests in current development | ||
# 2/18/2023 version is the first that supports logging | ||
# 3.11.0 supports new CLI but does not support logging | ||
version: [ nightly-latest, nightly-2023-02-18-ef4f346, 3.11.0] | ||
os: [ ubuntu-latest ] | ||
|
||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Install Dafny | ||
uses: dafny-lang/setup-dafny-action@v1 | ||
uses: dafny-lang/setup-dafny-action@v1.6.0 | ||
with: | ||
dafny-version: "3.9.1" | ||
dafny-version: ${{ matrix.version }} | ||
|
||
- name: Version information | ||
run: | | ||
dafny --version | ||
echo ${{ matrix.os }} ${{ runner.os }} ${{ matrix.version }} | ||
|
||
- name: Upgrade outdated pip | ||
run: python -m pip install --upgrade pip | ||
|
||
- name: Install lit | ||
run: pip install lit OutputCheck | ||
|
||
- name: Set up JS dependencies | ||
run: npm install bignumber.js | ||
|
||
- name: Verify Dafny Code | ||
run: lit --time-tests -v --param 'dafny_params=/verificationLogger:trx /verificationLogger:csv' . | ||
- name: Verify Code and Examples without logging | ||
id: nolog | ||
if: matrix.version == '3.11.0' | ||
run: lit --time-tests -v . | ||
|
||
- name: Verify Code and Examples | ||
id: withlog | ||
if: steps.nolog.conclusion == 'skipped' | ||
run: | | ||
lit --time-tests -v --param 'dafny_params=--log-format trx --log-format csv' . | ||
|
||
- name: Generate Report | ||
if: always() && steps.withlog.conclusion != 'skipped' | ||
run: find . -name '*.csv' -print0 | xargs -0 --verbose dafny-reportgenerator summarize-csv-results --max-duration-seconds 10 | ||
|
||
- uses: actions/upload-artifact@v2 # upload test results | ||
if: success() || failure() # run this step even if previous step failed | ||
if: always() && steps.withlog.conclusion != 'skipped' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the point of the extraneous There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So that the step runs even if the previous steps fail There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then why not JUST always()? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because if we (intentionally) run with an old version of dafny that does not support logging with new CLI (i.e. 3.11.0) then we don't want this step to run (and fail) if we have not produced any log files. |
||
with: | ||
name: verification-results | ||
path: '**/TestResults/*.trx' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,9 @@ | ||
**/.DS_Store | ||
**/Output/ | ||
**/TestResults/ | ||
examples/FileIO/ReadBytesFromFile.cs | ||
examples/FileIO/ReadBytesFromFile.jar | ||
examples/FileIO/ReadBytesFromFile.js | ||
examples/FileIO/WriteBytesToFile.cs | ||
examples/FileIO/WriteBytesToFile.jar | ||
examples/FileIO/WriteBytesToFile.js |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Testing the libraries | ||
|
||
The code in these libraries is tested both with deductive verification, using dafny, | ||
and with traditional runtime testing of compilations by dafny. | ||
The latter is important as a check that dafny compiled the (verified) dafny code correctly. | ||
Also, some functionality (e.g. FileIO) is partially implemented using | ||
custom code in the target programming language, which is not verified by dafny. | ||
All files are also checked that they conform to standard dafny formatting, | ||
using `dafny format`. | ||
|
||
The tests are run using `lit`. The configuration of the tests is controlled by | ||
(a) the lit.site.cfg file and (b) the yml files in .github/workflows. | ||
|
||
The tests are run on each push to a pull_request and are required to pass to enable merging. | ||
They are also run on a nightly schedule. | ||
|
||
To run the files manually: run `lit .` in this directory (`libraries`, at the top | ||
of the clone of the repo). You can also manually run individual files or directories, | ||
but `lit` must be invoked in the `libraries` directory. You can also trigger the workflow | ||
using `workflow_dispatch`. To do a manual check of formatting, use `dafny format --check <file or folder>`. | ||
|
||
The tests themselves are specially formatted lines (those beginning with `// RUN:`) in | ||
each .dfy file. The tests use dafny's new command-line syntax, using the lit | ||
macros `%verify` and `%run` and the like. | ||
|
||
The versions of dafny being run are set in the `tests.yml` file. The versions tested | ||
must be recent enough to support the new CLI syntax, so 3.11ff. Also, if | ||
verification logging is desired, the version must be at least that of 3/18/2023 when | ||
the logging parameters were implemented in the new CLI. | ||
|
||
Testing can be run on older versions if (a) the lit macros like `%verify` are redefined using | ||
old CLI syntax and (b) the runtime testing tests are rewritten to not use `dafny run`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#!/usr/bin/env python | ||
""" | ||
Simple driver around python's difflib that implements a basic ``diff`` like | ||
tool. This exists to provide a simple ``diff`` like tool that will run on | ||
Windows where only the ``fc`` tool is available. | ||
""" | ||
import argparse | ||
import difflib | ||
import os | ||
import sys | ||
|
||
def main(args): | ||
parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter, | ||
description=__doc__ | ||
) | ||
# Open in binary mode so python doesn't try and do | ||
# universal line endings for us. | ||
parser.add_argument('from-file', | ||
type=argparse.FileType('rb'), | ||
) | ||
parser.add_argument('to-file', | ||
type=argparse.FileType('rb'), | ||
) | ||
parser.add_argument('-U','--unified=', | ||
type=int, | ||
default=3, | ||
help='Number of context lines to show. ' | ||
'Default %(default)s' | ||
) | ||
parser.add_argument('--strip-trailing-cr', | ||
action='store_true', | ||
help='strip trailing carriage return when comparing' | ||
) | ||
parser.add_argument('--ignore-all-space','-w', | ||
action='store_true', | ||
help='Ignore all whitespace characters when comparing' | ||
) | ||
|
||
parsedArgs = parser.parse_args(args) | ||
fromFile, fromFileName = preProcess(getattr(parsedArgs,'from-file'), | ||
parsedArgs.strip_trailing_cr, | ||
parsedArgs.ignore_all_space | ||
) | ||
toFile, toFileName = preProcess(getattr(parsedArgs,'to-file'), | ||
parsedArgs.strip_trailing_cr, | ||
parsedArgs.ignore_all_space | ||
) | ||
result = difflib.unified_diff(fromFile, | ||
toFile, | ||
fromFileName, | ||
toFileName, | ||
n=getattr(parsedArgs,'unified='), | ||
) | ||
# Force lazy computation to happen now | ||
result = list(result) | ||
|
||
if len(result) == 0: | ||
# Files are identical | ||
return 0 | ||
else: | ||
for l in result: | ||
sys.stdout.write(l) | ||
return 1 | ||
|
||
def preProcess(openFile, stripTrailingCR=False, ignoreAllSpace=False): | ||
""" | ||
Helper function to read lines in a file and do any necessary | ||
pre-processing | ||
""" | ||
original = openFile.readlines() | ||
|
||
# Translation table deletes white space characters Note we don't remove | ||
# newline characters because this will create a mess when outputting the | ||
# diff. Is this the right behaviour? | ||
deleteChars=' \t' | ||
if sys.version_info.major >= 3: | ||
translationTable = str.maketrans('','', deleteChars) | ||
|
||
copy = [ ] | ||
for line in original: | ||
newLine = str(line.decode()) | ||
|
||
if stripTrailingCR: | ||
if newLine[-2:] == '\r\n' or newLine[-2:] == '\n\r': | ||
newLine = newLine[:-2] + '\n' | ||
|
||
if ignoreAllSpace: | ||
newLine = newLine.translate(translationTable) | ||
|
||
copy.append(newLine) | ||
|
||
return (copy, openFile.name) | ||
|
||
def getFileName(openFile): | ||
return openFile.name | ||
|
||
if __name__ == '__main__': | ||
sys.exit(main(sys.argv[1:])) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
## This small script takes as first argument a test indicator | ||
## and the rest of the arguments are a command to run, with its | ||
## command-line arguments. | ||
## The script runs the command and then if the first argument is | ||
## (1) -any -- returns success, ignoring the exit code of the command | ||
## (2) -z -- returns success iff the exit code is non-zero | ||
## (3) some integer literal -- return success iff the exit code | ||
## matches the given integer | ||
## (4) -skip -- does not run the command and just exits with success | ||
|
||
import sys | ||
import subprocess | ||
|
||
arg = sys.argv[1] | ||
if arg == "-skip": | ||
print( 'Skipping' ) | ||
exit(0) | ||
|
||
p = subprocess.run( sys.argv[2:] ) | ||
|
||
if arg == "-any": | ||
exit(0) | ||
if arg == "-z": | ||
if p.returncode == 0 : | ||
print( 'Expected non-zero exit code' ) | ||
exit(1) | ||
else: | ||
exit(0) | ||
if p.returncode != int(arg) : | ||
print( 'Expected exit code', arg, ', actual result is', p.returncode ) | ||
exit(1) | ||
|
||
exit(0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely happy with the solution of also using a specific nightly build to use the logging! But "nightly-latest" should only be used in the scheduled build, since otherwise the mainline CI can break spontaneously.
Here's how I set it up on the reportgenerator, which I intend to be the template for other projects: https://github.com/dafny-lang/dafny-reportgenerator/pull/17/files You should be able to do something similar, the only difference being that you have to make the matrix variable conditional instead, something like:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. But are you comfortable with that tweaking of the test scheduling after this PR is merged, so the changes to the script can be properly tested on master-branch files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, it's only going to be a maintenance pain for us if we don't fix it quickly. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put in the next PR. I learn new Github action syntax every day.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, this syntax does not work with lists -- tried numerous variations. So for now left out the nightly-latest from the CI build and made a separate nightly build. But this cries out for a reusable workflow that I'll figure out later.