Skip to content

Commit 36d74a4

Browse files
committed
initial check in
0 parents  commit 36d74a4

25 files changed

+340
-0
lines changed

Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
TOOLS = bap mc
2+
3+
check: runtest-exists
4+
@export status=0
5+
@for tool in $(TOOLS); do runtest --all --tool=$$tool || status=1; done
6+
@exit $$status
7+
8+
runtest-exists:
9+
@if runtest -version >/dev/null 2>&1; then :; \
10+
else echo "Please, install runtest (dejagnu)"; exit 1; fi
11+
12+
clean:
13+
rm -f *.log *.sum

README.md

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
BAP Test suite
2+
==============
3+
4+
This repository contains tests and test artifacts for Binary Analysis
5+
Platform. We use DejaGNU testing framework to glue everything in one
6+
piece. The tests are organized around different tools, namely `bap`,
7+
`mc`, `byteweight` (to be added), and so on.
8+
9+
Usage
10+
=====
11+
12+
Testing the Platform
13+
--------------------
14+
15+
The repository was designed to be ran automatically by Travis CI, but
16+
still can be used manually. Just clone it, make sure that you have
17+
`dejagnu` installed on your system, and run:
18+
19+
```
20+
make check
21+
```
22+
23+
This will run all tests for all tools. To test only specific `$tool`, run
24+
25+
```
26+
runtest --tool=$tool
27+
```
28+
29+
To run only a specific suite from a `file.exp` of a `$tool` use:
30+
31+
```
32+
runtest --tool=$tool file.exp
33+
```
34+
35+
See `man runtest` for more information.
36+
37+
38+
Adding new test
39+
---------------
40+
41+
To add a new test to an existing tool create a file `<testname>.exp`
42+
in a folder, that contains tests for the tool. For example, to add a
43+
new test to a `bap` frontend, add it to `bap.tests`. The tests are
44+
written in Tcl extended with `expect` command. The DejaGNU framework
45+
adds few functions, such as `pass`, `fail`. Even more functions are
46+
added by tool specific libraries, the `lib/$tool.exp` is evaluated
47+
before `$tool` test, making all its definitions available. Also
48+
`site.exp` file defines site configuration parameters (see Structure
49+
section below, for information on a structure of the suite).
50+
51+
Adding new tool
52+
---------------
53+
54+
To add new tool `$tool`, you need to create:
55+
- a folder `$tool.tests` where test suites will be stored;
56+
- add this test to the Makefile `TOOLS` variable
57+
- add `lib/$tool.exp` as a tool support package
58+
59+
60+
Adding new test artifact
61+
------------------------
62+
63+
We store artifacts in binary mode and if possible in source
64+
code. There are few reasons to commit the artifacts in the binary
65+
form:
66+
67+
1. it is quite to compile them in a portable way
68+
2. sometimes there're now source code for an artifact
69+
70+
The artifact name should have form `tripple-name`, where `tripple` is
71+
a canonical target representation, e.g., `arm-linux-gnueabi`,
72+
`i686-w64-mingw32`, etc. An example of a well-formed fully tripplified
73+
name would be: `arm-linux-androideabi-echo`.
74+
75+
Once a new test artifact is added, make sure that all existing tests
76+
are passing. If the don't then either create an issue (if you think,
77+
that they should pass), or fix the test.
78+
79+
Structure
80+
=========
81+
82+
The repository structure is defined by requirements of the DejaGNU
83+
framework. For each `$tool` there is a folder `$tool.tests` that
84+
contains tests for this `$tool`. A library `lib/$tool.exp` contains
85+
code that can be reused across different tools. Other modules from
86+
this folder can be loaded with `load_lib` procedure provide by the
87+
DejaGNU framework, e.g., `common.exp` is used for sharing code between
88+
all tools. The `config` folder contains configuration files (i.e.,
89+
files that define configuration constants) specific for
90+
boards. (Currently we support only unix board, so at this point of
91+
time it can be ignored).
92+
93+
The `src` folder contains source code for test artifacts. Each
94+
test-artifact that has a source should be rebuildable from the source,
95+
using a recipe in `src/Makefile`. The `src/Makefile` can contain
96+
recipes that are not portable.
97+
98+
The `bin` folder contains the test artifacts built from sources `src`,
99+
or obtained from some obscure system. The folder must contain only
100+
binary files for testing. If some object data is needed, then it
101+
should be stored in corresponding test folder in the test itself or as
102+
a file with `.dat` extension (or any other suitable extension). If you
103+
want to add some meta information to a file that is not backed by a
104+
source code, it would be a good idea to add a textual file with the
105+
same basename as the file into the `src` folder.
106+
107+
108+
Current Status
109+
==============
110+
111+
Currently the suite is an alpha stage and is not yet integrated with
112+
Travis CI. It will be as soon, as we will get `0` on the `make check`.

