blob: 15693a0af4fa44c9d71da31db761ae31a1f12eec [file] [log] [blame]
Manuel Pégourié-Gonnard4d5cc112014-11-25 12:21:48 +01001#!/bin/sh
2
3# Measure memory usage of a minimal client using a small configuration
Manuel Pégourié-Gonnardf166c542014-12-01 11:30:56 +01004# Currently hardwired to ccm-psk and suite-b, may be expanded later
5#
6# Use different build options for measuring executable size and memory usage,
7# since for memory we want debug information.
Bence Szépkúti700ee442020-05-26 00:33:31 +02008#
9# Copyright (C) 2014-2015, Arm Limited, All Rights Reserved
Bence Szépkútic7da1fe2020-05-26 01:54:15 +020010# SPDX-License-Identifier: Apache-2.0
11#
12# Licensed under the Apache License, Version 2.0 (the "License"); you may
13# not use this file except in compliance with the License.
14# You may obtain a copy of the License at
15#
16# http://www.apache.org/licenses/LICENSE-2.0
17#
18# Unless required by applicable law or agreed to in writing, software
19# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
20# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21# See the License for the specific language governing permissions and
22# limitations under the License.
Bence Szépkúti700ee442020-05-26 00:33:31 +020023#
24# This file is part of Mbed TLS (https://tls.mbed.org)
Manuel Pégourié-Gonnard4d5cc112014-11-25 12:21:48 +010025
26set -eu
27
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000028CONFIG_H='include/mbedtls/config.h'
Manuel Pégourié-Gonnardc5b849b2014-12-01 12:15:47 +010029
Manuel Pégourié-Gonnard4d5cc112014-11-25 12:21:48 +010030CLIENT='mini_client'
31
Manuel Pégourié-Gonnard47e02142015-03-18 16:52:20 +000032CFLAGS_EXEC='-fno-asynchronous-unwind-tables -Wl,--gc-section -ffunction-sections -fdata-sections'
Manuel Pégourié-Gonnardc5b849b2014-12-01 12:15:47 +010033CFLAGS_MEM=-g3
34
Manuel Pégourié-Gonnard4d5cc112014-11-25 12:21:48 +010035if [ -r $CONFIG_H ]; then :; else
36 echo "$CONFIG_H not found" >&2
37 exit 1
38fi
39
Manuel Pégourié-Gonnardf166c542014-12-01 11:30:56 +010040if grep -i cmake Makefile >/dev/null; then
41 echo "Not compatible with CMake" >&2
42 exit 1
43fi
44
Manuel Pégourié-Gonnard4a7ed712015-03-11 10:26:50 +000045if [ $( uname ) != Linux ]; then
46 echo "Only work on Linux" >&2
47 exit 1
48fi
49
Manuel Pégourié-Gonnardf166c542014-12-01 11:30:56 +010050if git status | grep -F $CONFIG_H >/dev/null 2>&1; then
51 echo "config.h not clean" >&2
52 exit 1
53fi
54
Manuel Pégourié-Gonnardc5b849b2014-12-01 12:15:47 +010055# make measurements with one configuration
56# usage: do_config <name> <unset-list> <server-args>
57do_config()
58{
59 NAME=$1
60 UNSET_LIST=$2
61 SERVER_ARGS=$3
62
63 echo ""
64 echo "config-$NAME:"
65 cp configs/config-$NAME.h $CONFIG_H
Gilles Peskine5d46f6a2019-07-27 23:52:53 +020066 scripts/config.py unset MBEDTLS_SSL_SRV_C
Manuel Pégourié-Gonnardc5b849b2014-12-01 12:15:47 +010067
68 for FLAG in $UNSET_LIST; do
Gilles Peskine5d46f6a2019-07-27 23:52:53 +020069 scripts/config.py unset $FLAG
Manuel Pégourié-Gonnardc5b849b2014-12-01 12:15:47 +010070 done
71
Manuel Pégourié-Gonnarda6b95f02015-09-09 13:47:28 +020072 grep -F SSL_MAX_CONTENT_LEN $CONFIG_H || echo 'SSL_MAX_CONTENT_LEN=16384'
73
Manuel Pégourié-Gonnardc5b849b2014-12-01 12:15:47 +010074 printf " Executable size... "
75
76 make clean
77 CFLAGS=$CFLAGS_EXEC make OFLAGS=-Os lib >/dev/null 2>&1
78 cd programs
79 CFLAGS=$CFLAGS_EXEC make OFLAGS=-Os ssl/$CLIENT >/dev/null
80 strip ssl/$CLIENT
Manuel Pégourié-Gonnard4a7ed712015-03-11 10:26:50 +000081 stat -c '%s' ssl/$CLIENT
Manuel Pégourié-Gonnardc5b849b2014-12-01 12:15:47 +010082 cd ..
83
84 printf " Peak ram usage... "
85
86 make clean
87 CFLAGS=$CFLAGS_MEM make OFLAGS=-Os lib >/dev/null 2>&1
88 cd programs
89 CFLAGS=$CFLAGS_MEM make OFLAGS=-Os ssl/$CLIENT >/dev/null
90 cd ..
91
92 ./ssl_server2 $SERVER_ARGS >/dev/null &
93 SRV_PID=$!
94 sleep 1;
95
96 if valgrind --tool=massif --stacks=yes programs/ssl/$CLIENT >/dev/null 2>&1
97 then
98 FAILED=0
99 else
100 echo "client failed" >&2
101 FAILED=1
102 fi
103
104 kill $SRV_PID
105 wait $SRV_PID
106
107 scripts/massif_max.pl massif.out.*
108 mv massif.out.* massif-$NAME.$$
109}
110
Manuel Pégourié-Gonnardf166c542014-12-01 11:30:56 +0100111# preparation
112
Manuel Pégourié-Gonnard4d5cc112014-11-25 12:21:48 +0100113CONFIG_BAK=${CONFIG_H}.bak
114cp $CONFIG_H $CONFIG_BAK
115
Manuel Pégourié-Gonnardf166c542014-12-01 11:30:56 +0100116rm -f massif.out.*
117
118printf "building server... "
119
120make clean
121make lib >/dev/null 2>&1
122(cd programs && make ssl/ssl_server2) >/dev/null
123cp programs/ssl/ssl_server2 .
124
125echo "done"
126
Manuel Pégourié-Gonnardc5b849b2014-12-01 12:15:47 +0100127# actual measurements
Manuel Pégourié-Gonnardf166c542014-12-01 11:30:56 +0100128
Manuel Pégourié-Gonnardc5b849b2014-12-01 12:15:47 +0100129do_config "ccm-psk-tls1_2" \
130 "" \
131 "psk=000102030405060708090A0B0C0D0E0F"
Manuel Pégourié-Gonnard4d5cc112014-11-25 12:21:48 +0100132
Manuel Pégourié-Gonnardc5b849b2014-12-01 12:15:47 +0100133do_config "suite-b" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200134 "MBEDTLS_BASE64_C MBEDTLS_PEM_PARSE_C MBEDTLS_CERTS_C" \
Manuel Pégourié-Gonnardc5b849b2014-12-01 12:15:47 +0100135 ""
Manuel Pégourié-Gonnardf166c542014-12-01 11:30:56 +0100136
137# cleanup
138
Manuel Pégourié-Gonnard4d5cc112014-11-25 12:21:48 +0100139mv $CONFIG_BAK $CONFIG_H
Manuel Pégourié-Gonnardf166c542014-12-01 11:30:56 +0100140make clean
141rm ssl_server2
Manuel Pégourié-Gonnard4d5cc112014-11-25 12:21:48 +0100142
143exit $FAILED