blob: c729c3291da516466e98aa4d2a4f2066423b4b85 [file] [log] [blame]
Pascal Brandc639ac82015-07-02 08:53:34 +02001/*
2 * Copyright (c) 2014, STMicroelectronics International N.V.
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#ifndef TB_MACROS_H
28#define TB_MACROS_H
29
30#include <tee_internal_api_extensions.h>
31
32#define TB_HEADER(str) \
33 printf("\n*********** TESTBENCH ***********" \
34 "\n*** RUNNING: <<< %s >>>" \
35 "\n*********************************\n\n", str)
36
37#define TB_FOOTER(str) \
38 printf("\n*********** TESTBENCH ***********" \
39 "\n*** PASSED: <<< %s >>>" \
40 "\n*********************************\n\n", str)
41
42#define TB_INFO(str) printf("*** INFO : %s \n", (str))
43
44#define HALT \
45 { \
46 printf("\n*** FAILED ***" \
47 "\nTestbench halted at line %d in function %s\n", \
48 __LINE__, __func__); \
49 printf("\nWaiting for keypress to enable debugging.\n"); \
50 TEE_Panic(0); \
51 }
52
53#define STARTING \
54 printf("\n*********** TESTBENCH ***********" \
55 "\n*** For the GlobalPlatform Math API" \
56 "\n*********************************\n\n")
57
58#define ALL_PASSED \
59 printf("\n*********** TESTBENCH ***********" \
60 "\n*** ALL TESTS PASSED ***" \
61 "\n*********************************\n\n")
62
63/*
64 * DEF_BIGINT defines and initialize a BigInt with name and size.
65 */
66#define DEF_BIGINT(name, size) \
67 TEE_BigInt *name; \
68 size_t name##_size; \
69 name##_size = TEE_BigIntSizeInU32(size); \
70 name = (TEE_BigInt *)TEE_Malloc(name##_size * sizeof(TEE_BigInt), 0); \
71 TEE_BigIntInit(name, name##_size)
72
73/*
74 * DEL_BIGINT frees the BigInt.
75 */
76#define DEL_BIGINT(name) TEE_Free(name)
77
78/*
79 * TB_PRINT_BIGINT prints the mpanum in base 16.
80 */
81#define TB_PRINT_BIGINT(n) \
82do { \
83 char *str; \
84 str = TEE_BigIntConvertToString(NULL, TEE_STRING_MODE_HEX_UC, 0, (n)); \
85 printf("%s\n", str); \
86 TEE_Free(str); \
87} while (0)
88
89#endif