gopkg.in/dotcloud/docker.v1@v1.13.1/daemon/graphdriver/overlay2/overlay_test.go (about)

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