blob: aa3fc95420dc4a0c544a84d4a833eb38e90fc53d [file] [log] [blame]
Manuel Pégourié-Gonnarde137ea62015-04-09 10:47:44 +02001#!/bin/sh
Simon Butcher71ebc582016-06-23 20:02:07 +01002#
3# This file is part of mbed TLS (https://tls.mbed.org)
4#
5# Copyright (c) 2015-2016, ARM Limited, All Rights Reserved
6#
7# Purpose
8#
9# This script confirms that the naming of all symbols and identifiers in mbed
10# TLS are consistent with the house style and are also self-consistent.
11#
Manuel Pégourié-Gonnarde137ea62015-04-09 10:47:44 +020012set -eu
13
Simon Butcher71ebc582016-06-23 20:02:07 +010014if grep --version|head -n1|grep GNU >/dev/null; then :; else
Ron Eldorbf007d22016-12-15 14:42:37 +020015 echo "This script requires GNU grep.">&2
Simon Butcher71ebc582016-06-23 20:02:07 +010016 exit 1
17fi
18
Gilles Peskineef39c492019-05-15 17:29:15 +020019trace=
20if [ $# -ne 0 ] && [ "$1" = "-v" ]; then
21 shift
22 trace='-x'
23 exec 2>check-names.err
24 trap 'echo "FAILED UNEXPECTEDLY, status=$?";
25 cat check-names.err' EXIT
26 set -x
27fi
28
Simon Butcher71ebc582016-06-23 20:02:07 +010029printf "Analysing source code...\n"
30
Gilles Peskineef39c492019-05-15 17:29:15 +020031sh $trace tests/scripts/list-macros.sh
Manuel Pégourié-Gonnarde137ea62015-04-09 10:47:44 +020032tests/scripts/list-enum-consts.pl
Gilles Peskineef39c492019-05-15 17:29:15 +020033sh $trace tests/scripts/list-identifiers.sh
34sh $trace tests/scripts/list-symbols.sh
Manuel Pégourié-Gonnarde137ea62015-04-09 10:47:44 +020035
36FAIL=0
37
Simon Butcher71ebc582016-06-23 20:02:07 +010038printf "\nExported symbols declared in header: "
Manuel Pégourié-Gonnarde137ea62015-04-09 10:47:44 +020039UNDECLARED=$( diff exported-symbols identifiers | sed -n -e 's/^< //p' )
Manuel Pégourié-Gonnard9afdc832015-08-04 17:15:13 +020040if [ "x$UNDECLARED" = "x" ]; then
Manuel Pégourié-Gonnarde137ea62015-04-09 10:47:44 +020041 echo "PASS"
42else
43 echo "FAIL"
44 echo "$UNDECLARED"
45 FAIL=1
46fi
47
48diff macros identifiers | sed -n -e 's/< //p' > actual-macros
49
50for THING in actual-macros enum-consts; do
51 printf "Names of $THING: "
52 test -r $THING
Simon Butcher71ebc582016-06-23 20:02:07 +010053 BAD=$( grep -v '^MBEDTLS_[0-9A-Z_]*[0-9A-Z]$\|^YOTTA_[0-9A-Z_]*[0-9A-Z]$' $THING || true )
Manuel Pégourié-Gonnarde137ea62015-04-09 10:47:44 +020054 if [ "x$BAD" = "x" ]; then
55 echo "PASS"
56 else
57 echo "FAIL"
58 echo "$BAD"
59 FAIL=1
60 fi
61done
62
63for THING in identifiers; do
64 printf "Names of $THING: "
65 test -r $THING
66 BAD=$( grep -v '^mbedtls_[0-9a-z_]*[0-9a-z]$' $THING || true )
67 if [ "x$BAD" = "x" ]; then
68 echo "PASS"
69 else
70 echo "FAIL"
71 echo "$BAD"
72 FAIL=1
73 fi
74done
75
Manuel Pégourié-Gonnardf9aae832015-04-09 12:20:53 +020076printf "Likely typos: "
77sort -u actual-macros enum-consts > _caps
78HEADERS=$( ls include/mbedtls/*.h | egrep -v 'compat-1\.3\.h' )
79NL='
80'
Manuel Pégourié-Gonnard6ad5d352015-05-28 15:08:28 +020081sed -n 's/MBED..._[A-Z0-9_]*/\'"$NL"'&\'"$NL"/gp \
Manuel Pégourié-Gonnardf9aae832015-04-09 12:20:53 +020082 $HEADERS library/*.c \
83 | grep MBEDTLS | sort -u > _MBEDTLS_XXX
84TYPOS=$( diff _caps _MBEDTLS_XXX | sed -n 's/^> //p' \
Manuel Pégourié-Gonnard32da9f62015-07-31 15:52:30 +020085 | egrep -v 'XXX|__|_$|^MBEDTLS_.*CONFIG_FILE$' || true )
Manuel Pégourié-Gonnardf9aae832015-04-09 12:20:53 +020086rm _MBEDTLS_XXX _caps
Manuel Pégourié-Gonnard9afdc832015-08-04 17:15:13 +020087if [ "x$TYPOS" = "x" ]; then
Manuel Pégourié-Gonnardf9aae832015-04-09 12:20:53 +020088 echo "PASS"
89else
90 echo "FAIL"
91 echo "$TYPOS"
92 FAIL=1
93fi
94
Gilles Peskineef39c492019-05-15 17:29:15 +020095if [ -n "$trace" ]; then
96 set +x
97 trap - EXIT
98 rm check-names.err
99fi
100
Simon Butcher71ebc582016-06-23 20:02:07 +0100101printf "\nOverall: "
Manuel Pégourié-Gonnarde137ea62015-04-09 10:47:44 +0200102if [ "$FAIL" -eq 0 ]; then
103 rm macros actual-macros enum-consts identifiers exported-symbols
104 echo "PASSED"
105 exit 0
106else
107 echo "FAILED"
108 exit 1
109fi