xref: /aosp_15_r20/external/tpm2-tss/test/unit/log.c (revision 758e9fba6fc9adbf15340f70c73baee7b168b1c9)
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /***********************************************************************
3  * Copyright (c) 2019, Infineon Technologies AG
4  *
5  * All rights reserved.
6  ***********************************************************************/
7 #ifdef HAVE_CONFIG_H
8 #include <config.h>
9 #endif
10 
11 #include <inttypes.h>
12 #include <stdio.h>
13 #include <stdbool.h>
14 #include <stdlib.h>
15 
16 #include <setjmp.h>
17 #include <cmocka.h>
18 
19 #include "tss2_tpm2_types.h"
20 
21 #include "util/io.h"
22 #define LOGMODULE test
23 #include "util/log.h"
24 
25 
26 static void
execute_doLog(char * env_log_level)27 execute_doLog(char *env_log_level){
28     setenv("TSS2_LOG", env_log_level, 1);
29     LOG_DEBUG("test");
30     LOG_TRACE("test");
31     LOG_INFO("test");
32     LOG_WARNING("test");
33     LOG_INFO("test");
34     /* reset log level for next test */
35     LOGMODULE_status = LOGLEVEL_UNDEFINED;
36 }
37 
38 static void
doLog_test(void ** state)39 doLog_test (void **state)
40 {
41     execute_doLog("ALL+none");
42     execute_doLog("ALL+unused");
43     execute_doLog("ALL+error");
44     execute_doLog("ALL+warning");
45     execute_doLog("ALL+info");
46     execute_doLog("ALL+debug");
47     execute_doLog("ALL+trace");
48     execute_doLog("ALL+xxxxx");
49     execute_doLog("marshal+xxxxx");
50     execute_doLog("marshal+debug");
51     execute_doLog("test+debug");
52     execute_doLog("test+xxxx");
53     execute_doLog("ukn+xxxx");
54     execute_doLog("test+xxxx");
55     execute_doLog("TEST+trace");
56     execute_doLog("ALL+xxxxx,mashal+xxxx,tcti+DEBug");
57     execute_doLog("ALL+none,mashal+WARNING,tcti+DEBug");
58 }
59 
60 int
main(int argc,char * argv[])61 main (int argc, char *argv[])
62 {
63     const struct CMUnitTest tests[] = {
64         cmocka_unit_test (doLog_test),
65     };
66     return cmocka_run_group_tests (tests, NULL, NULL);
67 }
68