blob: 2505c6507674065ee71697db7f16f9e74bb1564f [file] [log] [blame]
Joey Armstrong393daca2023-07-06 08:47:54 -04001# -*- makefile -*-
2# -----------------------------------------------------------------------
3# Copyright 2016-2023 Open Networking Foundation (ONF) and the ONF Contributors
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16# -----------------------------------------------------------------------
17
18$(if $(DEBUG),$(warning ENTER))
19
20# tests-dir := ./tests/results
21# tests-coverage := $(tests-dir)/go-test-coverage
22# tests-results := $(tests-dir)/go-test-results
23
24## -----------------------------------------------------------------------
25## -----------------------------------------------------------------------
26test-coverage-init:
27 $(RM) -r tests/results
28 @mkdir -p ./tests/results
29
30 # Chicken-n-egg problem: See Dockerfile.rw_core
31 # required by testing
32 # does not exist during build
33 @touch ./tests/results/go-test-coverage.out
34
35## -----------------------------------------------------------------------
36## -----------------------------------------------------------------------
37test-coverage: test-coverage-init
38
39 $(call banner-enter,$@)
40
41 $(RM) -r tests/results
42 @mkdir -p ./tests/results
43 @touch $(tests-coverage).out
44
45 @$(if $(LOCAL_FIX_PERMS),chmod 777 tests/results)
46
47 $(HIDE) $(MAKE) --no-print-directory test-go-coverage
48 $(HIDE) $(MAKE) --no-print-directory test-junit
49 $(HIDE) $(MAKE) --no-print-directory test-cobertura
50
51 @$(if $(LOCAL_FIX_PERMS),chmod 775 tests/results) # yes this may not run
52
53 $(call banner-leave,$@)
54
55## -----------------------------------------------------------------------
56## -----------------------------------------------------------------------
57test-go-coverage:
58 $(call banner-enter,$@)
59 @$(if $(LOCAL_FIX_PERMS),chmod 777 tests/results)
60
61 # Cannot simply tee output else go exit status lost
62 (\
63 set -euo pipefail\
64 && ${GO} test -mod=vendor -v -coverprofile "./tests/results/go-test-coverage.out" -covermode count ./... 2>&1\
65) | tee ./tests/results/go-test-results.out
66
67 @$(if $(LOCAL_FIX_PERMS),chmod 775 tests/results)
68 $(call banner-leave,$@)
69
70## -----------------------------------------------------------------------
71## -----------------------------------------------------------------------
72test-junit:
73 $(call banner-enter,$@)
74 @$(if $(LOCAL_FIX_PERMS),chmod 777 tests/results)
75
76 ${GO_JUNIT_REPORT} \
77 < ./tests/results/go-test-results.out \
78 > ./tests/results/go-test-results.xml
79
80 @$(if $(LOCAL_FIX_PERMS),chmod 775 tests/results)
81 $(call banner-leave,$@)
82
83## -----------------------------------------------------------------------
84## -----------------------------------------------------------------------
85test-cobertura:
86 $(call banner-enter,$@)
87 @$(if $(LOCAL_FIX_PERMS),chmod 777 tests/results)
88
89 ${GOCOVER_COBERTURA} \
90 < ./tests/results/go-test-coverage.out \
91 > ./tests/results/go-test-coverage.xml
92
93 @$(if $(LOCAL_FIX_PERMS),chmod 775 tests/results)
94 $(call banner-leave,$@)
95
96## -----------------------------------------------------------------------
97## -----------------------------------------------------------------------
98help ::
99 @echo '[TEST: coverage]'
100 @echo ' coverage Generate test coverage reports'
101 @echo ' test-go-coverage Generate a coverage report for vendor/'
102 @echo ' test-junit Digest go coverage, generate junit'
103 @echo ' test-cobertura Digest coverage and junit reports'
104
105
106## -----------------------------------------------------------------------
107## -----------------------------------------------------------------------
108clean-coverage :
109 $(RM) -r ./tests/results
110
111## -----------------------------------------------------------------------
112## -----------------------------------------------------------------------
113clean :: clean-coverage
114
115$(if $(DEBUG),$(warning LEAVE))
116
117# [EOF]