Skip to content

Commit 670e0a4

Browse files
committed
Add a test for inheriting the correct namespace
Signed-off-by: luke <luke.parkin@arm.com>
1 parent c8f0026 commit 670e0a4

1 file changed

Lines changed: 41 additions & 1 deletion

File tree

e2e/runtime_test.go

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,45 @@ func TestRuntimeWriteProcessPid(t *testing.T) {
128128
assertFileContent(t, pidFilePath, fmt.Sprintf("%d", pid))
129129
}
130130

131+
func TestRuntimeProxyInheritsCorrectNamespace(t *testing.T) {
132+
rootDir := t.TempDir()
133+
remoteprocName := "a-lovely-blue-device"
134+
sim := remoteproc.NewSimulator(rootDir).WithName(remoteprocName)
135+
if err := sim.Start(); err != nil {
136+
t.Fatalf("failed to run simulator: %s", err)
137+
}
138+
defer func() { _ = sim.Stop() }()
139+
140+
bin, err := repo.BuildRuntimeBin(t.TempDir(), rootDir, nil)
141+
require.NoError(t, err)
142+
143+
const containerName = "blue-container"
144+
bundlePath := t.TempDir()
145+
146+
require.NoError(t, generateBundle(
147+
bundlePath,
148+
remoteprocName,
149+
specs.LinuxNamespace{Type: specs.MountNamespace},
150+
))
151+
152+
_, err = invokeRuntime(bin, "create", "--bundle", bundlePath, containerName)
153+
require.NoError(t, err)
154+
155+
pid, err := getContainerPid(bin, containerName)
156+
require.NoError(t, err)
157+
require.Greater(t, pid, 0)
158+
159+
hostMountNS, err := os.Readlink("/proc/self/ns/mnt")
160+
require.NoError(t, err)
161+
proxyMountNS, err := os.Readlink(fmt.Sprintf("/proc/%d/ns/mnt", pid))
162+
require.NoError(t, err)
163+
164+
assert.NotEqual(t, hostMountNS, proxyMountNS)
165+
166+
_, err = invokeRuntime(bin, "delete", containerName)
167+
require.NoError(t, err)
168+
}
169+
131170
func assertContainerStatus(t testing.TB, bin repo.RuntimeBin, containerName string, wantStatus specs.ContainerState) {
132171
t.Helper()
133172
state, err := getContainerState(bin, containerName)
@@ -156,7 +195,7 @@ func getContainerState(bin repo.RuntimeBin, containerName string) (specs.State,
156195
return state, nil
157196
}
158197

159-
func generateBundle(targetDir string, remoteprocName string) error {
198+
func generateBundle(targetDir string, remoteprocName string, namespaces ...specs.LinuxNamespace) error {
160199
const bundleRoot = "rootfs"
161200
const firmwareName = "hello_world.elf"
162201

@@ -179,6 +218,7 @@ func generateBundle(targetDir string, remoteprocName string) error {
179218
Annotations: map[string]string{
180219
"remoteproc.name": remoteprocName,
181220
},
221+
Linux: &specs.Linux{Namespaces: namespaces},
182222
}
183223

184224
specPath := filepath.Join(targetDir, "config.json")

0 commit comments

Comments
 (0)