MCPcopy Index your code
hub / github.com/containerd/containerd / doFuzz

Function doFuzz

integration/client/container_fuzz_test.go:349–407  ·  view source on GitHub ↗

doFuzz() implements the logic of FuzzIntegCreateContainerNoTearDown() and FuzzIntegCreateContainerWithTearDown() and allows for the option to turn on/off teardown after each iteration. From a high level it: - Creates a client - Imports a bunch of fuzzed tar archives - Creates a bunch of containers

(t *testing.T, data []byte, shouldTearDown bool)

Source from the content-addressed store, hash-verified

347// - Imports a bunch of fuzzed tar archives
348// - Creates a bunch of containers
349func doFuzz(t *testing.T, data []byte, shouldTearDown bool) {
350 ctx, cancel := testContext(nil)
351 defer cancel()
352
353 // Check if daemon is running and start it if it isn't
354 if ctrd.cmd == nil {
355 startDaemon(ctx, t, shouldTearDown)
356 }
357 client, err := containerd.New(defaultAddress)
358 if err != nil {
359 // The error here is most likely with the socket.
360 // Deleting it will allow the creation of a new
361 // socket during next fuzz iteration.
362 deleteSocket()
363 return
364 }
365 defer client.Close()
366
367 f := fuzz.NewConsumer(data)
368
369 // Begin import tars:
370 noOfImports, err := f.GetInt()
371 if err != nil {
372 return
373 }
374 // maxImports is currently completely arbitrarily defined
375 maxImports := 30
376 for i := 0; i < noOfImports%maxImports; i++ {
377 // f.TarBytes() returns valid tar bytes.
378 tarBytes, err := f.TarBytes()
379 if err != nil {
380 return
381 }
382 _, _ = client.Import(ctx, bytes.NewReader(tarBytes))
383 }
384 // End import tars
385
386 // Begin create containers:
387 existingImages, err := client.ListImages(ctx)
388 if err != nil {
389 return
390 }
391 if len(existingImages) > 0 {
392 noOfContainers, err := f.GetInt()
393 if err != nil {
394 return
395 }
396 // maxNoOfContainers is currently
397 // completely arbitrarily defined
398 maxNoOfContainers := 50
399 for i := 0; i < noOfContainers%maxNoOfContainers; i++ {
400 container, err := newContainer(ctx, client, f)
401 if err == nil {
402 defer container.Delete(ctx, containerd.WithSnapshotCleanup)
403 }
404 }
405 }
406 // End create containers

Calls 8

testContextFunction · 0.85
deleteSocketFunction · 0.85
startDaemonFunction · 0.70
newContainerFunction · 0.70
CloseMethod · 0.65
ImportMethod · 0.65
ListImagesMethod · 0.65
DeleteMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…