File: api-test-coverage

package info (click to toggle)
kronosnet 1.32-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,080 kB
  • sloc: ansic: 25,419; sh: 5,295; makefile: 664
file content (91 lines) | stat: -rwxr-xr-x 2,458 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/sh
#
# Copyright (C) 2016-2025 Red Hat, Inc.  All rights reserved.
#
# Author: Fabio M. Di Nitto <fabbione@kronosnet.org>
#
# This software licensed under GPL-2.0+
#

srcdir="$1"/libknet/tests
builddir="$2"/libknet/tests

headerapicalls="$(grep knet_ "$srcdir"/../libknet.h | grep -v "^ \*" | grep -v ^struct | grep -v "^[[:space:]]" | grep -v typedef | sed -e 's/(.*//g' -e 's/^const //g' -e 's/\*//g' | awk '{print $2}')"

# The PowerPC64 ELFv1 ABI defines the address of a function as that of a
# function descriptor defined in .opd, a data (D) section.  Other ABIs
# use the entry address of the function itself in the text (T) section.
# Filter additional symbols exported by ln(1) on Solaris.
exportedapicalls="$(nm -B -D "$builddir"/../.libs/libknet.so | grep ' [DT] ' | awk '{if ($3 != "_edata" && $3 != "_GLOBAL_OFFSET_TABLE_" && $3 != "_PROCEDURE_LINKAGE_TABLE_") {print $3}}' | sed -e 's#@@LIBKNET##g')"

echo "Checking for exported symbols NOT available in header file"

for i in $exportedapicalls; do
	found=0
	for x in $headerapicalls; do
		if [ "$x" = "$i" ]; then
			found=1
			break;
		fi
	done
	if [ "$found" = 0 ]; then
		echo "Symbol $i not found in header file"
		exit 1
	fi
done

echo "Checking for symbols in header file NOT exported by binary lib"

for i in $headerapicalls; do
	found=0
	for x in $exportedapicalls; do
		if [ "$x" = "$i" ]; then
			found=1
			break;
		fi
	done
	if [ "$found" = 0 ]; then
		echo "Symbol $i not found in binary lib"
		exit 1
	fi
done

echo "Checking for tests with memcheck exceptions"

for i in $(grep -l is_memcheck "$srcdir"/*.c | grep -v test-common); do
	echo "WARNING: $(basename $i) - has memcheck exception enabled"
done

echo "Checking for tests with helgrind exceptions"

for i in $(grep -l is_helgrind "$srcdir"/*.c | grep -v test-common); do
	echo "WARNING: $(basename $i) has helgrind exception enabled"
done

echo "Checking for api test coverage"

numapicalls=0
found=0
missing=0

for i in $headerapicalls; do
	[ "$i" = knet_handle_new_ex ] && i=knet_handle_new # tested together
	numapicalls=$((numapicalls + 1))
	if [ -f $srcdir/api_${i}.c ]; then
		found=$((found + 1))
	else
		missing=$((missing + 1))
		echo "MISSING: $i"
	fi
done

echo "Summary"
echo "-------"
echo "Found   : $found"
echo "Missing : $missing"
echo "Total   : $numapicalls"
which bc > /dev/null 2>&1 && {
	coverage=$(echo "scale=3; $found / $numapicalls * 100" | bc -l)
	echo "Coverage: $coverage%"
}
exit 0