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

Function TestExecProcList

runsc/container/container_test.go:955–1006  ·  view source on GitHub ↗

TestExecProcList verifies that a container can exec a new program and it shows correctly in the process list.

(t *testing.T)

Source from the content-addressed store, hash-verified

953// TestExecProcList verifies that a container can exec a new program and it
954// shows correctly in the process list.
955func TestExecProcList(t *testing.T) {
956 for name, conf := range configs(t, false /* noOverlay */) {
957 t.Run(name, func(t *testing.T) {
958 const uid = 343
959 spec, _ := sleepSpecConf(t)
960
961 _, bundleDir, cleanup, err := testutil.SetupContainer(spec, conf)
962 if err != nil {
963 t.Fatalf("error setting up container: %v", err)
964 }
965 defer cleanup()
966
967 // Create and start the container.
968 args := Args{
969 ID: testutil.RandomContainerID(),
970 Spec: spec,
971 BundleDir: bundleDir,
972 }
973 cont, err := New(conf, args)
974 if err != nil {
975 t.Fatalf("error creating container: %v", err)
976 }
977 defer cont.Destroy()
978 if err := cont.Start(conf); err != nil {
979 t.Fatalf("error starting container: %v", err)
980 }
981
982 execArgs := &control.ExecArgs{
983 Filename: "/bin/sleep",
984 Argv: []string{"/bin/sleep", "5"},
985 WorkingDirectory: "/",
986 KUID: uid,
987 }
988
989 // Verify that "sleep 1000" and "sleep 5" are running after exec. First,
990 // start running exec asynchronously.
991 pid2, err := cont.Execute(conf, execArgs)
992 if err != nil {
993 t.Fatalf("error executing 'sleep 5' command: %v", err)
994 }
995
996 // expectedPL lists the expected process state of the container.
997 expectedPL := []*control.Process{
998 newProcessBuilder().PID(1).PPID(0).Cmd("sleep").UID(0).Process(),
999 newProcessBuilder().PID(kernel.ThreadID(pid2)).PPID(0).Cmd("sleep").UID(uid).Process(),
1000 }
1001 if err := waitForProcessList(cont, expectedPL); err != nil {
1002 t.Fatalf("error waiting for processes: %v", err)
1003 }
1004 })
1005 }
1006}
1007
1008// TestKillPid verifies that we can signal individual exec'd processes.
1009func TestKillPid(t *testing.T) {

Callers

nothing calls this directly

Calls 15

SetupContainerFunction · 0.92
RandomContainerIDFunction · 0.92
ThreadIDTypeAlias · 0.92
configsFunction · 0.85
sleepSpecConfFunction · 0.85
newProcessBuilderFunction · 0.85
waitForProcessListFunction · 0.85
CmdMethod · 0.80
PPIDMethod · 0.80
NewFunction · 0.70
RunMethod · 0.65
FatalfMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…