@@ -19,38 +19,79 @@ set -o errexit -o errtrace -o functrace -o nounset -o pipefail
19
19
root=" $( cd " $( dirname " ${BASH_SOURCE[0]:- $PWD } " ) " 2> /dev/null 1>&2 && pwd) "
20
20
readonly root
21
21
22
- if [[ " $( id -u ) " = " 0 " ]] ; then
23
- # Ensure securityfs is mounted for apparmor to work
24
- if ! mountpoint -q /sys/kernel/security ; then
25
- mount -tsecurityfs securityfs /sys/kernel/security
26
- fi
22
+ # If no argument is provided, run both flaky and not-flaky test suites.
23
+ if [ " $# " == 0 ] ; then
24
+ " $root " /integration.sh -test.only-flaky=false
25
+ " $root " /integration.sh -test.only-flaky=true
26
+ exit
27
27
fi
28
28
29
+ # #### Import helper libraries
30
+ # shellcheck source=/dev/null
31
+ . " $root " /../mod/wax/scripts/collector.sh
32
+
33
+ # #### Configuration
34
+ # Where to store report files
35
+ readonly report_location=" ${WAX_REPORT_LOCATION:- $HOME / nerdctl-test-report} "
36
+ # Where to store gotestsum log file
37
+ readonly gotestsum_log_main=" $report_location " /test-integration.log
38
+ readonly gotestsum_log_flaky=" $report_location " /test-integration-flaky.log
39
+ # Total run timeout
29
40
readonly timeout=" 60m"
41
+ # Number of retries for flaky tests
30
42
readonly retries=" 2"
31
- readonly needsudo=" ${WITH_SUDO:- } "
32
-
33
- # See https://github.com/containerd/nerdctl/blob/main/docs/testing/README.md#about-parallelization
34
- args=(--format=testname --jsonfile /tmp/test-integration.log --packages=" $root " /../cmd/nerdctl/...)
35
- # FIXME: not working on windows. Need to change approach: move away from --post-run-command and
36
- # just process the log file. This might also allow multi-steps/multi-target results aggregation.
37
- [ " $( uname -s) " != " Linux" ] || args+=(--post-run-command " $root " /github/gotestsum-reporter.sh)
38
-
39
- if [ " $# " == 0 ]; then
40
- " $root " /test-integration.sh -test.only-flaky=false
41
- " $root " /test-integration.sh -test.only-flaky=true
42
- exit
43
- fi
43
+ readonly need_sudo=" ${WITH_SUDO:- } "
44
44
45
+ # #### Prepare gotestsum arguments
46
+ mkdir -p " $report_location "
47
+ # Format and packages to test
48
+ args=(--format=testname --packages=" $root " /../cmd/nerdctl/...)
49
+ # Log file
50
+ gotestsum_log=" $gotestsum_log_main "
45
51
for arg in " $@ " ; do
46
52
if [ " $arg " == " -test.only-flaky=true" ] || [ " $arg " == " -test.only-flaky" ]; then
47
53
args+=(" --rerun-fails=$retries " )
54
+ gotestsum_log=" $gotestsum_log_flaky "
48
55
break
49
56
fi
50
57
done
58
+ args+=(--jsonfile " $gotestsum_log " --)
59
+
60
+ # #### Append go test arguments
61
+ # Honor sudo
62
+ [ " $need_sudo " != true ] && [ " $need_sudo " != yes ] && [ " $need_sudo " != 1 ] || args+=(-exec sudo)
63
+ # About `-p 1`, see https://github.com/containerd/nerdctl/blob/main/docs/testing/README.md#about-parallelization
64
+ args+=(-timeout=" $timeout " -p 1 -args -test.allow-kill-daemon " $@ " )
51
65
52
- if [ " $needsudo " == " true" ] || [ " $needsudo " == " yes" ] || [ " $needsudo " == " 1" ]; then
53
- gotestsum " ${args[@]} " -- -timeout=" $timeout " -p 1 -exec sudo -args -test.allow-kill-daemon " $@ "
54
- else
55
- gotestsum " ${args[@]} " -- -timeout=" $timeout " -p 1 -args -test.allow-kill-daemon " $@ "
66
+ # FIXME: this should not be the responsibility of the test script
67
+ # Instead, it should be in the Dockerfile (or other stack provisioning script) - eg: /etc/systemd/system/securityfs.service
68
+ # [Unit]
69
+ # Description=Kernel Security File System
70
+ # DefaultDependencies=no
71
+ # Before=sysinit.target
72
+ # Before=apparmor.service
73
+ # ConditionSecurity=apparmor
74
+ # ConditionPathIsMountPoint=!/sys/kernel/security
75
+ #
76
+ # [Service]
77
+ # Type=oneshot
78
+ # ExecStart=/bin/mount -t securityfs -o nosuid,nodev,noexec securityfs /sys/kernel/security
79
+ #
80
+ # [Install]
81
+ # WantedBy=sysinit.target
82
+ if [[ " $( id -u) " = " 0" ]]; then
83
+ # Ensure securityfs is mounted for apparmor to work
84
+ if ! mountpoint -q /sys/kernel/security; then
85
+ mount -tsecurityfs securityfs /sys/kernel/security
86
+ fi
56
87
fi
88
+
89
+ # #### Run it
90
+ ex=0
91
+ gotestsum " ${args[@]} " || ex=$?
92
+
93
+ # #### Post: collect logs into the report location
94
+ collect::logs " $report_location "
95
+
96
+ # Honor gotestsum exit code
97
+ exit " $ex "
0 commit comments