github.com/shivanshs9/go-overlay2@v0.0.0-20160814221707-8877415a0206/overlay_test.go (about) 1 // +build linux 2 3 // Copyright 2016 Dennis Chen <barracks510@gmail.com> 4 // Copyright 2013-2016 Docker, Inc. 5 // 6 // Licensed under the Apache License, Version 2.0 (the "License"); 7 // you may not use this file except in compliance with the License. 8 // You may obtain a copy of the License at 9 // 10 // http://www.apache.org/licenses/LICENSE-2.0 11 // 12 // Unless required by applicable law or agreed to in writing, software 13 // distributed under the License is distributed on an "AS IS" BASIS, 14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 // See the License for the specific language governing permissions and 16 // limitations under the License. 17 18 package overlay2 19 20 import ( 21 "os" 22 "syscall" 23 "testing" 24 25 "github.com/docker/docker/daemon/graphdriver" 26 "github.com/docker/docker/daemon/graphdriver/graphtest" 27 "github.com/docker/docker/pkg/archive" 28 ) 29 30 func init() { 31 // Do not sure chroot to speed run time and allow archive 32 // errors or hangs to be debugged directly from the test process. 33 untar = archive.UntarUncompressed 34 graphdriver.ApplyUncompressedLayer = archive.ApplyUncompressedLayer 35 } 36 37 func cdMountFrom(dir, device, target, mType, label string) error { 38 wd, err := os.Getwd() 39 if err != nil { 40 return err 41 } 42 os.Chdir(dir) 43 defer os.Chdir(wd) 44 45 return syscall.Mount(device, target, mType, 0, label) 46 } 47 48 // This avoids creating a new driver for each test if all tests are run 49 // Make sure to put new tests between TestOverlaySetup and TestOverlayTeardown 50 func TestOverlaySetup(t *testing.T) { 51 graphtest.GetDriver(t, driverName) 52 } 53 54 func TestOverlayCreateEmpty(t *testing.T) { 55 graphtest.DriverTestCreateEmpty(t, driverName) 56 } 57 58 func TestOverlayCreateBase(t *testing.T) { 59 graphtest.DriverTestCreateBase(t, driverName) 60 } 61 62 func TestOverlayCreateSnap(t *testing.T) { 63 graphtest.DriverTestCreateSnap(t, driverName) 64 } 65 66 func TestOverlay128LayerRead(t *testing.T) { 67 graphtest.DriverTestDeepLayerRead(t, 128, driverName) 68 } 69 70 func TestOverlayDiffApply10Files(t *testing.T) { 71 graphtest.DriverTestDiffApply(t, 10, driverName) 72 } 73 74 func TestOverlayChanges(t *testing.T) { 75 graphtest.DriverTestChanges(t, driverName) 76 } 77 78 func TestOverlayTeardown(t *testing.T) { 79 graphtest.PutDriver(t) 80 } 81 82 // Benchmarks should always setup new driver 83 84 func BenchmarkExists(b *testing.B) { 85 graphtest.DriverBenchExists(b, driverName) 86 } 87 88 func BenchmarkGetEmpty(b *testing.B) { 89 graphtest.DriverBenchGetEmpty(b, driverName) 90 } 91 92 func BenchmarkDiffBase(b *testing.B) { 93 graphtest.DriverBenchDiffBase(b, driverName) 94 } 95 96 func BenchmarkDiffSmallUpper(b *testing.B) { 97 graphtest.DriverBenchDiffN(b, 10, 10, driverName) 98 } 99 100 func BenchmarkDiff10KFileUpper(b *testing.B) { 101 graphtest.DriverBenchDiffN(b, 10, 10000, driverName) 102 } 103 104 func BenchmarkDiff10KFilesBottom(b *testing.B) { 105 graphtest.DriverBenchDiffN(b, 10000, 10, driverName) 106 } 107 108 func BenchmarkDiffApply100(b *testing.B) { 109 graphtest.DriverBenchDiffApplyN(b, 100, driverName) 110 } 111 112 func BenchmarkDiff20Layers(b *testing.B) { 113 graphtest.DriverBenchDeepLayerDiff(b, 20, driverName) 114 } 115 116 func BenchmarkRead20Layers(b *testing.B) { 117 graphtest.DriverBenchDeepLayerRead(b, 20, driverName) 118 }