mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-30 05:56:54 -05:00
update coverage
This commit is contained in:
parent
5dc80a2cc5
commit
25b30704a4
@ -1,19 +1,22 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
FAIL=0
|
FAIL=0
|
||||||
COVERAGE_FILE=coverage.txt
|
|
||||||
|
V2RAY_OUT=${GOPATH}/out/v2ray
|
||||||
|
V2RAY_COV=${V2RAY_OUT}/cov
|
||||||
|
COVERAGE_FILE=${V2RAY_COV}/coverage.txt
|
||||||
|
|
||||||
function test_package {
|
function test_package {
|
||||||
DIR="github.com/v2ray/v2ray-core/$1"
|
DIR="github.com/v2ray/v2ray-core/$1"
|
||||||
DEP=$(go list -f '{{ join .Deps "\n" }}' $DIR | grep v2ray | tr '\n' ',')
|
DEP=$(go list -f '{{ join .Deps "\n" }}' $DIR | grep v2ray | tr '\n' ',')
|
||||||
DEP=${DEP}$DIR
|
DEP=${DEP}$DIR
|
||||||
go test -tags "json coverage" -coverprofile=coversingle.out -coverpkg=$DEP $DIR || FAIL=1
|
RND_NAME=$(openssl rand -hex 16)
|
||||||
if [ -f coversingle.out ]; then
|
COV_PROFILE=${V2RAY_COV}/${RND_NAME}.out
|
||||||
cat coversingle.out | grep -v "mode: set" >> ${COVERAGE_FILE}
|
go test -tags "json coverage" -coverprofile=${COV_PROFILE} -coverpkg=$DEP $DIR || FAIL=1
|
||||||
rm coversingle.out
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rm -rf ${V2RAY_OUT}
|
||||||
|
mkdir -p ${V2RAY_COV}
|
||||||
touch ${COVERAGE_FILE}
|
touch ${COVERAGE_FILE}
|
||||||
|
|
||||||
TEST_FILES=(./*_test.go)
|
TEST_FILES=(./*_test.go)
|
||||||
@ -28,14 +31,17 @@ for DIR in $(find * -type d -not -path "*.git*"); do
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
cat ${COVERAGE_FILE} | sort -t: -k1 | grep -vw "testing" > coverallsorted.out
|
for OUT_FILE in $(find ${V2RAY_COV} -name "*.out"); do
|
||||||
echo "mode: set" | cat - coverallsorted.out > ${COVERAGE_FILE}
|
echo "Merging file ${OUT_FILE}"
|
||||||
rm coverallsorted.out
|
cat ${OUT_FILE} | grep -v "mode: set" >> ${COVERAGE_FILE}
|
||||||
|
done
|
||||||
|
|
||||||
|
COV_SORTED=${V2RAY_COV}/coverallsorted.out
|
||||||
|
cat ${COVERAGE_FILE} | sort -t: -k1 | grep -vw "testing" > ${COV_SORTED}
|
||||||
|
echo "mode: set" | cat - ${COV_SORTED} > ${COVERAGE_FILE}
|
||||||
|
|
||||||
if [ "$FAIL" -eq 0 ]; then
|
if [ "$FAIL" -eq 0 ]; then
|
||||||
bash <(curl -s https://codecov.io/bash) -f ${COVERAGE_FILE} || echo "Codecov did not collect coverage reports."
|
bash <(curl -s https://codecov.io/bash) -f ${COVERAGE_FILE} || echo "Codecov did not collect coverage reports."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rm -f ${COVERAGE_FILE}
|
|
||||||
|
|
||||||
exit $FAIL
|
exit $FAIL
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package scenarios
|
package scenarios
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -24,26 +23,20 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
runningServers = make([]*exec.Cmd, 0, 10)
|
runningServers = make([]*exec.Cmd, 0, 10)
|
||||||
|
|
||||||
binaryPath string
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func GetTestBinaryPath() string {
|
||||||
|
file := filepath.Join(os.Getenv("GOPATH"), "out", "v2ray", "v2ray.test")
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
file += ".exe"
|
||||||
|
}
|
||||||
|
return file
|
||||||
|
}
|
||||||
|
|
||||||
func GetSourcePath() string {
|
func GetSourcePath() string {
|
||||||
return filepath.Join("github.com", "v2ray", "v2ray-core", "shell", "point", "main")
|
return filepath.Join("github.com", "v2ray", "v2ray-core", "shell", "point", "main")
|
||||||
}
|
}
|
||||||
|
|
||||||
func FillBinaryPath() error {
|
|
||||||
dir, err := ioutil.TempDir("", "v2ray")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
binaryPath = filepath.Join(dir, "v2ray")
|
|
||||||
if runtime.GOOS == "windows" {
|
|
||||||
binaryPath += ".exe"
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestFile(filename string) string {
|
func TestFile(filename string) string {
|
||||||
return filepath.Join(os.Getenv("GOPATH"), "src", "github.com", "v2ray", "v2ray-core", "testing", "scenarios", "data", filename)
|
return filepath.Join(os.Getenv("GOPATH"), "src", "github.com", "v2ray", "v2ray-core", "testing", "scenarios", "data", filename)
|
||||||
}
|
}
|
||||||
@ -89,7 +82,8 @@ func InitializeServer(configFile string) error {
|
|||||||
func CloseAllServers() {
|
func CloseAllServers() {
|
||||||
log.Info("Closing all servers.")
|
log.Info("Closing all servers.")
|
||||||
for _, server := range runningServers {
|
for _, server := range runningServers {
|
||||||
server.Process.Kill()
|
server.Process.Signal(os.Interrupt)
|
||||||
|
server.Process.Wait()
|
||||||
}
|
}
|
||||||
runningServers = make([]*exec.Cmd, 0, 10)
|
runningServers = make([]*exec.Cmd, 0, 10)
|
||||||
log.Info("All server closed.")
|
log.Info("All server closed.")
|
||||||
|
@ -6,28 +6,26 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/v2ray/v2ray-core/common/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
func BuildV2Ray() error {
|
func BuildV2Ray() error {
|
||||||
|
binaryPath := GetTestBinaryPath()
|
||||||
if _, err := os.Stat(binaryPath); err == nil {
|
if _, err := os.Stat(binaryPath); err == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := FillBinaryPath(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd := exec.Command("go", "test", "-tags", "json coverage coveragemain", "-coverpkg", "github.com/v2ray/v2ray-core/...", "-c", "-o", binaryPath, GetSourcePath())
|
cmd := exec.Command("go", "test", "-tags", "json coverage coveragemain", "-coverpkg", "github.com/v2ray/v2ray-core/...", "-c", "-o", binaryPath, GetSourcePath())
|
||||||
return cmd.Run()
|
return cmd.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
func RunV2Ray(configFile string) *exec.Cmd {
|
func RunV2Ray(configFile string) *exec.Cmd {
|
||||||
profile := "coversingle.out"
|
binaryPath := GetTestBinaryPath()
|
||||||
wd, err := os.Getwd()
|
|
||||||
if err == nil {
|
covDir := filepath.Join(os.Getenv("GOPATH"), "out", "v2ray", "cov")
|
||||||
profile = filepath.Join(wd, profile)
|
profile := uuid.New().String() + ".out"
|
||||||
}
|
proc := exec.Command(binaryPath, "-config", configFile, "-test.run", "TestRunMainForCoverage", "-test.coverprofile", profile, "-test.outputdir", covDir)
|
||||||
proc := exec.Command(binaryPath, "-config", configFile, "-test.run", "TestRunMainForCoverage", "-test.coverprofile", profile)
|
|
||||||
proc.Stderr = os.Stderr
|
proc.Stderr = os.Stderr
|
||||||
proc.Stdout = os.Stdout
|
proc.Stdout = os.Stdout
|
||||||
|
|
||||||
|
@ -8,20 +8,18 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func BuildV2Ray() error {
|
func BuildV2Ray() error {
|
||||||
|
binaryPath := GetTestBinaryPath()
|
||||||
if _, err := os.Stat(binaryPath); err == nil {
|
if _, err := os.Stat(binaryPath); err == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := FillBinaryPath(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd := exec.Command("go", "build", "-tags=json", "-o="+binaryPath, GetSourcePath())
|
cmd := exec.Command("go", "build", "-tags=json", "-o="+binaryPath, GetSourcePath())
|
||||||
return cmd.Run()
|
return cmd.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
func RunV2Ray(configFile string) *exec.Cmd {
|
func RunV2Ray(configFile string) *exec.Cmd {
|
||||||
proc := exec.Command(binaryPath, "-config="+configFile)
|
binaryPath := GetTestBinaryPath()
|
||||||
|
proc := exec.Command(binaryPath, "-config", configFile)
|
||||||
proc.Stderr = os.Stderr
|
proc.Stderr = os.Stderr
|
||||||
proc.Stdout = os.Stdout
|
proc.Stdout = os.Stdout
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user