Skip to content

Instantly share code, notes, and snippets.

@ecomaikgolf
Last active May 22, 2020 19:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ecomaikgolf/2a0cc9a922f70d5a53aa24ccf49afe07 to your computer and use it in GitHub Desktop.
Save ecomaikgolf/2a0cc9a922f70d5a53aa24ccf49afe07 to your computer and use it in GitHub Desktop.
Autocorrector en paralelo (de ficheros de prueba .cpp/.cpp.sal)
#!/bin/bash
# Enable & install ccache to get faster compilations
# Project makefile to generate .o
MAKEFILE_LOCATION=../../
# Project include/ folder (.h)
INCLUDE_LOCATION=../../include
# Project object output location (.o)
OBJECT_LOCATION=../../obj
# Project lib location (.cpp)
LIB_LOCATION=../../lib
if ! [ -x "$(command -v make)" ]; then
echo -e "\e[31m[✘]: Dependency | Install make\e[0m"
fi
if ! [ -x "$(command -v valgrind)" ]; then
echo -e "\e[31m[✘]: Dependency | Install valgrind\e[0m"
fi
if ! [ -x "$(command -v g++)" ]; then
echo -e "\e[31m[✘]: Dependency | Install g++\e[0m"
fi
if ! [ -x "$(command -v ccache)" ]; then
echo -e "\e[31m[✘]: Dependency | Install ccache\e[0m"
fi
start=$(date +%s)
rm -f *.gcc *.out *.diff *.core.* *.valgrind main.gcc
echo -e "\e[36m[○] Compiling code | $(echo $LIB_LOCATION/*.cpp | sed -e 's/\n/ /g')\e[0m"
#g++ -I ../../include/ ../../lib/*.cpp -g -Wall -c > main.gcc 2>&1
#g++ -I ../../include/ ../../lib/*.cpp -g -Wall -c 2> main.gcc
make -j3 -C $MAKEFILE_LOCATION > main.gcc 2>&1
if [ $? != 0 ]; then
echo -e "\e[31m[✘]: Compiler error | main.gcc\e[0m"
exit 1
else
rm -f main.gcc
fi
process() {
# Compilation
ccache g++ -I $INCLUDE_LOCATION $OBJECT_LOCATION/*.o $1 -o $1.executable > /dev/null 2> $1.gcc
#g++ -I $INCLUDE_LOCATION $1 *.o -o $1.executable > /dev/null 2> $1.gcc
if [ $? != 0 ]; then
echo -e "\e[31m[✘]: Compiler error | $1.gcc\e[0m"
exit 1
else
rm -f $1.gcc
fi
{ valgrind --track-origins=yes --show-reachable=yes --leak-resolution=high --tool=memcheck --leak-check=full --error-exitcode=2 --log-file="$1.valgrind" ./$1.executable > $1.out 2>&1;} > /dev/null 2>&1
VALGRIND=$?
if [ $VALGRIND -eq 139 ]; then
echo -e "\e[31m[✘] Segfault | $1.executable\e[0m"
exit 1
fi
# Result
if [ -f $1.sal ]; then
diff -b $1.out $1.sal 1> $1.diff
if [ $? -ne 0 ]; then
echo -e "\e[31m[✘] Wrong result | $1.out ≠ $1.sal\e[0m"
if ! [ $VALGRIND == 2 ]; then
rm -f $1.valgrind
fi
exit 1
else
rm -f $1.out $1.executable $1.diff
fi
else
echo -e "\e[31m[✘] Missing .sal | $1.sal\e[0m"
fi
# Valgrind
if [ $VALGRIND == 2 ]; then
echo -e "\e[31m[✘] Valgrind error | $1.valgrind\e[0m"
exit 1
else
rm -f $1.valgrind
fi
echo -e "\e[32m[✓] Test passed | $1\e[0m"
}
echo -e "\e[36m[○] Loaded tests | $(ls 2>/dev/null -Ubad1 -- *.cpp | wc -l)\e[0m"
echo -e "\e[36m[○] CPU Cores | $(awk '/^cpu cores[[:blank:]]*:/{ print $NF }' /proc/cpuinfo | head -n 1)\e[0m"
echo -e "\e[36m[○] CPU Threads | $(grep -c processor /proc/cpuinfo)\e[0m"
# Fork proc & paralelo
for testFile in *.cpp; do process "$testFile" & done
wait
end=$(date +%s)
seconds=$(( end - start ))
echo -e "\e[36m[○] Total time | $seconds seconds\e[0m"
echo -e "\e[36m[○] Total tests | $(ls 2>/dev/null -Ubad1 -- *.cpp | wc -l) testfile and $(ls 2>/dev/null -Ubad1 -- *.sal | wc -l) solutions \e[0m"
echo -e "\e[36m[○] Compiler errors | $(ls 2>/dev/null -Ubad1 -- *.gcc | wc -l) \e[0m"
echo -e "\e[36m[○] Wrong results | $(ls 2>/dev/null -Ubad1 -- *.diff | wc -l) \e[0m"
echo -e "\e[36m[○] Valgrind errors | $(ls 2>/dev/null -Ubad1 -- *.valgrind | wc -l) \e[0m"
echo -e "\e[36m[○] Compiler vers. | gcc $(gcc -dumpversion) \e[0m"
echo -e "\e[36m[○] Valgrind vers. | $(valgrind --version) \e[0m"
if [ $(gcc -dumpversion) != "5.4.0" ]; then
echo -e "\e[33m[?] Warning | Compiler version ≠ DLSI server version (5.4.0 ubuntu-xenial)\e[0m"
fi
if ! [ -x "$(command -v bua)" ]; then
echo -e "[i] Try github.com/ecomaikgolf/BUACShell"
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment