Update mbedTLS sources
[platform/upstream/iotivity.git] / extlibs / mbedtls / mbedtls / tests / scripts / check-names.sh
1 #!/bin/sh
2 #
3 # This file is part of mbed TLS (https://tls.mbed.org)
4 #
5 # Copyright (c) 2015-2019, ARM Limited, All Rights Reserved
6
7 set -eu
8
9 if [ $# -ne 0 ] && [ "$1" = "--help" ]; then
10     cat <<EOF
11 $0 [-v]
12 This script confirms that the naming of all symbols and identifiers in mbed
13 TLS are consistent with the house style and are also self-consistent.
14
15   -v    If the script fails unexpectedly, print a command trace.
16 EOF
17     exit
18 fi
19
20 if grep --version|head -n1|grep GNU >/dev/null; then :; else
21     echo "This script requires GNU grep.">&2
22     exit 1
23 fi
24
25 trace=
26 if [ $# -ne 0 ] && [ "$1" = "-v" ]; then
27   shift
28   trace='-x'
29   exec 2>check-names.err
30   trap 'echo "FAILED UNEXPECTEDLY, status=$?";
31         cat check-names.err' EXIT
32   set -x
33 fi
34
35 printf "Analysing source code...\n"
36
37 sh $trace tests/scripts/list-macros.sh
38 tests/scripts/list-enum-consts.pl
39 sh $trace tests/scripts/list-identifiers.sh
40 sh $trace tests/scripts/list-symbols.sh
41
42 FAIL=0
43
44 printf "\nExported symbols declared in header: "
45 UNDECLARED=$( diff exported-symbols identifiers | sed -n -e 's/^< //p' )
46 if [ "x$UNDECLARED" = "x" ]; then
47     echo "PASS"
48 else
49     echo "FAIL"
50     echo "$UNDECLARED"
51     FAIL=1
52 fi
53
54 diff macros identifiers | sed -n -e 's/< //p' > actual-macros
55
56 for THING in actual-macros enum-consts; do
57     printf "Names of $THING: "
58     test -r $THING
59     BAD=$( grep -v '^MBEDTLS_[0-9A-Z_]*[0-9A-Z]$' $THING || true )
60     if [ "x$BAD" = "x" ]; then
61         echo "PASS"
62     else
63         echo "FAIL"
64         echo "$BAD"
65         FAIL=1
66     fi
67 done
68
69 for THING in identifiers; do
70     printf "Names of $THING: "
71     test -r $THING
72     BAD=$( grep -v '^mbedtls_[0-9a-z_]*[0-9a-z]$' $THING || true )
73     if [ "x$BAD" = "x" ]; then
74         echo "PASS"
75     else
76         echo "FAIL"
77         echo "$BAD"
78         FAIL=1
79     fi
80 done
81
82 printf "Likely typos: "
83 sort -u actual-macros enum-consts > _caps
84 HEADERS=$( ls include/mbedtls/*.h | egrep -v 'compat-1\.3\.h' )
85 NL='
86 '
87 sed -n 's/MBED..._[A-Z0-9_]*/\'"$NL"'&\'"$NL"/gp \
88     $HEADERS library/*.c \
89     | grep MBEDTLS | sort -u > _MBEDTLS_XXX
90 TYPOS=$( diff _caps _MBEDTLS_XXX | sed -n 's/^> //p' \
91             | egrep -v 'XXX|__|_$|^MBEDTLS_.*CONFIG_FILE$' || true )
92 rm _MBEDTLS_XXX _caps
93 if [ "x$TYPOS" = "x" ]; then
94     echo "PASS"
95 else
96     echo "FAIL"
97     echo "$TYPOS"
98     FAIL=1
99 fi
100
101 if [ -n "$trace" ]; then
102   set +x
103   trap - EXIT
104   rm check-names.err
105 fi
106
107 printf "\nOverall: "
108 if [ "$FAIL" -eq 0 ]; then
109     rm macros actual-macros enum-consts identifiers exported-symbols
110     echo "PASSED"
111     exit 0
112 else
113     echo "FAILED"
114     exit 1
115 fi