Line data Source code
1 : /**
2 : * Copyright Notice:
3 : * Copyright 2023-2025 DMTF. All rights reserved.
4 : * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
5 : **/
6 :
7 : #include "spdm_unit_test.h"
8 : #include "library/spdm_crypt_lib.h"
9 : #include "internal/libspdm_common_lib.h"
10 :
11 : #if LIBSPDM_FIPS_MODE
12 : uint8_t m_selftest_buffer[0x2000];
13 : #endif
14 :
15 1 : void libspdm_test_fips(void **state)
16 : {
17 : bool status;
18 1 : status = false;
19 :
20 : #if LIBSPDM_FIPS_MODE
21 :
22 : libspdm_fips_selftest_context_t fips_selftest_context;
23 1 : fips_selftest_context.tested_algo = 0;
24 1 : fips_selftest_context.self_test_result = 0;
25 1 : fips_selftest_context.selftest_buffer = m_selftest_buffer;
26 1 : fips_selftest_context.selftest_buffer_size = sizeof(m_selftest_buffer);
27 :
28 1 : status = libspdm_fips_run_selftest(&fips_selftest_context);
29 1 : assert_true(status);
30 : #else
31 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "test is valid only when LIBSPDM_FIPS_MODE is open.\n"));
32 : assert_true(status);
33 : #endif
34 1 : }
35 :
36 1 : int libspdm_crypt_lib_setup(void **state)
37 : {
38 1 : return 0;
39 : }
40 :
41 1 : int libspdm_crypt_lib_teardown(void **state)
42 : {
43 1 : return 0;
44 : }
45 :
46 1 : int libspdm_crypt_lib_test_main(void)
47 : {
48 1 : const struct CMUnitTest spdm_crypt_lib_tests[] = {
49 : cmocka_unit_test(libspdm_test_fips),
50 : };
51 :
52 1 : return cmocka_run_group_tests(spdm_crypt_lib_tests,
53 : libspdm_crypt_lib_setup,
54 : libspdm_crypt_lib_teardown);
55 : }
56 :
57 1 : int main(void)
58 : {
59 1 : int return_value = 0;
60 :
61 1 : if (libspdm_crypt_lib_test_main() != 0) {
62 0 : return_value = 1;
63 : }
64 :
65 1 : return return_value;
66 : }
|