overlay_test.go 2.8 KB

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