aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStewart Smith <stewart@linux.vnet.ibm.com>2014-12-18 18:21:29 +1100
committerStewart Smith <stewart@linux.vnet.ibm.com>2014-12-18 18:21:29 +1100
commitc652989453649b8d27f85dcfb882efcec8dbf64d (patch)
treed6e881c2017b4355ffd08cc0c85ca7f7c2395fd7
parent1f91d6796676dc75188011f6ef4d09fc8dd81a29 (diff)
downloadskiboot-c652989453649b8d27f85dcfb882efcec8dbf64d.zip
skiboot-c652989453649b8d27f85dcfb882efcec8dbf64d.tar.gz
skiboot-c652989453649b8d27f85dcfb882efcec8dbf64d.tar.bz2
Run the CCAN unit tests and add to coverage-report
With some fun Makefile rules, we can pick up all CCAN unit tests. We exclude the unit test source files from the lcov report itself. Add skeleton ccan config.h and tap.h that are enough for us to build and run the test suite. Currently, the minimalist versions should be fine (and we don't need CCAN configurator). Also includes -Werror fixes for ccan tests. Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
-rw-r--r--.gitignore2
-rw-r--r--Makefile.main6
-rw-r--r--ccan/Makefile.check43
-rw-r--r--ccan/array_size/test/run.c3
-rw-r--r--ccan/build_assert/test/run-BUILD_ASSERT_OR_ZERO.c3
-rw-r--r--ccan/check_type/test/run.c3
-rw-r--r--ccan/config.h30
-rw-r--r--ccan/container_of/test/run.c3
-rw-r--r--ccan/endian/test/run.c3
-rw-r--r--ccan/list/test/helper.c2
-rw-r--r--ccan/list/test/run-check-corrupt.c6
-rw-r--r--ccan/list/test/run-list_del_from-assert.c4
-rw-r--r--ccan/list/test/run-single-eval.c3
-rw-r--r--ccan/list/test/run.c4
-rw-r--r--ccan/short_types/test/run.c3
-rw-r--r--ccan/str/test/run-STR_MAX_CHARS.c9
-rw-r--r--ccan/str/test/run.c3
-rw-r--r--ccan/tap/tap.h25
18 files changed, 150 insertions, 5 deletions
diff --git a/.gitignore b/.gitignore
index 2304666..fbab18d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -18,6 +18,8 @@ cscope.out
asm/asm-offsets.s
include/asm-offsets.h
version.c
+ccan/*/test/*-gcov
+ccan/*/test/gmon.out
core/test/run-device
core/test/run-malloc
core/test/run-malloc-speed
diff --git a/Makefile.main b/Makefile.main
index d4249f0..4a8cbe4 100644
--- a/Makefile.main
+++ b/Makefile.main
@@ -167,8 +167,8 @@ coverage-report: skiboot.info
genhtml -q -o $@ $<
skiboot.info: coverage
- lcov -q -c -d . -o $@
-
+ lcov -q -c -d . $(LCOV_DIRS) -o $@
+ lcov -q -r $@ $(LCOV_EXCLUDE) -o $@
tags:
find . -name '*.[chS]' | xargs ctags
@@ -176,7 +176,7 @@ tags:
TAGS:
find . -name '*.[chS]' | xargs etags
-.PHONY: tags TAGS check
+.PHONY: tags TAGS check coverage
cscope:
find . -name '*.[chS]' | xargs cscope
diff --git a/ccan/Makefile.check b/ccan/Makefile.check
new file mode 100644
index 0000000..767b338
--- /dev/null
+++ b/ccan/Makefile.check
@@ -0,0 +1,43 @@
+CCAN_TEST_SRC := $(wildcard ccan/*/test/run*.c)
+
+LCOV_EXCLUDE += $(CCAN_TEST_SRC) ccan/list/test/helper.c
+
+CCAN_TEST := $(CCAN_TEST_SRC:%.c=%)
+
+
+.PHONY: $(CCAN_TEST:%=%-gcov-run) ccan-check
+
+ccan-check: $(CCAN_TEST:%=%-check)
+
+check: ccan-check $(CCAN_TEST:%=%-gcov-run)
+
+.PHONY: ccan-coverage
+
+coverage: ccan-coverage
+
+ccan-coverage: $(CCAN_TEST:%=%-gcov-run)
+
+$(CCAN_TEST:%=%-gcov-run) : %-run: %
+ $(eval LCOV_DIRS += -d $(dir $<) )
+ $(call Q, TEST-COVERAGE , (cd $(dir $<); GCOV_PREFIX_STRIP=`(c=0; while [ "\`pwd\`" != '/' ]; do cd ..; c=\`expr 1 + $$c\`; done; echo $$c)` ./$(notdir $<) ), $< )
+
+$(CCAN_TEST:%=%-check) : %-check: %
+ $(call Q, RUN-TEST , $(VALGRIND) $<, $<)
+
+$(CCAN_TEST) : % : %.c
+ $(call Q, HOSTCC ,$(HOSTCC) $(HOSTCFLAGS) -O0 -g -I . -Iccan/ -o $@ $<,$<)
+
+$(CCAN_TEST:%=%-gcov): %-gcov : %.c
+ $(call Q, HOSTCC , (cd $(dir $<); $(HOSTCC) $(HOSTCFLAGS) -fprofile-arcs -ftest-coverage -O0 -g -I $(shell pwd) -I$(shell pwd)/./ccan/ -pg -o $(notdir $@) $(notdir $<) ), $<)
+
+-include $(wildcard ccan/*/test/*.d)
+
+clean: ccan-test-clean
+
+ccan-test-clean:
+ $(RM) -f $(CCAN_TEST) \
+ $(CCAN_TEST:%=%-gcov) \
+ $(CCAN_TEST:%=%.d) \
+ $(CCAN_TEST:%=%.o) \
+ $(CCAN_TEST:%=%-gcov.gcda) \
+ $(CCAN_TEST:%=%-gcov.gcno) \ No newline at end of file
diff --git a/ccan/array_size/test/run.c b/ccan/array_size/test/run.c
index 37b4200..284e315 100644
--- a/ccan/array_size/test/run.c
+++ b/ccan/array_size/test/run.c
@@ -18,6 +18,9 @@ static int array4_size = ARRAY_SIZE(array4);
int main(int argc, char *argv[])
{
+ (void)argc;
+ (void)argv;
+
plan_tests(8);
ok1(array1_size == 1);
ok1(array2_size == 2);
diff --git a/ccan/build_assert/test/run-BUILD_ASSERT_OR_ZERO.c b/ccan/build_assert/test/run-BUILD_ASSERT_OR_ZERO.c
index 4185821..55e6f3c 100644
--- a/ccan/build_assert/test/run-BUILD_ASSERT_OR_ZERO.c
+++ b/ccan/build_assert/test/run-BUILD_ASSERT_OR_ZERO.c
@@ -3,6 +3,9 @@
int main(int argc, char *argv[])
{
+ (void)argc;
+ (void)argv;
+
plan_tests(1);
ok1(BUILD_ASSERT_OR_ZERO(1 == 1) == 0);
return exit_status();
diff --git a/ccan/check_type/test/run.c b/ccan/check_type/test/run.c
index 83b903c..767c9fd 100644
--- a/ccan/check_type/test/run.c
+++ b/ccan/check_type/test/run.c
@@ -5,6 +5,9 @@ int main(int argc, char *argv[])
{
int x = 0, y = 0;
+ (void)argc;
+ (void)argv;
+
plan_tests(9);
ok1(check_type(argc, int) == 0);
diff --git a/ccan/config.h b/ccan/config.h
new file mode 100644
index 0000000..39c0b4b
--- /dev/null
+++ b/ccan/config.h
@@ -0,0 +1,30 @@
+/* Copyright 2013-2014 IBM Corp.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/* Dummy config.h for CCAN test suite */
+
+#define HAVE_BUILTIN_TYPES_COMPATIBLE_P 1
+#define HAVE_TYPEOF 1
+
+#ifndef HAVE_BIG_ENDIAN
+#define HAVE_BIG_ENDIAN 0
+#endif
+
+#ifndef HAVE_LITTLE_ENDIAN
+#define HAVE_LITTLE_ENDIAN 0
+#endif
+
+#define HAVE_BYTESWAP_H 0
+#define HAVE_BSWAP_64 0
diff --git a/ccan/container_of/test/run.c b/ccan/container_of/test/run.c
index 96ef483..9e51b0d 100644
--- a/ccan/container_of/test/run.c
+++ b/ccan/container_of/test/run.c
@@ -12,6 +12,9 @@ int main(int argc, char *argv[])
int *intp = &foo.a;
char *charp = &foo.b;
+ (void)argc;
+ (void)argv;
+
plan_tests(6);
ok1(container_of(intp, struct foo, a) == &foo);
ok1(container_of(charp, struct foo, b) == &foo);
diff --git a/ccan/endian/test/run.c b/ccan/endian/test/run.c
index a00fce7..e5b054b 100644
--- a/ccan/endian/test/run.c
+++ b/ccan/endian/test/run.c
@@ -18,6 +18,9 @@ int main(int argc, char *argv[])
unsigned char u16_bytes[2];
} u16;
+ (void)argc;
+ (void)argv;
+
plan_tests(48);
/* Straight swap tests. */
diff --git a/ccan/list/test/helper.c b/ccan/list/test/helper.c
index ca4700b..4fb1c5a 100644
--- a/ccan/list/test/helper.c
+++ b/ccan/list/test/helper.c
@@ -1,6 +1,6 @@
#include <stdlib.h>
#include <stdbool.h>
-#include <timebase.h>
+#include <time.h>
#include <ccan/list/list.h>
#include "helper.h"
diff --git a/ccan/list/test/run-check-corrupt.c b/ccan/list/test/run-check-corrupt.c
index f4c20b5..da4578a 100644
--- a/ccan/list/test/run-check-corrupt.c
+++ b/ccan/list/test/run-check-corrupt.c
@@ -16,6 +16,9 @@ static int my_fprintf(FILE *stream, const char *format, ...)
{
va_list ap;
int ret;
+
+ (void)stream;
+
va_start(ap, format);
ret = vsnprintf(printf_buffer, sizeof(printf_buffer), format, ap);
va_end(ap);
@@ -32,6 +35,9 @@ int main(int argc, char *argv[])
struct list_node n1;
char expect[100];
+ (void)argc;
+ (void)argv;
+
plan_tests(9);
/* Empty list. */
list.n.next = &list.n;
diff --git a/ccan/list/test/run-list_del_from-assert.c b/ccan/list/test/run-list_del_from-assert.c
index 05d6cad..453dc0f 100644
--- a/ccan/list/test/run-list_del_from-assert.c
+++ b/ccan/list/test/run-list_del_from-assert.c
@@ -14,6 +14,9 @@ int main(int argc, char *argv[])
pid_t child;
int status;
+ (void)argc;
+ (void)argv;
+
plan_tests(1);
list_head_init(&list1);
list_head_init(&list2);
@@ -25,6 +28,7 @@ int main(int argc, char *argv[])
if (child) {
wait(&status);
} else {
+ close(2); /* Close stderr so we don't print confusing assert */
/* This should abort. */
list_del_from(&list1, &n3);
exit(0);
diff --git a/ccan/list/test/run-single-eval.c b/ccan/list/test/run-single-eval.c
index f90eed3..3c17e03 100644
--- a/ccan/list/test/run-single-eval.c
+++ b/ccan/list/test/run-single-eval.c
@@ -28,6 +28,9 @@ int main(int argc, char *argv[])
node_count = 0;
struct list_head list = LIST_HEAD_INIT(list);
+ (void)argc;
+ (void)argv;
+
plan_tests(74);
/* Test LIST_HEAD, LIST_HEAD_INIT, list_empty and check_list */
ok1(list_empty(ref(&static_list, static_count)));
diff --git a/ccan/list/test/run.c b/ccan/list/test/run.c
index 1d02acd..bc9d266 100644
--- a/ccan/list/test/run.c
+++ b/ccan/list/test/run.c
@@ -1,3 +1,4 @@
+#include <ccan/list/test/helper.c>
#include <ccan/list/list.h>
#include <ccan/tap/tap.h>
#include <ccan/list/list.c>
@@ -25,6 +26,9 @@ int main(int argc, char *argv[])
opaque_t *q, *nq;
struct list_head opaque_list = LIST_HEAD_INIT(opaque_list);
+ (void)argc;
+ (void)argv;
+
plan_tests(65);
/* Test LIST_HEAD, LIST_HEAD_INIT, list_empty and check_list */
ok1(list_empty(&static_list));
diff --git a/ccan/short_types/test/run.c b/ccan/short_types/test/run.c
index 5aa80d7..99f2138 100644
--- a/ccan/short_types/test/run.c
+++ b/ccan/short_types/test/run.c
@@ -5,6 +5,9 @@
int main(int argc, char *argv[])
{
+ (void)argc;
+ (void)argv;
+
plan_tests(22);
ok1(sizeof(u64) == 8);
diff --git a/ccan/str/test/run-STR_MAX_CHARS.c b/ccan/str/test/run-STR_MAX_CHARS.c
index ae6969c..1343e04 100644
--- a/ccan/str/test/run-STR_MAX_CHARS.c
+++ b/ccan/str/test/run-STR_MAX_CHARS.c
@@ -6,7 +6,7 @@
int main(int argc, char *argv[])
{
- char str[1000];
+ char *str = (char*)malloc(sizeof(char)*1000);
struct {
uint8_t u1byte;
int8_t s1byte;
@@ -19,6 +19,11 @@ int main(int argc, char *argv[])
void *ptr;
} types;
+ (void)argc;
+ (void)argv;
+
+ assert(str);
+
plan_tests(13);
memset(&types, 0xFF, sizeof(types));
@@ -55,5 +60,7 @@ int main(int argc, char *argv[])
sprintf(str, "%p", types.ptr);
ok1(strlen(str) < STR_MAX_CHARS(types.ptr));
+ free(str);
+
return exit_status();
}
diff --git a/ccan/str/test/run.c b/ccan/str/test/run.c
index 0f00ea3..216e141 100644
--- a/ccan/str/test/run.c
+++ b/ccan/str/test/run.c
@@ -25,6 +25,9 @@ int main(int argc, char *argv[])
{
unsigned int i, j, n;
char *strings[NUM_SUBSTRINGS * NUM_SUBSTRINGS];
+
+ (void)argc;
+ (void)argv;
n = 0;
for (i = 0; i < NUM_SUBSTRINGS; i++) {
diff --git a/ccan/tap/tap.h b/ccan/tap/tap.h
new file mode 100644
index 0000000..a772f1a
--- /dev/null
+++ b/ccan/tap/tap.h
@@ -0,0 +1,25 @@
+/* Copyright 2013-2014 IBM Corp.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* Dummy tap.h for ccan tests */
+
+#include <assert.h>
+
+#define plan_tests(x) do { } while(0)
+#define ok1(e) assert(e)
+#define ok(e, ...) assert(e)
+#define fail(...) assert(0)
+#define exit_status() (0)