Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coverage form Jenkins #5389

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ include $(dir)/Rules.mk

# include this file only if coverage target is executed
# it is quite expensive
ifneq ($(filter coverage% clean distclean,$(MAKECMDGOALS)),)
ifneq ($(filter coverage% clean distclean test/unit/gotest.junit.xml,$(MAKECMDGOALS)),)
# has to be after cmd/ipfs due to PATH
dir := coverage
include $(dir)/Rules.mk
Expand Down
9 changes: 5 additions & 4 deletions ci/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def sharness_step = { run, osname, makeargs, ignore ->
run "make gx-deps"

try {
run "make -j12 ${makeargs} test/sharness/test-results/sharness.xml CONTINUE_ON_S_FAILURE=1 TEST_NO_FUSE=1 TEST_NO_DOCKER=1"
run "make -j12 ${makeargs} coverage/sharness_tests.coverprofile test/sharness/test-results/sharness.xml CONTINUE_ON_S_FAILURE=1 TEST_NO_FUSE=1 TEST_NO_DOCKER=1 TEST_GENERATE_JUNIT=1"

try {
// archive trash directories if any
Expand All @@ -93,6 +93,7 @@ def sharness_step = { run, osname, makeargs, ignore ->
} finally {
if (!ignore) {
junit allowEmptyResults: true, testResults: 'test/sharness/test-results/sharness.xml'
run 'bash -c "bash <(curl -s https://codecov.io/bash) -f coverage/sharness_tests.coverprofile"'
}
}
}
Expand Down Expand Up @@ -162,12 +163,12 @@ ansiColor('xterm') { withEnv(['TERM=xterm-color']) {
run "make gx-deps"

try {
run test + ' -tags="nofuse" 2>&1 | tee output'
run 'cat output | go-junit-report > junit-report-linux.xml'
run 'make -j1 test/unit/gotest.junit.xml coverage/unit_tests.coverprofile GOTFLAGS=-tags="nofuse"'
} catch (err) {
throw err
} finally {
junit allowEmptyResults: true, testResults: 'junit-report-*.xml'
junit allowEmptyResults: true, testResults: 'test/unit/gotest.junit.xml'
run 'bash -c "bash <(curl -s https://codecov.io/bash) -f coverage/unit_tests.coverprofile"'
}
}
}
Expand Down
40 changes: 0 additions & 40 deletions circle.yml

This file was deleted.

6 changes: 3 additions & 3 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
codecov:
ci:
- "ci/circle-ci"
- "!ci/circle-ci"
- "!travis-ci.org"
- "!ci.ipfs.team:8111"
- "!ci.ipfs.team"
- "ci.ipfs.team:8111"
- "ci.ipfs.team"
notify:
require_ci_to_pass: no
after_n_builds: 2
Expand Down
6 changes: 4 additions & 2 deletions coverage/Rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@ endif

# unit tests coverage
UTESTS_$(d) := $(shell go list -f '{{if (len .TestGoFiles)}}{{.ImportPath}}{{end}}' $(go-flags-with-tags) ./... | grep -v go-ipfs/vendor | grep -v go-ipfs/Godeps)
UTESTS_$(d) += $(shell go list -f '{{if (len .XTestGoFiles)}}{{.ImportPath}}{{end}}' $(go-flags-with-tags) ./... | grep -v go-ipfs/vendor | grep -v go-ipfs/Godeps)

UCOVER_$(d) := $(addsuffix .coverprofile,$(addprefix $(d)/unitcover/, $(subst /,_,$(UTESTS_$(d)))))

$(UCOVER_$(d)): $(d)/coverage_deps ALWAYS
$(eval TMP_PKG := $(subst _,/,$(basename $(@F))))
$(eval TMP_DEPS := $(shell go list -f '{{range .Deps}}{{.}} {{end}}' $(go-flags-with-tags) $(TMP_PKG) | sed 's/ /\n/g' | grep ipfs/go-ipfs | grep -v ipfs/go-ipfs/Godeps) $(TMP_PKG))
$(eval TMP_DEPS_LIST := $(call join-with,$(comma),$(TMP_DEPS)))
go test $(go-flags-with-tags) $(GOTFLAGS) -covermode=atomic -coverpkg=$(TMP_DEPS_LIST) -coverprofile=$@ $(TMP_PKG)

go test $(go-flags-with-tags) $(GOTFLAGS) -v -covermode=atomic -json -coverpkg=$(TMP_DEPS_LIST) -coverprofile=$@ $(TMP_PKG) | tee -a test/unit/gotest.json

$(d)/unit_tests.coverprofile: $(UCOVER_$(d))
gocovmerge $^ > $@

.PHONY: $(d)/unit_tests.coverprofile

TGTS_$(d) := $(d)/unit_tests.coverprofile


Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,12 @@
"hash": "QmYfvQoJCUTCJ54Rog3zWSCDWAkwLWFTMKzcwaNMpXYSQT",
"name": "go-libp2p-quic-transport",
"version": "0.2.3"
},
{
"author": "magik6k",
"hash": "QmXEjYkYTXPNbzggMtueBgHKgz7Py94tvW8evhXUpJR3tz",
"name": "go-junit-report",
"version": "1.0.0"
}
],
"gxVersion": "0.10.0",
Expand Down
3 changes: 3 additions & 0 deletions test/Rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ include $(dir)/Rules.mk
dir := $(d)/sharness
include $(dir)/Rules.mk

