4 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the License);
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 #include <sys/types.h>
29 #include "hal-common.h"
30 #include "hal-common-interface.h"
32 #include "hal-api-conf.h"
34 #define BIT(x) (1ULL << x)
37 #define LSHAL_FLAG_BACKEND_VERIFICATION BIT(0)
38 #define LSHAL_FLAG_BACKEND_MODULE_NAME BIT(1)
39 #define LSHAL_FLAG_BACKEND_LIB_NAME BIT(2)
40 #define LSHAL_FLAG_BACKEND_SYMBOL_NAME BIT(3)
41 #define LSHAL_FLAG_BACKEND_NAME BIT(4)
42 #define LSHAL_FLAG_BACKEND_VENDOR_NAME BIT(5)
43 #define LSHAL_FLAG_BACKEND_USAGE_COUNT BIT(6)
44 #define LSHAL_FLAG_BACKEND_ABI_VERSION BIT(7)
46 struct _hal_backend_module_data {
48 * Each HAL module defines the different backend_module_data.
49 * In order to test the all HAL backends, just use the large buffer.
51 void *unused_buffer[10000];
52 } *backend_module_data;
54 static int lshal_verify_hal_backend(enum hal_module module)
58 ret = hal_common_get_backend(module, (void **)&backend_module_data);
62 ret = hal_common_put_backend(module, backend_module_data);
69 static void lshal_print_border(void) {
70 for (int i = 0; i < 267; i++)
75 static void lshal_print_hal_backend_info(u_int32_t flags) {
77 enum hal_module module;
79 int backend_verification_count = 0;
82 printf(" %-38s | | %-55s | %-10s | %-15s | %-45s | %-25s | %-25s | %-25s |\n",
88 "Backend ABI Version",
92 printf(" %-38s | ID | %-55s | %-10s | %-15s | %-45s | %-25s | %-25s | %-25s |\n",
94 "Backend Library Name",
98 "(Written by Developer)",
99 "(Written by Developer)",
100 "(Written by Developer)");
101 lshal_print_border();
103 for (module = HAL_MODULE_UNKNOWN + 1; module < HAL_MODULE_END; module++) {
104 if (LSHAL_FLAG_BACKEND_MODULE_NAME & flags) {
105 strncpy(str, "", BUFF_MAX - 1);
107 ret = hal_common_get_backend_module_name(module, str, BUFF_MAX - 1);
109 printf(" %-38s | %-2d |", "", module);
111 printf(" %-38s | %-2d |", str, module);
114 if (LSHAL_FLAG_BACKEND_LIB_NAME & flags) {
115 strncpy(str, "", BUFF_MAX - 1);
117 ret = hal_common_get_backend_library_name(module, str, BUFF_MAX - 1);
119 printf(" %-55s |", "");
121 printf(" %-55s |", str);
124 if (LSHAL_FLAG_BACKEND_USAGE_COUNT & flags) {
125 int count = hal_common_get_backend_count(module);
127 printf(" %-10s |", "");
129 printf(" %-10d |", count);
132 if (LSHAL_FLAG_BACKEND_VERIFICATION & flags) {
133 ret = lshal_verify_hal_backend(module);
135 if (ret == -ENOENT) {
136 printf(" %-15s |", "NO |");
137 } else if (ret < 0) {
138 printf(" %-15s |", " |");
140 printf(" %-15s |", "YES | VERIFIED");
141 backend_verification_count++;
145 if (LSHAL_FLAG_BACKEND_SYMBOL_NAME & flags) {
146 strncpy(str, "", BUFF_MAX - 1);
148 ret = hal_common_get_backend_symbol_name(module, str, BUFF_MAX - 1);
150 printf(" %-45s |", "");
152 printf(" %-45s |", str);
155 if (LSHAL_FLAG_BACKEND_ABI_VERSION & flags) {
156 strncpy(str, "", BUFF_MAX - 1);
158 ret = hal_common_get_backend_abi_version(module);
159 if (ret == HAL_ABI_VERSION_UNKNOWN)
160 printf(" %-25s |", "");
162 printf(" %-25s |", hal_abi_version_str[ret]);
165 if (LSHAL_FLAG_BACKEND_NAME & flags) {
166 strncpy(str, "", BUFF_MAX - 1);
168 ret = hal_common_get_backend_name(module, str, BUFF_MAX - 1);
170 printf(" %-25s |", "");
172 printf(" %-25s |", str);
175 if (LSHAL_FLAG_BACKEND_VENDOR_NAME & flags) {
176 strncpy(str, "", BUFF_MAX - 1);
178 ret = hal_common_get_backend_vendor(module, str, BUFF_MAX - 1);
180 printf(" %-25s |", "");
182 printf(" %-25s |", str);
188 lshal_print_border();
189 printf(" %-38s | %-2d | %-55s | %-10s | %15d | %-45s | %-25s | %-25s | %-25s |\n",
194 backend_verification_count,
199 lshal_print_border();
202 static void lshal_handle_signal(int signal) {}
204 static void lshal(void)
206 u_int32_t flags = (LSHAL_FLAG_BACKEND_VERIFICATION
207 | LSHAL_FLAG_BACKEND_LIB_NAME
208 | LSHAL_FLAG_BACKEND_SYMBOL_NAME
209 | LSHAL_FLAG_BACKEND_NAME
210 | LSHAL_FLAG_BACKEND_VENDOR_NAME
211 | LSHAL_FLAG_BACKEND_USAGE_COUNT);
213 lshal_print_hal_backend_info(flags);
216 int main(int argc, char *argv[])
218 /* Register signal handler for freeing resources */
219 signal(SIGINT, lshal_handle_signal);