blob: 7995c1896150532024ab4645683d52c883453bf6 [file] [log] [blame]
Igor Opaniukab88c952017-02-14 13:22:54 +02001/*
2 * Copyright (c) 2016, Linaro Limited
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
26 */
27#include <libgen.h>
28#include <linux/limits.h>
29#include <math.h>
30#include <stdlib.h>
31#include <stdio.h>
32#include <string.h>
33#include <unistd.h>
34
35#include "benchmark_aux.h"
Igor Opaniukf1f3fd02017-09-14 15:34:56 +030036#include "common.h"
Igor Opaniukab88c952017-02-14 13:22:54 +020037
38/* Misc auxilary functions */
39void tee_errx(const char *msg, TEEC_Result res)
40{
Igor Opaniukf1f3fd02017-09-14 15:34:56 +030041 ERROR_EXIT("%s: 0x%08x\n", msg, res);
Igor Opaniukab88c952017-02-14 13:22:54 +020042}
43
44void tee_check_res(TEEC_Result res, const char *errmsg)
45{
46 if (res != TEEC_SUCCESS)
47 tee_errx(errmsg, res);
48}
49
50const char *bench_str_src(uint64_t source)
51{
52 switch (source) {
53 case TEE_BENCH_CORE:
Igor Opaniukf1f3fd02017-09-14 15:34:56 +030054 return "core";
Igor Opaniukab88c952017-02-14 13:22:54 +020055 case TEE_BENCH_KMOD:
Igor Opaniukf1f3fd02017-09-14 15:34:56 +030056 return "kmodule";
Igor Opaniukab88c952017-02-14 13:22:54 +020057 case TEE_BENCH_CLIENT:
Igor Opaniukf1f3fd02017-09-14 15:34:56 +030058 return "libteec";
Igor Opaniukab88c952017-02-14 13:22:54 +020059 case TEE_BENCH_UTEE:
Igor Opaniukf1f3fd02017-09-14 15:34:56 +030060 return "libutee";
Igor Opaniukab88c952017-02-14 13:22:54 +020061 default:
Igor Opaniukf1f3fd02017-09-14 15:34:56 +030062 return "-";
Igor Opaniukab88c952017-02-14 13:22:54 +020063 }
64}
65
66void print_line(void)
67{
68 int n = 115;
69
70 while (n-- > 0)
71 printf("=");
72 printf("\n");
73}
74
75void alloc_argv(int argc, char *argv[], char **new_argv[])
76{
77 char *res, *base;
78 char path[PATH_MAX];
79 char **testapp_argv;
l00176142d1cfd652017-11-23 00:52:28 +080080 int i;
Igor Opaniukab88c952017-02-14 13:22:54 +020081
82 res = realpath(argv[1], path);
83 if (!res)
84 _exit(EXIT_FAILURE);
85
86 *new_argv = malloc(argc * sizeof(void *));
87 if (!(*new_argv))
88 _exit(EXIT_FAILURE);
89
90 testapp_argv = *new_argv;
91 testapp_argv[argc-1] = NULL;
92 base = basename(path);
93
94 testapp_argv[0] = malloc(strlen(base) + 1);
95 if (!testapp_argv[0])
96 _exit(EXIT_FAILURE);
97
98 memcpy(testapp_argv[0], base, strlen(base) + 1);
99
l00176142d1cfd652017-11-23 00:52:28 +0800100 for (i = 2; i < argc; i++) {
Igor Opaniukab88c952017-02-14 13:22:54 +0200101 size_t length = strlen(argv[i]) + 1;
102
103 testapp_argv[i - 1] = malloc(length);
104 if (!testapp_argv[i - 1])
105 _exit(EXIT_FAILURE);
106
107 memcpy(testapp_argv[i-1], argv[i], length);
108 }
109}
110
111void dealloc_argv(int new_argc, char **new_argv)
112{
l00176142d1cfd652017-11-23 00:52:28 +0800113 int i;
114 for (i = 0; i < new_argc; ++i)
Igor Opaniukab88c952017-02-14 13:22:54 +0200115 free(new_argv[i]);
116
117 free(new_argv);
118}
119
120uint32_t get_cores(void)
121{
122 return sysconf(_SC_NPROCESSORS_ONLN);
123}