(t *testing.T)
| 102 | } |
| 103 | |
| 104 | func TestAutoclearTrueLoop(t *testing.T) { |
| 105 | testutil.RequiresRoot(t) |
| 106 | |
| 107 | backingFile := createTempFile(t) |
| 108 | bInfo, err := os.Stat(backingFile) |
| 109 | require.NoError(t, err) |
| 110 | bInode := bInfo.Sys().(*syscall.Stat_t).Ino |
| 111 | |
| 112 | file, err := SetupLoop(backingFile, LoopParams{Autoclear: true}) |
| 113 | require.NoError(t, err) |
| 114 | dev := file.Name() |
| 115 | file.Close() |
| 116 | |
| 117 | var checkFn = func(loopDev string, expectedInode uint64) (_shouldRetry bool, _ error) { |
| 118 | loop, err := os.Open(loopDev) |
| 119 | if err != nil { |
| 120 | if os.IsNotExist(err) { |
| 121 | return false, nil |
| 122 | } |
| 123 | return false, fmt.Errorf("failed to open loop device: %w", err) |
| 124 | } |
| 125 | info, err := unix.IoctlLoopGetStatus64(int(loop.Fd())) |
| 126 | loop.Close() |
| 127 | if err != nil { |
| 128 | if errors.Is(err, unix.ENXIO) { |
| 129 | return false, nil |
| 130 | } |
| 131 | return false, fmt.Errorf("failed to get loop device info: %w", err) |
| 132 | } |
| 133 | |
| 134 | if info.Inode != expectedInode { |
| 135 | return false, nil |
| 136 | } |
| 137 | |
| 138 | t.Logf("loop device %s still present with backing inode %d", loopDev, expectedInode) |
| 139 | return true, nil |
| 140 | } |
| 141 | |
| 142 | for range 10 { |
| 143 | retry, err := checkFn(dev, bInode) |
| 144 | require.NoError(t, err) |
| 145 | if !retry { |
| 146 | return |
| 147 | } |
| 148 | time.Sleep(100 * time.Millisecond) |
| 149 | } |
| 150 | t.Fatalf("loop device %s still present after autoclear", dev) |
| 151 | } |
| 152 | |
| 153 | func TestAutoclearFalseLoop(t *testing.T) { |
| 154 | testutil.RequiresRoot(t) |
nothing calls this directly
no test coverage detected
searching dependent graphs…