github.com/demonoid81/containerd@v1.3.4/snapshots/overlay/check_test.go (about) 1 // +build linux 2 3 /* 4 Copyright The containerd Authors. 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 19 package overlay 20 21 import ( 22 "io/ioutil" 23 "os" 24 "os/exec" 25 "testing" 26 27 "github.com/containerd/containerd/pkg/testutil" 28 "github.com/containerd/continuity/testutil/loopback" 29 ) 30 31 func testOverlaySupported(t testing.TB, expected bool, mkfs ...string) { 32 testutil.RequiresRoot(t) 33 mnt, err := ioutil.TempDir("", "containerd-fs-test-supports-overlay") 34 if err != nil { 35 t.Fatal(err) 36 } 37 defer os.RemoveAll(mnt) 38 39 loop, err := loopback.New(100 << 20) // 100 MB 40 if err != nil { 41 t.Fatal(err) 42 } 43 if out, err := exec.Command(mkfs[0], append(mkfs[1:], loop.Device)...).CombinedOutput(); err != nil { 44 // not fatal 45 loop.Close() 46 t.Skipf("could not mkfs (%v) %s: %v (out: %q)", mkfs, loop.Device, err, string(out)) 47 } 48 if out, err := exec.Command("mount", loop.Device, mnt).CombinedOutput(); err != nil { 49 // not fatal 50 loop.Close() 51 t.Skipf("could not mount %s: %v (out: %q)", loop.Device, err, string(out)) 52 } 53 defer func() { 54 testutil.Unmount(t, mnt) 55 loop.Close() 56 }() 57 workload := func() { 58 err = Supported(mnt) 59 if expected && err != nil { 60 t.Fatal(err) 61 } 62 if !expected && err == nil { 63 t.Fatal("error is expected") 64 } 65 } 66 b, ok := t.(*testing.B) 67 if ok { 68 b.ResetTimer() 69 for i := 0; i < b.N; i++ { 70 workload() 71 } 72 b.StopTimer() 73 } else { 74 workload() 75 } 76 } 77 78 func BenchmarkOverlaySupportedOnExt4(b *testing.B) { 79 testOverlaySupported(b, true, "mkfs.ext4", "-F") 80 } 81 82 func BenchmarkOverlayUnsupportedOnFType0XFS(b *testing.B) { 83 testOverlaySupported(b, false, "mkfs.xfs", "-m", "crc=0", "-n", "ftype=0") 84 } 85 86 func BenchmarkOverlaySupportedOnFType1XFS(b *testing.B) { 87 testOverlaySupported(b, true, "mkfs.xfs", "-m", "crc=0", "-n", "ftype=1") 88 } 89 90 func BenchmarkOverlayUnsupportedOnFAT(b *testing.B) { 91 testOverlaySupported(b, false, "mkfs.fat") 92 }