From 18e184100f4bac097edc80f793d410f6cbe9be90 Mon Sep 17 00:00:00 2001 From: Intel A80486DX2-66 Date: Sun, 7 Jul 2024 00:55:16 +0300 Subject: [PATCH] initial test upload (shell script) --- test.sh | 68 +++++++++++++++++++++++++++++++++++++++++++ test_files/.gitignore | 2 ++ test_files/test.txt | 13 +++++++++ 3 files changed, 83 insertions(+) create mode 100644 test.sh create mode 100644 test_files/.gitignore create mode 100644 test_files/test.txt diff --git a/test.sh b/test.sh new file mode 100644 index 0000000..d45f7fc --- /dev/null +++ b/test.sh @@ -0,0 +1,68 @@ +#!/bin/sh + +mkdir_if_not_exists() { + [ -d "$1" ] || mkdir "$1" +} + +make_log="$(pwd)/make.log" + +exec_name='polonium_debug' +exec_file="$(pwd)/bin/$exec_name" +exec_log="$(pwd)/exec.log" + +corrupt() { + cp "$1" "$2" || return 1 + + file_name="$(pwd)/$2" + + args=("$file_name" "-p" "60" "-t" "2" "-n" "2" "--noconfirm" \ + "-s" "999999999") + + printf -- "--- [*] $exec_name ${args[*]}\n" + + "$exec_file" "${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 +} + +set +o histexpand # Disable parsing "!" as the history expansion character + +# If either binary or object files are present, clean up +[ -d ./bin -o -d ./obj ] && make clean > /dev/null 2>&1 + +printf "[*] Making\n" +make DEBUG=1 all > "$make_log" 2>&1 + +if [ "$?" -ne "0" ]; then + printf "[!] Makefile failed:\n" + cat "$make_log" + rm "$make_log" + exit 1 +fi + +rm "$make_log" + +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" diff --git a/test_files/.gitignore b/test_files/.gitignore new file mode 100644 index 0000000..fcf9167 --- /dev/null +++ b/test_files/.gitignore @@ -0,0 +1,2 @@ +# Test artifacts +corrupted/ diff --git a/test_files/test.txt b/test_files/test.txt new file mode 100644 index 0000000..2f35f88 --- /dev/null +++ b/test_files/test.txt @@ -0,0 +1,13 @@ +In the mystical realm of Gensokyo, a mischievous satori named Koishi Komeiji +delighted in playing tricks on her friends and foes alike. One day, she +stumbled upon a mysterious element known as Polonium, rumored to have the +power to corrupt even the most secure of digital files. Intrigued, Koishi +decided to test its potency. With a sly grin, she whispered an incantation, +and the Polonium began to glow with an otherworldly energy. + +As she waved her hand, the corrupted files began to spread like a digital +plague, infecting the computers and devices of those around her. Her friends, +including Reimu and Marisa, were baffled by the sudden malfunction of their +gadgets. Meanwhile, Koishi cackled with glee, reveling in the chaos she had +unleashed. But little did she know, her prank would soon have unintended +consequences, threatening the very fabric of Gensokyo's digital realm.