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

Function TestSignalProcessGroup

runsc/container/container_test.go:1083–1165  ·  view source on GitHub ↗

TestSignalProcessGroup verifies that SignalProcessGroup kills all processes in the targeted process group while leaving other groups running.

(t *testing.T)

Source from the content-addressed store, hash-verified

1081// processes in the targeted process group while leaving other groups
1082// running.
1083func TestSignalProcessGroup(t *testing.T) {
1084 for name, conf := range configs(t, false /* noOverlay */) {
1085 t.Run(name, func(t *testing.T) {
1086 app, err := testutil.FindFile("test/cmd/test_app/test_app")
1087 if err != nil {
1088 t.Fatal("error finding test_app:", err)
1089 }
1090
1091 spec := testutil.NewSpecWithArgs(app, "task-tree-pgid")
1092 _, bundleDir, cleanup, err := testutil.SetupContainer(spec, conf)
1093 if err != nil {
1094 t.Fatalf("error setting up container: %v", err)
1095 }
1096 defer cleanup()
1097
1098 args := Args{
1099 ID: testutil.RandomContainerID(),
1100 Spec: spec,
1101 BundleDir: bundleDir,
1102 }
1103 cont, err := New(conf, args)
1104 if err != nil {
1105 t.Fatalf("error creating container: %v", err)
1106 }
1107 defer cont.Destroy()
1108 if err := cont.Start(conf); err != nil {
1109 t.Fatalf("error starting container: %v", err)
1110 }
1111
1112 // Wait for all 3 processes: init, child, grandchild.
1113 if err := waitForProcessCount(cont, 3); err != nil {
1114 t.Fatalf("timed out waiting for processes: %v", err)
1115 }
1116
1117 // Collect PGIDs.
1118 procs, err := cont.Processes()
1119 if err != nil {
1120 t.Fatalf("failed to get process list: %v", err)
1121 }
1122 t.Logf("before signal: %s", procListToString(procs))
1123
1124 // Init (PID 1) is in PGID 1.
1125 // Child + grandchild should share a PGID != 1.
1126 pgidA := int32(1)
1127 pgidBCount := make(map[int32]int)
1128 for _, p := range procs {
1129 if int32(p.PGID) != pgidA {
1130 pgidBCount[int32(p.PGID)]++
1131 }
1132 }
1133
1134 // Find the PGID shared by child+grandchild.
1135 var pgidB int32
1136 for pgid, n := range pgidBCount {
1137 if n == 2 {
1138 pgidB = pgid
1139 }
1140 }

Callers

nothing calls this directly

Calls 15

FindFileFunction · 0.92
NewSpecWithArgsFunction · 0.92
SetupContainerFunction · 0.92
RandomContainerIDFunction · 0.92
configsFunction · 0.85
waitForProcessCountFunction · 0.85
procListToStringFunction · 0.85
NewFunction · 0.70
RunMethod · 0.65
FatalfMethod · 0.65
DestroyMethod · 0.65
StartMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…