server_env_coverage.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // +build coverage
  2. package scenarios
  3. import (
  4. "os"
  5. "os/exec"
  6. "path/filepath"
  7. "bytes"
  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", "json coverage coveragemain", "-coverpkg", "v2ray.com/core/...", "-c", "-o", testBinaryPath, GetSourcePath())
  16. return cmd.Run()
  17. }
  18. func RunV2Ray(configFile string) *exec.Cmd {
  19. GenTestBinaryPath()
  20. covDir := filepath.Join(os.Getenv("GOPATH"), "out", "v2ray", "cov")
  21. os.MkdirAll(covDir, os.ModeDir)
  22. profile := uuid.New().String() + ".out"
  23. proc := exec.Command(testBinaryPath, "-config", configFile, "-test.run", "TestRunMainForCoverage", "-test.coverprofile", profile, "-test.outputdir", covDir)
  24. proc.Stderr = os.Stderr
  25. proc.Stdout = os.Stdout
  26. return proc
  27. }
  28. func RunV2RayProtobuf(config []byte) *exec.Cmd {
  29. GenTestBinaryPath()
  30. covDir := filepath.Join(os.Getenv("GOPATH"), "out", "v2ray", "cov")
  31. os.MkdirAll(covDir, os.ModeDir)
  32. profile := uuid.New().String() + ".out"
  33. proc := exec.Command(testBinaryPath, "-config=stdin:", "-format=pb", "-test.run", "TestRunMainForCoverage", "-test.coverprofile", profile, "-test.outputdir", covDir)
  34. proc.Stdin = bytes.NewBuffer(config)
  35. proc.Stderr = os.Stderr
  36. proc.Stdout = os.Stdout
  37. return proc
  38. }