@@ -19,38 +19,79 @@ set -o errexit -o errtrace -o functrace -o nounset -o pipefail
1919root=" $( cd " $( dirname " ${BASH_SOURCE[0]:- $PWD } " ) " 2> /dev/null 1>&2  &&  pwd) " 
2020readonly  root
2121
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 
2727fi 
2828
29+ # #### Import helper libraries
30+ #  shellcheck source=/dev/null
31+ .  " $root " 
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 " 
38+ readonly  gotestsum_log_flaky=" $report_location " 
39+ #  Total run timeout
2940readonly  timeout=" 60m" 
41+ #  Number of retries for flaky tests
3042readonly  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 " 
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 " 
38- 
39- if  [ " $# " ==  0 ];  then 
40-   " $root " 
41-   " $root " 
42-   exit 
43- fi 
43+ readonly  need_sudo=" ${WITH_SUDO:- } " 
4444
45+ # #### Prepare gotestsum arguments
46+ mkdir -p " $report_location " 
47+ #  Format and packages to test
48+ args=(--format=testname --packages=" $root " 
49+ #  Log file
50+ gotestsum_log=" $gotestsum_log_main " 
4551for  arg  in  " $@ " ;  do 
4652  if  [ " $arg " ==  " -test.only-flaky=true" ||  [ " $arg " ==  " -test.only-flaky" ;  then 
4753    args+=(" --rerun-fails=$retries " 
54+     gotestsum_log=" $gotestsum_log_flaky " 
4855    break 
4956  fi 
5057done 
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 " " $@ " 
5165
52- if  [ " $needsudo " ==  " true" ||  [ " $needsudo " ==  " yes" ||  [ " $needsudo " ==  " 1" ;  then 
53-   gotestsum " ${args[@]} " " $timeout " " $@ " 
54- else 
55-   gotestsum " ${args[@]} " " $timeout " " $@ " 
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 
5687fi 
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