halcc: Check only explicitly specified manifest file 65/313165/4
authorYoungjae Cho <y0.cho@samsung.com>
Wed, 19 Jun 2024 12:37:59 +0000 (21:37 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Thu, 20 Jun 2024 04:12:51 +0000 (13:12 +0900)
halcc has changed to work only on top of manifest file specified in
hal-api-list.h instead of entire xml files at a directory.
Due to above, it becomes necessary that calling parsing function for
every single files, every requested hal module. To make it work,
fixed related function to operates on each single manifest file.

Change-Id: I67e48afb4d0248be37144b127d7068d9dff3452f
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
12 files changed:
src/common.h
src/hal-api-compatibility-checker-parser.c
src/hal-api-compatibility-checker.c
src/hal-api-conf.c
src/hal-api-list.h
tests/unittest/hal-api-common-hook.c
tests/unittest/hal-api-common-hook.h
tests/unittest/test-hal-compatibility-checker.cc
tests/unittest/test-hal-manifest/hal-api-device-manifest.xml [new file with mode: 0644]
tests/unittest/test-hal-manifest/hal-api-tdm-manifest.xml [new file with mode: 0644]
tests/unittest/test-hal-manifest/test-device-manifest.xml [deleted file]
tests/unittest/test-hal-manifest/test-tdm-manifest.xml [deleted file]

index 8b3a3075d47b0f68306b8b60fdf6a5b46c49d434..0524756a1a4ae98b1e334d6022ff96cdb1806914 100644 (file)
@@ -90,6 +90,7 @@ struct __hal_module_info {
        void *handle;
        hal_backend *backend;
        char *symbol_name;
+       char *manifest;
 
        bool hal_api;
        bool hal_backend_extension;
index 2ae0f96a77841784fcc2f7c72fdc68e687e61866..c4aa095aaf73c5ae45afbab354bd49a1a4ba5f97 100644 (file)
@@ -257,7 +257,7 @@ int halcc_parse_path(const char *filepath, halcc_manifest *manifest)
                return -EINVAL;
        }
 
-       doc = xmlReadFile(filepath, NULL, 0);
+       doc = xmlReadFile(filepath, NULL, XML_PARSE_NOWARNING);
        if (!doc) {
                printf("Failed to read doc %s\n", filepath);
                return -ENOENT;
index b541554987f1c3043a93e2f0fa3e585b750d476a..419617c126ac23ed5b75487c998eddb542a31da2 100644 (file)
 #include "hal-api-compatibility-checker-object.h"
 #include "hal-api-compatibility-checker-parser.h"
 
-#define HAL_CC_DEFAULT_HAL_MANIFEST_DIR                        "/etc/hal"
 #define HAL_CC_DEFAULT_COMPATIBILITY_RESULT_PATH       "/opt/etc/hal/.hal-backend-compatibility"
 
 #define COMPAT_INFO_MODULE_NAME_MAX                    64
 
 struct compatibility_info {
+       bool initialized;
        char module_name[COMPAT_INFO_MODULE_NAME_MAX];
        int version_list[HALCC_NUM_VERSION_LIST_MAX][2];
        int num_version_list;
        enum hal_common_backend_compatibility compatibility;
 };
 
-static const char *manifest_directory = HAL_CC_DEFAULT_HAL_MANIFEST_DIR;
 static const char *compatibility_result_path = HAL_CC_DEFAULT_COMPATIBILITY_RESULT_PATH;
 
-void set_compatibility_manifest_directory(const char *path)
-{
-       if (!path)
-               return;
-
-       manifest_directory = path;
-}
-
-void unset_compatibility_manifest_directory(void)
-{
-       manifest_directory = HAL_CC_DEFAULT_HAL_MANIFEST_DIR;
-}
-
 void set_compatibility_result_path(const char *path)
 {
        if (!path)
@@ -243,6 +229,8 @@ static void __convert_hal_to_info(void *data_hal, void *data_info, bool skip_ver
 
        if (halcc_hal_is_compatible_with_version(hal, major, minor))
                info->compatibility = HAL_COMMON_BACKEND_COMPATIBILITY_COMPATIBLE;
+
+       info->initialized = true;
 }
 
 static void convert_hal_to_info(void *data_hal, void *data_info)
@@ -311,6 +299,9 @@ static int create_directory(const char *path)
        // copy path except the last filename
        strncpy(directory_path, path, strrchr(path, '/') - path);
 
+       if (access(directory_path, F_OK) == 0)
+               return 0;
+
        p = strchr(directory_path + 1, '/');
        for (;;) {
                if (!p)
@@ -329,29 +320,49 @@ static int create_directory(const char *path)
 
 }
 
-static int write_comaptibility_info(struct compatibility_info *info, int entry_size)
+static int open_result_file(const char *path, int *fd_out, bool reset)
 {
-       int fd = -1;
        int ret;
-       ssize_t n_write;
+       int fd;
+       mode_t mode = O_WRONLY | O_CREAT;
 
-       ret = create_directory(compatibility_result_path);
+       if (reset)
+               mode |= O_TRUNC;
+       else
+               mode |= O_EXCL;
+
+       ret = create_directory(path);
        if (ret < 0) {
                errno = -ret;
-               _E("Failed to create directory for %s, %m",
-                       compatibility_result_path);
+               _E("Failed to create directory for %s, %m", path);
                return ret;
        }
 
-       fd = open(compatibility_result_path,
-               O_WRONLY | O_CREAT | O_EXCL, 0644);
+       fd = open(path, mode, 0644);
        if (fd == -1) {
-               _E("Failed to create %s, %m",
-                       compatibility_result_path);
+               if (errno == EEXIST) {
+                       /* file exists and reset is false: use that one */
+                       fd = open(path, O_WRONLY, 0);
+                       if (fd == -1)
+                               return -errno;
+
+                       *fd_out = fd;
+                       return 0;
+               }
+
+               _E("Failed to create %s, %m", path);
                return -errno;
        }
 
-       ret = set_owner(fd); // system_fw:system_fw
+       /* set a new file size */
+       ret = ftruncate(fd, sizeof(struct compatibility_info) * HAL_MODULE_END);
+       if (ret < 0) {
+               _E("Failed to ftruncate %s, %m", path);
+               return -errno;
+       }
+
+       /* system_fw:system_fw */
+       ret = set_owner(fd);
        if (ret < 0) {
                errno = -ret;
                _E("Failed to set owner, ret=%d, %m\n", ret);
@@ -359,7 +370,27 @@ static int write_comaptibility_info(struct compatibility_info *info, int entry_s
                return ret;
        }
 
-       n_write = write(fd, info, sizeof(struct compatibility_info) * entry_size);
+       *fd_out = fd;
+
+       return 0;
+}
+
+static int write_module_comaptibility_info(enum hal_module module,
+       struct compatibility_info *info)
+{
+       int fd = -1;
+       int ret;
+       ssize_t n_write;
+       off_t offset;
+
+       ret = open_result_file(compatibility_result_path, &fd, false);
+       if (ret < 0) {
+               _E("Failed to create open result file %s", compatibility_result_path);
+               return ret;
+       }
+
+       offset = sizeof(struct compatibility_info) * module;
+       n_write = pwrite(fd, info, sizeof(*info), offset);
        if (n_write == -1) {
                _E("Failed to write info, %m");
                close(fd);
@@ -397,6 +428,9 @@ static int load_module_compatibility_info(enum hal_module module,
 
        close(fd);
 
+       if (!info->initialized)
+               return -ENODATA;
+
        return 0;
 }
 
@@ -405,17 +439,28 @@ static int load_module_compatibility_info_fallback(enum hal_module module,
 {
        halcc_manifest *manifest = NULL;
        struct compatibility_info infos[HAL_MODULE_END] = { 0 , };
+       struct __hal_module_info *module_info = NULL;
        int ret;
 
-       assert(module >= HAL_MODULE_UNKNOWN);
-       assert(module < HAL_MODULE_END);
        assert(info);
 
+       if (_hal_api_conf_init()) {
+               return -ENODATA;
+       }
+
+       module_info = _hal_api_conf_get_module_info(module, NULL);
+       if (!module_info || !module_info->manifest) {
+               _hal_api_conf_exit();
+               return -EINVAL;
+       }
+
+       _hal_api_conf_exit();
+
        ret = halcc_manifest_new(&manifest);
        if (ret < 0)
                return ret;
 
-       ret = halcc_parse_directory(manifest_directory, manifest);
+       ret = halcc_parse_path(module_info->manifest, manifest);
        if (ret < 0) {
                halcc_manifest_free(manifest);
                return ret;
@@ -439,7 +484,14 @@ static int load_module_compatibility_info_fallback(enum hal_module module,
        if (skip_version_check)
                return 0;
 
-       return write_comaptibility_info(infos, HAL_MODULE_END);
+       /* Write all available(initialized) info */
+       for (enum hal_module index = HAL_MODULE_UNKNOWN; index < HAL_MODULE_END; ++index) {
+               if (!infos[index].initialized)
+                       continue;
+               write_module_comaptibility_info(index, &infos[index]);
+       }
+
+       return 0;
 }
 
 int hal_api_cc_check_backend_compatibility(enum hal_module module,
index 4efb22d80d3c2058bedd95b187bbd36e64dcfc0c..8e57d8a3e2ecfff1134396f386197135067779ba 100644 (file)
@@ -121,6 +121,7 @@ static struct __hal_module_info* _get_module_info_with_library_name(enum hal_mod
        new_info->library_name = g_strdup_printf("/hal/lib/%s", library_name);
 #endif
        new_info->symbol_name = g_strdup(info->symbol_name);
+       new_info->manifest = g_strdup(info->manifest);
        new_info->hal_api = info->hal_api;
        new_info->hal_backend_extension = true;
 
index 8a0a2cadbd40cd74c09cdae68342dbdaceffe986..0593456de849aa8e62283f6abc36d6d9b4170ef4 100644 (file)
@@ -32,6 +32,7 @@ static struct __hal_module_info g_hal_module_info[] = {
                .library_name           = "/hal/lib/libhal-backend-tbm.so",
                .library_name_64bit     = "/hal/lib64/libhal-backend-tbm.so",
                .symbol_name            = "hal_backend_tbm_data",
+               .manifest               = "/etc/hal/hal-api-tbm-manifest.xml",
                .hal_api                = true,
        },
        [HAL_MODULE_TDM] = {
@@ -43,6 +44,7 @@ static struct __hal_module_info g_hal_module_info[] = {
                .library_name           = "/hal/lib/libhal-backend-tdm.so",
                .library_name_64bit     = "/hal/lib64/libhal-backend-tdm.so",
                .symbol_name            = "hal_backend_tdm_data",
+               .manifest               = "/etc/hal/hal-api-tdm-manifest.xml",
                .hal_api                = true,
        },
        [HAL_MODULE_COREGL] = {
@@ -54,6 +56,7 @@ static struct __hal_module_info g_hal_module_info[] = {
                .library_name           = NULL,
                .library_name_64bit     = NULL,
                .symbol_name            = NULL,
+               .manifest               = NULL,
                .hal_api                = false,
        },
        [HAL_MODULE_INPUT] = {
@@ -65,6 +68,7 @@ static struct __hal_module_info g_hal_module_info[] = {
                .library_name           = NULL,
                .library_name_64bit     = NULL,
                .symbol_name            = NULL,
+               .manifest               = NULL,
                .hal_api                = false,
        },
 
@@ -78,6 +82,7 @@ static struct __hal_module_info g_hal_module_info[] = {
                .library_name           = "/hal/lib/libhal-backend-audio.so",
                .library_name_64bit     = "/hal/lib64/libhal-backend-audio.so",
                .symbol_name            = "hal_backend_audio_data",
+               .manifest               = "/etc/hal/hal-api-audio-manifest.xml",
                .hal_api                = true,
        },
        [HAL_MODULE_CAMERA] = {
@@ -89,6 +94,7 @@ static struct __hal_module_info g_hal_module_info[] = {
                .library_name           = "/hal/lib/libhal-backend-camera.so",
                .library_name_64bit     = "/hal/lib64/libhal-backend-camera.so",
                .symbol_name            = "hal_backend_camera_data",
+               .manifest               = "/etc/hal/hal-api-camera-manifest.xml",
                .hal_api                = true,
        },
        [HAL_MODULE_RADIO] = {
@@ -100,6 +106,7 @@ static struct __hal_module_info g_hal_module_info[] = {
                .library_name           = "/hal/lib/libhal-backend-radio.so",
                .library_name_64bit     = "/hal/lib64/libhal-backend-radio.so",
                .symbol_name            = "hal_backend_radio_data",
+               .manifest               = "/etc/hal/hal-api-radio-manifest.xml",
                .hal_api                = true,
        },
        [HAL_MODULE_CODEC] = {
@@ -111,6 +118,7 @@ static struct __hal_module_info g_hal_module_info[] = {
                .library_name           = NULL,
                .library_name_64bit     = NULL,
                .symbol_name            = NULL,
+               .manifest               = NULL,
                .hal_api                = false,
        },
        [HAL_MODULE_USB_AUDIO] = {
@@ -122,6 +130,7 @@ static struct __hal_module_info g_hal_module_info[] = {
                .library_name           = NULL,
                .library_name_64bit     = NULL,
                .symbol_name            = NULL,
+               .manifest               = NULL,
                .hal_api                = false,
        },
        [HAL_MODULE_ALSAUCM] = {
@@ -133,6 +142,7 @@ static struct __hal_module_info g_hal_module_info[] = {
                .library_name           = NULL,
                .library_name_64bit     = NULL,
                .symbol_name            = NULL,
+               .manifest               = NULL,
                .hal_api                = false,
        },
 
@@ -146,6 +156,7 @@ static struct __hal_module_info g_hal_module_info[] = {
                .library_name           = "/hal/lib/libhal-backend-bluetooth.so",
                .library_name_64bit     = "/hal/lib64/libhal-backend-bluetooth.so",
                .symbol_name            = "hal_backend_bluetooth_data",
+               .manifest               = "/etc/hal/hal-api-bluetooth-manifest.xml",
                .hal_api                = true,
        },
        [HAL_MODULE_WIFI] = {
@@ -157,6 +168,7 @@ static struct __hal_module_info g_hal_module_info[] = {
                .library_name           = "/hal/lib/libhal-backend-wifi.so",
                .library_name_64bit     = "/hal/lib64/libhal-backend-wifi.so",
                .symbol_name            = "hal_backend_wifi_data",
+               .manifest               = "/etc/hal/hal-api-wifi-manifest.xml",
                .hal_api                = true,
        },
        [HAL_MODULE_NAN] = {
@@ -168,6 +180,7 @@ static struct __hal_module_info g_hal_module_info[] = {
                .library_name           = NULL,
                .library_name_64bit     = NULL,
                .symbol_name            = NULL,
+               .manifest               = NULL,
                .hal_api                = false,
        },
        [HAL_MODULE_NFC] = {
@@ -179,6 +192,7 @@ static struct __hal_module_info g_hal_module_info[] = {
                .library_name           = "/hal/lib/libhal-backend-nfc.so",
                .library_name_64bit     = "/hal/lib64/libhal-backend-nfc.so",
                .symbol_name            = "hal_backend_nfc_data",
+               .manifest               = "/etc/hal/hal-api-nfc-manifest.xml",
                .hal_api                = true,
        },
        [HAL_MODULE_ZIGBEE] = {
@@ -190,6 +204,7 @@ static struct __hal_module_info g_hal_module_info[] = {
                .library_name           = "/hal/lib/libhal-backend-zigbee.so",
                .library_name_64bit     = "/hal/lib64/libhal-backend-zigbee.so",
                .symbol_name            = "hal_backend_zigbee_data",
+               .manifest               = "/etc/hal/hal-api-zigbee-manifest.xml",
                .hal_api                = true,
        },
        [HAL_MODULE_UWB] = {
@@ -201,6 +216,7 @@ static struct __hal_module_info g_hal_module_info[] = {
                .library_name           = "/hal/lib/libhal-backend-uwb.so",
                .library_name_64bit     = "/hal/lib64/libhal-backend-uwb.so",
                .symbol_name            = "hal_backend_uwb_data",
+               .manifest               = "/etc/hal/hal-api-uwb-manifest.xml",
                .hal_api                = true,
        },
        [HAL_MODULE_MTP] = {
@@ -212,6 +228,7 @@ static struct __hal_module_info g_hal_module_info[] = {
                .library_name           = NULL,
                .library_name_64bit     = NULL,
                .symbol_name            = NULL,
+               .manifest               = NULL,
                .hal_api                = false,
        },
 
@@ -225,6 +242,7 @@ static struct __hal_module_info g_hal_module_info[] = {
                .library_name           = NULL,
                .library_name_64bit     = NULL,
                .symbol_name            = NULL,
+               .manifest               = NULL,
                .hal_api                = false,
        },
 
@@ -238,6 +256,7 @@ static struct __hal_module_info g_hal_module_info[] = {
                .library_name           = "/hal/lib/libhal-backend-location.so",
                .library_name_64bit     = "/hal/lib64/libhal-backend-location.so",
                .symbol_name            = "hal_backend_location_data",
+               .manifest               = "/etc/hal/hal-api-location-manifest.xml",
                .hal_api                = true,
        },
 
@@ -251,6 +270,7 @@ static struct __hal_module_info g_hal_module_info[] = {
                .library_name           = NULL,
                .library_name_64bit     = NULL,
                .symbol_name            = NULL,
+               .manifest               = NULL,
                .hal_api                = true,
        },
        [HAL_MODULE_POWER] = {
@@ -262,6 +282,7 @@ static struct __hal_module_info g_hal_module_info[] = {
                .library_name           = "/hal/lib/libhal-backend-power.so",
                .library_name_64bit     = "/hal/lib64/libhal-backend-power.so",
                .symbol_name            = "hal_backend_power_data",
+               .manifest               = "/etc/hal/hal-api-power-manifest.xml",
                .hal_api                = true,
        },
        [HAL_MODULE_SENSOR] = {
@@ -273,6 +294,7 @@ static struct __hal_module_info g_hal_module_info[] = {
                .library_name           = "/hal/lib/libhal-backend-sensor.so",
                .library_name_64bit     = "/hal/lib64/libhal-backend-sensor.so",
                .symbol_name            = "hal_backend_sensor_data",
+               .manifest               = "/etc/hal/hal-api-sensor-manifest.xml",
                .hal_api                = true,
        },
        [HAL_MODULE_PERIPHERAL] = {
@@ -284,6 +306,7 @@ static struct __hal_module_info g_hal_module_info[] = {
                .library_name           = NULL,
                .library_name_64bit     = NULL,
                .symbol_name            = NULL,
+               .manifest               = NULL,
                .hal_api                = false,
        },
        [HAL_MODULE_DEVICE_BATTERY] = {
@@ -295,6 +318,7 @@ static struct __hal_module_info g_hal_module_info[] = {
                .library_name           = "/hal/lib/libhal-backend-device-battery.so",
                .library_name_64bit     = "/hal/lib64/libhal-backend-device-battery.so",
                .symbol_name            = "hal_backend_device_battery_data",
+               .manifest               = "/etc/hal/hal-api-device-manifest.xml",
                .hal_api                = true,
        },
        [HAL_MODULE_DEVICE_BEZEL] = {
@@ -306,6 +330,7 @@ static struct __hal_module_info g_hal_module_info[] = {
                .library_name           = "/hal/lib/libhal-backend-device-bezel.so",
                .library_name_64bit     = "/hal/lib64/libhal-backend-device-bezel.so",
                .symbol_name            = "hal_backend_device_bezel_data",
+               .manifest               = "/etc/hal/hal-api-device-manifest.xml",
                .hal_api                = true,
        },
        [HAL_MODULE_DEVICE_DISPLAY] = {
@@ -317,6 +342,7 @@ static struct __hal_module_info g_hal_module_info[] = {
                .library_name           = "/hal/lib/libhal-backend-device-display.so",
                .library_name_64bit     = "/hal/lib64/libhal-backend-device-display.so",
                .symbol_name            = "hal_backend_device_display_data",
+               .manifest               = "/etc/hal/hal-api-device-manifest.xml",
                .hal_api                = true,
        },
        [HAL_MODULE_DEVICE_IR] = {
@@ -328,6 +354,7 @@ static struct __hal_module_info g_hal_module_info[] = {
                .library_name           = "/hal/lib/libhal-backend-device-ir.so",
                .library_name_64bit     = "/hal/lib64/libhal-backend-device-ir.so",
                .symbol_name            = "hal_backend_device_ir_data",
+               .manifest               = "/etc/hal/hal-api-device-manifest.xml",
                .hal_api                = true,
        },
        [HAL_MODULE_DEVICE_TOUCHSCREEN] = {
@@ -339,6 +366,7 @@ static struct __hal_module_info g_hal_module_info[] = {
                .library_name           = "/hal/lib/libhal-backend-device-touchscreen.so",
                .library_name_64bit     = "/hal/lib64/libhal-backend-device-touchscreen.so",
                .symbol_name            = "hal_backend_device_touchscreen_data",
+               .manifest               = "/etc/hal/hal-api-device-manifest.xml",
                .hal_api                = true,
        },
        [HAL_MODULE_DEVICE_LED] = {
@@ -350,6 +378,7 @@ static struct __hal_module_info g_hal_module_info[] = {
                .library_name           = "/hal/lib/libhal-backend-device-led.so",
                .library_name_64bit     = "/hal/lib64/libhal-backend-device-led.so",
                .symbol_name            = "hal_backend_device_led_data",
+               .manifest               = "/etc/hal/hal-api-device-manifest.xml",
                .hal_api                = true,
        },
        [HAL_MODULE_DEVICE_BOARD] = {
@@ -361,6 +390,7 @@ static struct __hal_module_info g_hal_module_info[] = {
                .library_name           = "/hal/lib/libhal-backend-device-board.so",
                .library_name_64bit     = "/hal/lib64/libhal-backend-device-board.so",
                .symbol_name            = "hal_backend_device_board_data",
+               .manifest               = "/etc/hal/hal-api-device-manifest.xml",
                .hal_api                = true,
        },
        [HAL_MODULE_DEVICE_EXTERNAL_CONNECTION] = {
@@ -372,6 +402,7 @@ static struct __hal_module_info g_hal_module_info[] = {
                .library_name           = "/hal/lib/libhal-backend-device-external-connection.so",
                .library_name_64bit     = "/hal/lib64/libhal-backend-device-external-connection.so",
                .symbol_name            = "hal_backend_device_external_connection_data",
+               .manifest               = "/etc/hal/hal-api-device-manifest.xml",
                .hal_api                = true,
        },
        [HAL_MODULE_DEVICE_THERMAL] = {
@@ -383,6 +414,7 @@ static struct __hal_module_info g_hal_module_info[] = {
                .library_name           = "/hal/lib/libhal-backend-device-thermal.so",
                .library_name_64bit     = "/hal/lib64/libhal-backend-device-thermal.so",
                .symbol_name            = "hal_backend_device_thermal_data",
+               .manifest               = "/etc/hal/hal-api-device-manifest.xml",
                .hal_api                = true,
        },
        [HAL_MODULE_DEVICE_USB_GADGET] = {
@@ -394,6 +426,7 @@ static struct __hal_module_info g_hal_module_info[] = {
                .library_name           = "/hal/lib/libhal-backend-device-usb-gadget.so",
                .library_name_64bit     = "/hal/lib64/libhal-backend-device-usb-gadget.so",
                .symbol_name            = "hal_backend_device_usb_gadget_data",
+               .manifest               = "/etc/hal/hal-api-device-manifest.xml",
                .hal_api                = true,
        },
        [HAL_MODULE_DEVICE_HAPTIC] = {
@@ -405,6 +438,7 @@ static struct __hal_module_info g_hal_module_info[] = {
                .library_name           = "/hal/lib/libhal-backend-device-haptic.so",
                .library_name_64bit     = "/hal/lib64/libhal-backend-device-haptic.so",
                .symbol_name            = "hal_backend_device_haptic_data",
+               .manifest               = "/etc/hal/hal-api-device-manifest.xml",
                .hal_api                = true,
        },
        [HAL_MODULE_DEVICE_MEMORY] = {
@@ -416,6 +450,7 @@ static struct __hal_module_info g_hal_module_info[] = {
                .library_name           = "/hal/lib/libhal-backend-device-memory.so",
                .library_name_64bit     = "/hal/lib64/libhal-backend-device-memory.so",
                .symbol_name            = "hal_backend_device_memory_data",
+               .manifest               = "/etc/hal/hal-api-device-manifest.xml",
                .hal_api                = true,
        },
        [HAL_MODULE_DEVICE_INPUT] = {
@@ -427,6 +462,7 @@ static struct __hal_module_info g_hal_module_info[] = {
                .library_name           = "/hal/lib/libhal-backend-device-input.so",
                .library_name_64bit     = "/hal/lib64/libhal-backend-device-input.so",
                .symbol_name            = "hal_backend_device_input_data",
+               .manifest               = "/etc/hal/hal-api-device-manifest.xml",
                .hal_api                = true,
        },
        [HAL_MODULE_DEVICE_POWER] = {
@@ -438,6 +474,7 @@ static struct __hal_module_info g_hal_module_info[] = {
                .library_name           = "/hal/lib/libhal-backend-device-power.so",
                .library_name_64bit     = "/hal/lib64/libhal-backend-device-power.so",
                .symbol_name            = "hal_backend_device_power_data",
+               .manifest               = "/etc/hal/hal-api-device-manifest.xml",
                .hal_api                = true,
        },
 };
index 945289a402cc743d3cc897ac42e21023a273913d..e8d0ce3d0ef041db760f43c88604a7c57029d273 100644 (file)
@@ -14,6 +14,8 @@
  * limitations under the License.
  */
 
+#define _GNU_SOURCE
+#include <stdio.h>
 #include <stdlib.h>
 #include <dlfcn.h>
 #include <unistd.h>
@@ -25,6 +27,7 @@
 #include "hal-common.h"
 #include "hal-common-interface.h"
 #include "hal-api-common-hook.h"
+#include "../../src/hal-api-conf.h"
 #include "../../src/hal-api-list.h"
 
 /*
@@ -72,6 +75,78 @@ static enum hal_module get_module_by_library_name(const char *library_name)
        return HAL_MODULE_UNKNOWN;
 }
 
+int set_module_info_manifest(const char *our_directory)
+{
+       int ret;
+
+       if (!our_directory)
+               return -1;
+
+       _hal_api_conf_init();
+
+       for (enum hal_module module = HAL_MODULE_UNKNOWN; module < HAL_MODULE_END; ++module) {
+               struct __hal_module_info *info = _hal_api_conf_get_module_info(module, NULL);
+               char *orig_manifest = NULL;
+
+               if (!info) {
+                       _hal_api_conf_exit();
+                       return -1;
+               }
+
+               orig_manifest = info->manifest;
+               if (!orig_manifest)
+                       continue;
+
+               /* We sneak into the data structure and modify it to what we want */
+               ret = asprintf(&info->manifest,
+                       "%s%s", our_directory, strrchr(orig_manifest, '/'));
+               if (ret == -1) {
+                       _hal_api_conf_exit();
+                       return -1;
+               }
+       }
+
+       _hal_api_conf_exit();
+
+       return 0;
+}
+
+int unset_module_info_manifest(void)
+{
+       int ret;
+
+       _hal_api_conf_init();
+
+       for (enum hal_module module = HAL_MODULE_UNKNOWN; module < HAL_MODULE_END; ++module) {
+               struct __hal_module_info *info = _hal_api_conf_get_module_info(module, NULL);
+               char *orig_manifest = NULL;
+
+               if (!info) {
+                       _hal_api_conf_exit();
+                       return -1;
+               }
+
+               orig_manifest = info->manifest;
+               if (!orig_manifest)
+                       continue;
+
+               /* Put it back to the original */
+               ret = asprintf(&info->manifest,
+                       "/etc/hal%s", strrchr(orig_manifest, '/'));
+               if (ret == -1) {
+                       _hal_api_conf_exit();
+                       return -1;
+               }
+
+               free(orig_manifest);
+               orig_manifest = NULL;
+       }
+
+       _hal_api_conf_exit();
+
+       return 0;
+}
+
 void mock_hal_backend_data_set_version(enum hal_module module,
        unsigned int major, unsigned int minor)
 {
index 7bd456eaf8eb79f5b4335098c7292c91a380406a..4f1abb55564dccfe7b655610df349700613cd154 100644 (file)
@@ -35,6 +35,8 @@ extern "C" {
  */
 #define ACCESS_DO_NOT_HOOK             (ACCESS_UNUSED_MODES & -ACCESS_UNUSED_MODES)
 
+int set_module_info_manifest(const char *our_directory);
+int unset_module_info_manifest(void);
 void mock_hal_backend_data_set_version(enum hal_module module,
        unsigned int major, unsigned int minor);
 void mock_hal_backend_data_unset_version(enum hal_module module);
index 5b1310aac04ed6f16ac9ca317aee7b930929f9d2..9e88e9c93a67773deba8c715eedb9757a2a0182d 100644 (file)
@@ -43,12 +43,12 @@ class HalccObjectTest : public ::testing::Test
                        if (ret == -1)
                                FAIL();
 
+                       set_module_info_manifest(g_manifest_directory);
+
                        ret = asprintf(&g_compatibility_result_path, "%s/.hal-backend-compatibility", g_cwd);
                        if (ret == -1)
                                FAIL();
 
-                       set_compatibility_manifest_directory(g_manifest_directory);
-
                        ret = halcc_manifest_new(&g_manifest);
                        ASSERT_EQ(ret, 0);
 
@@ -60,7 +60,7 @@ class HalccObjectTest : public ::testing::Test
                        for (int module = HAL_MODULE_UNKNOWN; module < HAL_MODULE_END; ++module)
                                mock_hal_backend_data_unset_version((enum hal_module) module);
                        unlink(g_compatibility_result_path);
-                       unset_compatibility_manifest_directory();
+                       unset_module_info_manifest();
                        free(g_compatibility_result_path);
                        free(g_manifest_directory);
                        free(g_cwd);
diff --git a/tests/unittest/test-hal-manifest/hal-api-device-manifest.xml b/tests/unittest/test-hal-manifest/hal-api-device-manifest.xml
new file mode 100644 (file)
index 0000000..7b3c9d8
--- /dev/null
@@ -0,0 +1,22 @@
+<hal-api>
+       <manifest platform-version="9.0">
+               <hal-module>
+                       <name>HAL_MODULE_DEVICE_DISPLAY</name>
+                       <version>1.2</version>
+               </hal-module>
+       </manifest>
+       <manifest platform-version="10.0">
+               <hal-module>
+                       <name>HAL_MODULE_DEVICE_DISPLAY</name>
+                       <version>2.0</version>
+               </hal-module>
+       </manifest>
+       <manifest platform-version="11.0">
+               <hal-module>
+                       <name>HAL_MODULE_DEVICE_DISPLAY</name>
+                       <version>2.1</version>
+                       <version>3.0</version>
+               </hal-module>
+       </manifest>
+</hal-api>
+
diff --git a/tests/unittest/test-hal-manifest/hal-api-tdm-manifest.xml b/tests/unittest/test-hal-manifest/hal-api-tdm-manifest.xml
new file mode 100644 (file)
index 0000000..80174c7
--- /dev/null
@@ -0,0 +1,21 @@
+<hal-api>
+       <manifest platform-version="9.0">
+               <hal-module>
+                       <name>HAL_MODULE_TDM</name>
+                       <version>5.5</version>
+               </hal-module>
+       </manifest>
+       <manifest platform-version="10.0">
+               <hal-module>
+                       <name>HAL_MODULE_TDM</name>
+                       <version>5.5</version>
+               </hal-module>
+       </manifest>
+       <manifest platform-version="11.0">
+               <hal-module>
+                       <name>HAL_MODULE_TDM</name>
+                       <version>5.5</version>
+               </hal-module>
+       </manifest>
+</hal-api>
+
diff --git a/tests/unittest/test-hal-manifest/test-device-manifest.xml b/tests/unittest/test-hal-manifest/test-device-manifest.xml
deleted file mode 100644 (file)
index 7b3c9d8..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-<hal-api>
-       <manifest platform-version="9.0">
-               <hal-module>
-                       <name>HAL_MODULE_DEVICE_DISPLAY</name>
-                       <version>1.2</version>
-               </hal-module>
-       </manifest>
-       <manifest platform-version="10.0">
-               <hal-module>
-                       <name>HAL_MODULE_DEVICE_DISPLAY</name>
-                       <version>2.0</version>
-               </hal-module>
-       </manifest>
-       <manifest platform-version="11.0">
-               <hal-module>
-                       <name>HAL_MODULE_DEVICE_DISPLAY</name>
-                       <version>2.1</version>
-                       <version>3.0</version>
-               </hal-module>
-       </manifest>
-</hal-api>
-
diff --git a/tests/unittest/test-hal-manifest/test-tdm-manifest.xml b/tests/unittest/test-hal-manifest/test-tdm-manifest.xml
deleted file mode 100644 (file)
index 80174c7..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-<hal-api>
-       <manifest platform-version="9.0">
-               <hal-module>
-                       <name>HAL_MODULE_TDM</name>
-                       <version>5.5</version>
-               </hal-module>
-       </manifest>
-       <manifest platform-version="10.0">
-               <hal-module>
-                       <name>HAL_MODULE_TDM</name>
-                       <version>5.5</version>
-               </hal-module>
-       </manifest>
-       <manifest platform-version="11.0">
-               <hal-module>
-                       <name>HAL_MODULE_TDM</name>
-                       <version>5.5</version>
-               </hal-module>
-       </manifest>
-</hal-api>
-