Skip to content

Commit f5acc1d

Browse files
committed
Add tests
Fixes: #12 Signed-off-by: Darshan Sen <[email protected]>
1 parent 90a8f03 commit f5acc1d

File tree

15 files changed

+138
-104
lines changed

15 files changed

+138
-104
lines changed

.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ commands:
110110
- attach_workspace:
111111
at: .
112112

113-
- run: make check
113+
- run: make test
114114

115115
## JOBS ##
116116

Makefile

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ include vendor/vendorpull/targets.mk
33
include build/system.mk
44
include build/deps.mk
55

6-
all: vendor compile patch check
6+
all: vendor compile patch test
77

88
.PHONY: lief
99
lief: dist/lief
@@ -15,6 +15,6 @@ dist/lief:
1515
cd vendor/lief && python3 ./setup.py $(BUILD_OPTS) build_ext -b ../../$@ -j $(JOBS)
1616

1717

18-
.PHONY: check
19-
check:
20-
$(MAKE) -C examples/
18+
.PHONY: test
19+
test:
20+
./test.sh

README.markdown

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ $ ./postject.py --macho-segment-name __ELECTRON /Users/dsanders/electron/src/out
2929
### Testing
3030

3131
```sh
32-
$ make check
32+
$ make test
3333
```
3434

3535
## Design

examples/Makefile

-22
This file was deleted.

examples/test.S

-21
This file was deleted.

examples/test.c

-21
This file was deleted.

examples/test.cpp

-19
This file was deleted.

examples/test.sh

-15
This file was deleted.

test.sh

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/sh
2+
3+
set -o errexit
4+
set -o nounset
5+
6+
for test_directory in tests/*
7+
do
8+
if [ -d "$test_directory" ]
9+
then
10+
echo "---- Running $test_directory" 1>&2
11+
TEMPORARY_DIRECTORY="$(mktemp -d)"
12+
pwd="$PWD"
13+
cd "$test_directory"
14+
TEMPORARY_DIRECTORY="$TEMPORARY_DIRECTORY" ./test.sh \
15+
&& EXIT_CODE="$?" || EXIT_CODE="$?"
16+
cd "$pwd"
17+
rm -rf "$TEMPORARY_DIRECTORY"
18+
19+
if [ "$EXIT_CODE" = "0" ]
20+
then
21+
echo "\033[33;32m✓ PASS\x1b[0m $test_directory" 1>&2
22+
else
23+
echo "\033[33;31m× FAIL\x1b[0m $test_directory" 1>&2
24+
exit "$EXIT_CODE"
25+
fi
26+
fi
27+
done
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <assert.h>
2+
#include <stdio.h>
3+
4+
#include "../../postject-api.h"
5+
6+
int main()
7+
{
8+
size_t size;
9+
const void *ptr = postject_find_resource("foobar", &size, NULL);
10+
11+
assert(ptr != NULL);
12+
assert(size > 0);
13+
14+
fwrite(ptr, size, 1, stdout);
15+
16+
return 0;
17+
}
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/sh
2+
3+
set -o errexit
4+
set -o nounset
5+
6+
bin="$TEMPORARY_DIRECTORY/a.out"
7+
cc test.c -o "$bin"
8+
9+
input="$TEMPORARY_DIRECTORY/input.txt"
10+
head -c 1073741824 /dev/urandom > "$input"
11+
12+
../../postject.py --overwrite "$bin" "foobar" "$input"
13+
14+
output="$TEMPORARY_DIRECTORY/output.txt"
15+
16+
"$bin" > "$output"
17+
18+
diff "$input" "$output"
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <assert.h>
2+
#include <stdio.h>
3+
4+
#include "../../postject-api.h"
5+
6+
int main()
7+
{
8+
size_t size;
9+
const void *ptr = postject_find_resource("foobar", &size, NULL);
10+
11+
assert(ptr != NULL);
12+
assert(size > 0);
13+
14+
fwrite(ptr, size, 1, stdout);
15+
16+
return 0;
17+
}
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/sh
2+
3+
set -o errexit
4+
set -o nounset
5+
6+
bin="$TEMPORARY_DIRECTORY/a.out"
7+
cc test.c -o "$bin"
8+
9+
input="$TEMPORARY_DIRECTORY/input.txt"
10+
head -c 1024 /dev/urandom > "$input"
11+
12+
../../postject.py --overwrite "$bin" "foobar" "$input"
13+
14+
output="$TEMPORARY_DIRECTORY/output.txt"
15+
16+
"$bin" > "$output"
17+
18+
diff "$input" "$output"
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <assert.h>
2+
#include <stdio.h>
3+
4+
#include "../../postject-api.h"
5+
6+
int main()
7+
{
8+
size_t size;
9+
const void *ptr = postject_find_resource("foobar", &size, NULL);
10+
11+
assert(ptr != NULL);
12+
assert(size > 0);
13+
14+
fwrite(ptr, size, 1, stdout);
15+
16+
return 0;
17+
}
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/sh
2+
3+
set -o errexit
4+
set -o nounset
5+
6+
bin="$TEMPORARY_DIRECTORY/a.out"
7+
cc test.c -o "$bin"
8+
9+
input="$TEMPORARY_DIRECTORY/input.txt"
10+
head -c 1048576 /dev/urandom > "$input"
11+
12+
../../postject.py --overwrite "$bin" "foobar" "$input"
13+
14+
output="$TEMPORARY_DIRECTORY/output.txt"
15+
16+
"$bin" > "$output"
17+
18+
diff "$input" "$output"

0 commit comments

Comments
 (0)