Skip to content
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

Reproducible Docker build for test cases in src/test #288

Open
wants to merge 87 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
4357a5a
nix + docker work
katrinafyi Dec 4, 2024
d468595
move all docker things into script
katrinafyi Dec 4, 2024
a1882b8
add md5sum and docker hashing
katrinafyi Dec 4, 2024
4eda022
remove binaries in secret_write
katrinafyi Dec 4, 2024
dc5f18c
implement docker hashing
katrinafyi Dec 4, 2024
96f83ed
add hash files
katrinafyi Dec 4, 2024
6de43e5
check should depend on artefacts
katrinafyi Dec 4, 2024
59d965b
more things inside docker. use podman by default.
katrinafyi Dec 5, 2024
2084fc9
DELETE GENERATED FILES in src/test
katrinafyi Dec 5, 2024
a65f380
fix docker clang command and only md5sum certain files
katrinafyi Dec 5, 2024
83b6842
gitignore generated files
katrinafyi Dec 5, 2024
181ecb4
do not use -it in docker, to avoid CRLF
katrinafyi Dec 5, 2024
bec6d9f
add hash files in src/test
katrinafyi Dec 5, 2024
e096ee9
move docker commands into parent makefile
katrinafyi Dec 5, 2024
1a72342
fix running lift-directories.mk directly
katrinafyi Dec 5, 2024
9188366
add docker-flake
katrinafyi Dec 5, 2024
b3d1000
support 'env' inside docker-helper.sh
katrinafyi Dec 6, 2024
ec7ba8a
tweak and fix some things in hash generation
katrinafyi Dec 6, 2024
d9aa555
update hash with bap ite
katrinafyi Dec 6, 2024
f1c5475
tweaks to makefile
katrinafyi Dec 6, 2024
c65f7f6
add readme for docker usage
katrinafyi Dec 6, 2024
95b97e0
add bap-normalise and use original absolute paths in docker
katrinafyi Dec 9, 2024
dc10fad
update md5sums after bap-normalise
katrinafyi Dec 9, 2024
47e62b9
support nesting shell. fix bap-normalise. proto-json still broken
katrinafyi Dec 10, 2024
3df5ff7
split up targets to avoid inadvertent parallelism
katrinafyi Dec 10, 2024
48a65ca
add repro-check to readme
katrinafyi Dec 10, 2024
dd5e0d6
touch bap-normalise and make somewhat more atomic
katrinafyi Dec 10, 2024
69b56e1
update flake
katrinafyi Dec 10, 2024
265f432
fix bap normalise fr!
katrinafyi Dec 10, 2024
2cba5e3
hash changes after bap-normalise fix fr
katrinafyi Dec 10, 2024
3e844fa
support push/pull workflows in docker-helper
katrinafyi Dec 11, 2024
420c712
update flakes in docker-hash
katrinafyi Dec 11, 2024
5eff3b0
touch readme
katrinafyi Dec 11, 2024
6c430d7
big md5sums
katrinafyi Dec 11, 2024
2874d70
update md5sums after big md5sums
katrinafyi Dec 11, 2024
0092c63
update src/test with clearer steps and flow-chart
katrinafyi Dec 11, 2024
a57a12e
update development readme to mention Docker lifting
katrinafyi Dec 11, 2024
5ba93c4
update src/test/readme for new tests
katrinafyi Dec 11, 2024
419145e
remove files added from a docker shell
katrinafyi Dec 11, 2024
7af7677
update big md5sum
katrinafyi Dec 11, 2024
9dfe341
add gitattributes to mark generated files
katrinafyi Dec 11, 2024
bf4c9ed
remove suprious gcc1/gcc2
katrinafyi Dec 11, 2024
ecb3164
replace tabs in docker-helper
katrinafyi Dec 11, 2024
6ea272c
tarball extraction for compiled files
katrinafyi Dec 12, 2024
b5d37ca
ci: download and extract compiled files
katrinafyi Dec 12, 2024
f5230b2
makefile for everything in src/test and update readme
katrinafyi Dec 12, 2024
c78a06d
FIX missing arrays_simple
katrinafyi Dec 12, 2024
60cf168
use a docker-contents.txt instead of docker-hash everywhere
katrinafyi Dec 12, 2024
369473d
REMOVE GENERATED FILES in other directories
katrinafyi Dec 12, 2024
a080854
add md5sums for non-correct/incorret
katrinafyi Dec 12, 2024
7b1bdf9
add dsa/irred_loops, use tarbz2, add docker-contents
katrinafyi Dec 12, 2024
fd0e6d2
docker platform
katrinafyi Dec 12, 2024
3830d8b
avoid -v for macos
katrinafyi Dec 12, 2024
035658f
add macos notes, local notes, and dir mount notes
katrinafyi Dec 12, 2024
fb0a391
remove docker hash mentions
katrinafyi Dec 12, 2024
511558a
add sha1sum to compiled.url.txt
katrinafyi Dec 13, 2024
a45482f
Merge remote-tracking branch 'origin/main' into nix-docker-build
katrinafyi Dec 13, 2024
b0786ee
src/test/readme: fix markdown
katrinafyi Dec 13, 2024
113171f
UPDATE EXPECTED
katrinafyi Dec 13, 2024
2bf1d2e
extract set mtime to current time
katrinafyi Dec 13, 2024
e7b2fc3
allow file command to fail in Makefile
katrinafyi Dec 13, 2024
6cfd953
add new dsa examples
katrinafyi Dec 13, 2024
6c23bf0
handle empty directories and missing md5sum better
katrinafyi Dec 13, 2024
deaa46c
docker disable hardening
katrinafyi Dec 13, 2024
4eb193c
remove NIX_HARDENING from docker-helper
katrinafyi Dec 13, 2024
d19c174
gcc_pic: add -pie argument ?????
katrinafyi Dec 13, 2024
d9c9e2e
update binaries after -pie
katrinafyi Dec 13, 2024
d1612ad
sort big md5sum, use zst
katrinafyi Dec 13, 2024
dedc39b
update readme
katrinafyi Dec 13, 2024
fa740ff
support configuring LIFT_ARTEFACTS in config.mk and remove spurious B…
katrinafyi Dec 17, 2024
9073116
rename md5sum files to NAME.md5sum
katrinafyi Dec 17, 2024
33ba34c
remove dsa and irreducible_loop from the Makefile
katrinafyi Dec 17, 2024
306d0d8
exclude syscall/clang_O2:BAP
katrinafyi Dec 17, 2024
c040856
ci: run without docker, using pinned z3 and boogie
katrinafyi Dec 17, 2024
7a41b20
gitattibutes eol=lf for url and flake files
katrinafyi Dec 18, 2024
3a60c4c
docker-helper: push does not need platform
katrinafyi Dec 18, 2024
6bd37a2
document docker-helper variables, add DOCKER_TAG
katrinafyi Dec 18, 2024
d04b509
log url in make extract
katrinafyi Dec 18, 2024
9f38f73
lf for more files, use `stop` in docker-helper
katrinafyi Dec 18, 2024
5f3e137
add defaults for new tool variables
katrinafyi Dec 18, 2024
573af8f
choosing bap/gtirb based on existing files
katrinafyi Dec 18, 2024
ab1c744
update md5sums after bap/gtirb auto-detection
katrinafyi Dec 18, 2024
31b642f
-pie for gcc/gcc_O2 and update md5s
katrinafyi Dec 18, 2024
414de0c
preorder iterator
ailrst Dec 19, 2024
288b4e1
IndirectCallTests: auto-detect indirect call IDs
katrinafyi Dec 19, 2024
05e7deb
touch comment of ILForwardIterator
katrinafyi Dec 19, 2024
e9ad100
LiveVarsAnalysisTests: avoid fixed addresses
katrinafyi Jan 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
15 changes: 15 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
md5sums linguist-generated
compiled.md5sum linguist-generated
docker-hash linguist-generated
*.gts linguist-generated
*.adt linguist-generated
*.bir linguist-generated
*.relf linguist-generated

