123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- #!/bin/bash
- set -eo pipefail
- FAILED_TXT="${RED}[FAILED]${NC}"
- SUCCESS_TXT="${GREEN}[SUCCESS]${NC}"
- if [[ -z "$TESTS_DIR" ]]; then
- echo "Must provide \$TESTS_DIR env variable"
- exit 1
- fi
- if [[ -z "$INVOCATION_ID" ]]; then
- echo "Must provide \$INVOCATION_ID env variable"
- exit 1
- fi
- mkdir -p "$TESTS_DIR"/tester-lcmp
- if [ ! -f "$TESTS_DIR"/tester-lcmp/tester-lcmp."$INVOCATION_ID" ]; then
-
- rm -f "$TESTS_DIR"/tester-lcmp/*
-
- CPP_INCLUDE_DIR_=$CPP_INCLUDE_DIR
- export CPP_INCLUDE_DIR=$TESTS_DIR/lib
- bash "$TESTS_DIR"/scripts/compile "$TESTS_DIR"/src/tester-lcmp.cpp
- export CPP_INCLUDE_DIR=$CPP_INCLUDE_DIR_
-
- if [ ! -d ./tester-lcmp ]; then
- mv -f ./tester-lcmp "$TESTS_DIR"/tester-lcmp
- else
- mv -f ./tester-lcmp.exe "$TESTS_DIR"/tester-lcmp
- fi
-
- touch "$TESTS_DIR"/tester-lcmp/tester-lcmp."$INVOCATION_ID"
- fi
- ref_dir=$1
- if [[ -z "$ref_dir" ]]; then
- echo "Must provide \$1 for test-ref"
- exit 1
- fi
- refs=refs/$1
- shift 1
- if [ ! -d "$refs" ]; then
- if [[ "$TEST_REF_FORBID_GEN_REFS" == "true" ]]; then
- echo "You forgot to run push ref files for invocation: ""$*"""
- echo "Run test locally, it will produce ref files and push it into the repo"
- exit 1
- fi
-
- mkdir -p "$refs"
- echo Generating tester refs: "$*"
- exit_code=0
-
- $* 1>"$refs"/stdout 2>"$refs"/stderr || exit_code=$?
- echo $exit_code >"$refs"/exit_code
- echo -e "${SUCCESS_TXT} generated execution reference files (exit code: $exit_code)\n"
- else
-
- echo Testing refs: "$*"
- exit_code=0
-
- $* 1>"$refs"/stdout.aux 2>"$refs"/stderr.aux || exit_code=$?
- stdout_size=$(wc -c < "$refs"/stdout.aux)
- stderr_size=$(wc -c < "$refs"/stderr.aux)
- echo "Program exit code: $exit_code, stdout size: $stdout_size bytes, stderr size: $stderr_size bytes"
- echo $exit_code >"$refs"/exit_code.aux
-
- tester_lcmp_exit_code=0
- "$TESTS_DIR"/tester-lcmp/tester-lcmp "$TESTS_DIR"/tester-lcmp/tester-lcmp."$INVOCATION_ID" "$refs"/exit_code.aux "$refs"/exit_code 2>tester-lcmp.out || tester_lcmp_exit_code=$?
- if [[ ! "$tester_lcmp_exit_code" == "0" ]]; then
- echo -e "${FAILED_TXT} exit_code mismatched: found $(cat < "$refs"/exit_code.aux) but expected $(cat "$refs"/exit_code)\n"
- cat tester-lcmp.out
- rm -f tester-lcmp.out
- rm -f "$refs"/*.aux
- exit 1
- fi
- echo $exit_code >"$refs"/exit_code.aux
-
- "$TESTS_DIR"/tester-lcmp/tester-lcmp "$TESTS_DIR"/tester-lcmp/tester-lcmp."$INVOCATION_ID" "$refs"/stdout.aux "$refs"/stdout 2>tester-lcmp.out || tester_lcmp_exit_code=$?
- if [[ ! "$tester_lcmp_exit_code" == "0" ]]; then
- echo -e "${FAILED_TXT} stdout mismatched\n"
- cat tester-lcmp.out
- rm -f tester-lcmp.out
- rm -f "$refs"/*.aux
- exit 1
- fi
-
- "$TESTS_DIR"/tester-lcmp/tester-lcmp "$TESTS_DIR"/tester-lcmp/tester-lcmp."$INVOCATION_ID" "$refs"/stderr.aux "$refs"/stderr 2>tester-lcmp.out || tester_lcmp_exit_code=$?
- if [[ ! "$tester_lcmp_exit_code" == "0" ]]; then
- echo -e "${FAILED_TXT} stderr mismatched\n"
- cat tester-lcmp.out
- rm -f tester-lcmp.out
- rm -f "$refs"/*.aux
- exit 1
- fi
-
- echo -e "${SUCCESS_TXT} execution matched with reference (exit code: $exit_code)\n"
- rm -f tester-lcmp.out
- rm -f "$refs"/*.aux
- fi
|