MCPcopy
hub / github.com/google/gvisor / TestMultiContainerProcesses

Function TestMultiContainerProcesses

runsc/container/multi_container_test.go:1092–1147  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1090}
1091
1092func TestMultiContainerProcesses(t *testing.T) {
1093 rootDir, cleanup, err := testutil.SetupRootDir()
1094 if err != nil {
1095 t.Fatalf("error creating root dir: %v", err)
1096 }
1097 defer cleanup()
1098
1099 conf := testutil.TestConfig(t)
1100 conf.RootDir = rootDir
1101
1102 // Note: use curly braces to keep 'sh' process around. Otherwise, shell
1103 // will just execve into 'sleep' and both containers will look the
1104 // same.
1105 specs, ids := createSpecs(
1106 sleepCmd,
1107 []string{"sh", "-c", "{ sleep 1000; }"})
1108 containers, cleanup, err := startContainers(conf, specs, ids)
1109 if err != nil {
1110 t.Fatalf("error starting containers: %v", err)
1111 }
1112 defer cleanup()
1113
1114 // Check root's container process list doesn't include other containers.
1115 expectedPL0 := []*control.Process{
1116 newProcessBuilder().PID(1).Cmd("sleep").Process(),
1117 }
1118 if err := waitForProcessList(containers[0], expectedPL0); err != nil {
1119 t.Errorf("failed to wait for process to start: %v", err)
1120 }
1121
1122 // Same for the other container.
1123 expectedPL1 := []*control.Process{
1124 newProcessBuilder().PID(2).Cmd("sh").Process(),
1125 newProcessBuilder().PID(3).PPID(2).Cmd("sleep").Process(),
1126 }
1127 if err := waitForProcessList(containers[1], expectedPL1); err != nil {
1128 t.Errorf("failed to wait for process to start: %v", err)
1129 }
1130
1131 // Now exec into the second container and verify it shows up in the container.
1132 args := &control.ExecArgs{
1133 Filename: sleepCmd[0],
1134 Argv: sleepCmd,
1135 }
1136 if _, err := containers[1].Execute(conf, args); err != nil {
1137 t.Fatalf("error exec'ing: %v", err)
1138 }
1139 expectedPL1 = append(expectedPL1, newProcessBuilder().PID(4).Cmd("sleep").Process())
1140 if err := waitForProcessList(containers[1], expectedPL1); err != nil {
1141 t.Errorf("failed to wait for process to start: %v", err)
1142 }
1143 // Root container should remain unchanged.
1144 if err := waitForProcessList(containers[0], expectedPL0); err != nil {
1145 t.Errorf("failed to wait for process to start: %v", err)
1146 }
1147}
1148
1149// TestMultiContainerKillAll checks that all process that belong to a container

Callers

nothing calls this directly

Calls 13

SetupRootDirFunction · 0.92
TestConfigFunction · 0.92
newProcessBuilderFunction · 0.85
waitForProcessListFunction · 0.85
CmdMethod · 0.80
PPIDMethod · 0.80
createSpecsFunction · 0.70
startContainersFunction · 0.70
FatalfMethod · 0.65
ErrorfMethod · 0.65
ProcessMethod · 0.45
PIDMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…