镜像自地址
https://github.com/tuna/tunasync.git
已同步 2025-12-06 14:36:47 +00:00
cgroupv2: add test for reexec
这个提交包含在:
@@ -3,6 +3,7 @@ package worker
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -19,7 +20,65 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
reexec.Init()
|
||||
_, testReexec := os.LookupEnv("TESTREEXEC")
|
||||
if ! testReexec {
|
||||
reexec.Init()
|
||||
}
|
||||
}
|
||||
|
||||
func TestReexec(t *testing.T) {
|
||||
testCase, testReexec := os.LookupEnv("TESTREEXEC")
|
||||
if ! testReexec {
|
||||
return
|
||||
}
|
||||
for len(os.Args) > 1 {
|
||||
thisArg := os.Args[1]
|
||||
os.Args = append([]string{os.Args[0]}, os.Args[2:]...)
|
||||
if thisArg == "--" {
|
||||
break
|
||||
}
|
||||
}
|
||||
switch testCase {
|
||||
case "1":
|
||||
Convey("Reexec should panic when command not found", t, func(ctx C){
|
||||
So(func(){
|
||||
reexec.Init()
|
||||
}, ShouldPanicWith, exec.ErrNotFound)
|
||||
})
|
||||
case "2":
|
||||
Convey("Reexec should run when fd 3 is not open", t, func(ctx C){
|
||||
So((func() error{
|
||||
pipe := os.NewFile(3, "pipe")
|
||||
if pipe == nil {
|
||||
return errors.New("pipe is nil")
|
||||
} else {
|
||||
_, err := pipe.Stat()
|
||||
return err
|
||||
}
|
||||
})(), ShouldNotBeNil)
|
||||
So(func(){
|
||||
reexec.Init()
|
||||
}, ShouldPanicWith, syscall.ENOEXEC)
|
||||
})
|
||||
case "3":
|
||||
Convey("Reexec should fail when fd 3 is sent with abrt cmd", t, func(ctx C){
|
||||
So(func(){
|
||||
reexec.Init()
|
||||
}, ShouldPanicWith, "Exited on request")
|
||||
})
|
||||
case "4":
|
||||
Convey("Reexec should run when fd 3 is sent with cont cmd", t, func(ctx C){
|
||||
So(func(){
|
||||
reexec.Init()
|
||||
}, ShouldPanicWith, syscall.ENOEXEC)
|
||||
})
|
||||
case "5":
|
||||
Convey("Reexec should not be triggered when argv[0] is not reexec", t, func(ctx C){
|
||||
So(func(){
|
||||
reexec.Init()
|
||||
}, ShouldNotPanic)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestCgroup(t *testing.T) {
|
||||
|
||||
在新工单中引用
屏蔽一个用户