Skip to content

Commit 87437b3

Browse files
committed
Add tests for injecting large resources
Fixes: #12 Signed-off-by: Darshan Sen <[email protected]>
1 parent 90a8f03 commit 87437b3

File tree

16 files changed

+138
-104
lines changed

16 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.list

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
tests/inject_and_retrieve_data_1KB
2+
tests/inject_and_retrieve_data_1MB
3+
tests/inject_and_retrieve_data_1GB

test.sh

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/sh
2+
3+
set -o errexit
4+
set -o nounset
5+
6+
while IFS= read -r test_directory
7+
do
8+
echo "---- Running $test_directory" 1>&2
9+
TEMPORARY_DIRECTORY="$(mktemp -d)"
10+
pwd="$PWD"
11+
cd "$test_directory"
12+
TEMPORARY_DIRECTORY="$TEMPORARY_DIRECTORY" ./test.sh \
13+
&& EXIT_CODE="$?" || EXIT_CODE="$?"
14+
cd "$pwd"
15+
rm -rf "$TEMPORARY_DIRECTORY"
16+
17+
if [ "$EXIT_CODE" = "0" ]
18+
then
19+
echo "\033[33;32m✓ PASS\x1b[0m $test_directory" 1>&2
20+
else
21+
echo "\033[33;31m× FAIL\x1b[0m $test_directory" 1>&2
22+
exit "$EXIT_CODE"
23+
fi
24+
done < test.list
+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)