MCPcopy
hub / github.com/containerd/containerd / TestDMVerity

Function TestDMVerity

internal/dmverity/dmverity_test.go:37–185  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

35)
36
37func TestDMVerity(t *testing.T) {
38 testutil.RequiresRoot(t)
39
40 supported, err := IsSupported()
41 if !supported || err != nil {
42 t.Skipf("dm-verity is not supported on this system: %v", err)
43 }
44
45 t.Run("IsSupported", func(t *testing.T) {
46 supported, err := IsSupported()
47 assert.True(t, supported)
48 assert.NoError(t, err)
49 })
50
51 t.Run("WithSuperblock", func(t *testing.T) {
52 t.Run("SameDevice", func(t *testing.T) {
53 tempDir := t.TempDir()
54 _, loopDevice := createLoopbackDevice(t, tempDir, "1Mb")
55 defer func() {
56 assert.NoError(t, mount.DetachLoopDevice(loopDevice))
57 }()
58
59 opts := testOptions(true, 1048576)
60
61 // Format with superblock - data and hash on same device
62 rootHash, err := Format(loopDevice, loopDevice, &opts)
63 assert.NoError(t, err)
64 assert.NotEmpty(t, rootHash)
65
66 // Open with superblock mode - provide hashOffset, opts is nil
67 deviceName := testDeviceName + "-sb-same"
68 devicePath, err := Open(loopDevice, deviceName, loopDevice, rootHash, opts.HashOffset, nil)
69 assert.NoError(t, err)
70 assert.Equal(t, "/dev/mapper/"+deviceName, devicePath)
71
72 waitForDevice(t, devicePath)
73
74 // Close device
75 err = Close(deviceName)
76 assert.NoError(t, err)
77
78 // Verify device is removed
79 _, err = os.Stat(devicePath)
80 assert.True(t, os.IsNotExist(err))
81 })
82
83 t.Run("SeparateDevices", func(t *testing.T) {
84 tempDir := t.TempDir()
85 _, dataDevice := createLoopbackDevice(t, tempDir, "1Mb")
86 _, hashDevice := createLoopbackDevice(t, tempDir, "512Kb")
87 defer func() {
88 assert.NoError(t, mount.DetachLoopDevice(dataDevice))
89 assert.NoError(t, mount.DetachLoopDevice(hashDevice))
90 }()
91
92 // HashOffset is REQUIRED even for separate devices when using superblock.
93 // Typically 4096 bytes (one block) is sufficient for superblock metadata.
94 opts := testOptions(true, 4096)

Callers

nothing calls this directly

Calls 11

RequiresRootFunction · 0.92
DetachLoopDeviceFunction · 0.92
IsSupportedFunction · 0.70
createLoopbackDeviceFunction · 0.70
testOptionsFunction · 0.70
FormatFunction · 0.70
OpenFunction · 0.70
waitForDeviceFunction · 0.70
CloseFunction · 0.70
RunMethod · 0.65
StatMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…