common_coverage.go 907 B

12345678910111213141516171819202122232425262728293031323334353637
  1. //go:build coverage
  2. // +build coverage
  3. package scenarios
  4. import (
  5. "bytes"
  6. "os"
  7. "os/exec"
  8. "github.com/v2fly/v2ray-core/v5/common/uuid"
  9. )
  10. func BuildV2Ray() error {
  11. genTestBinaryPath()
  12. if _, err := os.Stat(testBinaryPath); err == nil {
  13. return nil
  14. }
  15. cmd := exec.Command("go", "test", "-tags", "coverage coveragemain", "-coverpkg", "github.com/v2fly/v2ray-core/v5/...", "-c", "-o", testBinaryPath, GetSourcePath())
  16. return cmd.Run()
  17. }
  18. func RunV2RayProtobuf(config []byte) *exec.Cmd {
  19. genTestBinaryPath()
  20. covDir := os.Getenv("V2RAY_COV")
  21. os.MkdirAll(covDir, os.ModeDir)
  22. randomID := uuid.New()
  23. profile := randomID.String() + ".out"
  24. proc := exec.Command(testBinaryPath, "run", "-format=pb", "-test.run", "TestRunMainForCoverage", "-test.coverprofile", profile, "-test.outputdir", covDir)
  25. proc.Stdin = bytes.NewBuffer(config)
  26. proc.Stderr = os.Stderr
  27. proc.Stdout = os.Stdout
  28. return proc
  29. }