src/test/compiled.url.txt text eol=lf
src/test/make/docker-flake.txt text eol=lf

Makefile text eol=lf
*.sh text eol=lf
*.mk text eol=lf
*.md5sum text eol=lf
33 changes: 26 additions & 7 deletions .github/workflows/run-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,44 @@ jobs:

SystemTests:
runs-on: ubuntu-latest
container:
# Requires repo to have action access in package settings
image: ghcr.io/uq-pac/basil-dev:latest
credentials:
username: ${{ github.actor }}
password: ${{ secrets.github_token }}
# container:
# # Requires repo to have action access in package settings
# image: ghcr.io/uq-pac/basil-dev:latest
# credentials:
# username: ${{ github.actor }}
# password: ${{ secrets.github_token }}
steps:
- name: Checkout
uses: actions/checkout@v4

- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'

- uses: actions/setup-dotnet@v4
with:
dotnet-version: '6.0.x'

- run: sudo apt-get update
- run: sudo apt-get install -y z3='4.8.12-*'
- run: dotnet tool install --global boogie --version '3.4.3'

- run: make extract
working-directory: src/test

- name: System Tests
run: ./mill test.testOnly 'SystemTests*'

- uses: actions/upload-artifact@v4
if: always()
with:
name: testresult-${{ github.run_number }}
path: |
src/test/*.csv
src/test/*.svg
- run: |
- if: always()
run: |
pushd src/test
tail -n+1 summary-*.csv
pasted="$(paste headers.md.part summary-*.md.part)"
Expand Down
22 changes: 12 additions & 10 deletions docs/development/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,22 +105,24 @@ The [dsl](../basil-ir.md#constructing-programs-in-code) can be used to construct
### Integration tests

These are the `SystemTests.scala` test case with the files present in `src/test/correct` for examples that should verify and `src/test/incorrect`
for examples that should not verify.
for examples that should not verify.

These are lifted via the Makefiles, to add another test simply add a directory, c source file, and optionally specification file and run

```sh
cd src/test/
make
```

The `config.mk` file in the test directory can be used to exclude unnecessary compilers, and change compilation flags.
Full details can be found [here](../src/test/readme.md).
These are run via the Makefiles in src/test.
A Docker image is used to compile and lift examples in a reproducible way.
See [src/test/readme.md](../src/test/readme.md) for details.

### Running Tests

The test suites use [ScalaTest](https://www.scalatest.org/).

This tests are defined as C source files and must be compiled before use.
Before running any tests, download the pre-compiled test case files with:
```bash
$ make -C src/test extract
```
For more details on this process, including adding and editing test cases,
see [src/test/readme.md](../src/test/readme.md).

To run the primary SystemTests suites (SystemTestsBAP and SystemTestsGTIRB) (which require Boogie):

```
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/ir/IRCursor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ trait IntraProcIRCursor extends IRWalk[CFGPosition, CFGPosition] {
case proc: Procedure => proc.entryBlock.toSet
case b: Block => b.statements.headOption.orElse(Some(b.jump)).toSet
case n: GoTo => n.targets.asInstanceOf[Set[CFGPosition]]
case h: Unreachable => Set()
case h: Unreachable => Set()
case h: Return => Set()
case c: Statement => IRWalk.nextCommandInBlock(c).toSet
}
Expand Down
99 changes: 71 additions & 28 deletions src/main/scala/ir/Program.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,55 @@ import analysis.{BitVectorEval, MergedRegion}
import util.intrusive_list.*
import translating.serialiseIL


/**
* Iterator in pre-order of procedures, blocks, and commands. GoTos targets are traversed in an unspecified order.
*/
private class ILForwardIterator(private val begin: IterableOnce[CFGPosition], val walk: IRWalk[CFGPosition, CFGPosition]) extends Iterator[CFGPosition] {
val seen = mutable.Set[CFGPosition]()
private val stack = mutable.Stack[CFGPosition]()
stack.pushAll(begin)
seen.addAll(begin)

override def hasNext: Boolean = {
stack.nonEmpty
}

override def next(): CFGPosition = {
val n: CFGPosition = stack.pop()
seen.add(n)

val next = walk.succ(n).filterNot(seen.contains(_))
seen.addAll(next)
stack.pushAll(next)
n
}
}

