Skip to content

Commit f3c0d27

Browse files
committed
squash! Add support for tap output from runtime test
* Use the new T.Skip(...) * Get TAP out of test_runtime.sh (move the harness, e.g. prove, to a higher level). Also make sure non-TAP stuff goes to stderr (and not stdout).
1 parent 9836fd8 commit f3c0d27

File tree

3 files changed

+26
-42
lines changed

3 files changed

+26
-42
lines changed

README.md

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,32 +29,16 @@ INFO[0000] Bundle validation succeeded.
2929

3030
## Testing OCI runtimes
3131

32-
With [prove][] installed:
32+
You can run [`test_runtime.sh`][test_runtime.sh] with any [TAP consumer][tap-consumer].
33+
For example, with [prove][]:
3334

3435
```
3536
$ make
3637
$ sudo make install
37-
$ sudo ./test_runtime.sh -r /usr/bin/runc
38-
/usr/bin/runc .. ok
38+
$ sudo prove ./test_runtime.sh -r /usr/bin/runc
39+
./test_runtime.sh .. ok
3940
All tests successful.
40-
Files=1, Tests=90, 0 wallclock secs ( 0.02 usr 0.01 sys + 0.02 cusr 0.01 csys = 0.06 CPU)
41-
Result: PASS
42-
```
43-
44-
You can also use the usual prove options (separated by `--`):
45-
46-
```
47-
$ sudo ./test_runtime.sh -r /usr/bin/runc -- -v
48-
/home/wking/bin/runc ..
49-
TAP version 13
50-
ok 1 - # SKIP root.readonly falsy
51-
ok 2 - hostname matches expected value
52-
53-
ok 90 - # SKIP linux.gidMappings checks (no mappings specified)
54-
1..90
55-
ok
56-
All tests successful.
57-
Files=1, Tests=90, 0 wallclock secs ( 0.02 usr 0.00 sys + 0.02 cusr 0.01 csys = 0.05 CPU)
41+
Files=1, Tests=90, 0 wallclock secs ( 0.02 usr 0.00 sys + 0.04 cusr 0.00 csys = 0.06 CPU)
5842
Result: PASS
5943
```
6044

@@ -63,6 +47,7 @@ Result: PASS
6347
[prove]: http://perldoc.perl.org/prove.html
6448
[runC]: https://github.com/opencontainers/runc
6549
[runtime-spec]: https://github.com/opencontainers/runtime-spec
50+
[tap-consumer]: https://testanything.org/consumers.html
6651

6752
[generate.1]: man/oci-runtime-tool-generate.1.md
6853
[validate.1]: man/oci-runtime-tool-validate.1.md

