-- Copyright (c) 2026 Huawei Technologies Co., Ltd.
-- openUBMC is licensed under Mulan PSL v2.
-- You can use this software according to the terms and conditions of the Mulan PSL v2.
-- You may obtain a copy of Mulan PSL v2 at: http://license.coscl.org.cn/MulanPSL2
-- THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
-- EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
-- MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
-- See the Mulan PSL v2 for more details.

-- Description: 升级模块测试初始化文件

local original_modules = {
    skynet = package.loaded['skynet'],
    logging = package.loaded['mc.logging'],
    context = package.loaded['mc.context'],
    utils = package.loaded['mc.utils'],
    global_utils = rawget(_G, 'utils'),
    client = package.loaded['storage.client'],
    parser_cfg = package.loaded['upgrade.parser_cfg'],
    controller_obj = package.loaded['controller.controller_object'],
    controller_firmware = package.loaded['controller_firmware.controller_firmware_object'],
    storageconfig = package.loaded['storageconfig.storageconfig_object'],
    drive_object = package.loaded['drive.drive_object'],
    drive_collection = package.loaded['drive.drive_collection'],
    method_misc = package.loaded['method_misc'],
    fructrl_handle = package.loaded['upgrade.fructrl_handle'],
    sml = package.loaded['sml'],
    bus_monitor_service = package.loaded['bus_monitor_service'],
}

-- 加载测试
require 'test_upgrade.test_parser_cfg'
require 'test_upgrade.test_controller_upgrade'
require 'test_upgrade.test_drive_upgrade'
require 'test_upgrade.test_fructrl_handle'
require 'test_upgrade.test_controller_firmware_obj'

-- 立即恢复原始模块，防止污染其他测试
package.loaded['skynet'] = original_modules.skynet
package.loaded['mc.logging'] = original_modules.logging
package.loaded['mc.context'] = original_modules.context
package.loaded['mc.utils'] = original_modules.utils
package.loaded['storage.client'] = original_modules.client
package.loaded['upgrade.parser_cfg'] = original_modules.parser_cfg
package.loaded['controller.controller_object'] = original_modules.controller_obj
package.loaded['controller_firmware.controller_firmware_object'] = original_modules.controller_firmware
package.loaded['storageconfig.storageconfig_object'] = original_modules.storageconfig
package.loaded['drive.drive_object'] = original_modules.drive_object
package.loaded['drive.drive_collection'] = original_modules.drive_collection
package.loaded['method_misc'] = original_modules.method_misc
package.loaded['upgrade.fructrl_handle'] = original_modules.fructrl_handle
package.loaded['sml'] = original_modules.sml
package.loaded['bus_monitor_service'] = original_modules.bus_monitor_service
rawset(_G, 'utils', original_modules.global_utils)
-- 注意：不恢复controller_upgrade和drive_upgrade，因为它们是被测试的模块
-- 注意：不恢复common_def，使用实际的common_def
-- 如果需要，可以清除它们: package.loaded['upgrade.controller_upgrade'] = nil
-- package.loaded['upgrade.drive_upgrade'] = nil

