github.com/SagerNet/gvisor@v0.0.0-20210707092255-7731c139d75c/test/fsstress/fsstress_test.go (about) 1 // Copyright 2021 The gVisor Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // Package fsstress runs fsstress tool inside a docker container. 16 package fsstress 17 18 import ( 19 "context" 20 "flag" 21 "math/rand" 22 "os" 23 "strconv" 24 "strings" 25 "testing" 26 "time" 27 28 "github.com/SagerNet/gvisor/pkg/test/dockerutil" 29 ) 30 31 func init() { 32 rand.Seed(int64(time.Now().Nanosecond())) 33 } 34 35 func TestMain(m *testing.M) { 36 dockerutil.EnsureSupportedDockerVersion() 37 flag.Parse() 38 os.Exit(m.Run()) 39 } 40 41 type config struct { 42 operations string 43 processes string 44 target string 45 } 46 47 func fsstress(t *testing.T, conf config) { 48 ctx := context.Background() 49 d := dockerutil.MakeContainer(ctx, t) 50 defer d.CleanUp(ctx) 51 52 const image = "basic/fsstress" 53 seed := strconv.FormatUint(uint64(rand.Uint32()), 10) 54 args := []string{"-d", conf.target, "-n", conf.operations, "-p", conf.processes, "-s", seed, "-X"} 55 t.Logf("Repro: docker run --rm --runtime=%s github.com/SagerNet/images/%s %s", dockerutil.Runtime(), image, strings.Join(args, " ")) 56 out, err := d.Run(ctx, dockerutil.RunOpts{Image: image}, args...) 57 if err != nil { 58 t.Fatalf("docker run failed: %v\noutput: %s", err, out) 59 } 60 // This is to catch cases where fsstress spews out error messages during clean 61 // up but doesn't return error. 62 if len(out) > 0 { 63 t.Fatalf("unexpected output: %s", out) 64 } 65 } 66 67 func TestFsstressTmpfs(t *testing.T) { 68 // This takes between 10s to run on my machine. Adjust as needed. 69 cfg := config{ 70 operations: "5000", 71 processes: "20", 72 target: "/tmp", 73 } 74 fsstress(t, cfg) 75 }