Manuel Pégourié-Gonnard | e137ea6 | 2015-04-09 10:47:44 +0200 | [diff] [blame] | 1 | #!/bin/sh |
Simon Butcher | 71ebc58 | 2016-06-23 20:02:07 +0100 | [diff] [blame] | 2 | # |
| 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é-Gonnard | e137ea6 | 2015-04-09 10:47:44 +0200 | [diff] [blame] | 12 | set -eu |
| 13 | |
Simon Butcher | 71ebc58 | 2016-06-23 20:02:07 +0100 | [diff] [blame] | 14 | if grep --version|head -n1|grep GNU >/dev/null; then :; else |
Ron Eldor | bf007d2 | 2016-12-15 14:42:37 +0200 | [diff] [blame] | 15 | echo "This script requires GNU grep.">&2 |
Simon Butcher | 71ebc58 | 2016-06-23 20:02:07 +0100 | [diff] [blame] | 16 | exit 1 |
| 17 | fi |
| 18 | |
Gilles Peskine | ef39c49 | 2019-05-15 17:29:15 +0200 | [diff] [blame^] | 19 | trace= |
| 20 | if [ $# -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 |
| 27 | fi |
| 28 | |
Simon Butcher | 71ebc58 | 2016-06-23 20:02:07 +0100 | [diff] [blame] | 29 | printf "Analysing source code...\n" |
| 30 | |
Gilles Peskine | ef39c49 | 2019-05-15 17:29:15 +0200 | [diff] [blame^] | 31 | sh $trace tests/scripts/list-macros.sh |
Manuel Pégourié-Gonnard | e137ea6 | 2015-04-09 10:47:44 +0200 | [diff] [blame] | 32 | tests/scripts/list-enum-consts.pl |
Gilles Peskine | ef39c49 | 2019-05-15 17:29:15 +0200 | [diff] [blame^] | 33 | sh $trace tests/scripts/list-identifiers.sh |
| 34 | sh $trace tests/scripts/list-symbols.sh |
Manuel Pégourié-Gonnard | e137ea6 | 2015-04-09 10:47:44 +0200 | [diff] [blame] | 35 | |
| 36 | FAIL=0 |
| 37 | |
Simon Butcher | 71ebc58 | 2016-06-23 20:02:07 +0100 | [diff] [blame] | 38 | printf "\nExported symbols declared in header: " |
Manuel Pégourié-Gonnard | e137ea6 | 2015-04-09 10:47:44 +0200 | [diff] [blame] | 39 | UNDECLARED=$( diff exported-symbols identifiers | sed -n -e 's/^< //p' ) |
Manuel Pégourié-Gonnard | 9afdc83 | 2015-08-04 17:15:13 +0200 | [diff] [blame] | 40 | if [ "x$UNDECLARED" = "x" ]; then |
Manuel Pégourié-Gonnard | e137ea6 | 2015-04-09 10:47:44 +0200 | [diff] [blame] | 41 | echo "PASS" |
| 42 | else |
| 43 | echo "FAIL" |
| 44 | echo "$UNDECLARED" |
| 45 | FAIL=1 |
| 46 | fi |
| 47 | |
| 48 | diff macros identifiers | sed -n -e 's/< //p' > actual-macros |
| 49 | |
| 50 | for THING in actual-macros enum-consts; do |
| 51 | printf "Names of $THING: " |
| 52 | test -r $THING |
Simon Butcher | 71ebc58 | 2016-06-23 20:02:07 +0100 | [diff] [blame] | 53 | BAD=$( grep -v '^MBEDTLS_[0-9A-Z_]*[0-9A-Z]$\|^YOTTA_[0-9A-Z_]*[0-9A-Z]$' $THING || true ) |
Manuel Pégourié-Gonnard | e137ea6 | 2015-04-09 10:47:44 +0200 | [diff] [blame] | 54 | if [ "x$BAD" = "x" ]; then |
| 55 | echo "PASS" |
| 56 | else |
| 57 | echo "FAIL" |
| 58 | echo "$BAD" |
| 59 | FAIL=1 |
| 60 | fi |
| 61 | done |
| 62 | |
| 63 | for 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 |
| 74 | done |
| 75 | |
Manuel Pégourié-Gonnard | f9aae83 | 2015-04-09 12:20:53 +0200 | [diff] [blame] | 76 | printf "Likely typos: " |
| 77 | sort -u actual-macros enum-consts > _caps |
| 78 | HEADERS=$( ls include/mbedtls/*.h | egrep -v 'compat-1\.3\.h' ) |
| 79 | NL=' |
| 80 | ' |
Manuel Pégourié-Gonnard | 6ad5d35 | 2015-05-28 15:08:28 +0200 | [diff] [blame] | 81 | sed -n 's/MBED..._[A-Z0-9_]*/\'"$NL"'&\'"$NL"/gp \ |
Manuel Pégourié-Gonnard | f9aae83 | 2015-04-09 12:20:53 +0200 | [diff] [blame] | 82 | $HEADERS library/*.c \ |
| 83 | | grep MBEDTLS | sort -u > _MBEDTLS_XXX |
| 84 | TYPOS=$( diff _caps _MBEDTLS_XXX | sed -n 's/^> //p' \ |
Manuel Pégourié-Gonnard | 32da9f6 | 2015-07-31 15:52:30 +0200 | [diff] [blame] | 85 | | egrep -v 'XXX|__|_$|^MBEDTLS_.*CONFIG_FILE$' || true ) |
Manuel Pégourié-Gonnard | f9aae83 | 2015-04-09 12:20:53 +0200 | [diff] [blame] | 86 | rm _MBEDTLS_XXX _caps |
Manuel Pégourié-Gonnard | 9afdc83 | 2015-08-04 17:15:13 +0200 | [diff] [blame] | 87 | if [ "x$TYPOS" = "x" ]; then |
Manuel Pégourié-Gonnard | f9aae83 | 2015-04-09 12:20:53 +0200 | [diff] [blame] | 88 | echo "PASS" |
| 89 | else |
| 90 | echo "FAIL" |
| 91 | echo "$TYPOS" |
| 92 | FAIL=1 |
| 93 | fi |
| 94 | |
Gilles Peskine | ef39c49 | 2019-05-15 17:29:15 +0200 | [diff] [blame^] | 95 | if [ -n "$trace" ]; then |
| 96 | set +x |
| 97 | trap - EXIT |
| 98 | rm check-names.err |
| 99 | fi |
| 100 | |
Simon Butcher | 71ebc58 | 2016-06-23 20:02:07 +0100 | [diff] [blame] | 101 | printf "\nOverall: " |
Manuel Pégourié-Gonnard | e137ea6 | 2015-04-09 10:47:44 +0200 | [diff] [blame] | 102 | if [ "$FAIL" -eq 0 ]; then |
| 103 | rm macros actual-macros enum-consts identifiers exported-symbols |
| 104 | echo "PASSED" |
| 105 | exit 0 |
| 106 | else |
| 107 | echo "FAILED" |
| 108 | exit 1 |
| 109 | fi |