@@ -20,23 +20,14 @@ import (
2020func TestRuntime (t * testing.T ) {
2121 limavm .Require (t )
2222
23- dirMountedInVM := t .TempDir ()
24-
25- rootpathPrefix := filepath .Join (dirMountedInVM , "fake-root" )
26- runtimeBin , err := repo .BuildRuntimeBin (t .TempDir (), rootpathPrefix , limavm .BinBuildEnv )
23+ rootpathPrefixInVM := filepath .Join ("/tmp" , "remoteproc-simulator-fake-root-for-standalone-runtime" )
24+ runtimeBin , err := repo .BuildRuntimeBin (t .TempDir (), rootpathPrefixInVM , limavm .BinBuildEnv )
2725 require .NoError (t , err )
2826
29- vm , err := limavm .NewDebian (dirMountedInVM )
27+ vm , err := limavm .NewDebian ()
3028 require .NoError (t , err )
3129 defer vm .Cleanup ()
3230
33- _ , _ , err = vm .RunCommand ("mkdir" , "-p" , filepath .Join (rootpathPrefix ))
34- require .NoError (t , err )
35- defer func () {
36- _ , _ , err := vm .RunCommand ("rm" , "-rf" , filepath .Join (rootpathPrefix ))
37- require .NoError (t , err )
38- }()
39-
4031 installedRuntime , err := vm .InstallBin (runtimeBin )
4132 require .NoError (t , err )
4233
@@ -48,15 +39,15 @@ func TestRuntime(t *testing.T) {
4839
4940 t .Run ("basic container lifecycle" , func (t * testing.T ) {
5041 remoteprocName := "yolo-device"
51- sim := remoteproc .NewSimulator (installedSimulator , rootpathPrefix ).WithName (remoteprocName ).WithIndex (getTestNumber ())
42+ sim := remoteproc .NewSimulator (installedSimulator , rootpathPrefixInVM ).WithName (remoteprocName ).WithIndex (getTestNumber ())
5243 if err := sim .Start (); err != nil {
5344 t .Fatalf ("failed to run simulator: %s" , err )
5445 }
5546 t .Cleanup (func () { _ = sim .Stop () })
5647
5748 uniqueID := testID (t )
5849 containerName := uniqueID
59- bundlePath := filepath .Join (dirMountedInVM , uniqueID )
50+ bundlePath := filepath .Join (t . TempDir () , uniqueID )
6051 require .NoError (t , generateBundle (t , bundlePath , remoteprocName ))
6152 copiedBundlePathInVM , err := copyToVM (t , vm .VM , bundlePath )
6253 require .NoError (t , err )
@@ -85,15 +76,16 @@ func TestRuntime(t *testing.T) {
8576
8677 t .Run ("errors when requested remoteproc name doesn't exist" , func (t * testing.T ) {
8778 processorName := "some-processor"
88- sim := remoteproc .NewSimulator (installedSimulator , rootpathPrefix ).WithName (processorName ).WithIndex (getTestNumber ())
79+ sim := remoteproc .NewSimulator (installedSimulator , rootpathPrefixInVM ).WithName (processorName ).WithIndex (getTestNumber ())
8980 if err := sim .Start (); err != nil {
9081 t .Fatalf ("failed to run simulator: %s" , err )
9182 }
9283 t .Cleanup (func () { _ = sim .Stop () })
9384
9485 uniqueID := testID (t )
86+
9587 containerName := uniqueID
96- bundlePath := filepath .Join (dirMountedInVM , uniqueID )
88+ bundlePath := filepath .Join (t . TempDir () , uniqueID )
9789 require .NoError (t , generateBundle (t , bundlePath , "other-processor" ))
9890 copiedBundlePathInVM , err := copyToVM (t , vm .VM , bundlePath )
9991 require .NoError (t , err )
@@ -106,15 +98,15 @@ func TestRuntime(t *testing.T) {
10698
10799 t .Run ("killing process by pid stops the running container" , func (t * testing.T ) {
108100 remoteprocName := "nice-processor"
109- sim := remoteproc .NewSimulator (installedSimulator , rootpathPrefix ).WithName (remoteprocName ).WithIndex (getTestNumber ())
101+ sim := remoteproc .NewSimulator (installedSimulator , rootpathPrefixInVM ).WithName (remoteprocName ).WithIndex (getTestNumber ())
110102 if err := sim .Start (); err != nil {
111103 t .Fatalf ("failed to run simulator: %s" , err )
112104 }
113105 t .Cleanup (func () { _ = sim .Stop () })
114106
115107 uniqueID := testID (t )
116108 containerName := uniqueID
117- bundlePath := filepath .Join (dirMountedInVM , uniqueID )
109+ bundlePath := filepath .Join (t . TempDir () , uniqueID )
118110 require .NoError (t , generateBundle (t , bundlePath , remoteprocName ))
119111 copiedBundlePathInVM , err := copyToVM (t , vm .VM , bundlePath )
120112 require .NoError (t , err )
@@ -137,15 +129,15 @@ func TestRuntime(t *testing.T) {
137129
138130 t .Run ("writes pid to file specified by --pid-file" , func (t * testing.T ) {
139131 remoteprocName := "oh-what-a-device"
140- sim := remoteproc .NewSimulator (installedSimulator , rootpathPrefix ).WithName (remoteprocName ).WithIndex (getTestNumber ())
132+ sim := remoteproc .NewSimulator (installedSimulator , rootpathPrefixInVM ).WithName (remoteprocName ).WithIndex (getTestNumber ())
141133 if err := sim .Start (); err != nil {
142134 t .Fatalf ("failed to run simulator: %s" , err )
143135 }
144136 t .Cleanup (func () { _ = sim .Stop () })
145137
146138 uniqueID := testID (t )
147139 containerName := uniqueID
148- bundlePath := filepath .Join (dirMountedInVM , uniqueID )
140+ bundlePath := filepath .Join (t . TempDir () , uniqueID )
149141 require .NoError (t , generateBundle (t , bundlePath , remoteprocName ))
150142 copiedBundlePathInVM , err := copyToVM (t , vm .VM , bundlePath )
151143 require .NoError (t , err )
@@ -162,25 +154,24 @@ func TestRuntime(t *testing.T) {
162154 pid , err := getContainerPid (installedRuntime , containerName )
163155 require .NoError (t , err )
164156 require .Greater (t , pid , 0 )
165-
166- require .FileExists (t , pidFile )
167- assertFileContent (t , pidFile , fmt .Sprintf ("%d" , pid ))
157+ requireFileExistsInVM (t , vm .VM , pidFile )
158+ assertFileContentInVM (t , vm .VM , pidFile , fmt .Sprintf ("%d" , pid ))
168159 })
169160
170161 t .Run ("proxy process namespacing" , func (t * testing.T ) {
171162 installedRuntimeSudo := limavm .NewSudo (installedRuntime )
172163
173164 t .Run ("creates process in requested namespace when root" , func (t * testing.T ) {
174165 remoteprocName := "lovely-blue-device"
175- sim := remoteproc .NewSimulator (installedSimulator , rootpathPrefix ).WithName (remoteprocName ).WithIndex (getTestNumber ())
166+ sim := remoteproc .NewSimulator (installedSimulator , rootpathPrefixInVM ).WithName (remoteprocName ).WithIndex (getTestNumber ())
176167 if err := sim .Start (); err != nil {
177168 t .Fatalf ("failed to run simulator: %s" , err )
178169 }
179170 t .Cleanup (func () { _ = sim .Stop () })
180171
181172 uniqueID := testID (t )
182173 containerName := uniqueID
183- bundlePath := filepath .Join (dirMountedInVM , uniqueID )
174+ bundlePath := filepath .Join (t . TempDir () , uniqueID )
184175 require .NoError (t , generateBundle (
185176 t ,
186177 bundlePath ,
@@ -212,15 +203,15 @@ func TestRuntime(t *testing.T) {
212203
213204 t .Run ("creates process in user's namespace when not root" , func (t * testing.T ) {
214205 remoteprocName := "lovely-green-device"
215- sim := remoteproc .NewSimulator (installedSimulator , rootpathPrefix ).WithName (remoteprocName ).WithIndex (getTestNumber ())
206+ sim := remoteproc .NewSimulator (installedSimulator , rootpathPrefixInVM ).WithName (remoteprocName ).WithIndex (getTestNumber ())
216207 if err := sim .Start (); err != nil {
217208 t .Fatalf ("failed to run simulator: %s" , err )
218209 }
219210 t .Cleanup (func () { _ = sim .Stop () })
220211
221212 uniqueID := testID (t )
222213 containerName := uniqueID
223- bundlePath := filepath .Join (dirMountedInVM , uniqueID )
214+ bundlePath := filepath .Join (t . TempDir () , uniqueID )
224215 require .NoError (t , generateBundle (
225216 t ,
226217 bundlePath ,
@@ -253,15 +244,15 @@ func TestRuntime(t *testing.T) {
253244
254245 t .Run ("When a custom path is set in /sys/module/firmware_class/parameters/path, the firmware will be stored there" , func (t * testing.T ) {
255246 remoteprocName := "nice-device"
256- sim := remoteproc .NewSimulator (installedSimulator , rootpathPrefix ).WithName (remoteprocName ).WithIndex (getTestNumber ())
247+ sim := remoteproc .NewSimulator (installedSimulator , rootpathPrefixInVM ).WithName (remoteprocName ).WithIndex (getTestNumber ())
257248 if err := sim .Start (); err != nil {
258249 t .Fatalf ("failed to run simulator: %s" , err )
259250 }
260251 t .Cleanup (func () { _ = sim .Stop () })
261252
262253 uniqueID := testID (t )
263254 containerName := uniqueID
264- bundlePath := filepath .Join (dirMountedInVM , uniqueID )
255+ bundlePath := filepath .Join (t . TempDir () , uniqueID )
265256 require .NoError (t , generateBundle (t , bundlePath , remoteprocName ))
266257 copiedBundlePathInVM , err := copyToVM (t , vm .VM , bundlePath )
267258 require .NoError (t , err )
@@ -272,12 +263,12 @@ func TestRuntime(t *testing.T) {
272263 containerName )
273264 require .NoError (t , err , "stderr: %s" , stderr )
274265
275- customFirmwareStorageDirectory := filepath .Join (rootpathPrefix , "my" , "firmware" , "path" )
266+ customFirmwareStorageDirectory := filepath .Join (rootpathPrefixInVM , "my" , "firmware" , "path" )
276267
277268 _ , _ , err = vm .RunCommand ("sh" , "-c" , fmt .Sprintf ("echo -n %s > %s" ,
278269 customFirmwareStorageDirectory ,
279270 filepath .Join (
280- rootpathPrefix ,
271+ rootpathPrefixInVM ,
281272 "sys" ,
282273 "module" ,
283274 "firmware_class" ,
@@ -291,14 +282,15 @@ func TestRuntime(t *testing.T) {
291282 require .NoError (t , err , "stderr: %s" , stderr )
292283 assertContainerStatus (t , installedRuntime , containerName , specs .StateRunning )
293284
294- assertFirmwareFileExists ( t , customFirmwareStorageDirectory )
285+ assertFirmwareFileExistsInVM ( t , vm . VM , customFirmwareStorageDirectory )
295286 })
296287}
297288
298- func assertFirmwareFileExists (t * testing.T , firmwareStorageDirectory string ) {
289+ func assertFirmwareFileExistsInVM (t * testing.T , vm limavm. VM , firmwareStorageDirectory string ) {
299290 t .Helper ()
300- entries , err := os . ReadDir ( firmwareStorageDirectory )
291+ entriesInString , _ , err := vm . RunCommand ( "ls" , firmwareStorageDirectory )
301292 require .NoError (t , err )
293+ entries := strings .Split (entriesInString , "\n " )
302294 require .Greater (t , len (entries ), 0 , "expected at least one firmware file in %s" , firmwareStorageDirectory )
303295}
304296
@@ -309,14 +301,20 @@ func assertContainerStatus(t testing.TB, runtime limavm.Runnable, containerName
309301 assert .Equal (t , wantStatus , state .Status )
310302}
311303
312- func assertFileContent (t * testing.T , path string , wantContent string ) {
304+ func assertFileContentInVM (t * testing.T , vm limavm. VM , path string , wantContent string ) {
313305 t .Helper ()
314- gotContent , err := os .ReadFile (path )
306+ gotContent , err := vm .ReadFile (path )
315307 if assert .NoError (t , err ) {
316- assert .Equal (t , wantContent , string ( gotContent ) )
308+ assert .Equal (t , wantContent , gotContent )
317309 }
318310}
319311
312+ func requireFileExistsInVM (t * testing.T , vm limavm.VM , path string ) {
313+ t .Helper ()
314+ _ , stderr , err := vm .RunCommand ("test" , "-e" , path )
315+ require .NoError (t , err , "failed to check file existence %s in VM: stderr: %s" , path , stderr )
316+ }
317+
320318func requireSameMountNamespace (t testing.TB , vm limavm.Debian , pid uint ) {
321319 t .Helper ()
322320 hostMountNS , stderr , err := vm .RunCommand ("readlink" , "/proc/self/ns/mnt" )
0 commit comments