blob: e9019e4169cc9d49cbea612145d0a1195bcae603 [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#
9# Copyright (C) 2014-2015, Arm Limited, All Rights Reserved
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# **********
50#
Bence Szépkútib7246ad2020-05-26 00:33:31 +020051# This file is part of Mbed TLS (https://tls.mbed.org)
Manuel Pégourié-Gonnard4d5cc112014-11-25 12:21:48 +010052
53set -eu
54
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000055CONFIG_H='include/mbedtls/config.h'
Manuel Pégourié-Gonnardc5b849b2014-12-01 12:15:47 +010056
Manuel Pégourié-Gonnard4d5cc112014-11-25 12:21:48 +010057CLIENT='mini_client'
58
Manuel Pégourié-Gonnard47e02142015-03-18 16:52:20 +000059CFLAGS_EXEC='-fno-asynchronous-unwind-tables -Wl,--gc-section -ffunction-sections -fdata-sections'
Manuel Pégourié-Gonnardc5b849b2014-12-01 12:15:47 +010060CFLAGS_MEM=-g3
61
Manuel Pégourié-Gonnard4d5cc112014-11-25 12:21:48 +010062if [ -r $CONFIG_H ]; then :; else
63 echo "$CONFIG_H not found" >&2
64 exit 1
65fi
66
Manuel Pégourié-Gonnardf166c542014-12-01 11:30:56 +010067if grep -i cmake Makefile >/dev/null; then
68 echo "Not compatible with CMake" >&2
69 exit 1
70fi
71
Manuel Pégourié-Gonnard4a7ed712015-03-11 10:26:50 +000072if [ $( uname ) != Linux ]; then
73 echo "Only work on Linux" >&2
74 exit 1
75fi
76
Manuel Pégourié-Gonnardf166c542014-12-01 11:30:56 +010077if git status | grep -F $CONFIG_H >/dev/null 2>&1; then
78 echo "config.h not clean" >&2
79 exit 1
80fi
81
Manuel Pégourié-Gonnardc5b849b2014-12-01 12:15:47 +010082# make measurements with one configuration
83# usage: do_config <name> <unset-list> <server-args>
84do_config()
85{
86 NAME=$1
87 UNSET_LIST=$2
88 SERVER_ARGS=$3
89
90 echo ""
91 echo "config-$NAME:"
92 cp configs/config-$NAME.h $CONFIG_H
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020093 scripts/config.pl unset MBEDTLS_SSL_SRV_C
Manuel Pégourié-Gonnardc5b849b2014-12-01 12:15:47 +010094
95 for FLAG in $UNSET_LIST; do
96 scripts/config.pl unset $FLAG
97 done
98
Manuel Pégourié-Gonnarda6b95f02015-09-09 13:47:28 +020099 grep -F SSL_MAX_CONTENT_LEN $CONFIG_H || echo 'SSL_MAX_CONTENT_LEN=16384'
100
Manuel Pégourié-Gonnardc5b849b2014-12-01 12:15:47 +0100101 printf " Executable size... "
102
103 make clean
104 CFLAGS=$CFLAGS_EXEC make OFLAGS=-Os lib >/dev/null 2>&1
105 cd programs
106 CFLAGS=$CFLAGS_EXEC make OFLAGS=-Os ssl/$CLIENT >/dev/null
107 strip ssl/$CLIENT
Manuel Pégourié-Gonnard4a7ed712015-03-11 10:26:50 +0000108 stat -c '%s' ssl/$CLIENT
Manuel Pégourié-Gonnardc5b849b2014-12-01 12:15:47 +0100109 cd ..
110
111 printf " Peak ram usage... "
112
113 make clean
114 CFLAGS=$CFLAGS_MEM make OFLAGS=-Os lib >/dev/null 2>&1
115 cd programs
116 CFLAGS=$CFLAGS_MEM make OFLAGS=-Os ssl/$CLIENT >/dev/null
117 cd ..
118
119 ./ssl_server2 $SERVER_ARGS >/dev/null &
120 SRV_PID=$!
121 sleep 1;
122
123 if valgrind --tool=massif --stacks=yes programs/ssl/$CLIENT >/dev/null 2>&1
124 then
125 FAILED=0
126 else
127 echo "client failed" >&2
128 FAILED=1
129 fi
130
131 kill $SRV_PID
132 wait $SRV_PID
133
134 scripts/massif_max.pl massif.out.*
135 mv massif.out.* massif-$NAME.$$
136}
137
Manuel Pégourié-Gonnardf166c542014-12-01 11:30:56 +0100138# preparation
139
Manuel Pégourié-Gonnard4d5cc112014-11-25 12:21:48 +0100140CONFIG_BAK=${CONFIG_H}.bak
141cp $CONFIG_H $CONFIG_BAK
142
Manuel Pégourié-Gonnardf166c542014-12-01 11:30:56 +0100143rm -f massif.out.*
144
145printf "building server... "
146
147make clean
148make lib >/dev/null 2>&1
149(cd programs && make ssl/ssl_server2) >/dev/null
150cp programs/ssl/ssl_server2 .
151
152echo "done"
153
Manuel Pégourié-Gonnardc5b849b2014-12-01 12:15:47 +0100154# actual measurements
Manuel Pégourié-Gonnardf166c542014-12-01 11:30:56 +0100155
Manuel Pégourié-Gonnardc5b849b2014-12-01 12:15:47 +0100156do_config "ccm-psk-tls1_2" \
157 "" \
158 "psk=000102030405060708090A0B0C0D0E0F"
Manuel Pégourié-Gonnard4d5cc112014-11-25 12:21:48 +0100159
Manuel Pégourié-Gonnardc5b849b2014-12-01 12:15:47 +0100160do_config "suite-b" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200161 "MBEDTLS_BASE64_C MBEDTLS_PEM_PARSE_C MBEDTLS_CERTS_C" \
Manuel Pégourié-Gonnardc5b849b2014-12-01 12:15:47 +0100162 ""
Manuel Pégourié-Gonnardf166c542014-12-01 11:30:56 +0100163
164# cleanup
165
Manuel Pégourié-Gonnard4d5cc112014-11-25 12:21:48 +0100166mv $CONFIG_BAK $CONFIG_H
Manuel Pégourié-Gonnardf166c542014-12-01 11:30:56 +0100167make clean
168rm ssl_server2
Manuel Pégourié-Gonnard4d5cc112014-11-25 12:21:48 +0100169
170exit $FAILED