blob: 4c66440e250b16c3dcf7f703c53dfbce0287b557 [file] [log] [blame] [raw]
Manuel Pégourié-Gonnarde137ea62015-04-09 10:47:44 +02001#!/bin/sh
Simon Butcher71ebc582016-06-23 20:02:07 +01002#
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é-Gonnarde137ea62015-04-09 10:47:44 +020012set -eu
Simon Butcher71ebc582016-06-23 20:02:07 +010013
14if grep --version|head -n1|grep GNU >/dev/null; then :; else
Ron Eldorbf007d22016-12-15 14:42:37 +020015 echo "This script requires GNU grep.">&2
Simon Butcher71ebc582016-06-23 20:02:07 +010016 exit 1
17fi
18
19printf "Analysing source code...\n"
Manuel Pégourié-Gonnarde137ea62015-04-09 10:47:44 +020020
21tests/scripts/list-macros.sh
22tests/scripts/list-enum-consts.pl
23tests/scripts/list-identifiers.sh
24tests/scripts/list-symbols.sh
25
26FAIL=0
27
Simon Butcher71ebc582016-06-23 20:02:07 +010028printf "\nExported symbols declared in header: "
Manuel Pégourié-Gonnarde137ea62015-04-09 10:47:44 +020029UNDECLARED=$( diff exported-symbols identifiers | sed -n -e 's/^< //p' )
Manuel Pégourié-Gonnard9afdc832015-08-04 17:15:13 +020030if [ "x$UNDECLARED" = "x" ]; then
Manuel Pégourié-Gonnarde137ea62015-04-09 10:47:44 +020031 echo "PASS"
32else
33 echo "FAIL"
34 echo "$UNDECLARED"
35 FAIL=1
36fi
37
38diff macros identifiers | sed -n -e 's/< //p' > actual-macros
39
40for THING in actual-macros enum-consts; do
41 printf "Names of $THING: "
42 test -r $THING
Simon Butcher71ebc582016-06-23 20:02:07 +010043 BAD=$( grep -v '^MBEDTLS_[0-9A-Z_]*[0-9A-Z]$\|^YOTTA_[0-9A-Z_]*[0-9A-Z]$' $THING || true )
Manuel Pégourié-Gonnarde137ea62015-04-09 10:47:44 +020044 if [ "x$BAD" = "x" ]; then
45 echo "PASS"
46 else
47 echo "FAIL"
48 echo "$BAD"
49 FAIL=1
50 fi
51done
52
53for 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
64done
65
Manuel Pégourié-Gonnardf9aae832015-04-09 12:20:53 +020066printf "Likely typos: "
67sort -u actual-macros enum-consts > _caps
68HEADERS=$( ls include/mbedtls/*.h | egrep -v 'compat-1\.3\.h' )
69NL='
70'
Manuel Pégourié-Gonnard6ad5d352015-05-28 15:08:28 +020071sed -n 's/MBED..._[A-Z0-9_]*/\'"$NL"'&\'"$NL"/gp \
Manuel Pégourié-Gonnardf9aae832015-04-09 12:20:53 +020072 $HEADERS library/*.c \
73 | grep MBEDTLS | sort -u > _MBEDTLS_XXX
74TYPOS=$( diff _caps _MBEDTLS_XXX | sed -n 's/^> //p' \
Manuel Pégourié-Gonnard32da9f62015-07-31 15:52:30 +020075 | egrep -v 'XXX|__|_$|^MBEDTLS_.*CONFIG_FILE$' || true )
Manuel Pégourié-Gonnardf9aae832015-04-09 12:20:53 +020076rm _MBEDTLS_XXX _caps
Manuel Pégourié-Gonnard9afdc832015-08-04 17:15:13 +020077if [ "x$TYPOS" = "x" ]; then
Manuel Pégourié-Gonnardf9aae832015-04-09 12:20:53 +020078 echo "PASS"
79else
80 echo "FAIL"
81 echo "$TYPOS"
82 FAIL=1
83fi
84
Simon Butcher71ebc582016-06-23 20:02:07 +010085printf "\nOverall: "
Manuel Pégourié-Gonnarde137ea62015-04-09 10:47:44 +020086if [ "$FAIL" -eq 0 ]; then
87 rm macros actual-macros enum-consts identifiers exported-symbols
88 echo "PASSED"
89 exit 0
90else
91 echo "FAILED"
92 exit 1
93fi