1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-27 14:26:11 -04:00

update coverage

This commit is contained in:
v2ray 2016-08-09 22:13:16 +02:00
parent 5dc80a2cc5
commit 25b30704a4
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
4 changed files with 38 additions and 42 deletions

View File

@ -1,19 +1,22 @@
#!/bin/bash
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 {
DIR="github.com/v2ray/v2ray-core/$1"
DEP=$(go list -f '{{ join .Deps "\n" }}' $DIR | grep v2ray | tr '\n' ',')
DEP=${DEP}$DIR
go test -tags "json coverage" -coverprofile=coversingle.out -coverpkg=$DEP $DIR || FAIL=1
if [ -f coversingle.out ]; then
cat coversingle.out | grep -v "mode: set" >> ${COVERAGE_FILE}
rm coversingle.out
fi
RND_NAME=$(openssl rand -hex 16)
COV_PROFILE=${V2RAY_COV}/${RND_NAME}.out
go test -tags "json coverage" -coverprofile=${COV_PROFILE} -coverpkg=$DEP $DIR || FAIL=1
}
rm -rf ${V2RAY_OUT}
mkdir -p ${V2RAY_COV}
touch ${COVERAGE_FILE}
TEST_FILES=(./*_test.go)
@ -28,14 +31,17 @@ for DIR in $(find * -type d -not -path "*.git*"); do
fi
done
cat ${COVERAGE_FILE} | sort -t: -k1 | grep -vw "testing" > coverallsorted.out
echo "mode: set" | cat - coverallsorted.out > ${COVERAGE_FILE}
rm coverallsorted.out
for OUT_FILE in $(find ${V2RAY_COV} -name "*.out"); do
echo "Merging file ${OUT_FILE}"
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
bash <(curl -s https://codecov.io/bash) -f ${COVERAGE_FILE} || echo "Codecov did not collect coverage reports."
fi
rm -f ${COVERAGE_FILE}
exit $FAIL

View File

@ -1,7 +1,6 @@
package scenarios
import (
"io/ioutil"
"os"
"os/exec"
"path/filepath"
@ -24,26 +23,20 @@ import (
var (
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 {
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 {
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() {
log.Info("Closing all servers.")
for _, server := range runningServers {
server.Process.Kill()
server.Process.Signal(os.Interrupt)
server.Process.Wait()
}
runningServers = make([]*exec.Cmd, 0, 10)
log.Info("All server closed.")

View File

@ -6,28 +6,26 @@ import (
"os"
"os/exec"
"path/filepath"
"github.com/v2ray/v2ray-core/common/uuid"
)
func BuildV2Ray() error {
binaryPath := GetTestBinaryPath()
if _, err := os.Stat(binaryPath); err == 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())
return cmd.Run()
}
func RunV2Ray(configFile string) *exec.Cmd {
profile := "coversingle.out"
wd, err := os.Getwd()
if err == nil {
profile = filepath.Join(wd, profile)
}
proc := exec.Command(binaryPath, "-config", configFile, "-test.run", "TestRunMainForCoverage", "-test.coverprofile", profile)
binaryPath := GetTestBinaryPath()
covDir := filepath.Join(os.Getenv("GOPATH"), "out", "v2ray", "cov")
profile := uuid.New().String() + ".out"
proc := exec.Command(binaryPath, "-config", configFile, "-test.run", "TestRunMainForCoverage", "-test.coverprofile", profile, "-test.outputdir", covDir)
proc.Stderr = os.Stderr
proc.Stdout = os.Stdout

View File

@ -8,20 +8,18 @@ import (
)
func BuildV2Ray() error {
binaryPath := GetTestBinaryPath()
if _, err := os.Stat(binaryPath); err == nil {
return nil
}
if err := FillBinaryPath(); err != nil {
return err
}
cmd := exec.Command("go", "build", "-tags=json", "-o="+binaryPath, GetSourcePath())
return cmd.Run()
}
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.Stdout = os.Stdout