-- 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.

local lu = require 'luaunit'
local upgrade_defs = require 'upgrade.upgrade_defs'

TEST_Upgrade_Defs = {}

-- 测试返回值常量
function TEST_Upgrade_Defs:test_ret_constants()
    lu.assertEquals(upgrade_defs.RET.OK, 0)
    lu.assertEquals(upgrade_defs.RET.ERR, -1)
    lu.assertEquals(upgrade_defs.RET.OTHERS_UPGRADING, 248)
    lu.assertEquals(upgrade_defs.RET.IN_UPGRADING, 36)
end

-- 测试升级目录常量
function TEST_Upgrade_Defs:test_upgrade_directory()
    lu.assertEquals(upgrade_defs.UPGRADE_NIC_DIR, '/data/backup/nic/up_cfg/')
    lu.assertNotNil(upgrade_defs.UPGRADE_NIC_DIR)
    lu.assertTrue(#upgrade_defs.UPGRADE_NIC_DIR > 0)
end

-- 测试升级文件名常量
function TEST_Upgrade_Defs:test_upgrade_filename()
    lu.assertEquals(upgrade_defs.UPGRADE_NIC_FILE_NAME, 'nic.hpm')
    lu.assertNotNil(upgrade_defs.UPGRADE_NIC_FILE_NAME)
end

-- 测试上电锁常量
function TEST_Upgrade_Defs:test_lock_forever_constant()
    lu.assertEquals(upgrade_defs.LOCK_FOREVER, 0xffff)
    lu.assertTrue(upgrade_defs.LOCK_FOREVER > 0)
end

-- 测试SPI驱动常量
function TEST_Upgrade_Defs:test_spi_driver_constants()
    lu.assertEquals(upgrade_defs.SPIKODRV, '/lib/modules/hibmc/sfc0_drv.ko')
    lu.assertEquals(upgrade_defs.DEVNAME_MTD, '/dev/mtd0')
    lu.assertNotNil(upgrade_defs.SPIKODRV)
    lu.assertNotNil(upgrade_defs.DEVNAME_MTD)
end

-- 测试Flash相关常量
function TEST_Upgrade_Defs:test_flash_constants()
    lu.assertEquals(upgrade_defs.PERIOD3_MHZ, 25)
    lu.assertEquals(upgrade_defs.FLASH_START_ADDRESS, 0)
    lu.assertEquals(upgrade_defs.SET_ROUTE_RETRY, 3)
    lu.assertEquals(upgrade_defs.O_SYNC_RDWR, 4098)
end

-- 测试协议常量
function TEST_Upgrade_Defs:test_protocol_constants()
    lu.assertEquals(upgrade_defs.PROTOCOL_NIC_SFC, 'SFC')
    lu.assertNotNil(upgrade_defs.PROTOCOL_NIC_SFC)
end

-- 测试所有常量都已定义
function TEST_Upgrade_Defs:test_all_constants_defined()
    lu.assertNotNil(upgrade_defs.RET)
    lu.assertNotNil(upgrade_defs.UPGRADE_NIC_DIR)
    lu.assertNotNil(upgrade_defs.UPGRADE_NIC_FILE_NAME)
    lu.assertNotNil(upgrade_defs.LOCK_FOREVER)
    lu.assertNotNil(upgrade_defs.SPIKODRV)
    lu.assertNotNil(upgrade_defs.DEVNAME_MTD)
    lu.assertNotNil(upgrade_defs.PROTOCOL_NIC_SFC)
end

return TEST_Upgrade_Defs

