tool: lshal: Print interface and backend version 52/313352/6
authorYoungjae Cho <y0.cho@samsung.com>
Mon, 24 Jun 2024 10:03:10 +0000 (19:03 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Tue, 25 Jun 2024 04:55:58 +0000 (13:55 +0900)
The last 2 columns have been added. For example
--------------------------------------------------------------------
                            | ...  | Interface           | Backend |
 HAL Module Name            | ...  | Versions            | Version |
--------------------------------------------------------------------
 ...                        |      |                     |         |
--------------------------------------------------------------------
 HAL_MODULE_DEVICE_DISPLAY  | ...  | 1.0, 2.3, 3.2, 4.1  | 1.0     |
--------------------------------------------------------------------
 ...                        |      |                     |         |

- Interface Versions
  : Versions specified at the manifest file,
    /etc/hal/hal-api-{module}-manifest.xml. Can be more than one
    if it has specified multiple supporting versions.

- Backend Version
  : Version that an actual backend has been implemented with.

Change-Id: I035617f86396a7b730d26e7e6312d0dd20c86429
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
tools/lshal/lshal.c

index 0530277af6514556c52e5f706b22b190961144e9..4ba2239688ea4384ab188873ac22be358ddc6cab 100644 (file)
@@ -41,6 +41,8 @@
 #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_VERSION             BIT(7)
+#define LSHAL_FLAG_MANIFEST_VERSION            BIT(8)
 
 struct _hal_backend_module_data {
        /**
@@ -66,7 +68,7 @@ static int lshal_verify_hal_backend(enum hal_module module)
 }
 
 static void lshal_print_border(void) {
-       for (int i = 0; i < 267; i++)
+       for (int i = 0; i < 287; i++)
                printf("-");
        printf("\n");
 }
@@ -78,23 +80,27 @@ static void lshal_print_hal_backend_info(u_int32_t flags) {
        int backend_verification_count = 0;
 
        lshal_print_border();
-       printf(" %-38s |    | %-55s | %-10s | %-15s | %-45s | %-25s | %-25s |\n",
+       printf(" %-38s |    | %-55s | %-10s | %-15s | %-45s | %-25s | %-25s | %-25s | %-15s |\n",
                        "",
                        "",
                        "Backend",
                        "Backend",
                        "Backend",
                        "Backend Name",
-                       "Vendor Name");
+                       "Vendor Name",
+                       "Interface",
+                       "Backend");
 
-       printf(" %-38s | ID | %-55s | %-10s | %-15s | %-45s | %-25s | %-25s |\n",
+       printf(" %-38s | ID | %-55s | %-10s | %-15s | %-45s | %-25s | %-25s | %-25s | %-15s |\n",
                        "HAL Module Name",
                        "Backend Library Name",
                        "Open Count",
                        "Verification",
                        "Symbol Name",
                        "(Written by Developer)",
-                       "(Written by Developer)");
+                       "(Written by Developer)",
+                       "Versions",
+                       "Version");
        lshal_print_border();
 
        for (module = HAL_MODULE_UNKNOWN + 1; module < HAL_MODULE_END; module++) {
@@ -169,11 +175,62 @@ static void lshal_print_hal_backend_info(u_int32_t flags) {
                                printf(" %-25s |", str);
                }
 
+               if (LSHAL_FLAG_MANIFEST_VERSION & flags) {
+                       unsigned int *major_versions = NULL;
+                       unsigned int *minor_versions = NULL;
+                       int num_versions = 0;
+
+                       strncpy(str, "", BUFF_MAX - 1);
+
+                       ret = hal_common_get_supported_interface_versions(module,
+                               &major_versions, &minor_versions, &num_versions);
+                       if (ret < 0) {
+                               printf(" %-25s |", "");
+                       } else {
+                               char *pos = str;
+                               char *const end = pos + sizeof(str);
+                               for (int i = 0; i < num_versions; ++i) {
+                                       if (pos >= end)
+                                               break;
+
+                                       pos += snprintf(pos, end - pos, "%u.%u, ",
+                                               major_versions[i], minor_versions[i]);
+                               }
+
+                               free(major_versions);
+                               major_versions = NULL;
+                               free(minor_versions);
+                               minor_versions = NULL;
+
+                               /* Remove trailing ',' and terminate the string */
+                               if (pos < end)
+                                       *(pos - 2) = '\0';
+
+                               printf(" %-25s |", str);
+                       }
+               }
+
+               if (LSHAL_FLAG_BACKEND_VERSION & flags) {
+                       unsigned int major, minor;
+
+                       strncpy(str, "", BUFF_MAX - 1);
+
+                       ret = hal_common_get_backend_version(module, &major, &minor);
+                       if (ret < 0) {
+                               printf(" %-15s |", "");
+                       } else if (major == 0 && minor == 0) {
+                               printf(" %-15s |", "");
+                       } else {
+                               snprintf(str, BUFF_MAX - 1, "%u.%u", major, minor);
+                               printf(" %-15s |", str);
+                       }
+               }
+
                printf("\n");
        }
 
        lshal_print_border();
-       printf(" %-38s | %-2d | %-55s | %-10s | %15d | %-45s | %-25s | %-25s | %-25s |\n",
+       printf(" %-38s | %-2d | %-55s | %-10s | %15d | %-45s | %-25s | %-25s | %-25s | %-25s | %-15s |\n",
                        "TOTAL",
                        HAL_MODULE_END - 1,
                        "",
@@ -182,6 +239,8 @@ static void lshal_print_hal_backend_info(u_int32_t flags) {
                        "",
                        "",
                        "",
+                       "",
+                       "",
                        "");
        lshal_print_border();
 }
@@ -196,7 +255,9 @@ static void lshal(void)
                        | LSHAL_FLAG_BACKEND_NAME
                        | LSHAL_FLAG_BACKEND_VENDOR_NAME
                        | LSHAL_FLAG_BACKEND_USAGE_COUNT
-                       | LSHAL_FLAG_BACKEND_MODULE_NAME);
+                       | LSHAL_FLAG_BACKEND_MODULE_NAME
+                       | LSHAL_FLAG_BACKEND_VERSION
+                       | LSHAL_FLAG_MANIFEST_VERSION);
 
        lshal_print_hal_backend_info(flags);
 }