@@ -128,6 +128,42 @@ 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+ spec := & specs.Spec {}
147+ require .NoError (t , generateBundle (
148+ bundlePath ,
149+ remoteprocName ,
150+ addLinuxNamespaces (spec , specs.LinuxNamespace {Type : specs .MountNamespace }),
151+ ))
152+
153+ _ , err = invokeRuntime (bin , "create" , "--bundle" , bundlePath , containerName )
154+ require .NoError (t , err )
155+
156+ hostMountNS , err := os .Readlink ("/proc/self/ns/mnt" )
157+ require .NoError (t , err )
158+ proxyMountNS , err := os .Readlink (fmt .Sprintf ("/proc/%d/ns/mnt" , pid ))
159+ require .NoError (t , err )
160+
161+ assert .NotEqual (t , hostMountNS , proxyMountNS )
162+
163+ _ , err = invokeRuntime (bin , "delete" , containerName )
164+ require .NoError (t , err )
165+ }
166+
131167func assertContainerStatus (t testing.TB , bin repo.RuntimeBin , containerName string , wantStatus specs.ContainerState ) {
132168 t .Helper ()
133169 state , err := getContainerState (bin , containerName )
@@ -156,7 +192,14 @@ func getContainerState(bin repo.RuntimeBin, containerName string) (specs.State,
156192 return state , nil
157193}
158194
159- func generateBundle (targetDir string , remoteprocName string ) error {
195+ func addLinuxNamespaces (spec * specs.Spec , namespaces ... specs.LinuxNamespace ) {
196+ if spec .Linux == nil {
197+ spec .Linux = & specs.Linux {}
198+ }
199+ spec .Linux .Namespaces = append (spec .Linux .Namespaces , namespaces ... )
200+ }
201+
202+ func generateBundle (targetDir string , remoteprocName string , namespaces ... specs.LinuxNamespace ) error {
160203 const bundleRoot = "rootfs"
161204 const firmwareName = "hello_world.elf"
162205
@@ -179,6 +222,7 @@ func generateBundle(targetDir string, remoteprocName string) error {
179222 Annotations : map [string ]string {
180223 "remoteproc.name" : remoteprocName ,
181224 },
225+ Linux : & specs.Linux {Namespaces : namespaces ,}
182226 }
183227
184228 specPath := filepath .Join (targetDir , "config.json" )
0 commit comments