@@ -1372,6 +1372,49 @@ func TestCheckpointResume(t *testing.T) {
13721372 }
13731373}
13741374
1375+ // TestUsageDiskBackedOverlay checks that data in a disk backed overlay is not
1376+ // reported as memory usage, before or after a checkpoint and restore.
1377+ func TestUsageDiskBackedOverlay (t * testing.T ) {
1378+ if ! testutil .IsCheckpointSupported () {
1379+ t .Skip ("Checkpoint not supported" )
1380+ }
1381+ conf := overlayTestConfig (t )
1382+
1383+ const size = 64 << 20
1384+ file := filepath .Join (testutil .TmpDir (), "usage-overlay" )
1385+ done := file + ".done"
1386+ script := fmt .Sprintf ("dd if=/dev/urandom of=%q bs=1M count=%d && echo ok > %q; while true; do sleep 1; done" , file , size >> 20 , done )
1387+ spec := testutil .NewSpecWithArgs ("bash" , "-c" , script )
1388+ bundleDir := setupBundle (t , conf , spec )
1389+ cont := startContainer (t , conf , spec , bundleDir , nil )
1390+ waitForGuestFiles (t , conf , cont , done )
1391+
1392+ checkUsage := func (cont * Container , when string ) {
1393+ t .Helper ()
1394+ m , err := cont .Sandbox .Usage (true /* Full */ )
1395+ if err != nil {
1396+ t .Fatalf ("error getting usage %s: %v" , when , err )
1397+ }
1398+ if m .Tmpfs >= size {
1399+ t .Errorf ("overlay data reported as tmpfs memory %s: got Tmpfs = %d, want < %d" , when , m .Tmpfs , size )
1400+ }
1401+ }
1402+ checkUsage (cont , "before checkpoint" )
1403+
1404+ dir := makeTempDir (t , "checkpoint" )
1405+ if err := cont .Checkpoint (conf , dir , sandbox.CheckpointOpts {}); err != nil {
1406+ t .Fatalf ("error checkpointing container: %v" , err )
1407+ }
1408+ cont2 := newContainer (t , conf , spec , bundleDir , func (args * Args ) {
1409+ args .CheckpointDirPath = dir
1410+ })
1411+ if err := cont2 .Restore (conf , dir , sandbox .DirectIOOff , false /* background */ , nil /* networkArgs */ ); err != nil {
1412+ t .Fatalf ("error restoring container: %v" , err )
1413+ }
1414+ waitForGuestFiles (t , conf , cont2 , file )
1415+ checkUsage (cont2 , "after restore" )
1416+ }
1417+
13751418func TestSplitFSCheckpointRestore (t * testing.T ) {
13761419 // We only run this test if checkpoint/restore is supported.
13771420 if ! testutil .IsCheckpointSupported () {
0 commit comments