mirror of
https://github.com/tuna/tunasync.git
synced 2025-04-20 20:14:12 +00:00
cgroupv2: add test for reexec
This commit is contained in:
parent
84fcc8e76b
commit
f8b6ea9c4e
17
.github/workflows/tunasync.yml
vendored
17
.github/workflows/tunasync.yml
vendored
@ -71,6 +71,20 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
make build-test-worker
|
make build-test-worker
|
||||||
sudo cgexec -g "*:/" bash -c "echo 0 > /sys/fs/cgroup/systemd/tasks; exec sudo -u $USER env USECURCGROUP=1 TERM=xterm-256color cgexec -g cpu,memory:tunasync ./worker.test -test.v=true -test.coverprofile profile2.cov -test.run TestCgroup"
|
sudo cgexec -g "*:/" bash -c "echo 0 > /sys/fs/cgroup/systemd/tasks; exec sudo -u $USER env USECURCGROUP=1 TERM=xterm-256color cgexec -g cpu,memory:tunasync ./worker.test -test.v=true -test.coverprofile profile2.cov -test.run TestCgroup"
|
||||||
|
touch /tmp/dummy_exec
|
||||||
|
chmod +x /tmp/dummy_exec
|
||||||
|
run_test_reexec (){
|
||||||
|
case="$1"
|
||||||
|
shift
|
||||||
|
argv0="$1"
|
||||||
|
shift
|
||||||
|
(TESTREEXEC="$case" TERM=xterm-256color exec -a "$argv0" ./worker.test -test.v=true -test.coverprofile "profile5_$case.cov" -test.run TestReexec -- "$@")
|
||||||
|
}
|
||||||
|
run_test_reexec 1 tunasync-exec __dummy__
|
||||||
|
run_test_reexec 2 tunasync-exec /tmp/dummy_exec
|
||||||
|
run_test_reexec 3 tunasync-exec /tmp/dummy_exec 3< <(echo -n "abrt")
|
||||||
|
run_test_reexec 4 tunasync-exec /tmp/dummy_exec 3< <(echo -n "cont")
|
||||||
|
run_test_reexec 5 tunasync-exec2
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v1
|
uses: docker/setup-buildx-action@v1
|
||||||
@ -209,7 +223,8 @@ jobs:
|
|||||||
CUSER="$(id --user --name)"
|
CUSER="$(id --user --name)"
|
||||||
"${HOME}/go/bin/gocovmerge" profile.cov profile2.cov \
|
"${HOME}/go/bin/gocovmerge" profile.cov profile2.cov \
|
||||||
"umlrootfs/home/${CUSER}/profile3.cov" \
|
"umlrootfs/home/${CUSER}/profile3.cov" \
|
||||||
"umlrootfs/home/${CUSER}/profile4.cov" > profile-all.cov
|
"umlrootfs/home/${CUSER}/profile4.cov" \
|
||||||
|
profile5_*.cov > profile-all.cov
|
||||||
|
|
||||||
- name: Convert coverage to lcov
|
- name: Convert coverage to lcov
|
||||||
uses: jandelgado/gcov2lcov-action@v1.0.0
|
uses: jandelgado/gcov2lcov-action@v1.0.0
|
||||||
|
1
go.mod
1
go.mod
@ -26,6 +26,7 @@ require (
|
|||||||
github.com/pkg/profile v1.4.0
|
github.com/pkg/profile v1.4.0
|
||||||
github.com/ryszard/goskiplist v0.0.0-20150312221310-2dfbae5fcf46
|
github.com/ryszard/goskiplist v0.0.0-20150312221310-2dfbae5fcf46
|
||||||
github.com/sirupsen/logrus v1.8.1 // indirect
|
github.com/sirupsen/logrus v1.8.1 // indirect
|
||||||
|
github.com/smartystreets/assertions v1.2.0 // indirect
|
||||||
github.com/smartystreets/goconvey v1.6.4
|
github.com/smartystreets/goconvey v1.6.4
|
||||||
github.com/syndtr/goleveldb v1.0.0
|
github.com/syndtr/goleveldb v1.0.0
|
||||||
github.com/urfave/cli v1.22.3
|
github.com/urfave/cli v1.22.3
|
||||||
|
2
go.sum
2
go.sum
@ -173,6 +173,8 @@ github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE
|
|||||||
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
||||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
|
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
|
||||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
||||||
|
github.com/smartystreets/assertions v1.2.0 h1:42S6lae5dvLc7BrLu/0ugRtcFVjoJNMC/N3yZFZkDFs=
|
||||||
|
github.com/smartystreets/assertions v1.2.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo=
|
||||||
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
|
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
|
||||||
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
|
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
|
||||||
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
|
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
|
||||||
|
@ -3,6 +3,7 @@ package worker
|
|||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -19,7 +20,65 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
_, testReexec := os.LookupEnv("TESTREEXEC")
|
||||||
|
if ! testReexec {
|
||||||
reexec.Init()
|
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) {
|
func TestCgroup(t *testing.T) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user