From 00faa3a1652a57c9f8f6ceeb930020680d3d5295 Mon Sep 17 00:00:00 2001
From: Jamie Anderson <jamieand@amazon.com>
Date: Tue, 2 Mar 2021 19:11:09 +0000
Subject: [PATCH] Skip devmapper tests that don't work in a buildroot

Signed-off-by: Jamie Anderson <jamieand@amazon.com>
---
 daemon/graphdriver/devmapper/devmapper_test.go | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/daemon/graphdriver/devmapper/devmapper_test.go b/daemon/graphdriver/devmapper/devmapper_test.go
index afd6c5b..dc59dc5 100644
--- a/daemon/graphdriver/devmapper/devmapper_test.go
+++ b/daemon/graphdriver/devmapper/devmapper_test.go
@@ -8,6 +8,7 @@ import (
 	"os/exec"
 	"syscall"
 	"testing"
+	"github.com/docker/docker/testutil"
 	"time"
 
 	"github.com/docker/docker/daemon/graphdriver"
@@ -17,6 +18,10 @@ import (
 )
 
 func init() {
+	if _, err := os.Stat("/.initialized"); err == nil {
+		// Don't try to call initLoopbacks() in a buildroot
+		return nil
+	}
 	// Reduce the size of the base fs and loopback for the tests
 	defaultDataLoopbackSize = 300 * 1024 * 1024
 	defaultMetaDataLoopbackSize = 200 * 1024 * 1024
@@ -71,26 +76,32 @@ func getBaseLoopStats() (*syscall.Stat_t, error) {
 // This avoids creating a new driver for each test if all tests are run
 // Make sure to put new tests between TestDevmapperSetup and TestDevmapperTeardown
 func TestDevmapperSetup(t *testing.T) {
+	testutil.SkipIfBuildroot(t)
 	graphtest.GetDriver(t, "devicemapper")
 }
 
 func TestDevmapperCreateEmpty(t *testing.T) {
+	testutil.SkipIfBuildroot(t)
 	graphtest.DriverTestCreateEmpty(t, "devicemapper")
 }
 
 func TestDevmapperCreateBase(t *testing.T) {
+	testutil.SkipIfBuildroot(t)
 	graphtest.DriverTestCreateBase(t, "devicemapper")
 }
 
 func TestDevmapperCreateSnap(t *testing.T) {
+	testutil.SkipIfBuildroot(t)
 	graphtest.DriverTestCreateSnap(t, "devicemapper")
 }
 
 func TestDevmapperTeardown(t *testing.T) {
+	testutil.SkipIfBuildroot(t)
 	graphtest.PutDriver(t)
 }
 
 func TestDevmapperReduceLoopBackSize(t *testing.T) {
+	testutil.SkipIfBuildroot(t)
 	tenMB := int64(10 * 1024 * 1024)
 	testChangeLoopBackSize(t, -tenMB, defaultDataLoopbackSize, defaultMetaDataLoopbackSize)
 }
@@ -101,6 +112,7 @@ func TestDevmapperIncreaseLoopBackSize(t *testing.T) {
 }
 
 func testChangeLoopBackSize(t *testing.T, delta, expectDataSize, expectMetaDataSize int64) {
+	testutil.SkipIfBuildroot(t)
 	driver := graphtest.GetDriver(t, "devicemapper").(*graphtest.Driver).Driver.(*graphdriver.NaiveDiffDriver).ProtoDriver.(*Driver)
 	defer graphtest.PutDriver(t)
 	// make sure data or metadata loopback size are the default size
@@ -129,6 +141,7 @@ func testChangeLoopBackSize(t *testing.T, delta, expectDataSize, expectMetaDataS
 
 // Make sure devices.Lock() has been release upon return from cleanupDeletedDevices() function
 func TestDevmapperLockReleasedDeviceDeletion(t *testing.T) {
+	testutil.SkipIfBuildroot(t)
 	driver := graphtest.GetDriver(t, "devicemapper").(*graphtest.Driver).Driver.(*graphdriver.NaiveDiffDriver).ProtoDriver.(*Driver)
 	defer graphtest.PutDriver(t)
 
-- 
2.25.0.24.gbc7a3d4

