Skip to content

Commit

Permalink
update TestForkExec with invalid testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
leongross committed Oct 27, 2024
1 parent 1b8ecc2 commit 64060ec
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/os/exec_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ func (p *Process) release() error {
// * No parent-child communication via pipes (TODO)
// * No waiting for crashes child processes to prohibit zombie process accumulation / Wait status checking (TODO)
func forkExec(argv0 string, argv []string, attr *ProcAttr) (pid int, err error) {
if argv == nil {
return 0, errors.New("exec: no argv")
}

if len(argv) == 0 {
return 0, errors.New("exec: no argv")
}
Expand Down
13 changes: 10 additions & 3 deletions src/os/exec_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,22 @@ func TestForkExec(t *testing.T) {
return
}

proc, err := StartProcess("/bin/echo", []string{"hello", "world"}, &ProcAttr{})
proc, err := StartProcess("echo", []string{"/bin/echo", "hello", "world"}, &ProcAttr{})
if !errors.Is(err, nil) {
t.Fatalf("forkExec failed: %v", err)
return
}

if proc.Pid == 0 {
t.Fatalf("forkExec failed: new process has pid 0")
}

t.Logf("forkExec succeeded: new process has pid %d", proc)

proc, err = StartProcess("invalid", []string{"/bin/nonexistent"}, &ProcAttr{})
if errors.Is(err, nil) {
t.Fatalf("wanted err, got nil")
}

if proc.Pid != 0 {
t.Fatalf("wanted 0, got %v", proc.Pid)
}
}

0 comments on commit 64060ec

Please sign in to comment.