dir := $(d)/unit
include $(dir)/Rules.mk

include mk/footer.mk
4 changes: 4 additions & 0 deletions test/bin/Rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ $(d)/ma-pipe-unidir: test/dependencies/ma-pipe-unidir
$(go-build)
TGTS_$(d) += $(d)/ma-pipe-unidir

$(d)/json-to-junit: test/dependencies/json-to-junit
$(go-build)
TGTS_$(d) += $(d)/json-to-junit

TGTS_GX_$(d) := hang-fds iptb
TGTS_GX_$(d) := $(addprefix $(d)/,$(TGTS_GX_$(d)))

Expand Down
138 changes: 138 additions & 0 deletions test/dependencies/json-to-junit/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
package main

import (
"bufio"
"encoding/json"
"encoding/xml"
"log"
"os"
)

type testMsg struct {
Time string
Action string
Package string
Test string

Output string
Elapsed float64
}

type testsuites struct {
XMLName xml.Name `xml:"testsuites"`

Name string `xml:"name,attr"`
Testsuites []testsuite
}

type testsuite struct {
XMLName xml.Name `xml:"testsuite"`

Package string `xml:"package,attr"`

Errors int `xml:"errors,attr"`
Failures int `xml:"failures,attr"`
Tests int `xml:"tests,attr"`

Time float64 `xml:"time,attr"`

Testcases []testcase
}

type testcase struct {
XMLName xml.Name `xml:"testcase"`

Name string `xml:"name,attr"`
Classname string `xml:"classname,attr"`
Time float64 `xml:"time,attr"`

Sout string `xml:"system-out"`
Serr string `xml:"system-err"`

Skipped string `xml:"skipped,omitempty"`
Failure string `xml:"failure,omitempty"`
}

func main() {
scanner := bufio.NewScanner(os.Stdin)
tests := make(map[string]map[string]testcase)
var packages []testsuite

for scanner.Scan() {
msg := testMsg{}
if err := json.Unmarshal(scanner.Bytes(), &msg); err != nil {
log.Fatal(err)
}

switch {
case msg.Action == "run":
if tests[msg.Package] == nil {
tests[msg.Package] = make(map[string]testcase)
}
tests[msg.Package][msg.Test] = testcase{
Name: msg.Test,
Classname: msg.Package,
}
case msg.Action == "output":
if msg.Test == "" {
continue
}
test := tests[msg.Package][msg.Test]
test.Sout = test.Sout + msg.Output + "\n"
tests[msg.Package][msg.Test] = test
case msg.Action == "skip":
fallthrough
case msg.Action == "fail":
fallthrough
case msg.Action == "pass":
if msg.Test != "" {
test := tests[msg.Package][msg.Test]
test.Time = msg.Elapsed
if msg.Action == "skip" {
test.Skipped = "skipped"
}
if msg.Action == "fail" {
test.Failure = "failed"
}
tests[msg.Package][msg.Test] = test
continue
}
ts := testsuite{
Package: msg.Package,
Time: msg.Elapsed,
}

for _, test := range tests[msg.Package] {
ts.Testcases = append(ts.Testcases, test)
ts.Tests++
if test.Failure != "" {
ts.Failures++
}
}

packages = append(packages, ts)

case msg.Action == "cont":
case msg.Action == "pause":
// ??
default:
log.Fatalf("unknown action %s", msg.Action)
}
}

if err := scanner.Err(); err != nil {
log.Fatal(err)
}

out := testsuites{
Name: "go test",
Testsuites: packages,
}

output, err := xml.MarshalIndent(&out, " ", " ")
if err != nil {
log.Fatalf("error: %v\n", err)
}

os.Stdout.Write(output)
}
2 changes: 2 additions & 0 deletions test/unit/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
gotest.json
gotest.junit.xml
8 changes: 8 additions & 0 deletions test/unit/Rules.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
include mk/header.mk

CLEAN += $(d)/gotest.json $(d)/gotest.junit.xml

$(d)/gotest.junit.xml: clean test/bin/json-to-junit coverage/unit_tests.coverprofile
cat $(@D)/gotest.json | json-to-junit > $(@D)/gotest.junit.xml

include mk/footer.mk