diff options
| author | Ophestra <cat@gensokyo.uk> | 2026-05-07 15:40:47 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2026-05-07 15:55:19 +0900 |
| commit | 575ef307ad5cedb13a514cd038a4880ab8c91242 (patch) | |
| tree | 71c0bd20e32e08c56ce1be6824f8dbe0f1a091ed /container/binfmt_test.go | |
| parent | d4144fcf7f9217d2a2dcec21202421d5fa9d4928 (diff) | |
container: binfmt registration
This arranges for binfmt entries to be registered for the container.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'container/binfmt_test.go')
| -rw-r--r-- | container/binfmt_test.go | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/container/binfmt_test.go b/container/binfmt_test.go new file mode 100644 index 00000000..7345b094 --- /dev/null +++ b/container/binfmt_test.go @@ -0,0 +1,62 @@ +package container + +import ( + "strings" + "testing" + + "hakurei.app/fhs" +) + +func TestEscapeBinfmt(t *testing.T) { + t.Parallel() + + testCases := []struct { + name string + magic string + want string + }{ + {"packed DOS applications", "\x0eDEX", "\x0eDEX"}, + + {"riscv64 magic", + "\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xf3\x00", + "\x7fELF\x02\x01\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\x02\\x00\xf3\\x00"}, + {"riscv64 mask", + "\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff", + "\xff\xff\xff\xff\xff\xff\xff\\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff"}, + } + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + + got := escapeBinfmt(new(strings.Builder), tc.magic) + if got != tc.want { + t.Errorf("escapeBinfmt: %q, want %q", got, tc.want) + } + }) + } +} + +func TestBinfmtEntry(t *testing.T) { + t.Parallel() + + testCases := []struct { + name string + e BinfmtEntry + valid bool + }{ + {"zero", BinfmtEntry{}, false}, + {"large offset", BinfmtEntry{Offset: 128}, false}, + {"long magic", BinfmtEntry{Magic: strings.Repeat("\x00", 128)}, false}, + {"long mask", BinfmtEntry{Mask: strings.Repeat("\x00", 128)}, false}, + {"valid", BinfmtEntry{Interpreter: fhs.AbsRoot}, true}, + } + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + + if tc.e.Valid() != tc.valid { + t.Errorf("Valid: %v", !tc.valid) + } + }) + } +} |
