Debian Codegraph @

libknet/tests/api-test-coverage

raw
1 #!/bin/sh
2 #
3 # Copyright (C) 2016-2026 Red Hat, Inc. All rights reserved.
4 #
5 # Author: Fabio M. Di Nitto <[email protected]>
6 #
7 # This software licensed under GPL-2.0+
8 #
9
10 srcdir="$1"/libknet/tests
11 builddir="$2"/libknet/tests
12
13 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}')"
14
15 # The PowerPC64 ELFv1 ABI defines the address of a function as that of a
16 # function descriptor defined in .opd, a data (D) section. Other ABIs
17 # use the entry address of the function itself in the text (T) section.
18 # Filter additional symbols exported by ln(1) on Solaris.
19 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')"
20
21 echo "Checking for exported symbols NOT available in header file"
22
23 for i in $exportedapicalls; do
24 found=0
25 for x in $headerapicalls; do
26 if [ "$x" = "$i" ]; then
27 found=1
28 break;
29 fi
30 done
31 if [ "$found" = 0 ]; then
32 echo "Symbol $i not found in header file"
33 exit 1
34 fi
35 done
36
37 echo "Checking for symbols in header file NOT exported by binary lib"
38
39 for i in $headerapicalls; do
40 found=0
41 for x in $exportedapicalls; do
42 if [ "$x" = "$i" ]; then
43 found=1
44 break;
45 fi
46 done
47 if [ "$found" = 0 ]; then
48 echo "Symbol $i not found in binary lib"
49 exit 1
50 fi
51 done
52
53 echo "Checking for tests with memcheck exceptions"
54
55 for i in $(grep -l is_memcheck "$srcdir"/*.c | grep -v test-common); do
56 echo "WARNING: $(basename $i) - has memcheck exception enabled"
57 done
58
59 echo "Checking for tests with helgrind exceptions"
60
61 for i in $(grep -l is_helgrind "$srcdir"/*.c | grep -v test-common); do
62 echo "WARNING: $(basename $i) has helgrind exception enabled"
63 done
64
65 echo "Checking for api test coverage"
66
67 numapicalls=0
68 found=0
69 missing=0
70
71 for i in $headerapicalls; do
72 [ "$i" = knet_handle_new_ex ] && i=knet_handle_new # tested together
73 numapicalls=$((numapicalls + 1))
74 if [ -f $srcdir/api_${i}.c ]; then
75 found=$((found + 1))
76 else
77 missing=$((missing + 1))
78 echo "MISSING: $i"
79 fi
80 done
81
82 echo "Summary"
83 echo "-------"
84 echo "Found : $found"
85 echo "Missing : $missing"
86 echo "Total : $numapicalls"
87 which bc > /dev/null 2>&1 && {
88 coverage=$(echo "scale=3; $found / $numapicalls * 100" | bc -l)
89 echo "Coverage: $coverage%"
90 }
91 exit 0