diff options
Diffstat (limited to 'container/seccomp/syscall_test.go')
| -rw-r--r-- | container/seccomp/syscall_test.go | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/container/seccomp/syscall_test.go b/container/seccomp/syscall_test.go index 151f6321..98076cf3 100644 --- a/container/seccomp/syscall_test.go +++ b/container/seccomp/syscall_test.go @@ -23,17 +23,41 @@ func TestSyscallResolveName(t *testing.T) { } } -func TestRuleSize(t *testing.T) { +func TestRuleType(t *testing.T) { + assertKind[ScmpUint, scmpUint](t) + assertKind[ScmpInt, scmpInt](t) + assertSize[NativeRule, syscallRule](t) - assertSize[ScmpDatum, scmpDatum](t) + assertKind[ScmpDatum, scmpDatum](t) + assertKind[ScmpCompare, scmpCompare](t) assertSize[ScmpArgCmp, scmpArgCmp](t) } // assertSize asserts that native and equivalent are of the same size. func assertSize[native, equivalent any](t *testing.T) { - got := unsafe.Sizeof(*new(native)) - want := unsafe.Sizeof(*new(equivalent)) + t.Helper() + + got, want := unsafe.Sizeof(*new(native)), unsafe.Sizeof(*new(equivalent)) if got != want { t.Fatalf("%s: %d, want %d", reflect.TypeFor[native]().Name(), got, want) } } + +// assertKind asserts that native and equivalent are of the same kind. +func assertKind[native, equivalent any](t *testing.T) { + t.Helper() + + assertSize[native, equivalent](t) + nativeType, equivalentType := reflect.TypeFor[native](), reflect.TypeFor[equivalent]() + got, want := nativeType.Kind(), equivalentType.Kind() + + if got == reflect.Invalid || want == reflect.Invalid { + t.Fatalf("%s: invalid call to assertKind", nativeType.Name()) + } + if got == reflect.Struct { + t.Fatalf("%s: struct is unsupported by assertKind", nativeType.Name()) + } + if got != want { + t.Fatalf("%s: %s, want %s", nativeType.Name(), nativeType.Kind(), equivalentType.Kind()) + } +} |
