v2fly/testing/scenarios/common_coverage.go

38 lines
907 B
Go
Raw Normal View History

//go:build coverage
2016-08-08 22:55:36 +00:00
// +build coverage
package scenarios
import (
2017-03-31 15:12:33 +00:00
"bytes"
2016-08-08 22:55:36 +00:00
"os"
"os/exec"
2016-08-09 20:13:16 +00:00
2021-02-16 20:31:50 +00:00
"github.com/v2fly/v2ray-core/v4/common/uuid"
2016-08-08 22:55:36 +00:00
)
func BuildV2Ray() error {
2017-03-31 15:12:33 +00:00
genTestBinaryPath()
2016-11-17 23:01:37 +00:00
if _, err := os.Stat(testBinaryPath); err == nil {
2016-08-08 22:55:36 +00:00
return nil
}
2021-02-16 20:31:50 +00:00
cmd := exec.Command("go", "test", "-tags", "coverage coveragemain", "-coverpkg", "github.com/v2fly/v2ray-core/v4/...", "-c", "-o", testBinaryPath, GetSourcePath())
2016-08-08 22:55:36 +00:00
return cmd.Run()
}
2016-12-16 20:39:00 +00:00
func RunV2RayProtobuf(config []byte) *exec.Cmd {
2017-03-31 15:12:33 +00:00
genTestBinaryPath()
2016-12-16 20:39:00 +00:00
2019-02-13 10:06:39 +00:00
covDir := os.Getenv("V2RAY_COV")
2016-12-16 20:39:00 +00:00
os.MkdirAll(covDir, os.ModeDir)
2018-02-16 14:29:22 +00:00
randomID := uuid.New()
profile := randomID.String() + ".out"
proc := exec.Command(testBinaryPath, "run", "-format=pb", "-test.run", "TestRunMainForCoverage", "-test.coverprofile", profile, "-test.outputdir", covDir)
2016-12-16 20:39:00 +00:00
proc.Stdin = bytes.NewBuffer(config)
proc.Stderr = os.Stderr
proc.Stdout = os.Stdout
return proc
}