github.com/ktock/storage@v1.12.13/drivers/overlay/overlay_test.go (about) 1 // +build linux 2 3 package overlay 4 5 import ( 6 "io/ioutil" 7 "os" 8 "testing" 9 10 "github.com/containers/storage/drivers" 11 "github.com/containers/storage/drivers/graphtest" 12 "github.com/containers/storage/pkg/archive" 13 "github.com/containers/storage/pkg/reexec" 14 "golang.org/x/sys/unix" 15 ) 16 17 const driverName = "overlay" 18 19 func init() { 20 // Do not sure chroot to speed run time and allow archive 21 // errors or hangs to be debugged directly from the test process. 22 untar = archive.UntarUncompressed 23 graphdriver.ApplyUncompressedLayer = archive.ApplyUncompressedLayer 24 25 reexec.Init() 26 } 27 28 func cdMountFrom(dir, device, target, mType, label string) error { 29 wd, err := os.Getwd() 30 if err != nil { 31 return err 32 } 33 os.Chdir(dir) 34 defer os.Chdir(wd) 35 36 return unix.Mount(device, target, mType, 0, label) 37 } 38 39 func skipIfNaive(t *testing.T) { 40 td, err := ioutil.TempDir("", "naive-check-") 41 if err != nil { 42 t.Fatalf("Failed to create temp dir: %v", err) 43 } 44 defer os.RemoveAll(td) 45 46 if err := doesSupportNativeDiff(td, ""); err != nil { 47 t.Skipf("Cannot run test with naive diff") 48 } 49 } 50 51 // This avoids creating a new driver for each test if all tests are run 52 // Make sure to put new tests between TestOverlaySetup and TestOverlayTeardown 53 func TestOverlaySetup(t *testing.T) { 54 graphtest.GetDriver(t, driverName) 55 } 56 57 func TestOverlayCreateEmpty(t *testing.T) { 58 graphtest.DriverTestCreateEmpty(t, driverName) 59 } 60 61 func TestOverlayCreateBase(t *testing.T) { 62 graphtest.DriverTestCreateBase(t, driverName) 63 } 64 65 func TestOverlayCreateSnap(t *testing.T) { 66 graphtest.DriverTestCreateSnap(t, driverName) 67 } 68 69 func TestOverlayCreateFromTemplate(t *testing.T) { 70 graphtest.DriverTestCreateFromTemplate(t, driverName) 71 } 72 73 func TestOverlay128LayerRead(t *testing.T) { 74 graphtest.DriverTestDeepLayerRead(t, 128, driverName) 75 } 76 77 func TestOverlayDiffApply10Files(t *testing.T) { 78 skipIfNaive(t) 79 graphtest.DriverTestDiffApply(t, 10, driverName) 80 } 81 82 func TestOverlayChanges(t *testing.T) { 83 skipIfNaive(t) 84 graphtest.DriverTestChanges(t, driverName) 85 } 86 87 func TestOverlayTeardown(t *testing.T) { 88 graphtest.PutDriver(t) 89 } 90 91 func TestOverlayEcho(t *testing.T) { 92 graphtest.DriverTestEcho(t, driverName) 93 } 94 95 // Benchmarks should always setup new driver 96 97 func BenchmarkExists(b *testing.B) { 98 graphtest.DriverBenchExists(b, driverName) 99 } 100 101 func BenchmarkGetEmpty(b *testing.B) { 102 graphtest.DriverBenchGetEmpty(b, driverName) 103 } 104 105 func BenchmarkDiffBase(b *testing.B) { 106 graphtest.DriverBenchDiffBase(b, driverName) 107 } 108 109 func BenchmarkDiffSmallUpper(b *testing.B) { 110 graphtest.DriverBenchDiffN(b, 10, 10, driverName) 111 } 112 113 func BenchmarkDiff10KFileUpper(b *testing.B) { 114 graphtest.DriverBenchDiffN(b, 10, 10000, driverName) 115 } 116 117 func BenchmarkDiff10KFilesBottom(b *testing.B) { 118 graphtest.DriverBenchDiffN(b, 10000, 10, driverName) 119 } 120 121 func BenchmarkDiffApply100(b *testing.B) { 122 graphtest.DriverBenchDiffApplyN(b, 100, driverName) 123 } 124 125 func BenchmarkDiff20Layers(b *testing.B) { 126 graphtest.DriverBenchDeepLayerDiff(b, 20, driverName) 127 } 128 129 func BenchmarkRead20Layers(b *testing.B) { 130 graphtest.DriverBenchDeepLayerRead(b, 20, driverName) 131 }