(m *testing.M)
| 61 | } |
| 62 | |
| 63 | func TestMain(m *testing.M) { |
| 64 | flag.Parse() |
| 65 | if testing.Short() { |
| 66 | os.Exit(m.Run()) |
| 67 | } |
| 68 | testutil.RequiresRootM() |
| 69 | // check if criu is installed on the system |
| 70 | _, err := exec.LookPath("criu") |
| 71 | supportsCriu = err == nil && !noCriu |
| 72 | |
| 73 | var ( |
| 74 | buf = bytes.NewBuffer(nil) |
| 75 | ctx, cancel = testContext(nil) |
| 76 | ) |
| 77 | defer cancel() |
| 78 | |
| 79 | if !noDaemon { |
| 80 | _ = forceRemoveAll(defaultRoot) |
| 81 | |
| 82 | stdioFile, err := os.CreateTemp("", "") |
| 83 | if err != nil { |
| 84 | fmt.Fprintf(os.Stderr, "could not create a new stdio temp file: %s\n", err) |
| 85 | os.Exit(1) |
| 86 | } |
| 87 | defer func() { |
| 88 | stdioFile.Close() |
| 89 | os.Remove(stdioFile.Name()) |
| 90 | }() |
| 91 | ctrdStdioFilePath = stdioFile.Name() |
| 92 | stdioWriter := io.MultiWriter(stdioFile, buf) |
| 93 | |
| 94 | err = ctrd.start("containerd", address, []string{ |
| 95 | "--root", defaultRoot, |
| 96 | "--state", defaultState, |
| 97 | "--log-level", "debug", |
| 98 | "--config", createShimDebugConfig(), |
| 99 | }, stdioWriter, stdioWriter) |
| 100 | if err != nil { |
| 101 | fmt.Fprintf(os.Stderr, "%s: %s\n", err, buf.String()) |
| 102 | os.Exit(1) |
| 103 | } |
| 104 | } else { |
| 105 | // Otherwise if no-daemon was specified we need to connect to an already running ctrd instance. |
| 106 | // Set the addr field on the daemon object so it knows what to try connecting to. |
| 107 | ctrd.addr = address |
| 108 | } |
| 109 | |
| 110 | waitCtx, waitCancel := context.WithTimeout(ctx, 4*time.Second) |
| 111 | client, err := ctrd.waitForStart(waitCtx) |
| 112 | waitCancel() |
| 113 | if err != nil { |
| 114 | ctrd.Kill() |
| 115 | ctrd.Wait() |
| 116 | fmt.Fprintf(os.Stderr, "%s: %s\n", err, buf.String()) |
| 117 | os.Exit(1) |
| 118 | } |
| 119 | |
| 120 | // print out the version in information |
nothing calls this directly
no test coverage detected
searching dependent graphs…