common_coverage.go 905 B

12345678910111213141516171819202122232425262728293031323334353637
  1. //go:build coverage
  2. // +build coverage
  3. package scenarios
  4. import (
  5. "bytes"
  6. "os"
  7. "os/exec"
  8. "github.com/xtls/xray-core/common/uuid"
  9. )
  10. func BuildXray() 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/xtls/xray-core/...", "-c", "-o", testBinaryPath, GetSourcePath())
  16. return cmd.Run()
  17. }
  18. func RunXrayProtobuf(config []byte) *exec.Cmd {
  19. genTestBinaryPath()
  20. covDir := os.Getenv("XRAY_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. }