1
0
mirror of https://git.disroot.org/80486DX2-66/polonium.git synced 2024-11-08 13:42:31 +05:30

refactor: move testing script into Makefile

This commit is contained in:
Intel A80486DX2-66 2024-07-08 21:36:53 +03:00
parent 7eb1d1dbdf
commit 06510ce7f1
Signed by: 80486DX2-66
GPG Key ID: 83631EF27054609B
3 changed files with 35 additions and 54 deletions

View File

@ -18,4 +18,4 @@ build-and-test: # Build and check if the program works
stage: build-and-test
environment: production
script:
- make && . ./test.sh
- make && make test

View File

@ -12,7 +12,8 @@ SRCDIR = ./src
INCDIR = ./include
OBJDIR = ./obj
BINDIR = ./bin
TESTDIR = ./test_files/corrupted
TESTDIR_SAMPLES = ./test_files
TESTDIR = $(TESTDIR_SAMPLES)/corrupted
SRC = $(wildcard $(SRCDIR)/*.c)
OBJ = $(SRC:$(SRCDIR)/%.c=$(OBJDIR)/%.o)
@ -88,7 +89,38 @@ clean:
distclean:
$(call rmdirs,$(DIRECTORIES_TO_REMOVE))
# Variables for testing
EXEC_LOG = ./exec.log
PROGRAM_ARGS := -p 60 -t 2 -n 2 --noconfirm -c -s 999999999
test:
@if [ ! -e "$(EXECPATH)" ]; then \
printf -- "[!] Polonium executable (\`$(EXECUTABLE)\`) is not \
available, attempting to build\n"; \
$(MAKE) all; \
exit 0; \
fi
@printf -- "[*] Generating corrupted versions of test files\n"
@mkdir -p $(TESTDIR)
@find $(TESTDIR_SAMPLES) -maxdepth 1 -type f -name 'test.*' | while IFS= \
read -r file; do \
basename=$$(basename "$$file"); \
workfile="$(TESTDIR)/$$basename"; \
cp "$$file" "$$workfile" || exit 1; \
printf -- "--- [*] $(EXECUTABLE) $(basename "$2")$(PROGRAM_ARGS)\n"; \
$(EXECPATH) "$$workfile" $(PROGRAM_ARGS) > $(EXEC_LOG) 2>&1; \
if [ "$$?" -ne "0" ]; then \
printf -- "[!] Polonium failed:\n"; \
cat $(EXEC_LOG); \
rm $(EXEC_LOG); \
exit 1; \
fi; \
rm $(EXEC_LOG); \
done
@printf "[>] All done!\n"
testclean:
$(call rmdirs,$(TESTDIR))
.PHONY: all clean distclean testclean
.PHONY: all clean distclean test testclean

51
test.sh
View File

@ -1,51 +0,0 @@
#!/bin/sh
set +o histexpand # Disable parsing "!" as the history expansion character
set +e # Continue script execution even if a command fails
mkdir_if_not_exists() {
[ -d "$1" ] || mkdir "$1"
}
exec_name='polonium'
exec_file="$(pwd)/bin/$exec_name"
exec_log="$(pwd)/exec.log"
corrupt() {
cp "$1" "$2" || return 1
file_name="$(pwd)/$2"
args=("-p" "60" "-t" "2" "-n" "2" "--noconfirm" "-c" "-s" "999999999")
printf -- "--- [*] $exec_name $(basename "$2") ${args[*]}\n"
"$exec_file" "$file_name" "${args[@]}" > "$exec_log" 2>&1
return $?
}
iterate_on_test_files() {
find "$1" -maxdepth 1 -type f -name 'test.*' | while IFS= read -r file; do
basename="$(basename "$file")"
corrupt "$file" "./corrupted/$basename"
if [ "$?" -ne "0" ]; then
printf "[!] Polonium failed:\n"
cat "$exec_log"
rm "$exec_log"
return 1
fi
rm "$exec_log"
return 0
done
}
cd ./test_files || exit 1
printf "[*] Generating corrupted versions of test files\n"
mkdir_if_not_exists ./corrupted/
iterate_on_test_files .
if [ "$?" -ne "0" ]; then
exit 1
fi
printf "[>] All done!\n"