Skip to content

Commit 8ea2d6c

Browse files
committed
update TestForkExec with invalid testcase
1 parent 34e370f commit 8ea2d6c

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/os/exec_linux.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ func (p *Process) release() error {
4545
// * No parent-child communication via pipes (TODO)
4646
// * No waiting for crashes child processes to prohibit zombie process accumulation / Wait status checking (TODO)
4747
func forkExec(argv0 string, argv []string, attr *ProcAttr) (pid int, err error) {
48+
if argv == nil {
49+
return 0, errors.New("exec: no argv")
50+
}
51+
4852
if len(argv) == 0 {
4953
return 0, errors.New("exec: no argv")
5054
}

src/os/exec_linux_test.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,22 @@ func TestForkExec(t *testing.T) {
1818
return
1919
}
2020

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

2726
if proc.Pid == 0 {
2827
t.Fatalf("forkExec failed: new process has pid 0")
2928
}
30-
3129
t.Logf("forkExec succeeded: new process has pid %d", proc)
30+
31+
proc, err = StartProcess("invalid", []string{"/bin/nonexistent"}, &ProcAttr{})
32+
if errors.Is(err, nil) {
33+
t.Fatalf("wanted err, got nil")
34+
}
35+
36+
if proc.Pid != 0 {
37+
t.Fatalf("wanted 0, got %v", proc.Pid)
38+
}
3239
}

0 commit comments

Comments
 (0)