blob: 6d9ab0ea302b5234637d4def8b367af0031b73bc [file] [log] [blame]
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
13
Simon Butcher71ebc582016-06-23 20:02:07 +010014if 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"
20
Manuel Pégourié-Gonnarde137ea62015-04-09 10:47:44 +020021tests/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: "
Jarno Lamsace3cb642019-04-29 12:07:43 +030029UNDECLARED=$(diff exported-symbols identifiers | sed -n -e 's/^< //p') > undeclared
Jarno Lamsa8557fc92019-04-26 16:22:10 +030030
31FILTERED=$( diff tests/scripts/whitelist undeclared | sed -n -e 's/^< //p')
32
Jarno Lamsace3cb642019-04-29 12:07:43 +030033if [ "x$UNDECLARED" != "x" ]; then
Jarno Lamsa8557fc92019-04-26 16:22:10 +030034if [ "x$FILTERED" = "x" ]; then
Manuel Pégourié-Gonnarde137ea62015-04-09 10:47:44 +020035 echo "PASS"
36else
37 echo "FAIL"
Jarno Lamsa8557fc92019-04-26 16:22:10 +030038 echo "$FILTERED"
Manuel Pégourié-Gonnarde137ea62015-04-09 10:47:44 +020039 FAIL=1
40fi
Jarno Lamsace3cb642019-04-29 12:07:43 +030041else
42 echo "PASS"
43fi
Manuel Pégourié-Gonnarde137ea62015-04-09 10:47:44 +020044
45diff macros identifiers | sed -n -e 's/< //p' > actual-macros
46
47for THING in actual-macros enum-consts; do
48 printf "Names of $THING: "
49 test -r $THING
Simon Butcher3ad2efd2018-05-02 14:49:38 +010050 BAD=$( grep -v '^MBEDTLS_[0-9A-Z_]*[0-9A-Z]$' $THING || true )
Manuel Pégourié-Gonnarde137ea62015-04-09 10:47:44 +020051 if [ "x$BAD" = "x" ]; then
52 echo "PASS"
53 else
54 echo "FAIL"
55 echo "$BAD"
56 FAIL=1
57 fi
58done
59
60for THING in identifiers; do
61 printf "Names of $THING: "
62 test -r $THING
63 BAD=$( grep -v '^mbedtls_[0-9a-z_]*[0-9a-z]$' $THING || true )
64 if [ "x$BAD" = "x" ]; then
65 echo "PASS"
66 else
67 echo "FAIL"
68 echo "$BAD"
69 FAIL=1
70 fi
71done
72
Manuel Pégourié-Gonnardf9aae832015-04-09 12:20:53 +020073printf "Likely typos: "
74sort -u actual-macros enum-consts > _caps
75HEADERS=$( ls include/mbedtls/*.h | egrep -v 'compat-1\.3\.h' )
76NL='
77'
Manuel Pégourié-Gonnard6ad5d352015-05-28 15:08:28 +020078sed -n 's/MBED..._[A-Z0-9_]*/\'"$NL"'&\'"$NL"/gp \
Manuel Pégourié-Gonnardf9aae832015-04-09 12:20:53 +020079 $HEADERS library/*.c \
80 | grep MBEDTLS | sort -u > _MBEDTLS_XXX
81TYPOS=$( diff _caps _MBEDTLS_XXX | sed -n 's/^> //p' \
Manuel Pégourié-Gonnard32da9f62015-07-31 15:52:30 +020082 | egrep -v 'XXX|__|_$|^MBEDTLS_.*CONFIG_FILE$' || true )
Manuel Pégourié-Gonnardf9aae832015-04-09 12:20:53 +020083rm _MBEDTLS_XXX _caps
Manuel Pégourié-Gonnard9afdc832015-08-04 17:15:13 +020084if [ "x$TYPOS" = "x" ]; then
Manuel Pégourié-Gonnardf9aae832015-04-09 12:20:53 +020085 echo "PASS"
86else
87 echo "FAIL"
88 echo "$TYPOS"
89 FAIL=1
90fi
91
Simon Butcher71ebc582016-06-23 20:02:07 +010092printf "\nOverall: "
Manuel Pégourié-Gonnarde137ea62015-04-09 10:47:44 +020093if [ "$FAIL" -eq 0 ]; then
Jarno Lamsa8557fc92019-04-26 16:22:10 +030094 rm macros actual-macros enum-consts identifiers exported-symbols undeclared
Manuel Pégourié-Gonnarde137ea62015-04-09 10:47:44 +020095 echo "PASSED"
96 exit 0
97else
98 echo "FAILED"
99 exit 1
100fi