common_coverage.go 918 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // +build coverage
  2. package scenarios
  3. import (
  4. "bytes"
  5. "os"
  6. "os/exec"
  7. "path/filepath"
  8. "v2ray.com/core/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", "v2ray.com/core/...", "-c", "-o", testBinaryPath, GetSourcePath())
  16. return cmd.Run()
  17. }
  18. func RunV2RayProtobuf(config []byte) *exec.Cmd {
  19. genTestBinaryPath()
  20. covDir := filepath.Join(os.Getenv("GOPATH"), "out", "v2ray", "cov")
  21. os.MkdirAll(covDir, os.ModeDir)
  22. randomID := uuid.New()
  23. profile := randomID.String() + ".out"
  24. proc := exec.Command(testBinaryPath, "-config=stdin:", "-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. }