github.com/zhuohuang-hust/src-cbuild@v0.0.0-20230105071821-c7aab3e7c840/mergeCode/runc/libcontainer/integration/init_test.go (about) 1 package integration 2 3 import ( 4 "os" 5 "runtime" 6 "testing" 7 8 "github.com/Sirupsen/logrus" 9 "github.com/opencontainers/runc/libcontainer" 10 "github.com/opencontainers/runc/libcontainer/cgroups/systemd" 11 _ "github.com/opencontainers/runc/libcontainer/nsenter" 12 ) 13 14 // init runs the libcontainer initialization code because of the busybox style needs 15 // to work around the go runtime and the issues with forking 16 func init() { 17 if len(os.Args) < 2 || os.Args[1] != "init" { 18 return 19 } 20 runtime.GOMAXPROCS(1) 21 runtime.LockOSThread() 22 factory, err := libcontainer.New("") 23 if err != nil { 24 logrus.Fatalf("unable to initialize for container: %s", err) 25 } 26 if err := factory.StartInitialization(); err != nil { 27 logrus.Fatal(err) 28 } 29 } 30 31 var ( 32 factory libcontainer.Factory 33 systemdFactory libcontainer.Factory 34 ) 35 36 func TestMain(m *testing.M) { 37 var ( 38 err error 39 ret int 40 ) 41 42 logrus.SetOutput(os.Stderr) 43 logrus.SetLevel(logrus.InfoLevel) 44 45 factory, err = libcontainer.New("/run/libctTests", libcontainer.Cgroupfs) 46 if err != nil { 47 logrus.Error(err) 48 os.Exit(1) 49 } 50 if systemd.UseSystemd() { 51 systemdFactory, err = libcontainer.New("/run/libctTests", libcontainer.SystemdCgroups) 52 if err != nil { 53 logrus.Error(err) 54 os.Exit(1) 55 } 56 } 57 58 ret = m.Run() 59 os.Exit(ret) 60 }