MCPcopy
hub / github.com/moby/moby / TestPrivilegedHostDevices

Function TestPrivilegedHostDevices

integration/container/run_linux_test.go:132–178  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

130}
131
132func TestPrivilegedHostDevices(t *testing.T) {
133 // Host devices are linux only. Also it creates host devices,
134 // so needs to be same host.
135 skip.If(t, testEnv.IsRemoteDaemon)
136 skip.If(t, testEnv.DaemonInfo.OSType != "linux")
137
138 ctx := setupTest(t)
139 apiClient := testEnv.APIClient()
140
141 const (
142 devTest = "/dev/test"
143 devRootOnlyTest = "/dev/root-only/test"
144 )
145
146 // Create Null devices.
147 if err := unix.Mknod(devTest, unix.S_IFCHR|0o600, int(unix.Mkdev(1, 3))); err != nil {
148 t.Fatal(err)
149 }
150 defer os.Remove(devTest)
151 if err := os.Mkdir(filepath.Dir(devRootOnlyTest), 0o700); err != nil {
152 t.Fatal(err)
153 }
154 defer os.RemoveAll(filepath.Dir(devRootOnlyTest))
155 if err := unix.Mknod(devRootOnlyTest, unix.S_IFCHR|0o600, int(unix.Mkdev(1, 3))); err != nil {
156 t.Fatal(err)
157 }
158 defer os.Remove(devRootOnlyTest)
159
160 cID := container.Run(ctx, t, apiClient, container.WithPrivileged(true))
161
162 // Check test device.
163 res, err := container.Exec(ctx, apiClient, cID, []string{"ls", devTest})
164 assert.NilError(t, err)
165 assert.Equal(t, 0, res.ExitCode)
166 assert.Check(t, is.Equal(strings.TrimSpace(res.Stdout()), devTest))
167
168 // Check root-only test device.
169 res, err = container.Exec(ctx, apiClient, cID, []string{"ls", devRootOnlyTest})
170 assert.NilError(t, err)
171 if testEnv.IsRootless() {
172 assert.Equal(t, 1, res.ExitCode)
173 assert.Check(t, is.Contains(res.Stderr(), "No such file or directory"))
174 } else {
175 assert.Equal(t, 0, res.ExitCode)
176 assert.Check(t, is.Equal(strings.TrimSpace(res.Stdout()), devRootOnlyTest))
177 }
178}
179
180func TestRunConsoleSize(t *testing.T) {
181 skip.If(t, testEnv.DaemonInfo.OSType != "linux")

Callers

nothing calls this directly

Calls 13

RunFunction · 0.92
WithPrivilegedFunction · 0.92
ExecFunction · 0.92
APIClientMethod · 0.80
RemoveAllMethod · 0.80
EqualMethod · 0.80
CheckMethod · 0.80
setupTestFunction · 0.70
RemoveMethod · 0.65
StdoutMethod · 0.45
IsRootlessMethod · 0.45
ContainsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…