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 | |
| 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: " |
Jarno Lamsa | 8557fc9 | 2019-04-26 16:22:10 +0300 | [diff] [blame] | 29 | diff exported-symbols identifiers | sed -n -e 's/^< //p' > undeclared |
| 30 | |
| 31 | FILTERED=$( diff tests/scripts/whitelist undeclared | sed -n -e 's/^< //p') |
| 32 | |
| 33 | if [ "x$FILTERED" = "x" ]; then |
Manuel Pégourié-Gonnard | e137ea6 | 2015-04-09 10:47:44 +0200 | [diff] [blame] | 34 | echo "PASS" |
| 35 | else |
| 36 | echo "FAIL" |
Jarno Lamsa | 8557fc9 | 2019-04-26 16:22:10 +0300 | [diff] [blame] | 37 | echo "$FILTERED" |
Manuel Pégourié-Gonnard | e137ea6 | 2015-04-09 10:47:44 +0200 | [diff] [blame] | 38 | FAIL=1 |
| 39 | fi |
| 40 | |
| 41 | diff macros identifiers | sed -n -e 's/< //p' > actual-macros |
| 42 | |
| 43 | for THING in actual-macros enum-consts; do |
| 44 | printf "Names of $THING: " |
| 45 | test -r $THING |
Simon Butcher | 3ad2efd | 2018-05-02 14:49:38 +0100 | [diff] [blame] | 46 | BAD=$( grep -v '^MBEDTLS_[0-9A-Z_]*[0-9A-Z]$' $THING || true ) |
Manuel Pégourié-Gonnard | e137ea6 | 2015-04-09 10:47:44 +0200 | [diff] [blame] | 47 | if [ "x$BAD" = "x" ]; then |
| 48 | echo "PASS" |
| 49 | else |
| 50 | echo "FAIL" |
| 51 | echo "$BAD" |
| 52 | FAIL=1 |
| 53 | fi |
| 54 | done |
| 55 | |
| 56 | for THING in identifiers; 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 | |
Manuel Pégourié-Gonnard | f9aae83 | 2015-04-09 12:20:53 +0200 | [diff] [blame] | 69 | printf "Likely typos: " |
| 70 | sort -u actual-macros enum-consts > _caps |
| 71 | HEADERS=$( ls include/mbedtls/*.h | egrep -v 'compat-1\.3\.h' ) |
| 72 | NL=' |
| 73 | ' |
Manuel Pégourié-Gonnard | 6ad5d35 | 2015-05-28 15:08:28 +0200 | [diff] [blame] | 74 | sed -n 's/MBED..._[A-Z0-9_]*/\'"$NL"'&\'"$NL"/gp \ |
Manuel Pégourié-Gonnard | f9aae83 | 2015-04-09 12:20:53 +0200 | [diff] [blame] | 75 | $HEADERS library/*.c \ |
| 76 | | grep MBEDTLS | sort -u > _MBEDTLS_XXX |
| 77 | TYPOS=$( diff _caps _MBEDTLS_XXX | sed -n 's/^> //p' \ |
Manuel Pégourié-Gonnard | 32da9f6 | 2015-07-31 15:52:30 +0200 | [diff] [blame] | 78 | | egrep -v 'XXX|__|_$|^MBEDTLS_.*CONFIG_FILE$' || true ) |
Manuel Pégourié-Gonnard | f9aae83 | 2015-04-09 12:20:53 +0200 | [diff] [blame] | 79 | rm _MBEDTLS_XXX _caps |
Manuel Pégourié-Gonnard | 9afdc83 | 2015-08-04 17:15:13 +0200 | [diff] [blame] | 80 | if [ "x$TYPOS" = "x" ]; then |
Manuel Pégourié-Gonnard | f9aae83 | 2015-04-09 12:20:53 +0200 | [diff] [blame] | 81 | echo "PASS" |
| 82 | else |
| 83 | echo "FAIL" |
| 84 | echo "$TYPOS" |
| 85 | FAIL=1 |
| 86 | fi |
| 87 | |
Simon Butcher | 71ebc58 | 2016-06-23 20:02:07 +0100 | [diff] [blame] | 88 | printf "\nOverall: " |
Manuel Pégourié-Gonnard | e137ea6 | 2015-04-09 10:47:44 +0200 | [diff] [blame] | 89 | if [ "$FAIL" -eq 0 ]; then |
Jarno Lamsa | 8557fc9 | 2019-04-26 16:22:10 +0300 | [diff] [blame] | 90 | rm macros actual-macros enum-consts identifiers exported-symbols undeclared |
Manuel Pégourié-Gonnard | e137ea6 | 2015-04-09 10:47:44 +0200 | [diff] [blame] | 91 | echo "PASSED" |
| 92 | exit 0 |
| 93 | else |
| 94 | echo "FAILED" |
| 95 | exit 1 |
| 96 | fi |