blob: 8f8dcd7162e12dcdca622e8e0c82732a50598440 [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útib7246ad2020-05-26 00:33:31 +02008#
Bence Szépkúti44bfbe32020-08-19 16:54:51 +02009# Copyright The Mbed TLS Contributors
Bence Szépkúti4e9f7122020-06-05 13:02:18 +020010# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
11#
12# This file is provided under the Apache License 2.0, or the
13# GNU General Public License v2.0 or later.
14#
15# **********
16# Apache License 2.0:
Bence Szépkúti09b4f192020-05-26 01:54:15 +020017#
18# Licensed under the Apache License, Version 2.0 (the "License"); you may
19# not use this file except in compliance with the License.
20# You may obtain a copy of the License at
21#
22# http://www.apache.org/licenses/LICENSE-2.0
23#
24# Unless required by applicable law or agreed to in writing, software
25# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
26# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27# See the License for the specific language governing permissions and
28# limitations under the License.
Bence Szépkútib7246ad2020-05-26 00:33:31 +020029#
Bence Szépkúti4e9f7122020-06-05 13:02:18 +020030# **********
31#
32# **********
33# GNU General Public License v2.0 or later:
34#
35# This program is free software; you can redistribute it and/or modify
36# it under the terms of the GNU General Public License as published by
37# the Free Software Foundation; either version 2 of the License, or
38# (at your option) any later version.
39#
40# This program is distributed in the hope that it will be useful,
41# but WITHOUT ANY WARRANTY; without even the implied warranty of
42# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
43# GNU General Public License for more details.
44#
45# You should have received a copy of the GNU General Public License along
46# with this program; if not, write to the Free Software Foundation, Inc.,
47# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
48#
49# **********
Manuel Pégourié-Gonnard4d5cc112014-11-25 12:21:48 +010050
51set -eu
52
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000053CONFIG_H='include/mbedtls/config.h'
Manuel Pégourié-Gonnardc5b849b2014-12-01 12:15:47 +010054
Manuel Pégourié-Gonnard4d5cc112014-11-25 12:21:48 +010055CLIENT='mini_client'
56
Manuel Pégourié-Gonnard47e02142015-03-18 16:52:20 +000057CFLAGS_EXEC='-fno-asynchronous-unwind-tables -Wl,--gc-section -ffunction-sections -fdata-sections'
Manuel Pégourié-Gonnardc5b849b2014-12-01 12:15:47 +010058CFLAGS_MEM=-g3
59
Manuel Pégourié-Gonnard4d5cc112014-11-25 12:21:48 +010060if [ -r $CONFIG_H ]; then :; else
61 echo "$CONFIG_H not found" >&2
62 exit 1
63fi
64
Manuel Pégourié-Gonnardf166c542014-12-01 11:30:56 +010065if grep -i cmake Makefile >/dev/null; then
66 echo "Not compatible with CMake" >&2
67 exit 1
68fi
69
Manuel Pégourié-Gonnard4a7ed712015-03-11 10:26:50 +000070if [ $( uname ) != Linux ]; then
71 echo "Only work on Linux" >&2
72 exit 1
73fi
74
Manuel Pégourié-Gonnardf166c542014-12-01 11:30:56 +010075if git status | grep -F $CONFIG_H >/dev/null 2>&1; then
76 echo "config.h not clean" >&2
77 exit 1
78fi
79
Manuel Pégourié-Gonnardc5b849b2014-12-01 12:15:47 +010080# make measurements with one configuration
81# usage: do_config <name> <unset-list> <server-args>
82do_config()
83{
84 NAME=$1
85 UNSET_LIST=$2
86 SERVER_ARGS=$3
87
88 echo ""
89 echo "config-$NAME:"
90 cp configs/config-$NAME.h $CONFIG_H
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020091 scripts/config.pl unset MBEDTLS_SSL_SRV_C
Manuel Pégourié-Gonnardc5b849b2014-12-01 12:15:47 +010092
93 for FLAG in $UNSET_LIST; do
94 scripts/config.pl unset $FLAG
95 done
96
Manuel Pégourié-Gonnarda6b95f02015-09-09 13:47:28 +020097 grep -F SSL_MAX_CONTENT_LEN $CONFIG_H || echo 'SSL_MAX_CONTENT_LEN=16384'
98
Manuel Pégourié-Gonnardc5b849b2014-12-01 12:15:47 +010099 printf " Executable size... "
100
101 make clean
102 CFLAGS=$CFLAGS_EXEC make OFLAGS=-Os lib >/dev/null 2>&1
103 cd programs
104 CFLAGS=$CFLAGS_EXEC make OFLAGS=-Os ssl/$CLIENT >/dev/null
105 strip ssl/$CLIENT
Manuel Pégourié-Gonnard4a7ed712015-03-11 10:26:50 +0000106 stat -c '%s' ssl/$CLIENT
Manuel Pégourié-Gonnardc5b849b2014-12-01 12:15:47 +0100107 cd ..
108
109 printf " Peak ram usage... "
110
111 make clean
112 CFLAGS=$CFLAGS_MEM make OFLAGS=-Os lib >/dev/null 2>&1
113 cd programs
114 CFLAGS=$CFLAGS_MEM make OFLAGS=-Os ssl/$CLIENT >/dev/null
115 cd ..
116
117 ./ssl_server2 $SERVER_ARGS >/dev/null &
118 SRV_PID=$!
119 sleep 1;
120
121 if valgrind --tool=massif --stacks=yes programs/ssl/$CLIENT >/dev/null 2>&1
122 then
123 FAILED=0
124 else
125 echo "client failed" >&2
126 FAILED=1
127 fi
128
129 kill $SRV_PID
130 wait $SRV_PID
131
132 scripts/massif_max.pl massif.out.*
133 mv massif.out.* massif-$NAME.$$
134}
135
Manuel Pégourié-Gonnardf166c542014-12-01 11:30:56 +0100136# preparation
137
Manuel Pégourié-Gonnard4d5cc112014-11-25 12:21:48 +0100138CONFIG_BAK=${CONFIG_H}.bak
139cp $CONFIG_H $CONFIG_BAK
140
Manuel Pégourié-Gonnardf166c542014-12-01 11:30:56 +0100141rm -f massif.out.*
142
143printf "building server... "
144
145make clean
146make lib >/dev/null 2>&1
147(cd programs && make ssl/ssl_server2) >/dev/null
148cp programs/ssl/ssl_server2 .
149
150echo "done"
151
Manuel Pégourié-Gonnardc5b849b2014-12-01 12:15:47 +0100152# actual measurements
Manuel Pégourié-Gonnardf166c542014-12-01 11:30:56 +0100153
Manuel Pégourié-Gonnardc5b849b2014-12-01 12:15:47 +0100154do_config "ccm-psk-tls1_2" \
155 "" \
156 "psk=000102030405060708090A0B0C0D0E0F"
Manuel Pégourié-Gonnard4d5cc112014-11-25 12:21:48 +0100157
Manuel Pégourié-Gonnardc5b849b2014-12-01 12:15:47 +0100158do_config "suite-b" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200159 "MBEDTLS_BASE64_C MBEDTLS_PEM_PARSE_C MBEDTLS_CERTS_C" \
Manuel Pégourié-Gonnardc5b849b2014-12-01 12:15:47 +0100160 ""
Manuel Pégourié-Gonnardf166c542014-12-01 11:30:56 +0100161
162# cleanup
163
Manuel Pégourié-Gonnard4d5cc112014-11-25 12:21:48 +0100164mv $CONFIG_BAK $CONFIG_H
Manuel Pégourié-Gonnardf166c542014-12-01 11:30:56 +0100165make clean
166rm ssl_server2
Manuel Pégourié-Gonnard4d5cc112014-11-25 12:21:48 +0100167
168exit $FAILED