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 | # |
Gilles Peskine | 0c12e30 | 2019-05-22 18:22:45 +0200 | [diff] [blame] | 5 | # Copyright (c) 2015-2019, ARM Limited, All Rights Reserved |
| 6 | |
Manuel Pégourié-Gonnard | e137ea6 | 2015-04-09 10:47:44 +0200 | [diff] [blame] | 7 | set -eu |
| 8 | |
Gilles Peskine | 0c12e30 | 2019-05-22 18:22:45 +0200 | [diff] [blame] | 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 | |
Simon Butcher | 71ebc58 | 2016-06-23 20:02:07 +0100 | [diff] [blame] | 20 | if grep --version|head -n1|grep GNU >/dev/null; then :; else |
Ron Eldor | bf007d2 | 2016-12-15 14:42:37 +0200 | [diff] [blame] | 21 | echo "This script requires GNU grep.">&2 |
Simon Butcher | 71ebc58 | 2016-06-23 20:02:07 +0100 | [diff] [blame] | 22 | exit 1 |
| 23 | fi |
| 24 | |
Gilles Peskine | 36428d3 | 2019-05-15 17:29:15 +0200 | [diff] [blame] | 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 | |
Simon Butcher | 71ebc58 | 2016-06-23 20:02:07 +0100 | [diff] [blame] | 35 | printf "Analysing source code...\n" |
| 36 | |
Gilles Peskine | 36428d3 | 2019-05-15 17:29:15 +0200 | [diff] [blame] | 37 | sh $trace tests/scripts/list-macros.sh |
Manuel Pégourié-Gonnard | e137ea6 | 2015-04-09 10:47:44 +0200 | [diff] [blame] | 38 | tests/scripts/list-enum-consts.pl |
Gilles Peskine | 36428d3 | 2019-05-15 17:29:15 +0200 | [diff] [blame] | 39 | sh $trace tests/scripts/list-identifiers.sh |
| 40 | sh $trace tests/scripts/list-symbols.sh |
Manuel Pégourié-Gonnard | e137ea6 | 2015-04-09 10:47:44 +0200 | [diff] [blame] | 41 | |
| 42 | FAIL=0 |
| 43 | |
Simon Butcher | 71ebc58 | 2016-06-23 20:02:07 +0100 | [diff] [blame] | 44 | printf "\nExported symbols declared in header: " |
Manuel Pégourié-Gonnard | e137ea6 | 2015-04-09 10:47:44 +0200 | [diff] [blame] | 45 | UNDECLARED=$( diff exported-symbols identifiers | sed -n -e 's/^< //p' ) |
Manuel Pégourié-Gonnard | 9afdc83 | 2015-08-04 17:15:13 +0200 | [diff] [blame] | 46 | if [ "x$UNDECLARED" = "x" ]; then |
Manuel Pégourié-Gonnard | e137ea6 | 2015-04-09 10:47:44 +0200 | [diff] [blame] | 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 |
Nir Sonnenschein | 03091d1 | 2019-01-08 18:15:50 +0200 | [diff] [blame] | 59 | BAD=$( grep -E -v '^(MBEDTLS|PSA)_[0-9A-Z_]*[0-9A-Z]$' $THING || true ) |
Manuel Pégourié-Gonnard | e137ea6 | 2015-04-09 10:47:44 +0200 | [diff] [blame] | 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 |
Gilles Peskine | 2d9d6db | 2018-06-18 23:25:28 +0200 | [diff] [blame] | 72 | BAD=$( grep -E -v '^(mbedtls|psa)_[0-9a-z_]*[0-9a-z]$' $THING || true ) |
Manuel Pégourié-Gonnard | e137ea6 | 2015-04-09 10:47:44 +0200 | [diff] [blame] | 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 | |
Manuel Pégourié-Gonnard | f9aae83 | 2015-04-09 12:20:53 +0200 | [diff] [blame] | 82 | printf "Likely typos: " |
| 83 | sort -u actual-macros enum-consts > _caps |
Nir Sonnenschein | 03091d1 | 2019-01-08 18:15:50 +0200 | [diff] [blame] | 84 | HEADERS=$( ls include/mbedtls/*.h include/psa/*.h | egrep -v 'compat-1\.3\.h' ) |
Christoph M. Wintersteiger | 8a0f5bb | 2018-12-14 15:46:34 +0000 | [diff] [blame^] | 85 | HEADERS="$HEADERS 3rdparty/everest/include/everest/everest.h 3rdparty/everest/include/everest/x25519.h" |
| 86 | LIBRARY="$( ls library/*.c ) 3rdparty/everest/library/everest.c 3rdparty/everest/library/x25519.c" |
Manuel Pégourié-Gonnard | f9aae83 | 2015-04-09 12:20:53 +0200 | [diff] [blame] | 87 | NL=' |
| 88 | ' |
Manuel Pégourié-Gonnard | 6ad5d35 | 2015-05-28 15:08:28 +0200 | [diff] [blame] | 89 | sed -n 's/MBED..._[A-Z0-9_]*/\'"$NL"'&\'"$NL"/gp \ |
Christoph M. Wintersteiger | 8a0f5bb | 2018-12-14 15:46:34 +0000 | [diff] [blame^] | 90 | $HEADERS $LIBRARY \ |
Manuel Pégourié-Gonnard | f9aae83 | 2015-04-09 12:20:53 +0200 | [diff] [blame] | 91 | | grep MBEDTLS | sort -u > _MBEDTLS_XXX |
| 92 | TYPOS=$( diff _caps _MBEDTLS_XXX | sed -n 's/^> //p' \ |
Manuel Pégourié-Gonnard | 32da9f6 | 2015-07-31 15:52:30 +0200 | [diff] [blame] | 93 | | egrep -v 'XXX|__|_$|^MBEDTLS_.*CONFIG_FILE$' || true ) |
Manuel Pégourié-Gonnard | f9aae83 | 2015-04-09 12:20:53 +0200 | [diff] [blame] | 94 | rm _MBEDTLS_XXX _caps |
Manuel Pégourié-Gonnard | 9afdc83 | 2015-08-04 17:15:13 +0200 | [diff] [blame] | 95 | if [ "x$TYPOS" = "x" ]; then |
Manuel Pégourié-Gonnard | f9aae83 | 2015-04-09 12:20:53 +0200 | [diff] [blame] | 96 | echo "PASS" |
| 97 | else |
| 98 | echo "FAIL" |
| 99 | echo "$TYPOS" |
| 100 | FAIL=1 |
| 101 | fi |
| 102 | |
Gilles Peskine | 36428d3 | 2019-05-15 17:29:15 +0200 | [diff] [blame] | 103 | if [ -n "$trace" ]; then |
| 104 | set +x |
| 105 | trap - EXIT |
| 106 | rm check-names.err |
| 107 | fi |
| 108 | |
Simon Butcher | 71ebc58 | 2016-06-23 20:02:07 +0100 | [diff] [blame] | 109 | printf "\nOverall: " |
Manuel Pégourié-Gonnard | e137ea6 | 2015-04-09 10:47:44 +0200 | [diff] [blame] | 110 | if [ "$FAIL" -eq 0 ]; then |
| 111 | rm macros actual-macros enum-consts identifiers exported-symbols |
| 112 | echo "PASSED" |
| 113 | exit 0 |
| 114 | else |
| 115 | echo "FAILED" |
| 116 | exit 1 |
| 117 | fi |