Refactoring of aes-perf/sha-perf benchmark code in xtest
1. Moved verbosity macros and defines for default values into the common header
2. Minor fixes
Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
Signed-off-by: Igor Opaniuk <igor.opaniuk@linaro.org>
diff --git a/host/xtest/aes_perf.c b/host/xtest/aes_perf.c
index 44bdbce..62a5417 100644
--- a/host/xtest/aes_perf.c
+++ b/host/xtest/aes_perf.c
@@ -39,18 +39,7 @@
#include <tee_client_api.h>
#include "ta_aes_perf.h"
-#include "aes_perf.h"
-
-#define _verbose(lvl, ...) \
- do { \
- if (verbosity >= lvl) { \
- printf(__VA_ARGS__); \
- fflush(stdout); \
- } \
- } while (0)
-
-#define verbose(...) _verbose(1, __VA_ARGS__)
-#define vverbose(...) _verbose(2, __VA_ARGS__)
+#include "crypto_common.h"
/*
* TEE client stuff
@@ -394,15 +383,17 @@
*/
size_t size = 1024; /* Buffer size (-s) */
- unsigned int n = 5000; /* Number of measurements (-n) */
- unsigned int l = 1; /* Inner loops (-l) */
- int verbosity = 0; /* Verbosity (-v) */
+ unsigned int n = CRYPTO_DEF_COUNT; /*Number of measurements (-n)*/
+ unsigned int l = CRYPTO_DEF_LOOPS; /* Inner loops (-l) */
+ int verbosity = CRYPTO_DEF_VERBOSITY; /* Verbosity (-v) */
int decrypt = 0; /* Encrypt by default, -d to decrypt */
- int keysize = 128; /* AES key size (-k) */
+ int keysize = AES_128; /* AES key size (-k) */
int mode = TA_AES_ECB; /* AES mode (-m) */
- int random_in = 0; /* Get input data from /dev/urandom (-r) */
- int in_place = 0; /* 1: use same buffer for in and out (-i) */
- int warmup = 2; /* Start with a 2-second busy loop (-w) */
+ /* Get input data from /dev/urandom (-r) */
+ int random_in = CRYPTO_USE_RANDOM;
+ /* Use same buffer for in and out (-i) */
+ int in_place = AES_PERF_INPLACE;
+ int warmup = CRYPTO_DEF_WARMUP; /* Start with a 2-second busy loop (-w) */
/* Parse command line */
for (i = 1; i < argc; i++) {
diff --git a/host/xtest/aes_perf.h b/host/xtest/crypto_common.h
similarity index 63%
rename from host/xtest/aes_perf.h
rename to host/xtest/crypto_common.h
index c4be316..cd9edd4 100644
--- a/host/xtest/aes_perf.h
+++ b/host/xtest/crypto_common.h
@@ -25,14 +25,49 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef XTEST_AES_PERF_H
-#define XTEST_AES_PERF_H
+#ifndef XTEST_CRYPTO_COMMON_H
+#define XTEST_CRYPTO_COMMON_H
#include "ta_aes_perf.h"
+#include "ta_sha_perf.h"
+
+
+
+
+#define AES_PERF_INPLACE 0
+
+#define CRYPTO_DEF_LOOPS 1 /* Default amount of inner loops */
+
+#define CRYPTO_USE_RANDOM 1 /* Get input data from /dev/urandom */
+#define CRYPTO_NOT_RANDOM 0
+
+#define CRYPTO_DEF_WARMUP 2 /* Start with a 2-second busy loop */
+#define CRYPTO_DEF_COUNT 5000 /* Default number of measurements */
+#define CRYPTO_DEF_VERBOSITY 0
+
+
+#define _verbose(lvl, ...) \
+ do { \
+ if (verbosity >= lvl) { \
+ printf(__VA_ARGS__); \
+ fflush(stdout); \
+ } \
+ } while (0)
+
+#define verbose(...) _verbose(1, __VA_ARGS__)
+#define vverbose(...) _verbose(2, __VA_ARGS__)
+
int aes_perf_runner_cmd_parser(int argc, char *argv[]);
void aes_perf_run_test(int mode, int keysize, int decrypt, size_t size,
unsigned int n, unsigned int l, int random_in,
int in_place, int warmup, int verbosity);
-#endif /* XTEST_AES_PERF_H */
+int sha_perf_runner_cmd_parser(int argc, char *argv[]);
+void sha_perf_run_test(int algo, size_t size, unsigned int n,
+ unsigned int l, int random_in, int offset,
+ int warmup, int verbosity);
+
+
+
+#endif /* XTEST_CRYPTO_PERF_H */
diff --git a/host/xtest/sha_perf.c b/host/xtest/sha_perf.c
index 8045e7e..fa757d9 100644
--- a/host/xtest/sha_perf.c
+++ b/host/xtest/sha_perf.c
@@ -39,18 +39,7 @@
#include <adbg.h>
#include <tee_client_api.h>
-#include "sha_perf.h"
-
-#define _verbose(lvl, ...) \
- do { \
- if (verbosity >= lvl) { \
- printf(__VA_ARGS__); \
- fflush(stdout); \
- } \
- } while (0)
-
-#define verbose(...) _verbose(1, __VA_ARGS__)
-#define vverbose(...) _verbose(2, __VA_ARGS__)
+#include "crypto_common.h"
/*
* TEE client stuff
@@ -418,13 +407,15 @@
/* Command line params */
size_t size = 1024; /* Buffer size (-s) */
- unsigned int n = 5000; /* Number of measurements (-n) */
- unsigned int l = 1; /* Inner loops (-l) */
- int verbosity = 0; /* Verbosity (-v) */
+ unsigned int n = CRYPTO_DEF_COUNT;/* Number of measurements (-n)*/
+ unsigned int l = CRYPTO_DEF_LOOPS; /* Inner loops (-l) */
+ int verbosity = CRYPTO_DEF_VERBOSITY; /* Verbosity (-v) */
int algo = TA_SHA_SHA1; /* Algorithm (-a) */
- int random_in = 0; /* Get input data from /dev/urandom (-r) */
- int warmup = 2; /* Start with a 2-second busy loop (-w) */
- int offset = 0; /* Buffer offset wrt. alloc'ed address (-u) */
+ /* Get input data from /dev/urandom (-r) */
+ int random_in = CRYPTO_USE_RANDOM;
+ /* Start with a 2-second busy loop (-w) */
+ int warmup = CRYPTO_DEF_WARMUP;
+ int offset = 0; /* Buffer offset wrt. alloc'ed address (-u) */
/* Parse command line */
diff --git a/host/xtest/sha_perf.h b/host/xtest/sha_perf.h
deleted file mode 100644
index fbdea87..0000000
--- a/host/xtest/sha_perf.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (c) 2015, Linaro Limited
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef XTEST_SHA_PERF_H
-#define XTEST_SHA_PERF_H
-
-#include "ta_sha_perf.h"
-
-int sha_perf_runner_cmd_parser(int argc, char *argv[]);
-void sha_perf_run_test(int algo, size_t size, unsigned int n,
- unsigned int l, int random_in, int offset,
- int warmup, int verbosity);
-
-#endif /* XTEST_SHA_PERF_H */
diff --git a/host/xtest/xtest_benchmark_2000.c b/host/xtest/xtest_benchmark_2000.c
index 4af1788..fb46999 100644
--- a/host/xtest/xtest_benchmark_2000.c
+++ b/host/xtest/xtest_benchmark_2000.c
@@ -18,23 +18,9 @@
#include "xtest_test.h"
#include "xtest_helpers.h"
-#include <sha_perf.h>
-#include <aes_perf.h>
+#include <crypto_common.h>
#include <util.h>
-#define SHA_PERF_COUNT 5000 /* Number of measurements */
-#define SHA_PERF_WARMUP 2 /* Start with a 2-second busy loop */
-#define SHA_PERF_LOOPS 1 /* Inner loops */
-#define SHA_PERF_RANDOM_IN 1 /* Get input data from /dev/urandom */
-#define SHA_PERF_VERBOSITY 0
-
-#define AES_PERF_COUNT 5000 /* Number of measurements */
-#define AES_PERF_WARMUP 2 /* Start with a 2-second busy loop */
-#define AES_PERF_LOOPS 1 /* Inner loops */
-#define AES_PERF_RANDOM_IN 1 /* Get input data from /dev/urandom */
-#define AES_PERF_VERBOSITY 0
-#define AES_PERF_INPLACE 0
-
/* SHA bechmarks */
static void xtest_tee_benchmark_2001(ADBG_Case_t *Case_p);
static void xtest_tee_benchmark_2002(ADBG_Case_t *Case_p);
@@ -55,9 +41,9 @@
size_t size = 1024; /* Buffer size */
int offset = 0; /* Buffer offset wrt. alloc'ed address */
- sha_perf_run_test(algo, size, SHA_PERF_COUNT,
- SHA_PERF_LOOPS, SHA_PERF_RANDOM_IN, offset,
- SHA_PERF_WARMUP, SHA_PERF_VERBOSITY);
+ sha_perf_run_test(algo, size, CRYPTO_DEF_COUNT,
+ CRYPTO_DEF_LOOPS, CRYPTO_USE_RANDOM, offset,
+ CRYPTO_DEF_WARMUP, CRYPTO_DEF_VERBOSITY);
}
@@ -69,9 +55,9 @@
size_t size = 4096; /* Buffer size */
int offset = 0; /* Buffer offset wrt. alloc'ed address */
- sha_perf_run_test(algo, size, SHA_PERF_COUNT,
- SHA_PERF_LOOPS, SHA_PERF_RANDOM_IN, offset,
- SHA_PERF_WARMUP, SHA_PERF_VERBOSITY);
+ sha_perf_run_test(algo, size, CRYPTO_DEF_COUNT,
+ CRYPTO_DEF_LOOPS, CRYPTO_USE_RANDOM, offset,
+ CRYPTO_DEF_WARMUP, CRYPTO_DEF_VERBOSITY);
}
@@ -107,28 +93,23 @@
int keysize = AES_128;
size_t size = 1024; /* Buffer size */
-
- aes_perf_run_test(mode, keysize, decrypt, size, AES_PERF_COUNT,
- AES_PERF_LOOPS, AES_PERF_RANDOM_IN, AES_PERF_INPLACE,
- AES_PERF_WARMUP, AES_PERF_VERBOSITY);
-
+ aes_perf_run_test(mode, keysize, decrypt, size, CRYPTO_DEF_COUNT,
+ CRYPTO_DEF_LOOPS, CRYPTO_USE_RANDOM, AES_PERF_INPLACE,
+ CRYPTO_DEF_WARMUP, CRYPTO_DEF_VERBOSITY);
}
static void xtest_tee_benchmark_2012(ADBG_Case_t *c)
{
UNUSED(c);
- int mode = TA_AES_ECB; /* AES mode */
+ int mode = TA_AES_CBC; /* AES mode */
int decrypt = 0; /* Encrypt */
- int keysize = AES_128;
+ int keysize = AES_256;
size_t size = 1024; /* Buffer size */
- aes_perf_run_test(mode, keysize, decrypt, size, AES_PERF_COUNT,
- AES_PERF_LOOPS, AES_PERF_RANDOM_IN, AES_PERF_INPLACE,
- AES_PERF_WARMUP, AES_PERF_VERBOSITY);
-
-
-
+ aes_perf_run_test(mode, keysize, decrypt, size, CRYPTO_DEF_COUNT,
+ CRYPTO_DEF_LOOPS, CRYPTO_USE_RANDOM, AES_PERF_INPLACE,
+ CRYPTO_DEF_WARMUP, CRYPTO_DEF_VERBOSITY);
}
ADBG_CASE_DEFINE(XTEST_TEE_BENCHMARK_2011, xtest_tee_benchmark_2011,
diff --git a/host/xtest/xtest_main.c b/host/xtest/xtest_main.c
index ec61314..d19384a 100644
--- a/host/xtest/xtest_main.c
+++ b/host/xtest/xtest_main.c
@@ -21,8 +21,7 @@
#include "xtest_helpers.h"
/* include here shandalone tests */
-#include "sha_perf.h"
-#include "aes_perf.h"
+#include "crypto_common.h"
#ifdef WITH_GP_TESTS
#include "adbg_entry_declare.h"