| 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 | 
|  | 15 | echo "This script requires GNU grep." | 
|  | 16 | exit 1 | 
|  | 17 | fi | 
|  | 18 |  | 
|  | 19 | printf "Analysing source code...\n" | 
|  | 20 |  | 
| Manuel Pégourié-Gonnard | e137ea6 | 2015-04-09 10:47:44 +0200 | [diff] [blame] | 21 | tests/scripts/list-macros.sh | 
|  | 22 | tests/scripts/list-enum-consts.pl | 
|  | 23 | tests/scripts/list-identifiers.sh | 
|  | 24 | tests/scripts/list-symbols.sh | 
|  | 25 |  | 
|  | 26 | FAIL=0 | 
|  | 27 |  | 
| Simon Butcher | 71ebc58 | 2016-06-23 20:02:07 +0100 | [diff] [blame] | 28 | printf "\nExported symbols declared in header: " | 
| Manuel Pégourié-Gonnard | e137ea6 | 2015-04-09 10:47:44 +0200 | [diff] [blame] | 29 | UNDECLARED=$( diff exported-symbols identifiers | sed -n -e 's/^< //p' ) | 
| Manuel Pégourié-Gonnard | 9afdc83 | 2015-08-04 17:15:13 +0200 | [diff] [blame] | 30 | if [ "x$UNDECLARED" = "x" ]; then | 
| Manuel Pégourié-Gonnard | e137ea6 | 2015-04-09 10:47:44 +0200 | [diff] [blame] | 31 | echo "PASS" | 
|  | 32 | else | 
|  | 33 | echo "FAIL" | 
|  | 34 | echo "$UNDECLARED" | 
|  | 35 | FAIL=1 | 
|  | 36 | fi | 
|  | 37 |  | 
|  | 38 | diff macros identifiers | sed -n -e 's/< //p' > actual-macros | 
|  | 39 |  | 
|  | 40 | for THING in actual-macros enum-consts; do | 
|  | 41 | printf "Names of $THING: " | 
|  | 42 | test -r $THING | 
| Simon Butcher | 71ebc58 | 2016-06-23 20:02:07 +0100 | [diff] [blame] | 43 | 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] | 44 | if [ "x$BAD" = "x" ]; then | 
|  | 45 | echo "PASS" | 
|  | 46 | else | 
|  | 47 | echo "FAIL" | 
|  | 48 | echo "$BAD" | 
|  | 49 | FAIL=1 | 
|  | 50 | fi | 
|  | 51 | done | 
|  | 52 |  | 
|  | 53 | for THING in identifiers; do | 
|  | 54 | printf "Names of $THING: " | 
|  | 55 | test -r $THING | 
|  | 56 | BAD=$( grep -v '^mbedtls_[0-9a-z_]*[0-9a-z]$' $THING || true ) | 
|  | 57 | if [ "x$BAD" = "x" ]; then | 
|  | 58 | echo "PASS" | 
|  | 59 | else | 
|  | 60 | echo "FAIL" | 
|  | 61 | echo "$BAD" | 
|  | 62 | FAIL=1 | 
|  | 63 | fi | 
|  | 64 | done | 
|  | 65 |  | 
| Manuel Pégourié-Gonnard | f9aae83 | 2015-04-09 12:20:53 +0200 | [diff] [blame] | 66 | printf "Likely typos: " | 
|  | 67 | sort -u actual-macros enum-consts > _caps | 
|  | 68 | HEADERS=$( ls include/mbedtls/*.h | egrep -v 'compat-1\.3\.h' ) | 
|  | 69 | NL=' | 
|  | 70 | ' | 
| Manuel Pégourié-Gonnard | 6ad5d35 | 2015-05-28 15:08:28 +0200 | [diff] [blame] | 71 | sed -n 's/MBED..._[A-Z0-9_]*/\'"$NL"'&\'"$NL"/gp \ | 
| Manuel Pégourié-Gonnard | f9aae83 | 2015-04-09 12:20:53 +0200 | [diff] [blame] | 72 | $HEADERS library/*.c \ | 
|  | 73 | | grep MBEDTLS | sort -u > _MBEDTLS_XXX | 
|  | 74 | TYPOS=$( diff _caps _MBEDTLS_XXX | sed -n 's/^> //p' \ | 
| Manuel Pégourié-Gonnard | 32da9f6 | 2015-07-31 15:52:30 +0200 | [diff] [blame] | 75 | | egrep -v 'XXX|__|_$|^MBEDTLS_.*CONFIG_FILE$' || true ) | 
| Manuel Pégourié-Gonnard | f9aae83 | 2015-04-09 12:20:53 +0200 | [diff] [blame] | 76 | rm _MBEDTLS_XXX _caps | 
| Manuel Pégourié-Gonnard | 9afdc83 | 2015-08-04 17:15:13 +0200 | [diff] [blame] | 77 | if [ "x$TYPOS" = "x" ]; then | 
| Manuel Pégourié-Gonnard | f9aae83 | 2015-04-09 12:20:53 +0200 | [diff] [blame] | 78 | echo "PASS" | 
|  | 79 | else | 
|  | 80 | echo "FAIL" | 
|  | 81 | echo "$TYPOS" | 
|  | 82 | FAIL=1 | 
|  | 83 | fi | 
|  | 84 |  | 
| Simon Butcher | 71ebc58 | 2016-06-23 20:02:07 +0100 | [diff] [blame] | 85 | printf "\nOverall: " | 
| Manuel Pégourié-Gonnard | e137ea6 | 2015-04-09 10:47:44 +0200 | [diff] [blame] | 86 | if [ "$FAIL" -eq 0 ]; then | 
|  | 87 | rm macros actual-macros enum-consts identifiers exported-symbols | 
|  | 88 | echo "PASSED" | 
|  | 89 | exit 0 | 
|  | 90 | else | 
|  | 91 | echo "FAILED" | 
|  | 92 | exit 1 | 
|  | 93 | fi |