/**
* Iterator in approximate syntactic pre-order of procedures, blocks, and commands. Blocks and procedures are
* not guaranteed to be in any defined order.
*/
private class ILLexicalIterator(private val begin: Iterable[CFGPosition]) extends Iterator[CFGPosition] {
private val stack = mutable.Stack[CFGPosition]()
stack.pushAll(begin)

override def hasNext: Boolean = {
stack.nonEmpty
}

override def next(): CFGPosition = {
val n: CFGPosition = stack.pop()

stack.pushAll(n match {
case p: Procedure => p.blocks
case b: Block => Seq() ++ b.statements.toSeq ++ Seq(b.jump)
case s: Command => Seq()
})
n
}
}

class Program(var procedures: ArrayBuffer[Procedure],
var mainProcedure: Procedure,
val initialMemory: mutable.TreeMap[BigInt, MemorySection]) extends Iterable[CFGPosition] {
Expand Down Expand Up @@ -92,37 +141,16 @@ class Program(var procedures: ArrayBuffer[Procedure],

}

/**
* Iterator in approximate syntactic pre-order of procedures, blocks, and commands. Blocks and procedures are
* not guaranteed to be in any defined order.
*/
private class ILUnorderedIterator(private val begin: Program) extends Iterator[CFGPosition] {
private val stack = mutable.Stack[CFGPosition]()
stack.addAll(begin.procedures)

override def hasNext: Boolean = {
stack.nonEmpty
}

override def next(): CFGPosition = {
val n: CFGPosition = stack.pop()

stack.pushAll(n match {
case p: Procedure => p.blocks
case b: Block => Seq() ++ b.statements.toSeq ++ Seq(b.jump)
case s: Command => Seq()
})
n
}

}

/**
* Get an Iterator in approximate syntactic pre-order of procedures, blocks, and commands. Blocks and procedures are
* not guaranteed to be in any defined order.
*/
def iterator: Iterator[CFGPosition] = {
ILUnorderedIterator(this)
ILLexicalIterator(this.procedures)
}

def preOrderIterator: Iterator[CFGPosition] = {
ILForwardIterator(this.procedures, IntraProcIRCursor)
}

private def memoryLookup(memory: mutable.TreeMap[BigInt, MemorySection], address: BigInt) = {
Expand Down Expand Up @@ -166,7 +194,7 @@ class Procedure private (
var out: ArrayBuffer[Parameter],
var requires: List[BExpr],
var ensures: List[BExpr],
) {
) extends Iterable[CFGPosition] {
private val _callers = mutable.HashSet[DirectCall]()
_blocks.foreach(_.parent = this)
// class invariant
Expand All @@ -177,6 +205,21 @@ class Procedure private (
this(name, address, entryBlock, returnBlock, mutable.LinkedHashSet.from(blocks), ArrayBuffer.from(in), ArrayBuffer.from(out), List.from(requires), List.from(ensures))
}

/**
* Get an Iterator in approximate syntactic pre-order of procedures, blocks, and commands. Blocks and procedures are
* not guaranteed to be in any defined order.
*/
def iterator: Iterator[CFGPosition] = {
ILLexicalIterator(Seq(this))
}

/**
* Iterate in cfg pre order.
*/
def preOrderIterator: Iterator[CFGPosition] = {
ILForwardIterator(Seq(this), IntraProcIRCursor)
}

override def toString: String = {
s"Procedure $name at ${address.getOrElse("None")} with ${blocks.size} blocks and ${in.size} in and ${out.size} out parameters"
}
Expand Down Expand Up @@ -479,4 +522,4 @@ case class MemorySection(name: String, address: BigInt, size: Int, bytes: Seq[Bi
}
}

}
}
15 changes: 14 additions & 1 deletion src/test/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,17 @@
*.csv
*.md
*.md.part
*.svg
*.svg

# files reproducibly generated
*.relf
*.adt
*.bir
*.gtirb
*.gts
docker-hash-new
!compiled.url.txt
*.gz
*.bz2
*.xz
*.zst
55 changes: 47 additions & 8 deletions src/test/Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,51 @@
TARGETSS := all verify clean cleanall cleanlift recompile json cleanjson cleangts gts
TARGETSS := all verify repro-stash repro-check md5sum-check md5sum-update clean cleanall cleanlift recompile json cleanjson cleangts gts

SUBTARGETS = $(wildcard correct/*/ incorrect/*/)
.PHONY : $(TARGETSS) $(SUBTARGETS) correct incorrect
# subdirectories of src/test. to be entered into by this makefile.
DIRS := correct incorrect extraspec_correct extraspec_incorrect indirect_calls memory_regions procedure_summaries
# dirs with different directory structure: dsa, irreducible_loops

$(TARGETSS): $(SUBTARGETS)
# non-test dirs: make, scala, unimplemented

correct: $(realpath $(wildcard correct/*))
incorrect: $(realpath $(wildcard incorrect/*))
# in case the user specfies DIRS, make sure all dirs exist.
$(foreach d, $(DIRS), \
$(if $(wildcard $(d)/.), \
, \
$(error user error: directory "$(d)" in DIRS variable does not exist)))

$(SUBTARGETS):
-$(MAKE) -C $@ -f $(realpath ./make/lift-directories.mk) $(MAKECMDGOALS)
SUBDIRS = $(wildcard $(addsuffix /*/,$(DIRS)))
.PHONY : $(TARGETSS) $(SUBDIRS) $(DIRS)

# through some unpleasantness, this lets the user specify either DIRS or SUBDIRS
# on the command line, and the make operation will be narrowed to that directory
$(TARGETSS): $(SUBDIRS)

$(SUBDIRS):
$(MAKE) -C $@ -f $(realpath ./make/lift-directories.mk) $(MAKECMDGOALS)

# concats md5sums files in subdirectories into a compiled.md5sum.
# check with `md5sum -c compiled.md5sum` in src/test.
.PHONY: compiled.md5sum
compiled.md5sum:
find $(DIRS) -name '*.md5sum' -exec cat '{}' + | sort -k2 > compiled.md5sum

TARBALL := compiled.tar.zst

$(TARBALL) docker-contents.txt &: compiled.md5sum
set -u; $$DOCKER_CMD hash > docker-contents.txt # before compessing, make sure docker-contents.txt is up to date.
md5sum --quiet -c compiled.md5sum # before compressing, make sure our files match expected hashes.
list=`mktemp`; cut -d' ' -f3 compiled.md5sum > $$list && tar caf $(TARBALL) -T $$list && rm $$list
sha1sum $(TARBALL)

.PHONY: extract
extract:
# log URL and expected hash
{ head -n1 compiled.url.txt; tail -n1 compiled.url.txt; } | cat -v
# check existing file, otherwise download fresh copy.
{ tail -n1 compiled.url.txt | sha1sum -c - ; } \
|| curl "$$(head -n1 compiled.url.txt)" -o $(TARBALL)
# check file type.
l-kent marked this conversation as resolved.
Show resolved Hide resolved
-file $(TARBALL)
# validate the hash, otherwise remove the incorrect file and abort.
{ tail -n1 compiled.url.txt | sha1sum -c - ; } || { rm -v $(TARBALL); exit 1; }
tar xf $(TARBALL) --keep-old-files --touch
md5sum --quiet -c compiled.md5sum # check that extracted files match expected checksums
Loading
Loading