-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_docker_tests.sh
More file actions
executable file
·123 lines (102 loc) · 3.62 KB
/
run_docker_tests.sh
File metadata and controls
executable file
·123 lines (102 loc) · 3.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env bash
set -euo pipefail
IMAGE_NAME="eslab-task3-tests"
CONTAINER_NAME="eslab-task3-tests-runner"
cleanup() {
docker rm -f "$CONTAINER_NAME" >/dev/null 2>&1 || true
}
trap cleanup EXIT
# Build the Docker image used for tests.
docker build -f docker/Dockerfile.servers -t "$IMAGE_NAME" .
echo "Container image '$IMAGE_NAME' built successfully. Running tests inside the container..."
# Start a container in the background, then execute tests inside it.
docker run -d --name "$CONTAINER_NAME" "$IMAGE_NAME"
REPORT_FILE="$(mktemp)"
cleanup_report() {
rm -f "$REPORT_FILE"
}
trap 'cleanup_report; cleanup' EXIT
set +e
docker exec "$CONTAINER_NAME" /usr/eslab/estask3/run_tests.sh >"$REPORT_FILE"
#docker exec "$CONTAINER_NAME" /usr/eslab/estask3/run_tests.sh
#docker exec "$CONTAINER_NAME" /usr/eslab/estask3/run_task.sh
exec_status=$?
set -e
python3 - "$REPORT_FILE" <<'PY'
import json
import re
import sys
from pathlib import Path
report_path = Path(sys.argv[1])
if not report_path.exists():
print("Summary: report.json was not generated")
raise SystemExit(1)
report = json.loads(report_path.read_text())
summary = report.get("summary", {})
passed = summary.get("passed", 0)
failed = summary.get("failed", summary.get("error", 0))
total = summary.get("total", passed + failed)
print("+----------------+---------+--------+")
print(f"| {'Total':<14} | {'Passed':<7} | {'Failed':<6} |")
print("+----------------+---------+--------+")
print(f"| {total:<14} | {passed:<7} | {failed:<6} |")
print("+----------------+---------+--------+")
failed_tests = []
for test in report.get("tests", []):
if test.get("outcome") not in {"failed", "error"}:
continue
nodeid = test.get("nodeid", "unknown test")
call = test.get("call", {})
def to_text(value):
if value is None:
return ""
if isinstance(value, str):
return value
if isinstance(value, (list, tuple)):
return "\n".join(to_text(item) for item in value if to_text(item))
if isinstance(value, dict):
parts = []
for key in ("reprcrash", "message", "longrepr", "path", "line", "crash"):
if key in value:
text = to_text(value[key])
if text:
parts.append(text)
if parts:
return "\n".join(parts)
return json.dumps(value)
return str(value)
raw_text = "\n".join(
to_text(call.get(key)) for key in ("longrepr", "crash", "stderr", "stdout")
if to_text(call.get(key))
)
lines = [line.rstrip() for line in raw_text.splitlines() if line.strip()]
short_message = None
for line in lines:
if "GTest" in line and "failed:" in line:
short_message = line.strip().lstrip("E ")
break
if not short_message:
for line in lines:
if "AssertionError:" in line:
short_message = line.strip().lstrip("E ")
break
if not short_message:
short_message = lines[0].strip() if lines else "Test failed"
friendly_name = nodeid
match = re.search(r"AssertionError:\s*(.+?)\s+FAILED:", raw_text)
if match:
friendly_name = match.group(1).strip()
failed_tests.append((friendly_name, short_message))
if failed_tests:
print("Failed tests:")
for name, message in failed_tests:
width = max(len(name), len(message), 20)
border = "+" + "-" * (width + 2) + "+"
print(border)
print(f"| {name:<{width}} |")
print(f"| {message:<{width}} |")
print(border)
else:
print("Failed tests: none")
PY
exit "$exec_status"