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

Expand tests to cover more cases including encryption #96

Merged
merged 1 commit into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,11 @@ $(B)/libencrypt.so: libencrypt.c


tests: $(B)/memcr
$(MAKE) -C tests CC=$(CC) MEMCR=../$<
$(MAKE) -C tests CC=$(CC) MEMCR=../$< ENCRYPT=$(ENCRYPT)

ifeq ($(ENCRYPT), 1)
tests: $(B)/libencrypt.so
endif


clean:
Expand Down
82 changes: 66 additions & 16 deletions tests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,87 @@ MEMCR=$1

CUID=$(id -u)
if [ "$CUID" != "0" ]; then
DO="sudo"
DO="sudo "
else
DO=""
fi

TESTS="test-malloc"
# text formatting
WHITE='\033[37m'
RED='\033[0;31m'
GREEN='\033[0;32m'
BOLD='\033[1m'
NOFMT='\033[0m'

TEST_CNT=0

do_memcr_test()
{
MEMCR_CMD=$1
TEST=$2

for TEST in $TESTS; do
echo "######## running $TEST ########"
TEST_CNT=$((TEST_CNT + 1))
echo "${WHITE}[test $TEST_CNT] $MEMCR_CMD for $TEST${NOFMT}"

# start the test
./$TEST &
TPID=$!

# wait
sleep 0.2
sleep 0.05

# memcr
$DO $MEMCR -p $! -n -f
$MEMCR_CMD -p $TPID
if [ $? -ne 0 ]; then
kill $!
echo "[-] $TEST failed"
break
kill $TPID
echo "${RED}[test $TEST_CNT] failed${NOFMT}"
return 1
fi

# stop the test
kill -USR1 $!
wait $!
if [ $? -eq 0 ]; then
echo "[+] $TEST passed"
else
echo "[-] $TEST failed"
break
kill -USR1 $TPID
wait $TPID
if [ $? -ne 0 ]; then
echo "${RED}[test $TEST_CNT] failed${NOFMT}"
return 1
fi

echo "${GREEN}[test $TEST_CNT] passed${NOFMT}"
return 0
}

TESTS="test-malloc"

TIME_START=$(date +%s%N)

# basic tests
for OPT in "" "--proc-mem" "--rss-file" "--proc-mem --rss-file"; do
MEMCR_CMD="${DO}$MEMCR -n $OPT"

for TEST in $TESTS; do
do_memcr_test "$MEMCR_CMD" "$TEST" || exit 1
done
done

# encryption tests
if [ "$ENCRYPT" = "1" ]; then
if [ ! -f ../libencrypt.so ]; then
echo "${RED}libencrypt.so not found${NOFMT}"
exit 1
fi

for OPT in "--rss-file" "--proc-mem --rss-file"; do
for ENC in "" "aes-128-cbc" "aes-192-cbc" "aes-256-cbc"; do
MEMCR_CMD="${DO}env LD_PRELOAD=../libencrypt.so $MEMCR -n $OPT --encrypt $ENC"

for TEST in $TESTS; do
do_memcr_test "$MEMCR_CMD" "$TEST" || exit 1
done
done
done
fi

TIME_END=$(date +%s%N)
TIME_ELAPSED_MS=$(((TIME_END - TIME_START) / 1000000))

echo "${BOLD}[+] all $TEST_CNT tests passed, took $TIME_ELAPSED_MS ms${NOFMT}"