cmd/runtimetest/main.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func loadSpecConfig() (spec *rspec.Spec, err error) {
7373
// should be included by other platform specified process validation
7474
func validateGeneralProcess(harness *tap.T, spec *rspec.Spec) error {
7575
if spec.Process.Cwd == "" {
76-
harness.Pass("# SKIP process.cwd not set")
76+
harness.Skip(1, "process.cwd not set")
7777
} else {
7878
cwd, err := os.Getwd()
7979
if err != nil {
@@ -192,7 +192,7 @@ func validateCapabilities(harness *tap.T, spec *rspec.Spec) error {
192192

193193
func validateHostname(harness *tap.T, spec *rspec.Spec) error {
194194
if spec.Hostname == "" {
195-
harness.Pass("# SKIP hostname not set")
195+
harness.Skip(1, "hostname not set")
196196
} else {
197197
hostname, err := os.Hostname()
198198
if err != nil {
@@ -273,7 +273,7 @@ func validateRootFS(harness *tap.T, spec *rspec.Spec) error {
273273
return err
274274
}
275275
} else {
276-
harness.Pass("# SKIP root.readonly falsy")
276+
harness.Skip(1, "root.readonly falsy")
277277
}
278278

279279
return nil
@@ -302,7 +302,7 @@ func validateDefaultFS(harness *tap.T, spec *rspec.Spec) error {
302302

303303
func validateLinuxDevices(harness *tap.T, spec *rspec.Spec) error {
304304
if len(spec.Linux.Devices) == 0 {
305-
harness.Pass("# SKIP linux.devices (no devices configured)")
305+
harness.Skip(1, "linux.devices (no devices configured)")
306306
}
307307
for _, device := range spec.Linux.Devices {
308308
fi, err := os.Stat(device.Path)
@@ -345,7 +345,7 @@ func validateLinuxDevices(harness *tap.T, spec *rspec.Spec) error {
345345
}
346346
}
347347
if device.FileMode == nil {
348-
harness.Pass(fmt.Sprintf("# SKIP device %v has unconfigured permissions", device.Path))
348+
harness.Skip(1, fmt.Sprintf("device %v has unconfigured permissions", device.Path))
349349
} else {
350350
expectedPerm := *device.FileMode & os.ModePerm
351351
actualPerm := fi.Mode() & os.ModePerm
@@ -355,15 +355,15 @@ func validateLinuxDevices(harness *tap.T, spec *rspec.Spec) error {
355355
}
356356
}
357357
if device.UID == nil {
358-
harness.Pass(fmt.Sprintf("# SKIP device %v has an unconfigured user ID", device.Path))
358+
harness.Skip(1, fmt.Sprintf("device %v has an unconfigured user ID", device.Path))
359359
} else {
360360
harness.Ok(fStat.Uid == *device.UID, fmt.Sprintf("device %v has expected user ID", device.Path))
361361
if fStat.Uid != *device.UID {
362362
harness.Diagnosticf("device %v user ID epected: %v, actual: %v", device.Path, *device.UID, fStat.Uid)
363363
}
364364
}
365365
if device.GID == nil {
366-
harness.Pass(fmt.Sprintf("# SKIP device %v has an unconfigured group ID", device.Path))
366+
harness.Skip(1, fmt.Sprintf("device %v has an unconfigured group ID", device.Path))
367367
} else {
368368
harness.Ok(fStat.Gid == *device.GID, fmt.Sprintf("device %v has expected group ID", device.Path))
369369
if fStat.Gid != *device.GID {
@@ -380,7 +380,7 @@ func validateDefaultSymlinks(harness *tap.T, spec *rspec.Spec) error {
380380
fi, err := os.Lstat(symlink)
381381
harness.Ok(err == nil, fmt.Sprintf("lstat default symlink %v", symlink))
382382
if err != nil {
383-
harness.Pass(fmt.Sprintf("# SKIP default symlink %v checks (failed lstat)", symlink))
383+
harness.Skip(1, fmt.Sprintf("default symlink %v checks (failed lstat)", symlink))
384384
} else {
385385
harness.Ok(fi.Mode()&os.ModeSymlink == os.ModeSymlink, fmt.Sprintf("default symlink %v is a symlink", symlink))
386386
realDest, err := os.Readlink(symlink)
@@ -405,7 +405,7 @@ func validateDefaultDevices(harness *tap.T, spec *rspec.Spec) error {
405405
fi, err := os.Stat(device)
406406
harness.Ok(err == nil, fmt.Sprintf("stat default device %v", device))
407407
if err != nil {
408-
harness.Pass(fmt.Sprintf("# SKIP default device %v checks (failed stat)", device))
408+
harness.Skip(1, fmt.Sprintf("default device %v checks (failed stat)", device))
409409
} else {
410410
harness.Ok(fi.Mode()&os.ModeDevice == os.ModeDevice, fmt.Sprintf("default device %v is a device", device))
411411
}
@@ -419,7 +419,7 @@ func validateMaskedPaths(harness *tap.T, spec *rspec.Spec) error {
419419
f, err := os.Open(maskedPath)
420420
harness.Ok(err == nil, fmt.Sprintf("open masked path %v", maskedPath))
421421
if err != nil {
422-
harness.Pass(fmt.Sprintf("# SKIP masked path %v checks (failed open)", maskedPath))
422+
harness.Skip(1, fmt.Sprintf("masked path %v checks (failed open)", maskedPath))
423423
} else {
424424
defer f.Close()
425425
b := make([]byte, 1)
@@ -443,13 +443,13 @@ func validateROPaths(harness *tap.T, spec *rspec.Spec) error {
443443

444444
func validateOOMScoreAdj(harness *tap.T, spec *rspec.Spec) error {
445445
if spec.Linux.Resources == nil || spec.Linux.Resources.OOMScoreAdj == nil {
446-
harness.Pass("# SKIP linux.resources.oomScoreAdj falsy")
446+
harness.Skip(1, "linux.resources.oomScoreAdj falsy")
447447
} else {
448448
expected := *spec.Linux.Resources.OOMScoreAdj
449449
f, err := os.Open("/proc/1/oom_score_adj")
450450
harness.Ok(err == nil, "open /proc/1/oom_score_adj")
451451
if err != nil {
452-
harness.Pass("# SKIP oomScoreAdj checks (failed open)")
452+
harness.Skip(1, "oomScoreAdj checks (failed open)")
453453
return nil
454454
}
455455
defer f.Close()
@@ -459,14 +459,14 @@ func validateOOMScoreAdj(harness *tap.T, spec *rspec.Spec) error {
459459
err := s.Err()
460460
harness.Ok(err == nil, "scan /proc/1/oom_score_adj")
461461
if err != nil {
462-
harness.Pass("# SKIP oomScoreAdj checks (failed scan)")
462+
harness.Skip(1, "oomScoreAdj checks (failed scan)")
463463
return nil
464464
}
465465
text := strings.TrimSpace(s.Text())
466466
actual, err := strconv.Atoi(text)
467467
harness.Ok(err == nil, "convert scanned /proc/1/oom_score_adj value to an integer")
468468
if err != nil {
469-
harness.Pass("# SKIP oomScoreAdj checks (failed integer conversion)")
469+
harness.Skip(1, "oomScoreAdj checks (failed integer conversion)")
470470
return nil
471471
}
472472
harness.Ok(actual == expected, "has expected oomScoreAdj")
@@ -518,13 +518,13 @@ func getIDMappings(path string) ([]rspec.IDMapping, error) {
518518

519519
func validateIDMappings(harness *tap.T, mappings []rspec.IDMapping, path string, property string) error {
520520
if len(mappings) == 0 {
521-
harness.Pass(fmt.Sprintf("# SKIP %s checks (no mappings specified)", property))
521+
harness.Skip(1, fmt.Sprintf("%s checks (no mappings specified)", property))
522522
return nil
523523
}
524524
idMaps, err := getIDMappings(path)
525525
harness.Ok(err == nil, fmt.Sprintf("get ID mappings from %s", path))
526526
if err != nil {
527-
harness.Pass(fmt.Sprintf("# SKIP %s checks (failed to get mappings)", property))
527+
harness.Skip(1, fmt.Sprintf("%s checks (failed to get mappings)", property))
528528
return nil
529529
}
530530
harness.Ok(len(idMaps) == len(mappings), fmt.Sprintf("%s has expected number of mappings", path))

test_runtime.sh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ TEST_ARGS=('--args' '/runtimetest')
1919
KEEP=0 # Track whether we keep the test directory around or clean it up
2020

2121
usage() {
22-
echo "$0 -l <log-level> -r <runtime> -k -h [-- [prove-options]]"
22+
echo "$0 -l <log-level> -r <runtime> -k -h"
2323
}
2424

2525
error() {
26-
echo $*
26+
echo "$*" >&2
2727
exit 1
2828
}
2929

3030
info() {
31-
echo $*
31+
echo "$*" >&2
3232
}
3333

3434
while getopts "l:r:kh" opt; do
@@ -52,7 +52,6 @@ while getopts "l:r:kh" opt; do
5252
;;
5353
esac
5454
done
55-
shift $((${OPTIND} - 1))
5655

5756
if ! command -v ${RUNTIME} > /dev/null; then
5857
error "Runtime ${RUNTIME} not found in the path"
@@ -77,4 +76,4 @@ cp runtimetest ${TESTDIR}
7776
oci-runtime-tool generate --output "${TESTDIR}/config.json" "${TEST_ARGS[@]}" --rootfs-path '.'
7877

7978
cd ${TESTDIR}
80-
prove "${@}" ${RUNTIME} :: start $(uuidgen)
79+
${RUNTIME} start $(uuidgen)

0 commit comments

Comments
 (0)