mbed TLS Build
tests/scripts/check-names.sh@0:cdf462088d13, 2017-01-05 (annotated)
- Committer:
- markrad
- Date:
- Thu Jan 05 00:18:44 2017 +0000
- Revision:
- 0:cdf462088d13
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
markrad | 0:cdf462088d13 | 1 | #!/bin/sh |
markrad | 0:cdf462088d13 | 2 | # |
markrad | 0:cdf462088d13 | 3 | # This file is part of mbed TLS (https://tls.mbed.org) |
markrad | 0:cdf462088d13 | 4 | # |
markrad | 0:cdf462088d13 | 5 | # Copyright (c) 2015-2016, ARM Limited, All Rights Reserved |
markrad | 0:cdf462088d13 | 6 | # |
markrad | 0:cdf462088d13 | 7 | # Purpose |
markrad | 0:cdf462088d13 | 8 | # |
markrad | 0:cdf462088d13 | 9 | # This script confirms that the naming of all symbols and identifiers in mbed |
markrad | 0:cdf462088d13 | 10 | # TLS are consistent with the house style and are also self-consistent. |
markrad | 0:cdf462088d13 | 11 | # |
markrad | 0:cdf462088d13 | 12 | set -eu |
markrad | 0:cdf462088d13 | 13 | |
markrad | 0:cdf462088d13 | 14 | if grep --version|head -n1|grep GNU >/dev/null; then :; else |
markrad | 0:cdf462088d13 | 15 | echo "This script requires GNU grep." |
markrad | 0:cdf462088d13 | 16 | exit 1 |
markrad | 0:cdf462088d13 | 17 | fi |
markrad | 0:cdf462088d13 | 18 | |
markrad | 0:cdf462088d13 | 19 | printf "Analysing source code...\n" |
markrad | 0:cdf462088d13 | 20 | |
markrad | 0:cdf462088d13 | 21 | tests/scripts/list-macros.sh |
markrad | 0:cdf462088d13 | 22 | tests/scripts/list-enum-consts.pl |
markrad | 0:cdf462088d13 | 23 | tests/scripts/list-identifiers.sh |
markrad | 0:cdf462088d13 | 24 | tests/scripts/list-symbols.sh |
markrad | 0:cdf462088d13 | 25 | |
markrad | 0:cdf462088d13 | 26 | FAIL=0 |
markrad | 0:cdf462088d13 | 27 | |
markrad | 0:cdf462088d13 | 28 | printf "\nExported symbols declared in header: " |
markrad | 0:cdf462088d13 | 29 | UNDECLARED=$( diff exported-symbols identifiers | sed -n -e 's/^< //p' ) |
markrad | 0:cdf462088d13 | 30 | if [ "x$UNDECLARED" = "x" ]; then |
markrad | 0:cdf462088d13 | 31 | echo "PASS" |
markrad | 0:cdf462088d13 | 32 | else |
markrad | 0:cdf462088d13 | 33 | echo "FAIL" |
markrad | 0:cdf462088d13 | 34 | echo "$UNDECLARED" |
markrad | 0:cdf462088d13 | 35 | FAIL=1 |
markrad | 0:cdf462088d13 | 36 | fi |
markrad | 0:cdf462088d13 | 37 | |
markrad | 0:cdf462088d13 | 38 | diff macros identifiers | sed -n -e 's/< //p' > actual-macros |
markrad | 0:cdf462088d13 | 39 | |
markrad | 0:cdf462088d13 | 40 | for THING in actual-macros enum-consts; do |
markrad | 0:cdf462088d13 | 41 | printf "Names of $THING: " |
markrad | 0:cdf462088d13 | 42 | test -r $THING |
markrad | 0:cdf462088d13 | 43 | BAD=$( grep -v '^MBEDTLS_[0-9A-Z_]*[0-9A-Z]$\|^YOTTA_[0-9A-Z_]*[0-9A-Z]$' $THING || true ) |
markrad | 0:cdf462088d13 | 44 | if [ "x$BAD" = "x" ]; then |
markrad | 0:cdf462088d13 | 45 | echo "PASS" |
markrad | 0:cdf462088d13 | 46 | else |
markrad | 0:cdf462088d13 | 47 | echo "FAIL" |
markrad | 0:cdf462088d13 | 48 | echo "$BAD" |
markrad | 0:cdf462088d13 | 49 | FAIL=1 |
markrad | 0:cdf462088d13 | 50 | fi |
markrad | 0:cdf462088d13 | 51 | done |
markrad | 0:cdf462088d13 | 52 | |
markrad | 0:cdf462088d13 | 53 | for THING in identifiers; do |
markrad | 0:cdf462088d13 | 54 | printf "Names of $THING: " |
markrad | 0:cdf462088d13 | 55 | test -r $THING |
markrad | 0:cdf462088d13 | 56 | BAD=$( grep -v '^mbedtls_[0-9a-z_]*[0-9a-z]$' $THING || true ) |
markrad | 0:cdf462088d13 | 57 | if [ "x$BAD" = "x" ]; then |
markrad | 0:cdf462088d13 | 58 | echo "PASS" |
markrad | 0:cdf462088d13 | 59 | else |
markrad | 0:cdf462088d13 | 60 | echo "FAIL" |
markrad | 0:cdf462088d13 | 61 | echo "$BAD" |
markrad | 0:cdf462088d13 | 62 | FAIL=1 |
markrad | 0:cdf462088d13 | 63 | fi |
markrad | 0:cdf462088d13 | 64 | done |
markrad | 0:cdf462088d13 | 65 | |
markrad | 0:cdf462088d13 | 66 | printf "Likely typos: " |
markrad | 0:cdf462088d13 | 67 | sort -u actual-macros enum-consts > _caps |
markrad | 0:cdf462088d13 | 68 | HEADERS=$( ls include/mbedtls/*.h | egrep -v 'compat-1\.3\.h' ) |
markrad | 0:cdf462088d13 | 69 | NL=' |
markrad | 0:cdf462088d13 | 70 | ' |
markrad | 0:cdf462088d13 | 71 | sed -n 's/MBED..._[A-Z0-9_]*/\'"$NL"'&\'"$NL"/gp \ |
markrad | 0:cdf462088d13 | 72 | $HEADERS library/*.c \ |
markrad | 0:cdf462088d13 | 73 | | grep MBEDTLS | sort -u > _MBEDTLS_XXX |
markrad | 0:cdf462088d13 | 74 | TYPOS=$( diff _caps _MBEDTLS_XXX | sed -n 's/^> //p' \ |
markrad | 0:cdf462088d13 | 75 | | egrep -v 'XXX|__|_$|^MBEDTLS_.*CONFIG_FILE$' || true ) |
markrad | 0:cdf462088d13 | 76 | rm _MBEDTLS_XXX _caps |
markrad | 0:cdf462088d13 | 77 | if [ "x$TYPOS" = "x" ]; then |
markrad | 0:cdf462088d13 | 78 | echo "PASS" |
markrad | 0:cdf462088d13 | 79 | else |
markrad | 0:cdf462088d13 | 80 | echo "FAIL" |
markrad | 0:cdf462088d13 | 81 | echo "$TYPOS" |
markrad | 0:cdf462088d13 | 82 | FAIL=1 |
markrad | 0:cdf462088d13 | 83 | fi |
markrad | 0:cdf462088d13 | 84 | |
markrad | 0:cdf462088d13 | 85 | printf "\nOverall: " |
markrad | 0:cdf462088d13 | 86 | if [ "$FAIL" -eq 0 ]; then |
markrad | 0:cdf462088d13 | 87 | rm macros actual-macros enum-consts identifiers exported-symbols |
markrad | 0:cdf462088d13 | 88 | echo "PASSED" |
markrad | 0:cdf462088d13 | 89 | exit 0 |
markrad | 0:cdf462088d13 | 90 | else |
markrad | 0:cdf462088d13 | 91 | echo "FAILED" |
markrad | 0:cdf462088d13 | 92 | exit 1 |
markrad | 0:cdf462088d13 | 93 | fi |