--- /dev/null
+/*
+ * lshal Tool
+ *
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <glib.h>
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <signal.h>
+#include <unistd.h>
+#include <inttypes.h>
+
+#include "hal-common.h"
+#include "hal-common-interface.h"
+
+#include "hal-api-conf.h"
+
+#define BIT(x) (1ULL << x)
+#define BUFF_MAX 256
+
+#define LSHAL_FLAG_BACKEND_VERIFICATION BIT(0)
+#define LSHAL_FLAG_BACKEND_MODULE_NAME BIT(1)
+#define LSHAL_FLAG_BACKEND_LIB_NAME BIT(2)
+#define LSHAL_FLAG_BACKEND_SYMBOL_NAME BIT(3)
+#define LSHAL_FLAG_BACKEND_NAME BIT(4)
+#define LSHAL_FLAG_BACKEND_VENDOR_NAME BIT(5)
+#define LSHAL_FLAG_BACKEND_USAGE_COUNT BIT(6)
+#define LSHAL_FLAG_BACKEND_ABI_VERSION BIT(7)
+
+struct _hal_backend_module_data {
+ /**
+ * Each HAL module defines the different backend_module_data.
+ * In order to test the all HAL backends, just use the large buffer.
+ */
+ void *unused_buffer[10000];
+} *backend_module_data;
+
+static int lshal_verify_hal_backend(enum hal_module module)
+{
+ int ret;
+
+ ret = hal_common_get_backend(module, (void **)&backend_module_data);
+ if (ret < 0)
+ return ret;
+
+ ret = hal_common_put_backend(module, backend_module_data);
+ if (ret < 0)
+ return ret;
+
+ return 0;
+}
+
+static void lshal_print_border(void) {
+ for (int i = 0; i < 267; i++)
+ printf("-");
+ printf("\n");
+}
+
+static void lshal_print_hal_backend_info(u_int32_t flags) {
+ int ret;
+ enum hal_module module;
+ char str[BUFF_MAX];
+ int backend_verification_count = 0;
+
+ lshal_print_border();
+ printf(" %-38s | | %-55s | %-10s | %-15s | %-45s | %-25s | %-25s | %-25s |\n",
+ "",
+ "",
+ "Backend",
+ "Backend",
+ "Backend",
+ "Backend ABI Version",
+ "Backend Name",
+ "Vendor Name");
+
+ printf(" %-38s | ID | %-55s | %-10s | %-15s | %-45s | %-25s | %-25s | %-25s |\n",
+ "HAL Module Name",
+ "Backend Library Name",
+ "Open Count",
+ "Verification",
+ "Symbol Name",
+ "(Written by Developer)",
+ "(Written by Developer)",
+ "(Written by Developer)");
+ lshal_print_border();
+
+ for (module = HAL_MODULE_UNKNOWN + 1; module < HAL_MODULE_END; module++) {
+ if (LSHAL_FLAG_BACKEND_MODULE_NAME | flags) {
+ strncpy(str, "", BUFF_MAX - 1);
+
+ ret = hal_common_get_backend_module_name(module, str, BUFF_MAX - 1);
+ if (ret < 0)
+ printf(" %-38s | %-2d |", "", module);
+ else
+ printf(" %-38s | %-2d |", str, module);
+ }
+
+ if (LSHAL_FLAG_BACKEND_LIB_NAME | flags) {
+ strncpy(str, "", BUFF_MAX - 1);
+
+ ret = hal_common_get_backend_library_name(module, str, BUFF_MAX - 1);
+ if (ret < 0)
+ printf(" %-55s |", "");
+ else
+ printf(" %-55s |", str);
+ }
+
+ if (LSHAL_FLAG_BACKEND_USAGE_COUNT | flags) {
+ int count = hal_common_get_backend_count(module);
+ if (count < 0)
+ printf(" %-10s |", "");
+ else
+ printf(" %-10d |", count);
+ }
+
+ if (LSHAL_FLAG_BACKEND_VERIFICATION | flags) {
+ ret = lshal_verify_hal_backend(module);
+
+ if (ret == -ENOENT) {
+ printf(" %-15s |", "NO |");
+ } else if (ret < 0) {
+ printf(" %-15s |", " |");
+ } else {
+ printf(" %-15s |", "YES | VERIFIED");
+ backend_verification_count++;
+ }
+ }
+
+ if (LSHAL_FLAG_BACKEND_SYMBOL_NAME | flags) {
+ strncpy(str, "", BUFF_MAX - 1);
+
+ ret = hal_common_get_backend_symbol_name(module, str, BUFF_MAX - 1);
+ if (ret < 0)
+ printf(" %-45s |", "");
+ else
+ printf(" %-45s |", str);
+ }
+
+ if (LSHAL_FLAG_BACKEND_ABI_VERSION | flags) {
+ strncpy(str, "", BUFF_MAX - 1);
+
+ ret = hal_common_get_backend_abi_version(module);
+ if (ret == HAL_ABI_VERSION_UNKNOWN)
+ printf(" %-25s |", "");
+ else
+ printf(" %-25s |", hal_abi_version_str[ret]);
+ }
+
+ if (LSHAL_FLAG_BACKEND_NAME | flags) {
+ strncpy(str, "", BUFF_MAX - 1);
+
+ ret = hal_common_get_backend_name(module, str, BUFF_MAX - 1);
+ if (ret < 0)
+ printf(" %-25s |", "");
+ else
+ printf(" %-25s |", str);
+ }
+
+ if (LSHAL_FLAG_BACKEND_VENDOR_NAME | flags) {
+ strncpy(str, "", BUFF_MAX - 1);
+
+ ret = hal_common_get_backend_vendor(module, str, BUFF_MAX - 1);
+ if (ret < 0)
+ printf(" %-25s |", "");
+ else
+ printf(" %-25s |", str);
+ }
+
+ printf("\n");
+ }
+
+ lshal_print_border();
+ printf(" %-38s | %-2d | %-55s | %-10s | %15d | %-45s | %-25s | %-25s | %-25s |\n",
+ "TOTAL",
+ HAL_MODULE_END - 1,
+ "",
+ "",
+ backend_verification_count,
+ "",
+ "",
+ "",
+ "");
+ lshal_print_border();
+}
+
+static void lshal_handle_signal(int signal) {}
+
+static void lshal(void)
+{
+ u_int32_t flags = (LSHAL_FLAG_BACKEND_VERIFICATION
+ | LSHAL_FLAG_BACKEND_LIB_NAME
+ | LSHAL_FLAG_BACKEND_SYMBOL_NAME
+ | LSHAL_FLAG_BACKEND_NAME
+ | LSHAL_FLAG_BACKEND_VENDOR_NAME
+ | LSHAL_FLAG_BACKEND_USAGE_COUNT);
+
+ lshal_print_hal_backend_info(flags);
+}
+
+int main(int argc, char *argv[])
+{
+ /* Register signal handler for freeing resources */
+ signal(SIGINT, lshal_handle_signal);
+
+ lshal();
+
+ return 0;
+}