TestExecProcList verifies that a container can exec a new program and it shows correctly in the process list.
(t *testing.T)
| 953 | // TestExecProcList verifies that a container can exec a new program and it |
| 954 | // shows correctly in the process list. |
| 955 | func 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. |
| 1009 | func TestKillPid(t *testing.T) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…