xref: /aosp_15_r20/trusty/kernel/include/shared/lk/trusty_bench_option_cb.h (revision 344aa361028b423587d4ef3fa52a23d194628137)
1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining
5  * a copy of this software and associated documentation files
6  * (the "Software"), to deal in the Software without restriction,
7  * including without limitation the rights to use, copy, modify, merge,
8  * publish, distribute, sublicense, and/or sell copies of the Software,
9  * and to permit persons to whom the Software is furnished to do so,
10  * subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be
13  * included in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22  */
23 #pragma once
24 
25 #include <lib/unittest/unittest.h>
26 #include <lk/list.h>
27 
28 /* Build Time Option Switching */
29 #if (BENCHMARK_MACHINE_READABLE == 1)
30 #define BENCHMARK_PRINT_CB trusty_bench_print_json_metric_list
31 #else
32 #define BENCHMARK_PRINT_CB trusty_bench_print_vertical_metric_list
33 #endif
34 
35 /**
36  * typedef trusty_bench_get_param_name_callback - Type of the callback to
37  * customize header names of parameter columns
38  * @buf:            To be filled with the desired name.
39  * @buf_size:       size of the buffer.
40  * @param_idx:      Index of the parameter whose name is to be written into the
41  *                  buffer.
42  */
43 typedef void (*trusty_bench_get_param_name_callback_t)(char* buf,
44                                                        size_t buf_size,
45                                                        size_t param_idx);
46 
47 /*
48  * trusty_bench_get_param_name_cb - To be set during BENCH_SETUP with a
49  * callback of trusty_bench_get_param_name_callback type. Will be used to print
50  * param columns headers and then reset to NULL after BENCH_TEARDOWN
51  */
52 static trusty_bench_get_param_name_callback_t trusty_bench_get_param_name_cb;
53 
54 // Forward declaration for the trusty_bench_check_results_callback_t definition
55 struct bench_metric_list_node;
56 
57 /**
58  * typedef trusty_bench_check_results_callback_t - Type of the callback to
59  *                  check if aggregate values are in desired range
60  * @metric_node:    The metric node to be validated
61  */
62 typedef bool (*trusty_bench_check_results_callback_t)(
63         struct bench_metric_list_node* metric_node);
64 
65 /**
66  * typedef trusty_bench_get_formatted_value_callback - Type of the callback to
67  * customize value printing
68  * @buf:            To be filled with the desired name.
69  * @buf_size:       size of the buffer.
70  * @value:          value to be formatted.
71  * @metric_name:    Name of the metric this value is associated to.
72  */
73 typedef void (*trusty_bench_get_formatted_value_callback_t)(
74         char* buf,
75         size_t buf_size,
76         int64_t value,
77         const char* metric_name);
78 
79 /*
80  * trusty_bench_get_formatted_value_cb - To be set during BENCH_SETUP with a
81  * callback of trusty_bench_get_formatted_value_callback type. Will be used to
82  * print formatted aggregates values and then reset to NULL after BENCH_TEARDOWN
83  */
84 static trusty_bench_get_formatted_value_callback_t
85         trusty_bench_get_formatted_value_cb;
86 
87 /**
88  * typedef trusty_bench_print_callback -    Function pointer to Print a summary
89  * table of all statistical aggregates for all param/metric in the last BENCH.
90  * Use to switch between different printing formats.
91  * @metric_list:        List of metrics aggregated during all BENCH runs.
92  * @nb_params:          Number of Parameters in the param array of BENCH.
93  * @suite_name:         Name of the Bench Suite
94  * @bench_name:         Name of Current Bench
95  */
96 typedef void (*trusty_bench_print_callback_t)(struct list_node* metric_list,
97                                               size_t nb_params,
98                                               const char* suite_name,
99                                               const char* bench_name);
100 
101 /*
102  * trusty_bench_print_cb - To be set with a callback
103  * of trusty_bench_print_callback type. Defaults to vertical printing until
104  * command line switch is added.
105  */
106 static trusty_bench_print_callback_t trusty_bench_print_cb;
107