Added checker files
This commit is contained in:
parent
adde72c74d
commit
436459c232
|
@ -0,0 +1,17 @@
|
||||||
|
.PHONY: all clean run pack build-pre build-post
|
||||||
|
|
||||||
|
all: build-pre run build-post
|
||||||
|
|
||||||
|
build-pre:
|
||||||
|
|
||||||
|
build-post:
|
||||||
|
|
||||||
|
run:
|
||||||
|
@./run_all.sh
|
||||||
|
|
||||||
|
pack:
|
||||||
|
zip -r run_test_lin.zip _test/ Makefile.checker \
|
||||||
|
run_all.sh README
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f *~
|
|
@ -0,0 +1 @@
|
||||||
|
file passed through stdin
|
|
@ -0,0 +1 @@
|
||||||
|
bad.file
|
|
@ -0,0 +1,10 @@
|
||||||
|
#define ABC "10"
|
||||||
|
#define BCD 20 + 4
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
printf("%s\n", ABC);
|
||||||
|
int x = BCD + 20;
|
||||||
|
printf("%x\n", x);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
#define ABC 10
|
||||||
|
#define ABCD 2
|
||||||
|
#define BCD ABC + 15
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
printf("%d\n", ABC);
|
||||||
|
int x = BCD + 20;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
#define VAR0 1 \
|
||||||
|
+ 2\
|
||||||
|
+ 3\
|
||||||
|
+ 4
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int y = VAR0 + 1;
|
||||||
|
printf("%d\n", VAR0);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
int main() {
|
||||||
|
#if 1
|
||||||
|
printf("Yes!\n");
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
int main() {
|
||||||
|
#if 0
|
||||||
|
printf("No!\n");
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
#define TEST 1
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
#if TEST
|
||||||
|
printf("Yes!\n");
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
#define TEST 0
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
#if TEST
|
||||||
|
printf("Yes!\n");
|
||||||
|
#endif
|
||||||
|
return 0
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
int main() {
|
||||||
|
#if 1
|
||||||
|
printf("True!\n");
|
||||||
|
#else
|
||||||
|
printf("False!\n");
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
int main() {
|
||||||
|
#if 0
|
||||||
|
printf("True!\n");
|
||||||
|
#else
|
||||||
|
printf("False!\n");
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
#define TEST 1
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
#if TEST
|
||||||
|
printf("True!\n");
|
||||||
|
#else
|
||||||
|
printf("False!\n");
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
-X bad param
|
|
@ -0,0 +1,9 @@
|
||||||
|
int main() {
|
||||||
|
#if TEST
|
||||||
|
printf("True!\n");
|
||||||
|
#else
|
||||||
|
printf("False!\n");
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
-D TEST=0
|
|
@ -0,0 +1,12 @@
|
||||||
|
#define FALSE 0
|
||||||
|
#define NOT 0
|
||||||
|
#define TRUE 1
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
#if FALSE
|
||||||
|
printf("False!\n");
|
||||||
|
#elif NOT
|
||||||
|
printf("True!\n");
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
#define FALSE 0
|
||||||
|
#define NOT 0
|
||||||
|
#define TRUE 1
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
#if FALSE
|
||||||
|
printf("False!\n");
|
||||||
|
#elif TRUE
|
||||||
|
printf("True!\n");
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
#define FALSE 0
|
||||||
|
#define NOT 0
|
||||||
|
#define TRUE 1
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
#if FALSE
|
||||||
|
printf("False!\n");
|
||||||
|
#elif TRUE
|
||||||
|
printf("True!\n");
|
||||||
|
#else
|
||||||
|
printf("Bad!\n");
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
#define FALSE 0
|
||||||
|
#define NOT 0
|
||||||
|
#define TRUE 1
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
#if FALSE
|
||||||
|
printf("False!\n");
|
||||||
|
#elif NOT
|
||||||
|
printf("True!\n");
|
||||||
|
#else
|
||||||
|
printf("Good!\n");
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
#define VAR0 1
|
||||||
|
#define TEST_IF 5
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
#if 0
|
||||||
|
printf("No\n");
|
||||||
|
#elif 0
|
||||||
|
printf("Maybe\n");
|
||||||
|
#elif VAR0
|
||||||
|
printf("ABC\n");
|
||||||
|
#else
|
||||||
|
printf("Yes\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if TEST_IF
|
||||||
|
printf("#defines working in #ifs\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int y = VAR0 + 1;
|
||||||
|
printf("%d\n", VAR0);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
#ifdef DEBUG
|
||||||
|
printf("DEBUG\n");
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
#ifdef DEBUG
|
||||||
|
printf("DEBUG\n");
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
-DDEBUG
|
|
@ -0,0 +1,9 @@
|
||||||
|
#ifndef VAR0
|
||||||
|
#define VAR0 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
printf("VAR0 = %d\n", VAR0);
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
#ifdef VAR0
|
||||||
|
#undef VAR0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
printf("VAR0 = %d\n", VAR0);
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
-D VAR0
|
|
@ -0,0 +1 @@
|
||||||
|
input error file
|
|
@ -0,0 +1 @@
|
||||||
|
_test/inputs/test3.in test3.out test3.err
|
|
@ -0,0 +1,6 @@
|
||||||
|
#include "no-file.h"
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
_test/inputs/test30.in
|
|
@ -0,0 +1,5 @@
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
printf("%d\n", VAR0 + VAR1);
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
-D VAR0=0 -D VAR1=1
|
|
@ -0,0 +1 @@
|
||||||
|
int var;
|
|
@ -0,0 +1,7 @@
|
||||||
|
#include "test32.h"
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
printf("var = %d\n", var);
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
int var;
|
|
@ -0,0 +1,7 @@
|
||||||
|
#include "test33.dir/test33.h"
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
printf("var = %d\n", var);
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
int var;
|
|
@ -0,0 +1,8 @@
|
||||||
|
#include "test34.h"
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
printf("var = %d\n", var);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
-I _test/inputs/test34.dir
|
|
@ -0,0 +1 @@
|
||||||
|
#define VAR 1
|
|
@ -0,0 +1 @@
|
||||||
|
#define VAR 2
|
|
@ -0,0 +1 @@
|
||||||
|
#define VAR 0
|
|
@ -0,0 +1,8 @@
|
||||||
|
#include "test35.h"
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
printf("VAR = %d\n", VAR);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
-I _test/inputs/test35.dir -I _test/inputs/test35.dir/test35.subdir
|
|
@ -0,0 +1 @@
|
||||||
|
#define VAR 1
|
|
@ -0,0 +1 @@
|
||||||
|
#define VAR 2
|
|
@ -0,0 +1,8 @@
|
||||||
|
#include "test36.h"
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
printf("VAR = %d\n", VAR);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
-I _test/inputs/test36.dir -I _test/inputs/test36.dir/test36.subdir
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
#ifndef _TEST_33_H_
|
||||||
|
#define _TEST_33_H_
|
||||||
|
|
||||||
|
int var;
|
||||||
|
|
||||||
|
#endif /* TEST_33_H_ */
|
|
@ -0,0 +1,7 @@
|
||||||
|
#include "test37.h"
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
printf("var = %d\n", var);
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
#ifndef _DEBUG_H_
|
||||||
|
#define _DEBUG_H_
|
||||||
|
|
||||||
|
#ifndef DEBUG_STR
|
||||||
|
#define DEBUG_STR "debuging"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
#define debug fprintf(stderr, DEBUG_STR "\n")
|
||||||
|
#else
|
||||||
|
#define debug
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* _DEBUG_H_ */
|
|
@ -0,0 +1,12 @@
|
||||||
|
#ifndef _TEST38_H_
|
||||||
|
#define _TEST38_H_
|
||||||
|
|
||||||
|
#ifdef CUSTOM_DBG
|
||||||
|
#define DEBUG_STR CUSTOM_DBG
|
||||||
|
#else
|
||||||
|
#define DEBUG_STR "my debugging"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "debug.h"
|
||||||
|
|
||||||
|
#endif /* _TEST38_H_ */
|
|
@ -0,0 +1,7 @@
|
||||||
|
#include "test38.h"
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
debug;
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
-D DEBUG=1 -D CUSTOM_DBG=custom-debugging -I _test/inputs/test38.dir
|
|
@ -0,0 +1 @@
|
||||||
|
file passed through standard input
|
|
@ -0,0 +1 @@
|
||||||
|
file passed through parameter
|
|
@ -0,0 +1 @@
|
||||||
|
file passed as output
|
|
@ -0,0 +1,8 @@
|
||||||
|
#define VAR0 1
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int y = VAR0 + 1;
|
||||||
|
printf("%d\n", VAR0);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
int main() {
|
||||||
|
int y = VAR0 + 1;
|
||||||
|
printf("%d\n", VAR0);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
-D VAR0=1
|
|
@ -0,0 +1,10 @@
|
||||||
|
#define VAR0 1
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int y = VAR0 + 1;
|
||||||
|
printf("%d\n", VAR0);
|
||||||
|
#undef VAR0
|
||||||
|
printf("%d\n", VAR0);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1,254 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#
|
||||||
|
# Tema1 Test Suite
|
||||||
|
#
|
||||||
|
# 2020, Operating Systems
|
||||||
|
#
|
||||||
|
|
||||||
|
# ----------------- General declarations and util functions ------------------ #
|
||||||
|
INPUT_DIR=_test/inputs
|
||||||
|
REF_DIR=_test/ref
|
||||||
|
OUT_DIR=_test/outputs
|
||||||
|
EXEC_NAME=./so-cpp
|
||||||
|
|
||||||
|
max_points=95
|
||||||
|
|
||||||
|
TEST_LIB=_test/test_lib.sh
|
||||||
|
|
||||||
|
MEMCHECK=""
|
||||||
|
CPP="cpp -P"
|
||||||
|
[ $(uname -s) == "Linux" ]
|
||||||
|
IS_LINUX=$?
|
||||||
|
|
||||||
|
if [ $IS_LINUX -eq 0 ]; then
|
||||||
|
MEMCHECK="valgrind --leak-check=full \
|
||||||
|
--show-reachable=yes \
|
||||||
|
--vex-iropt-register-updates=allregs-at-mem-access \
|
||||||
|
--show-leak-kinds=all \
|
||||||
|
--error-exitcode=1 \
|
||||||
|
$MEMCHECK_EXTRA \
|
||||||
|
--log-file=_log "
|
||||||
|
else
|
||||||
|
MEMCHECK="drmemory -batch \
|
||||||
|
-exit_code_if_errors 1 \
|
||||||
|
-quiet \
|
||||||
|
$MEMCHECK_EXTRA \
|
||||||
|
-- "
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# load the lib functions
|
||||||
|
if ! [ -e "$TEST_LIB" ]; then
|
||||||
|
echo "Test library not found. Check \$TEST_LIB ($TEST_LIB)"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
source "$TEST_LIB"
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------- #
|
||||||
|
|
||||||
|
# ----------------- Init and cleanup tests ----------------------------------- #
|
||||||
|
|
||||||
|
init_test()
|
||||||
|
{
|
||||||
|
if ! [ -e "$EXEC_NAME" ]; then
|
||||||
|
echo "$EXEC_NAME not found! Cannot run the test"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
unset malloc_limit
|
||||||
|
unset calloc_limit
|
||||||
|
unset realloc_limit
|
||||||
|
|
||||||
|
input_f=$INPUT_DIR"/test"$test_index".in"
|
||||||
|
param_f=$INPUT_DIR"/test"$test_index".param"
|
||||||
|
ref_f=$OUT_DIR"/test"$test_index".ref"
|
||||||
|
out_f=$OUT_DIR"/test"$test_index".out"
|
||||||
|
params="$(test -f $param_f && cat $param_f || echo "")"
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanup_test()
|
||||||
|
{
|
||||||
|
rm -f $out_f
|
||||||
|
}
|
||||||
|
|
||||||
|
init_world()
|
||||||
|
{
|
||||||
|
print_header "Testing - SO Preprocessor"
|
||||||
|
mkdir -p $OUT_DIR
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanup_world()
|
||||||
|
{
|
||||||
|
rm -rf $OUT_DIR &> /dev/null
|
||||||
|
}
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------- #
|
||||||
|
|
||||||
|
# ----------------- Test Suite ----------------------------------------------- #
|
||||||
|
|
||||||
|
test_cpp()
|
||||||
|
{
|
||||||
|
init_test
|
||||||
|
$CPP $params $input_f > $ref_f
|
||||||
|
$MEMCHECK $EXEC_NAME $params $input_f > $out_f
|
||||||
|
mem_res=$?
|
||||||
|
basic_test compare $out_f $ref_f
|
||||||
|
memory_test $mem_res
|
||||||
|
cleanup_test
|
||||||
|
}
|
||||||
|
|
||||||
|
test_cpp_stdin()
|
||||||
|
{
|
||||||
|
init_test
|
||||||
|
$CPP $params < $input_f > $ref_f
|
||||||
|
$MEMCHECK $EXEC_NAME $params < $input_f > $out_f
|
||||||
|
mem_res=$?
|
||||||
|
basic_test compare $out_f $ref_f
|
||||||
|
memory_test $mem_res
|
||||||
|
cleanup_test
|
||||||
|
}
|
||||||
|
|
||||||
|
test_cpp_stdout()
|
||||||
|
{
|
||||||
|
init_test
|
||||||
|
$CPP $params $input_f $ref_f
|
||||||
|
$MEMCHECK $EXEC_NAME $params $input_f $out_f
|
||||||
|
mem_res=$?
|
||||||
|
basic_test compare $out_f $ref_f
|
||||||
|
memory_test $mem_res
|
||||||
|
cleanup_test
|
||||||
|
}
|
||||||
|
|
||||||
|
test_bad_params()
|
||||||
|
{
|
||||||
|
init_test
|
||||||
|
$EXEC_NAME $params 2> /dev/null
|
||||||
|
basic_test test $? -ne 0
|
||||||
|
cleanup_test
|
||||||
|
}
|
||||||
|
|
||||||
|
run_until_success()
|
||||||
|
{
|
||||||
|
REF_CODE=12 # ENOMEM
|
||||||
|
NR_RUNS=1000 # How many times to run
|
||||||
|
|
||||||
|
for ((i = 0; i < $NR_RUNS; i++)); do
|
||||||
|
init_test
|
||||||
|
export "$1_limit"=$i
|
||||||
|
if [ $IS_LINUX -eq 0 ]; then
|
||||||
|
LD_PRELOAD="./libso.so" $EXEC_NAME $params $input_f > $out_f
|
||||||
|
else
|
||||||
|
"./run.exe" "$EXEC_NAME $params $input_f" > $out_f
|
||||||
|
fi
|
||||||
|
|
||||||
|
retcode=$?
|
||||||
|
|
||||||
|
# If there is no error then the output file must be checked
|
||||||
|
if test $retcode -eq 0; then
|
||||||
|
return $?
|
||||||
|
fi
|
||||||
|
|
||||||
|
if test $retcode -ne $REF_CODE; then
|
||||||
|
basic_test false
|
||||||
|
return -1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if test $1 != "realloc"; then
|
||||||
|
cleanup_test
|
||||||
|
fi
|
||||||
|
|
||||||
|
done
|
||||||
|
basic_test false
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
test_so_alloc()
|
||||||
|
{
|
||||||
|
if [ $IS_LINUX -eq 0 ]; then
|
||||||
|
lines=$(find . -maxdepth 1 -name "libso.so" | wc -l)
|
||||||
|
else
|
||||||
|
lines=$(find . -maxdepth 1 -name "run.exe" | wc -l)
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $lines -eq 0 ]; then
|
||||||
|
basic_test false
|
||||||
|
else
|
||||||
|
|
||||||
|
init_test
|
||||||
|
$CPP $input_f $params > $ref_f
|
||||||
|
|
||||||
|
run_until_success "malloc"
|
||||||
|
if test $? -ne 0; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
run_until_success "calloc"
|
||||||
|
if test $? -ne 0; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
run_until_success "realloc"
|
||||||
|
|
||||||
|
basic_test compare $out_f $ref_f
|
||||||
|
|
||||||
|
cleanup_test
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
test_fun_array=( \
|
||||||
|
test_coding_style "Sources check" 5 0 \
|
||||||
|
test_bad_params "Test bad input" 1 0 \
|
||||||
|
test_bad_params "Test bad parameters" 1 0 \
|
||||||
|
test_bad_params "Test multiple files" 1 0 \
|
||||||
|
test_cpp_stdin "Test stdin file" 1 1 \
|
||||||
|
test_cpp "Test simple file" 1 1 \
|
||||||
|
test_cpp_stdout "Test simple out file" 1 1 \
|
||||||
|
test_cpp "Test simple define" 2 1 \
|
||||||
|
test_cpp "Test param define" 2 1 \
|
||||||
|
test_cpp "Test simple define/undef" 2 1 \
|
||||||
|
test_cpp "Test multiple defines" 2 1 \
|
||||||
|
test_cpp "Test nested defines" 3 1 \
|
||||||
|
test_cpp "Test multi-lines defines" 2 1 \
|
||||||
|
test_cpp "Test simple if true" 1 1 \
|
||||||
|
test_cpp "Test simple if false" 1 1 \
|
||||||
|
test_cpp "Test define if true" 1 1 \
|
||||||
|
test_cpp "Test define if false" 1 1 \
|
||||||
|
test_cpp "Test simple if-else true" 1 1 \
|
||||||
|
test_cpp "Test simple if-else false" 1 1 \
|
||||||
|
test_cpp "Test define if-else true" 1 1 \
|
||||||
|
test_cpp "Test define param if-else false" 1 1 \
|
||||||
|
test_cpp "Test simple elif false" 1 1 \
|
||||||
|
test_cpp "Test simple elif true" 1 1 \
|
||||||
|
test_cpp "Test simple elif-else true" 1 1 \
|
||||||
|
test_cpp "Test simple elif-else false" 1 1 \
|
||||||
|
test_cpp "Test complex if-elif-else" 2 1 \
|
||||||
|
test_cpp "Test simple ifdef false" 1 1 \
|
||||||
|
test_cpp "Test simple ifdef true" 1 1 \
|
||||||
|
test_cpp "Test simple ifndef" 1 1 \
|
||||||
|
test_cpp "Test simple ifndef undef" 1 1 \
|
||||||
|
test_bad_params "Test bad include" 1 0 \
|
||||||
|
test_cpp "Test double define params" 1 1 \
|
||||||
|
test_cpp "Test simple include" 2 1 \
|
||||||
|
test_cpp "Test include directory" 1 1 \
|
||||||
|
test_cpp "Test include param" 1 1 \
|
||||||
|
test_cpp "Test include order" 1 1 \
|
||||||
|
test_cpp "Test include order no main" 1 1 \
|
||||||
|
test_cpp "Test include guard" 2 1 \
|
||||||
|
test_so_alloc "Test everything" 10 0 \
|
||||||
|
)
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------- #
|
||||||
|
|
||||||
|
# ----------------- Run test ------------------------------------------------- #
|
||||||
|
|
||||||
|
# first we check if we have everything defined
|
||||||
|
check_tests
|
||||||
|
|
||||||
|
# run tests
|
||||||
|
run_tests $@
|
||||||
|
|
||||||
|
exit 0
|
|
@ -0,0 +1,229 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#
|
||||||
|
# Tema1 Test Suite
|
||||||
|
#
|
||||||
|
# 2012-2018, Operating Systems
|
||||||
|
#
|
||||||
|
|
||||||
|
# ----------------- General declarations and util functions ------------------ #
|
||||||
|
|
||||||
|
# Enable/disable exiting when program fails.
|
||||||
|
EXIT_IF_FAIL=0
|
||||||
|
# Enable/disable debug (1/0).
|
||||||
|
DEBUG_=0
|
||||||
|
# checkpatch.pl URL
|
||||||
|
CHECKPATCH_URL="https://raw.githubusercontent.com/torvalds/linux/master/scripts/checkpatch.pl"
|
||||||
|
COMMON_IGNORE_FLAGS="
|
||||||
|
SPLIT_STRING,SSCANF_TO_KSTRTO,NEW_TYPEDEFS,VOLATILE,INLINE,USE_FUNC,AVOID_EXTERNS,CONST_STRUCT,SPDX_LICENSE_TAG"
|
||||||
|
LIN_IGNORE_FLAGS="$COMMON_IGNORE_FLAGS"
|
||||||
|
WIN_IGNORE_FLAGS="$COMMON_IGNORE_FLAGS,DOS_LINE_ENDINGS"
|
||||||
|
|
||||||
|
if [ $(uname -s) == "Linux" ]; then
|
||||||
|
CHECKPATCH_IGNORE_FLAGS=$LIN_IGNORE_FLAGS
|
||||||
|
else
|
||||||
|
CHECKPATCH_IGNORE_FLAGS=$WIN_IGNORE_FLAGS
|
||||||
|
fi
|
||||||
|
|
||||||
|
CHECKPATCH_ARGS="
|
||||||
|
--no-tree
|
||||||
|
--no-summary
|
||||||
|
--terse
|
||||||
|
--ignore $CHECKPATCH_IGNORE_FLAGS
|
||||||
|
--show-types"
|
||||||
|
|
||||||
|
DEBUG()
|
||||||
|
{
|
||||||
|
if test "x$DEBUG_" = "x1"; then
|
||||||
|
$@ 1>&2
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
print_header()
|
||||||
|
{
|
||||||
|
header="${1}"
|
||||||
|
header_len=${#header}
|
||||||
|
printf "\n"
|
||||||
|
if [ $header_len -lt 71 ]; then
|
||||||
|
padding=$(((71 - $header_len) / 2))
|
||||||
|
for ((i = 0; i < $padding; i++)); do
|
||||||
|
printf " "
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
printf "= %s =\n\n" "${header}"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
test_do_fail()
|
||||||
|
{
|
||||||
|
printf "failed [ 0/%02d]\n" "$max_points"
|
||||||
|
if test "x$EXIT_IF_FAIL" = "x1"; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
test_do_pass()
|
||||||
|
{
|
||||||
|
printf "passed [%02d/%02d]\n" "$1" "$max_points"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
DF=${DF:--BEbwu}
|
||||||
|
|
||||||
|
# Compares to files and prints the first 10
|
||||||
|
# lines if the files differ
|
||||||
|
function compare()
|
||||||
|
{
|
||||||
|
diff $DF $1 $2 > __result
|
||||||
|
ret=$?
|
||||||
|
if [ $ret != 0 ] ; then
|
||||||
|
echo "$1 vs $2:"
|
||||||
|
cat __result | head -n 10
|
||||||
|
fi
|
||||||
|
rm -f __result
|
||||||
|
return $ret
|
||||||
|
}
|
||||||
|
|
||||||
|
memory_test()
|
||||||
|
{
|
||||||
|
DEBUG echo "MEM TEST"
|
||||||
|
|
||||||
|
res=$1
|
||||||
|
memcheck_description="$description - memcheck"
|
||||||
|
printf "%02d) %s" "$test_index" "$memcheck_description"
|
||||||
|
|
||||||
|
for ((i = 0; i < 56 - ${#memcheck_description}; i++)); do
|
||||||
|
printf "."
|
||||||
|
done
|
||||||
|
|
||||||
|
if test $res -eq 0; then
|
||||||
|
test_do_pass "$mem_points"
|
||||||
|
else
|
||||||
|
test_do_fail "$mem_poits"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
basic_test()
|
||||||
|
{
|
||||||
|
DEBUG echo "TEST: $@"
|
||||||
|
$@
|
||||||
|
res=$?
|
||||||
|
printf "%02d) %s" "$test_index" "$description"
|
||||||
|
|
||||||
|
for ((i = 0; i < 56 - ${#description}; i++)); do
|
||||||
|
printf "."
|
||||||
|
done
|
||||||
|
|
||||||
|
if test $res -eq 0; then
|
||||||
|
test_do_pass "$points"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
test_do_fail "$points"
|
||||||
|
return -1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
check_source()
|
||||||
|
{
|
||||||
|
# check to see if we have checkpatch
|
||||||
|
check_patch=$(which checkpatch.pl 2> /dev/null)
|
||||||
|
if ! [ -x "$check_patch" ]; then
|
||||||
|
echo "'checkpatch.pl' tool not found on your system."\
|
||||||
|
"Skipping source check..."
|
||||||
|
echo "Please download 'checkpatch.pl' from '$CHECKPATCH_URL'"\
|
||||||
|
"and install it in your \$PATH."
|
||||||
|
echo
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
# try to find sources in the current directory
|
||||||
|
src_files="$(find "${SRC_DIR:-.}" -type f -iregex \
|
||||||
|
'.*\.\(c\|h\|cpp\|hpp\|cc\|hh\|cxx\|hxx\)')"
|
||||||
|
if [ -z "$src_files" ]; then
|
||||||
|
read -t 60 -e -p 'Please provide path to your sources: ' SRC_DIR
|
||||||
|
if [ "$?" -ne "0" -o -z "$SRC_DIR" ]; then
|
||||||
|
echo -e "No path provided! Skipping source check...\n"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
if ! [ -e "$SRC_DIR" ]; then
|
||||||
|
echo -e "File or directory '$SRC_DIR' does not exist. " \
|
||||||
|
"Skipping source check...\n"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
src_files="$(find "$SRC_DIR" -type f -iregex \
|
||||||
|
'.*\.\(c\|h\|cpp\|hpp\|cc\|hh\|cxx\|hxx\)')"
|
||||||
|
if [ -z "$src_files" ]; then
|
||||||
|
echo -e "No sources found in '$SRC_DIR'. " \
|
||||||
|
"Skipping source check...\n"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
# now we have sources in $SRC_DIR or .
|
||||||
|
OUT=$(find "${SRC_DIR:-.}" -type f -iregex \
|
||||||
|
'.*\.\(c\|h\|cpp\|hpp\|cc\|hh\|cxx\|hxx\)' | \
|
||||||
|
xargs $check_patch $CHECKPATCH_ARGS -f 2>&1 | tail -n +2 | \
|
||||||
|
sort -u -t":" -k4,4 | head -n 20)
|
||||||
|
echo "$OUT"
|
||||||
|
}
|
||||||
|
|
||||||
|
test_coding_style()
|
||||||
|
{
|
||||||
|
check_source
|
||||||
|
[ -n "$src_files" -a -z "$OUT" ]
|
||||||
|
basic_test [ $? -eq 0 ]
|
||||||
|
}
|
||||||
|
|
||||||
|
check_tests()
|
||||||
|
{
|
||||||
|
# we need to have the test_fun_array defined
|
||||||
|
if [ -z "$test_fun_array" ]; then
|
||||||
|
echo "test_fun_array is not defined - don't know what to run" 1>&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# max_points
|
||||||
|
if [ -z "$max_points" ]; then
|
||||||
|
echo "max_points is not defined - don't the total number of points" 1>&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
run_tests()
|
||||||
|
{
|
||||||
|
if test $# -ne 1; then
|
||||||
|
echo "Usage: $0 test_number | init | cleanup" 1>&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
test_index=$1
|
||||||
|
|
||||||
|
if test $test_index == "init"; then
|
||||||
|
init_world
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if test $test_index == "cleanup"; then
|
||||||
|
cleanup_world
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if test $test_index == "check"; then
|
||||||
|
check_source
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
arr_index=$(($test_index * 4))
|
||||||
|
last_test=$((${#test_fun_array[@]} / 4))
|
||||||
|
description=${test_fun_array[$(($arr_index + 1))]}
|
||||||
|
|
||||||
|
points=${test_fun_array[$(($arr_index + 2))]}
|
||||||
|
mem_points=${test_fun_array[$(($arr_index + 3))]}
|
||||||
|
|
||||||
|
if test "$test_index" -gt "$last_test" -o "$arr_index" -lt 0; then
|
||||||
|
echo "Error: Test index is out range (1 < test_index <= $last_test)." 1>&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Run proper function
|
||||||
|
${test_fun_array[$(($arr_index))]}
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#
|
||||||
|
# Tema1 Test Suite
|
||||||
|
#
|
||||||
|
# 2020, Operating Systems
|
||||||
|
#
|
||||||
|
first_test=0
|
||||||
|
last_test=38
|
||||||
|
script=./_test/run_test.sh
|
||||||
|
|
||||||
|
# Call init to set up testing environment
|
||||||
|
bash "$script" init
|
||||||
|
|
||||||
|
# check the source (disabled, part of tests now)
|
||||||
|
#bash "$script" check
|
||||||
|
|
||||||
|
for i in $(seq $first_test $last_test); do
|
||||||
|
bash "$script" $i
|
||||||
|
done | tee results.txt
|
||||||
|
|
||||||
|
cat results.txt | grep -a '\[.*\]$' | awk -F '[] /[]+' '
|
||||||
|
BEGIN {
|
||||||
|
sum=0
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
sum += $(NF-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
END {
|
||||||
|
printf "\n%66s [%02d/95]\n", "Total:", sum;
|
||||||
|
}'
|
||||||
|
|
||||||
|
# Cleanup testing environment
|
||||||
|
bash "$script" cleanup
|
||||||
|
rm -f results.txt
|
Loading…
Reference in New Issue