@@ -664,33 +664,50 @@ func TestHandleShm(t *testing.T) {
664664 shmSize : 8192 ,
665665 }
666666
667- g := & pb. Spec {
668- Hooks : & pb. Hooks {},
669- Mounts : []pb .Mount {
670- { Destination : "/dev/shm" } ,
671- } ,
667+ var ociMounts []specs. Mount
668+
669+ mount := specs .Mount {
670+ Type : "bind" ,
671+ Destination : "/dev/shm" ,
672672 }
673673
674- k .handleShm (g , sandbox )
674+ ociMounts = append (ociMounts , mount )
675+ k .handleShm (ociMounts , sandbox )
675676
676- assert .Len (g . Mounts , 1 )
677- assert .NotEmpty (g . Mounts [0 ].Destination )
678- assert .Equal (g . Mounts [0 ].Destination , "/dev/shm" )
679- assert .Equal (g . Mounts [0 ].Type , "bind" )
680- assert .NotEmpty (g . Mounts [0 ].Source , filepath .Join (kataGuestSharedDir (), shmDir ))
681- assert .Equal (g . Mounts [0 ].Options , []string {"rbind" })
677+ assert .Len (ociMounts , 1 )
678+ assert .NotEmpty (ociMounts [0 ].Destination )
679+ assert .Equal (ociMounts [0 ].Destination , "/dev/shm" )
680+ assert .Equal (ociMounts [0 ].Type , "bind" )
681+ assert .NotEmpty (ociMounts [0 ].Source , filepath .Join (kataGuestSharedDir (), shmDir ))
682+ assert .Equal (ociMounts [0 ].Options , []string {"rbind" })
682683
683684 sandbox .shmSize = 0
684- k .handleShm (g , sandbox )
685-
686- assert .Len (g .Mounts , 1 )
687- assert .NotEmpty (g .Mounts [0 ].Destination )
688- assert .Equal (g .Mounts [0 ].Destination , "/dev/shm" )
689- assert .Equal (g .Mounts [0 ].Type , "tmpfs" )
690- assert .Equal (g .Mounts [0 ].Source , "shm" )
685+ k .handleShm (ociMounts , sandbox )
691686
687+ assert .Len (ociMounts , 1 )
688+ assert .Equal (ociMounts [0 ].Destination , "/dev/shm" )
689+ assert .Equal (ociMounts [0 ].Type , "tmpfs" )
690+ assert .Equal (ociMounts [0 ].Source , "shm" )
692691 sizeOption := fmt .Sprintf ("size=%d" , DefaultShmSize )
693- assert .Equal (g .Mounts [0 ].Options , []string {"noexec" , "nosuid" , "nodev" , "mode=1777" , sizeOption })
692+ assert .Equal (ociMounts [0 ].Options , []string {"noexec" , "nosuid" , "nodev" , "mode=1777" , sizeOption })
693+
694+ // In case the type of mount is ephemeral, the container mount is not
695+ // shared with the sandbox shm.
696+ ociMounts [0 ].Type = KataEphemeralDevType
697+ mountSource := "/tmp/mountPoint"
698+ ociMounts [0 ].Source = mountSource
699+ k .handleShm (ociMounts , sandbox )
700+
701+ assert .Len (ociMounts , 1 )
702+ assert .Equal (ociMounts [0 ].Type , KataEphemeralDevType )
703+ assert .NotEmpty (ociMounts [0 ].Source , mountSource )
704+
705+ epheStorages := k .handleEphemeralStorage (ociMounts )
706+ epheMountPoint := epheStorages [0 ].GetMountPoint ()
707+ expected := filepath .Join (ephemeralPath (), filepath .Base (mountSource ))
708+ assert .Equal (epheMountPoint , expected ,
709+ "Ephemeral mount point didn't match: got %s, expecting %s" , epheMountPoint , expected )
710+
694711}
695712
696713func testIsPidNamespacePresent (grpcSpec * pb.Spec ) bool {
0 commit comments