TF-M Reference Manual  1.2.0
TrustedFirmware-M
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
qcbor_ns_testsuite.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #include "qcbor_ns_tests.h"
9 #include <stdio.h>
10 #include "run_tests.h"
11 
12 /*
13  * The QCBOR test cases are defined in: lib/ext/qcbor/test/run_test.c
14  *
15  * There are two types of configuration to execute test cases:
16  * - All tests: Just pass an array containing a NULL pointer to RunTest():
17  * qcbor_test_cases_all[]. This is the default configuration.
18  *
19  * - Selected tests: qcbor_test_cases[] array contains the name of all tests.
20  * To execute only selected test cases, just remove/comment
21  * out the unwanted tests from the array and pass it to
22  * RunTests(). This configuration disables all tests with a
23  * long execution time to speed up development.
24  */
25 
26 /* Define test suite for QCBOR library */
27 static void tfm_qcbor_test_7001(struct test_result_t *ret);
28 
29 static struct test_t qcbor_regression_test[] = {
30  {&tfm_qcbor_test_7001, "TFM_QCBOR_TEST_7001",
31  "Regression test of QCBOR library", {TEST_PASSED} },
32 };
33 
34 /* To execute only selected test cases, then remove unwanted ones from the array
35  * and pass it to RunTests().
36  * Not static to avoid compiler warning due to non-usage
37  */
38 const char *qcbor_test_cases[] = {
39  "ParseMapAsArrayTest",
40  "AllocAllStringsTest",
41  "IndefiniteLengthNestTest",
42  "NestedMapTestIndefLen",
43  "ParseSimpleTest",
44  "EncodeRawTest",
45  "RTICResultsTest",
46  "MapEncodeTest",
47  "ArrayNestingTest1",
48  "ArrayNestingTest2",
49  "ArrayNestingTest3",
50  "EncodeDateTest",
51  "SimpleValuesTest1",
52  "IntegerValuesTest1",
53  "AllAddMethodsTest",
54  "ParseTooDeepArrayTest",
55  "ComprehensiveInputTest",
56  "ParseMapTest",
57  "IndefiniteLengthArrayMapTest",
58  "BasicEncodeTest",
59  "NestedMapTest",
60  "BignumParseTest",
61  "OptTagParseTest",
62  "DateParseTest",
63  "ShortBufferParseTest2",
64  "ShortBufferParseTest",
65  "ParseDeepArrayTest",
66  "SimpleArrayTest",
67  "IntegerValuesParseTest",
68  "MemPoolTest",
69  "IndefiniteLengthStringTest",
70  "HalfPrecisionDecodeBasicTests",
71  "DoubleAsSmallestTest",
72  "HalfPrecisionAgainstRFCCodeTest",
73  "BstrWrapTest",
74  "BstrWrapErrorTest",
75  "BstrWrapNestTest",
76  "CoseSign1TBSTest",
77  "StringDecoderModeFailTest",
78  /* "BigComprehensiveInputTest", */ /* Takes too long to execute */
79  "EncodeErrorTests",
80  "UBUTest_CopyUtil",
81  "UOBTest_NonAdversarial",
82  "TestBasicSanity",
83  "UOBTest_BoundaryConditionsTest",
84  "UBMacroConversionsTest",
85  "UBUtilTests",
86  "UIBTest_IntegerFormat",
87 };
88 
89 /* To execute all test cases, then pass this array to RunTests()
90  * Test cases are defined in: lib/ext/qcbor/test/run_tests.c
91  */
92 const static char *qcbor_test_cases_all[] = {
93  0, /* Indicates to run all enabled test case */
94 };
95 
103 static void fputs_wrapper(const char *string, void *out_ctx, int new_line)
104 {
105  (void)out_ctx;
106  (void)new_line;
107  /*
108  * To get test result per test case, change
109  * the preprocessor '#if 0' to '#if 1'.
110  */
111 # if 0
112  TEST_LOG("%s\r\n", string);
113 #else
114  (void)string;
115 #endif
116 }
117 
118 static void tfm_qcbor_test_7001(struct test_result_t *ret)
119 {
120  int32_t test_failed_cnt = 0;
121 
122  test_failed_cnt = RunTestsQCBOR(qcbor_test_cases_all, fputs_wrapper,
123  NULL, NULL);
124  if (test_failed_cnt != 0) {
125  TEST_FAIL("QCBOR test failed");
126  return;
127  }
128 
129  ret->val = TEST_PASSED;
130 }
131 
132 void
134 {
135  uint32_t list_size;
136 
137  list_size = (sizeof(qcbor_regression_test) /
138  sizeof(qcbor_regression_test[0]));
139 
140  set_testsuite("QCBOR regression test"
141  "(TFM_QCBOR_TEST_7XXX)",
142  qcbor_regression_test, list_size, p_test_suite);
143 }
void register_testsuite_ns_qcbor(struct test_suite_t *p_test_suite)
Register test suite for the QCBOR library.
#define TEST_FAIL(info_msg)
enum test_suite_err_t set_testsuite(const char *name, struct test_t *test_list, uint32_t size, struct test_suite_t *p_ts)
Sets test suite parameters.
struct test_result_t ret
const char * qcbor_test_cases[]
#define TEST_LOG(...)
enum test_status_t val