bap.tests/api-main.exp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
set test "api-main"
2+
3+
set testsuite {
4+
"arm-linux-gnueabi" {
5+
"sub main(main_argc, main_argv, main_result)"
6+
"main_argc :: in u32 = R0"
7+
"main_argv :: in out u32 = R1"
8+
"main_result :: out u32 = R0"
9+
}
10+
"arm-linux-androideabi" {
11+
"sub main(main_argc, main_argv, main_result)"
12+
"main_argc :: in u32 = R0"
13+
"main_argv :: in out u32 = R1"
14+
"main_result :: out u32 = R0"
15+
}
16+
"arm-linux-gnueabihf" {
17+
"sub main(main_argc, main_argv, main_result)"
18+
"main_argc :: in u32 = R0"
19+
"main_argv :: in out u32 = R1"
20+
"main_result :: out u32 = R0"
21+
}
22+
"i686-w64-mingw32" {
23+
"sub main(main_argc, main_argv, main_result)"
24+
"main_argc :: in u32 = *"
25+
"main_argv :: in out u32 = *"
26+
"main_result :: out u32 = *"
27+
}
28+
"x86_64-w64-mingw32" {
29+
"sub main(main_argc, main_argv, main_result)"
30+
"main_argc :: in u64 = *"
31+
"main_argv :: in out u64 = *"
32+
"main_result :: out u64 = *"
33+
}
34+
"x86_64-linux-gnu" {
35+
"sub main(main_argc, main_argv, main_result)"
36+
"main_argc :: in u64 = *"
37+
"main_argv :: in out u64 = *"
38+
"main_result :: out u64 = *"
39+
}
40+
}
41+
42+
43+
foreach {target lines} $testsuite {
44+
set file "$bindir/$target-echo"
45+
foreach line $lines {
46+
spawn bap $file -d
47+
expect {
48+
$line {pass "$test <$line> in $target"}
49+
default {
50+
if [file exists $file ] {
51+
fail "$test <$line> $target"
52+
} else {
53+
untested "$test $target"
54+
}
55+
}
56+
}
57+
}
58+
}

bap.tests/byteweight.exp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
set test "byteweight"
2+
3+
foreach-binary {file "*"} "bap -d --rooter=byteweight" {
4+
"sub *main" {pass "$test $file"}
5+
default {
6+
if [string match "*-*-gnueabihf-*" $file] {
7+
note "signatures do not handle gnueabihf mode"
8+
xfail "$test in $file"
9+
} else {
10+
fail "$test in $file"
11+
}
12+
}
13+
}

bap.tests/echo-main.exp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
set test "echo.main"
2+
3+
foreach-binary {file "*-echo"} "bap -d" {
4+
"sub *main" {pass "$test $file"}
5+
default {fail "$test in $file"}
6+
}

bap.tests/plugins.exp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
set test "plugins"
2+
3+
set listed_plugins [exec bap --list-plugins]
4+
set plugins [lmap x [split $listed_plugins "\n"] {lindex [split $x] 3}]
5+
6+
7+
exec bap --version
8+
9+
foreach plugin $plugins {
10+
spawn cat $logfile
11+
expect {
12+
"Loaded $plugin" {pass "is_loaded $plugin"}
13+
default {fail "$plugin wasn't loaded"}
14+
}
15+
}

bap.tests/taint.exp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
set test "propagate taint"
2+
set regs {ZF}
3+
set taint_opts [lmap x $regs {list "--taint-reg=$x"}]
4+
set bir_attrs {tainted-reg tainted-regs visited}
5+
set bir_attrs_opts [lmap x $bir_attrs {list "--print-bir-attr=$x"}]
6+
set opts "$taint_opts $bir_attrs_opts -d --propagate-taint"
7+
8+
foreach attr $bir_attrs {
9+
foreach-binary {file *} "bap $opts" {
10+
".$attr" {pass "$test $attr in $file"}
11+
default {fail "$test $attr in $file"}
12+
}
13+
}

bap.tests/version.exp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
set test "version"
2+
spawn bap --version
3+
expect {
4+
"error" {fail $test}
5+
"1" {pass $test}
6+
eof {fail $test}
7+
}
8+
9+
exec bap --version

bin/arm-linux-androideabi-echo

3.31 KB
Binary file not shown.

bin/arm-linux-gnueabi-echo

8.38 KB
Binary file not shown.

0 commit comments

Comments
 (0)