Skip to content

Commit

Permalink
tests: add tests for injecting large resources
Browse files Browse the repository at this point in the history
Fixes: #12
Signed-off-by: Darshan Sen <[email protected]>
  • Loading branch information
RaisinTen committed Sep 20, 2022
1 parent 90a8f03 commit fd5855c
Show file tree
Hide file tree
Showing 18 changed files with 174 additions and 104 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ commands:
- attach_workspace:
at: .

- run: make check
- run: make test

## JOBS ##

Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ include vendor/vendorpull/targets.mk
include build/system.mk
include build/deps.mk

all: vendor compile patch check
all: vendor compile patch test

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


.PHONY: check
check:
$(MAKE) -C examples/
.PHONY: test
test:
./test.sh
2 changes: 1 addition & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ $ ./postject.py --macho-segment-name __ELECTRON /Users/dsanders/electron/src/out
### Testing

```sh
$ make check
$ make test
```

## Design
Expand Down
22 changes: 0 additions & 22 deletions examples/Makefile

This file was deleted.

21 changes: 0 additions & 21 deletions examples/test.S

This file was deleted.

21 changes: 0 additions & 21 deletions examples/test.c

This file was deleted.

19 changes: 0 additions & 19 deletions examples/test.cpp

This file was deleted.

15 changes: 0 additions & 15 deletions examples/test.sh

This file was deleted.

4 changes: 4 additions & 0 deletions test.list
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
tests/inject_and_retrieve_data_1KB
tests/inject_and_retrieve_data_1MB
tests/inject_and_retrieve_data_1GB
tests/inject_and_retrieve_data_3GB
24 changes: 24 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/sh

set -o errexit
set -o nounset

while IFS= read -r test_directory
do
echo "---- Running $test_directory" 1>&2
TEMPORARY_DIRECTORY="$(mktemp -d)"
pwd="$PWD"
cd "$test_directory"
TEMPORARY_DIRECTORY="$TEMPORARY_DIRECTORY" ./test.sh \
&& EXIT_CODE="$?" || EXIT_CODE="$?"
cd "$pwd"
rm -rf "$TEMPORARY_DIRECTORY"

if [ "$EXIT_CODE" = "0" ]
then
echo "\033[33;32m✓ PASS\x1b[0m $test_directory" 1>&2
else
echo "\033[33;31m× FAIL\x1b[0m $test_directory" 1>&2
exit "$EXIT_CODE"
fi
done < test.list
17 changes: 17 additions & 0 deletions tests/inject_and_retrieve_data_1GB/test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <assert.h>
#include <stdio.h>

#include "../../postject-api.h"

int main()
{
size_t size;
const void *ptr = postject_find_resource("foobar", &size, NULL);

assert(ptr != NULL);
assert(size > 0);

fwrite(ptr, size, 1, stdout);

return 0;
}
18 changes: 18 additions & 0 deletions tests/inject_and_retrieve_data_1GB/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh

set -o errexit
set -o nounset

bin="$TEMPORARY_DIRECTORY/a.out"
cc test.c -o "$bin"

input="$TEMPORARY_DIRECTORY/input.txt"
head -c 1073741824 /dev/urandom > "$input"

../../postject.py --overwrite "$bin" "foobar" "$input"

output="$TEMPORARY_DIRECTORY/output.txt"

"$bin" > "$output"

diff "$input" "$output"
17 changes: 17 additions & 0 deletions tests/inject_and_retrieve_data_1KB/test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <assert.h>
#include <stdio.h>

#include "../../postject-api.h"

int main()
{
size_t size;
const void *ptr = postject_find_resource("foobar", &size, NULL);

assert(ptr != NULL);
assert(size > 0);

fwrite(ptr, size, 1, stdout);

return 0;
}
18 changes: 18 additions & 0 deletions tests/inject_and_retrieve_data_1KB/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh

set -o errexit
set -o nounset

bin="$TEMPORARY_DIRECTORY/a.out"
cc test.c -o "$bin"

input="$TEMPORARY_DIRECTORY/input.txt"
head -c 1024 /dev/urandom > "$input"

../../postject.py --overwrite "$bin" "foobar" "$input"

output="$TEMPORARY_DIRECTORY/output.txt"

"$bin" > "$output"

diff "$input" "$output"
17 changes: 17 additions & 0 deletions tests/inject_and_retrieve_data_1MB/test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <assert.h>
#include <stdio.h>

#include "../../postject-api.h"

int main()
{
size_t size;
const void *ptr = postject_find_resource("foobar", &size, NULL);

assert(ptr != NULL);
assert(size > 0);

fwrite(ptr, size, 1, stdout);

return 0;
}
18 changes: 18 additions & 0 deletions tests/inject_and_retrieve_data_1MB/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh

set -o errexit
set -o nounset

bin="$TEMPORARY_DIRECTORY/a.out"
cc test.c -o "$bin"

input="$TEMPORARY_DIRECTORY/input.txt"
head -c 1048576 /dev/urandom > "$input"

../../postject.py --overwrite "$bin" "foobar" "$input"

output="$TEMPORARY_DIRECTORY/output.txt"

"$bin" > "$output"

diff "$input" "$output"
17 changes: 17 additions & 0 deletions tests/inject_and_retrieve_data_3GB/test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <assert.h>
#include <stdio.h>

#include "../../postject-api.h"

int main()
{
size_t size;
const void *ptr = postject_find_resource("foobar", &size, NULL);

assert(ptr != NULL);
assert(size > 0);

fwrite(ptr, size, 1, stdout);

return 0;
}
18 changes: 18 additions & 0 deletions tests/inject_and_retrieve_data_3GB/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh

set -o errexit
set -o nounset

bin="$TEMPORARY_DIRECTORY/a.out"
cc test.c -o "$bin"

input="$TEMPORARY_DIRECTORY/input.txt"
head -c 3221225472 /dev/urandom > "$input"

../../postject.py --overwrite "$bin" "foobar" "$input"

output="$TEMPORARY_DIRECTORY/output.txt"

"$bin" > "$output"

diff "$input" "$output"

0 comments on commit fd5855c

Please sign in to comment.