common_coverage.go 898 B

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