Пример #1
0
func (cs *ContainerdSuite) SetUpSuite(c *check.C) {
	bundleMap = make(map[string]Bundle)
	cs.eventFilters = make(map[string]func(event *types.Event))

	// Get working directory for tests
	wd := utils.GetTestOutDir()
	if err := os.Chdir(wd); err != nil {
		c.Fatalf("Could not change working directory: %v", err)
	}
	cs.cwd = wd

	// Clean old bundles
	os.RemoveAll(utils.BundlesRoot)

	// Ensure the oci bundles directory exists
	if err := os.MkdirAll(utils.BundlesRoot, 0755); err != nil {
		c.Fatalf("Failed to create bundles directory: %v", err)
	}

	// Generate the reference spec
	if err := utils.GenerateReferenceSpecs(utils.BundlesRoot); err != nil {
		c.Fatalf("Unable to generate OCI reference spec: %v", err)
	}

	// Create our output directory
	cs.outputDir = fmt.Sprintf(utils.OutputDirFormat, time.Now().Format("2006-01-02_150405.000000"))

	cs.stateDir = filepath.Join(cs.outputDir, "containerd-master")
	if err := os.MkdirAll(cs.stateDir, 0755); err != nil {
		c.Fatalf("Unable to created output directory '%s': %v", cs.stateDir, err)
	}

	cs.grpcSocket = "unix://" + filepath.Join(cs.outputDir, "containerd-master", "containerd.sock")
	cdLogFile := filepath.Join(cs.outputDir, "containerd-master", "containerd.log")

	f, err := os.OpenFile(cdLogFile, os.O_CREATE|os.O_TRUNC|os.O_RDWR|os.O_SYNC, 0777)
	if err != nil {
		c.Fatalf("Failed to create master containerd log file: %v", err)
	}
	cs.logFile = f

	cs.syncChild = make(chan error)
	cs.RestartDaemon(false)
}
func BenchmarkBusyboxSh(b *testing.B) {
	bundleName := "busybox-sh"

	wd := utils.GetTestOutDir()
	if err := os.Chdir(wd); err != nil {
		b.Fatalf("Could not change working directory: %v", err)
	}

	if err := setup(); err != nil {
		b.Fatalf("Error setting up test: %v", err)
	}
	defer teardown()

	for n := 0; n < b.N; n++ {
		bundlePath, err := setupBundle(bundleName)
		if err != nil {
			return
		}

		s, err := setupStdio(wd, bundlePath, bundleName)
		if err != nil {
			return
		}

		c, err := New(ContainerOpts{
			Root:    utils.StateDir,
			ID:      bundleName,
			Bundle:  filepath.Join(wd, bundlePath),
			Runtime: *runtimeTool,
			Shim:    "containerd-shim",
			Timeout: 15 * time.Second,
		})

		if err != nil {
			b.Fatalf("Error creating a New container: ", err)
		}

		benchmarkStartContainer(b, c, s, bundleName)

		teardownBundle(bundleName)
	}
}