hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* SPDX-License-Identifier: BSD-2-Clause */
/*
 * Copyright (c) 2014, STMicroelectronics International N.V.
 * All rights reserved.
 */
#ifndef TB_MACROS_H
#define TB_MACROS_H
 
#include <tee_internal_api_extensions.h>
 
#define TB_HEADER(str)                               \
   printf("\n*********** TESTBENCH ***********" \
          "\n***         RUNNING: <<< %s >>>"   \
          "\n*********************************\n\n", str)
 
#define TB_FOOTER(str)                               \
   printf("\n*********** TESTBENCH ***********" \
          "\n***         PASSED:  <<< %s >>>"   \
          "\n*********************************\n\n", str)
 
#define TB_INFO(str) printf("*** INFO : %s \n", (str))
 
#define HALT                                                             \
   {                                                                \
       printf("\n*** FAILED ***"                                \
              "\nTestbench halted at line %d in function %s\n", \
            __LINE__, __func__);                            \
       printf("\nWaiting for keypress to enable debugging.\n"); \
       TEE_Panic(0);                                            \
   }
 
#define STARTING                                       \
   printf("\n*********** TESTBENCH ***********"   \
          "\n*** For the GlobalPlatform Math API" \
          "\n*********************************\n\n")
 
#define ALL_PASSED \
   printf("\n*********** TESTBENCH ***********" \
          "\n***     ALL TESTS PASSED      ***" \
          "\n*********************************\n\n")
 
/*
 * DEF_BIGINT defines and initialize a BigInt with name and size.
 */
#define DEF_BIGINT(name, size)                                                \
   TEE_BigInt *name;                                                     \
   size_t name##_size;                                                   \
   name##_size = TEE_BigIntSizeInU32(size);                              \
   name = (TEE_BigInt *)TEE_Malloc(name##_size * sizeof(TEE_BigInt), 0); \
   TEE_BigIntInit(name, name##_size)
 
/*
 * DEL_BIGINT frees the BigInt.
 */
#define DEL_BIGINT(name) TEE_Free(name)
 
/*
 * TB_PRINT_BIGINT prints the mpanum in base 16.
 */
#define TB_PRINT_BIGINT(n)                                                     \
do {                                                                           \
   char *str;                                                             \
   str = TEE_BigIntConvertToString(NULL, TEE_STRING_MODE_HEX_UC, 0, (n)); \
   printf("%s\n", str);                                                   \
   TEE_Free(str);                                                         \
} while (0)
 
#endif