mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-11-01 19:07:51 +00:00
Unit test case for ocmp_ina226
This commit is contained in:
@@ -49,6 +49,21 @@
|
||||
/*****************************************************************************
|
||||
* STRUCT/ENUM DEFINITIONS
|
||||
*****************************************************************************/
|
||||
typedef enum INA226Status {
|
||||
INA226_STATUS_BUS_VOLTAGE = 0,
|
||||
INA226_STATUS_SHUNT_VOLTAGE,
|
||||
INA226_STATUS_CURRENT,
|
||||
INA226_STATUS_POWER,
|
||||
} INA226Status;
|
||||
|
||||
typedef enum INA226Config {
|
||||
INA226_CONFIG_CURRENT_LIM = 0,
|
||||
} INA226Config;
|
||||
|
||||
typedef enum INA226Alert {
|
||||
INA226_ALERT_OVERCURRENT = 0,
|
||||
} INA226Alert;
|
||||
|
||||
typedef enum INA226_Event {
|
||||
INA226_EVT_SOL = INA_MSK_SOL, /* Shunt over-voltage */
|
||||
INA226_EVT_SUL = INA_MSK_SUL, /* Shunt under-voltage */
|
||||
|
||||
@@ -11,21 +11,6 @@
|
||||
#include "common/inc/global/Framework.h"
|
||||
#include "inc/devices/ina226.h"
|
||||
|
||||
typedef enum INA226Status {
|
||||
INA226_STATUS_BUS_VOLTAGE = 0,
|
||||
INA226_STATUS_SHUNT_VOLTAGE,
|
||||
INA226_STATUS_CURRENT,
|
||||
INA226_STATUS_POWER,
|
||||
} INA226Status;
|
||||
|
||||
typedef enum INA226Config {
|
||||
INA226_CONFIG_CURRENT_LIM = 0,
|
||||
} INA226Config;
|
||||
|
||||
typedef enum INA226Alert {
|
||||
INA226_ALERT_OVERCURRENT = 0,
|
||||
} INA226Alert;
|
||||
|
||||
static bool _get_status(void *driver, unsigned int param_id, void *return_buf)
|
||||
{
|
||||
switch (param_id) {
|
||||
|
||||
@@ -166,6 +166,9 @@ $(PATHB)Test_ocmp_ltc4015$(TARGET_EXTENSION): $(STD_FILES) $(TEST_OCMP_LTC4015_S
|
||||
TEST_OCMP_powerSource_SRC=$(OCWARE_ROOT)/src/devices/ocmp_wrappers/ocmp_powerSource.c $(OCWARE_ROOT)/src/devices/powerSource.c $(OCWARE_ROOT)/src/drivers/GpioSX1509.c $(OCWARE_ROOT)/src/devices/sx1509.c $(OCWARE_ROOT)/src/helpers/memory.c $(OCWARE_ROOT)/src/devices/i2cbus.c fake/fake_GPIO.c fake/fake_I2C.c fake/fake_ThreadedISR.c stub/stub_GateMutex.c stub/stub_GateMutex.c $(OCWARE_ROOT)/src/post/post_util.c fake/fake_SX1509_register.c fake/fake_powerSource.c $(OCWARE_ROOT)/platform/oc-sdr/cfg/OC_CONNECT_GBC.c
|
||||
$(PATHB)Test_ocmp_powerSource$(TARGET_EXTENSION): $(STD_FILES) $(TEST_OCMP_powerSource_SRC) $(INC_M)
|
||||
|
||||
TEST_OCMP_INA226_SRC=$(OCWARE_ROOT)/src/devices/ocmp_wrappers/ocmp_ina226.c $(OCWARE_ROOT)/src/devices/ina226.c $(OCWARE_ROOT)/src/drivers/GpioSX1509.c $(OCWARE_ROOT)/src/devices/sx1509.c $(OCWARE_ROOT)/src/helpers/memory.c $(OCWARE_ROOT)/src/devices/i2cbus.c fake/fake_GPIO.c fake/fake_I2C.c fake/fake_ThreadedISR.c stub/stub_GateMutex.c stub/stub_GateMutex.c stub/stub_ina226.c $(OCWARE_ROOT)/src/post/post_util.c fake/fake_SX1509_register.c fake/fake_ina226.c $(OCWARE_ROOT)/platform/oc-sdr/cfg/OC_CONNECT_GBC.c $(OCWARE_ROOT)/platform/oc-sdr/cfg/OC_CONNECT_SDR.c $(OCWARE_ROOT)/platform/oc-sdr/cfg/OC_CONNECT_FE.c
|
||||
$(PATHB)Test_ocmp_ina226$(TARGET_EXTENSION): $(STD_FILES) $(TEST_OCMP_INA226_SRC) $(INC_M)
|
||||
|
||||
$(PATHB)%$(TARGET_EXTENSION):
|
||||
$(C_COMPILER) $(CFLAGS) $(INC_DIRS) $(SYMBOLS) $^ -o $@
|
||||
$(COV_CMDS)
|
||||
|
||||
52
firmware/ec/test/fake/fake_ina226.c
Normal file
52
firmware/ec/test/fake/fake_ina226.c
Normal file
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* Copyright (c) 2017-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
#include "include/test_ina226.h"
|
||||
|
||||
OcGpio_Port ec_io = {
|
||||
.fn_table = &FakeGpio_fnTable,
|
||||
.object_data = &(FakeGpio_Obj){},
|
||||
};
|
||||
INA226_Dev ina226_invalid_dev = {
|
||||
.cfg =
|
||||
{
|
||||
.dev =
|
||||
{
|
||||
.bus = 4,
|
||||
.slave_addr = 0x02,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
INA226_Dev ina226_invalid_bus = {
|
||||
.cfg =
|
||||
{
|
||||
.dev =
|
||||
{
|
||||
.bus = 0xFF,
|
||||
.slave_addr = 0x01,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
uint16_t INA226_regs[] = {
|
||||
[INA226_CONFIG_REG] = 0x0000, [INA226_SHUNT_VOLT_REG] = 0x0000,
|
||||
[INA226_BUS_VOLT_REG] = 0x0000, [INA226_POWER_REG] = 0x0000,
|
||||
[INA226_CURRENT_REG] = 0x0000, [INA226_CALIBRATION_REG] = 0x0000,
|
||||
[INA226_MASK_ENABLE_REG] = 0x0000, [INA226_ALERT_REG] = 0x0000,
|
||||
[INA226_MANF_ID_REG] = 0x0000, [INA226_DIE_ID_REG] = 0x0000,
|
||||
[INA226_END_REG] = 0x0000,
|
||||
};
|
||||
|
||||
bool INA226_GpioPins[] = {
|
||||
[0x05] = OCGPIO_CFG_INPUT,
|
||||
};
|
||||
|
||||
uint32_t INA226_GpioConfig[] = {
|
||||
[0x05] = OCGPIO_CFG_INPUT,
|
||||
};
|
||||
55
firmware/ec/test/include/test_ina226.h
Normal file
55
firmware/ec/test/include/test_ina226.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* Copyright (c) 2017-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
#ifndef _TEST_INA226_H
|
||||
#define _TEST_INA226_H
|
||||
|
||||
#include "common/inc/global/Framework.h"
|
||||
#include "common/inc/ocmp_wrappers/ocmp_ina226.h"
|
||||
#include "fake/fake_GPIO.h"
|
||||
#include "fake/fake_I2C.h"
|
||||
#include "fake/fake_ThreadedISR.h"
|
||||
#include "inc/devices/ina226.h"
|
||||
#include <string.h>
|
||||
#include "unity.h"
|
||||
/* ======================== Constants & variables =========================== */
|
||||
#define INA226_ALERT_MASK 0x8000
|
||||
#define INA226_CAL_VALUE 0
|
||||
#define INA226_DEVICE_ID 0x2260
|
||||
#define INA226_INVALID_CONFIG_PARAMID 1
|
||||
#define INA226_INVALID_DEVICE_ID 0xC802
|
||||
#define INA226_INVALID_MANF_ID 0x5DC7
|
||||
#define INA226_INVALID_STATUS_PARAMID 4
|
||||
#define INA226_LOWER_BOUND_VAL -345
|
||||
#define INA226_MANF_ID 0x5449
|
||||
#define INA226_POST_DATA_NULL 0x00
|
||||
#define INA226_RESET 0x0001
|
||||
#define INA226_REG_VALUE 0x0960
|
||||
#define INA226_UPPER_BOUND_VAL 65535
|
||||
|
||||
typedef enum INA226Regs {
|
||||
INA226_CONFIG_REG = 0x0000,
|
||||
INA226_SHUNT_VOLT_REG,
|
||||
INA226_BUS_VOLT_REG,
|
||||
INA226_POWER_REG,
|
||||
INA226_CURRENT_REG,
|
||||
INA226_CALIBRATION_REG,
|
||||
INA226_MASK_ENABLE_REG,
|
||||
INA226_ALERT_REG,
|
||||
INA226_MANF_ID_REG = 0xFE,
|
||||
INA226_DIE_ID_REG = 0xFF,
|
||||
INA226_END_REG = 0xFFFF,
|
||||
} INA226Regs;
|
||||
|
||||
uint16_t ina226_stub_set_currentLimit(uint16_t currentLimt);
|
||||
uint16_t ina226_stub_get_currentLimit(uint16_t currentLimt);
|
||||
uint16_t ina226_stub_get_busVlotage_status(uint16_t busVoltage);
|
||||
uint16_t ina226_stub_get_shuntVlotage_status(uint16_t shuntVoltage);
|
||||
uint16_t ina226_stub_get_current_status(uint16_t current);
|
||||
uint16_t ina226_stub_get_power_status(uint16_t power);
|
||||
#endif
|
||||
52
firmware/ec/test/stub/stub_ina226.c
Normal file
52
firmware/ec/test/stub/stub_ina226.c
Normal file
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* Copyright (c) 2017-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
#include <stdint.h>
|
||||
#include "include/test_ina226.h"
|
||||
|
||||
uint16_t ina226_stub_set_currentLimit(uint16_t currentLimt)
|
||||
{
|
||||
uint16_t expCurrentLimt = 0;
|
||||
expCurrentLimt = (2048 * (currentLimt / (0.1)) / (0x6400));
|
||||
return expCurrentLimt;
|
||||
}
|
||||
|
||||
uint16_t ina226_stub_get_currentLimit(uint16_t currentLimt)
|
||||
{
|
||||
uint16_t expCurrentLimt = 0;
|
||||
expCurrentLimt = ((currentLimt * (0.1) * (0x6400)) / 2048);
|
||||
return expCurrentLimt;
|
||||
}
|
||||
|
||||
uint16_t ina226_stub_get_busVlotage_status(uint16_t busVoltage)
|
||||
{
|
||||
uint16_t expBusVoltage = 0;
|
||||
expBusVoltage = busVoltage * 1.25;
|
||||
return expBusVoltage;
|
||||
}
|
||||
|
||||
uint16_t ina226_stub_get_shuntVlotage_status(uint16_t shuntVoltage)
|
||||
{
|
||||
uint16_t expshuntVoltage = 0;
|
||||
expshuntVoltage = shuntVoltage * 2.5;
|
||||
return expshuntVoltage;
|
||||
}
|
||||
|
||||
uint16_t ina226_stub_get_current_status(uint16_t current)
|
||||
{
|
||||
uint16_t expCurrent = 0;
|
||||
expCurrent = current * 0.1;
|
||||
return expCurrent;
|
||||
}
|
||||
|
||||
uint16_t ina226_stub_get_power_status(uint16_t power)
|
||||
{
|
||||
uint16_t expPower = 0;
|
||||
expPower = power * 2.5;
|
||||
return expPower;
|
||||
}
|
||||
Binary file not shown.
320
firmware/ec/test/suites/Test_ocmp_ina226.c
Normal file
320
firmware/ec/test/suites/Test_ocmp_ina226.c
Normal file
@@ -0,0 +1,320 @@
|
||||
/**
|
||||
* Copyright (c) 2017-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
#include "include/test_ina226.h"
|
||||
|
||||
extern bool INA226_GpioPins[0x05];
|
||||
extern INA226_Config fact_sdr_3v_ps_cfg;
|
||||
extern INA226_Dev ina226_invalid_bus;
|
||||
extern INA226_Dev ina226_invalid_dev;
|
||||
extern INA226_Dev sdr_fpga_ps;
|
||||
extern OcGpio_Port ec_io;
|
||||
extern uint16_t INA226_regs[INA226_END_REG];
|
||||
extern uint32_t INA226_GpioConfig[0x05];
|
||||
/* ============================= Boilerplate ================================ */
|
||||
void suite_setUp(void)
|
||||
{
|
||||
FakeGpio_registerDevSimple(INA226_GpioPins, INA226_GpioConfig);
|
||||
fake_I2C_init();
|
||||
|
||||
fake_I2C_registerDevSimple(sdr_fpga_ps.cfg.dev.bus,
|
||||
sdr_fpga_ps.cfg.dev.slave_addr, INA226_regs,
|
||||
sizeof(INA226_regs) + 1, sizeof(INA226_regs[0]),
|
||||
sizeof(uint8_t), FAKE_I2C_DEV_BIG_ENDIAN);
|
||||
}
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
memset(INA226_regs, 0, sizeof(INA226_regs));
|
||||
|
||||
ina226_init(&sdr_fpga_ps);
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void suite_tearDown(void)
|
||||
{
|
||||
fake_I2C_deinit(); /* This will automatically unregister devices */
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
||||
void OCMP_GenerateAlert(const AlertData *alert_data, unsigned int alert_id,
|
||||
const void *data)
|
||||
{
|
||||
}
|
||||
#pragma GCC diagnostic pop
|
||||
/* ================================ Tests =================================== */
|
||||
void test_probe(void)
|
||||
{
|
||||
POSTData postData;
|
||||
/* Test with the actual values */
|
||||
INA226_regs[INA226_DIE_ID_REG] = INA226_DEVICE_ID;
|
||||
INA226_regs[INA226_MANF_ID_REG] = INA226_MANF_ID;
|
||||
TEST_ASSERT_EQUAL(POST_DEV_FOUND,
|
||||
INA226_fxnTable.cb_probe(&sdr_fpga_ps, &postData));
|
||||
TEST_ASSERT_EQUAL(sdr_fpga_ps.cfg.dev.bus, postData.i2cBus);
|
||||
TEST_ASSERT_EQUAL_HEX8(sdr_fpga_ps.cfg.dev.slave_addr, postData.devAddr);
|
||||
TEST_ASSERT_EQUAL_HEX8(INA226_MANF_ID, postData.manId);
|
||||
TEST_ASSERT_EQUAL_HEX8(INA226_DEVICE_ID, postData.devId);
|
||||
|
||||
postData.i2cBus = INA226_POST_DATA_NULL;
|
||||
postData.devAddr = INA226_POST_DATA_NULL;
|
||||
postData.manId = INA226_POST_DATA_NULL;
|
||||
postData.devId = INA226_POST_DATA_NULL;
|
||||
|
||||
/* Test with an incorrect device ID */
|
||||
INA226_regs[INA226_DIE_ID_REG] = INA226_INVALID_DEVICE_ID;
|
||||
TEST_ASSERT_EQUAL(POST_DEV_ID_MISMATCH,
|
||||
INA226_fxnTable.cb_probe(&sdr_fpga_ps, &postData));
|
||||
TEST_ASSERT_EQUAL(INA226_POST_DATA_NULL, postData.i2cBus);
|
||||
TEST_ASSERT_EQUAL_HEX8(INA226_POST_DATA_NULL, postData.devAddr);
|
||||
TEST_ASSERT_EQUAL_HEX8(INA226_POST_DATA_NULL, postData.manId);
|
||||
TEST_ASSERT_EQUAL_HEX8(INA226_POST_DATA_NULL, postData.devId);
|
||||
|
||||
/* Test with an incorrect mfg ID */
|
||||
INA226_regs[INA226_DIE_ID_REG] = INA226_DEVICE_ID;
|
||||
INA226_regs[INA226_MANF_ID_REG] = INA226_INVALID_MANF_ID;
|
||||
TEST_ASSERT_EQUAL(POST_DEV_ID_MISMATCH,
|
||||
INA226_fxnTable.cb_probe(&sdr_fpga_ps, &postData));
|
||||
TEST_ASSERT_EQUAL(INA226_POST_DATA_NULL, postData.i2cBus);
|
||||
TEST_ASSERT_EQUAL_HEX8(INA226_POST_DATA_NULL, postData.devAddr);
|
||||
TEST_ASSERT_EQUAL_HEX8(INA226_POST_DATA_NULL, postData.manId);
|
||||
TEST_ASSERT_EQUAL_HEX8(INA226_POST_DATA_NULL, postData.devId);
|
||||
|
||||
/* Test with a missing device */
|
||||
TEST_ASSERT_EQUAL(POST_DEV_MISSING,
|
||||
INA226_fxnTable.cb_probe(&ina226_invalid_dev, &postData));
|
||||
TEST_ASSERT_EQUAL(INA226_POST_DATA_NULL, postData.i2cBus);
|
||||
TEST_ASSERT_EQUAL_HEX8(INA226_POST_DATA_NULL, postData.devAddr);
|
||||
TEST_ASSERT_EQUAL_HEX8(INA226_POST_DATA_NULL, postData.manId);
|
||||
TEST_ASSERT_EQUAL_HEX8(INA226_POST_DATA_NULL, postData.devId);
|
||||
|
||||
/* Test with a missing bus */
|
||||
TEST_ASSERT_EQUAL(POST_DEV_MISSING,
|
||||
INA226_fxnTable.cb_probe(&ina226_invalid_bus, &postData));
|
||||
TEST_ASSERT_EQUAL(INA226_POST_DATA_NULL, postData.i2cBus);
|
||||
TEST_ASSERT_EQUAL_HEX8(INA226_POST_DATA_NULL, postData.devAddr);
|
||||
TEST_ASSERT_EQUAL_HEX8(INA226_POST_DATA_NULL, postData.manId);
|
||||
TEST_ASSERT_EQUAL_HEX8(INA226_POST_DATA_NULL, postData.devId);
|
||||
}
|
||||
|
||||
void test_init(void)
|
||||
{
|
||||
uint16_t expCurrentVal = 0;
|
||||
|
||||
INA226_regs[INA226_CONFIG_REG] = 0;
|
||||
INA226_regs[INA226_CALIBRATION_REG] = 0;
|
||||
INA226_regs[INA226_ALERT_REG] = 0;
|
||||
INA226_regs[INA226_MASK_ENABLE_REG] = 0;
|
||||
AlertData alert_data = {
|
||||
.subsystem = 7,
|
||||
.componentId = 1,
|
||||
.deviceId = 0,
|
||||
};
|
||||
|
||||
TEST_ASSERT_EQUAL(POST_DEV_CFG_DONE,
|
||||
INA226_fxnTable.cb_init(&sdr_fpga_ps, &fact_sdr_3v_ps_cfg,
|
||||
&alert_data));
|
||||
expCurrentVal =
|
||||
ina226_stub_set_currentLimit(fact_sdr_3v_ps_cfg.current_lim);
|
||||
|
||||
/* Make sure we've reset the device */
|
||||
TEST_ASSERT_BITS_HIGH(INA226_RESET, INA226_regs[INA226_CONFIG_REG]);
|
||||
|
||||
/* Make sure calibration register gets initialized */
|
||||
TEST_ASSERT_NOT_EQUAL(INA226_CAL_VALUE,
|
||||
INA226_regs[INA226_CALIBRATION_REG]);
|
||||
|
||||
/* Set CurrentLimit */
|
||||
TEST_ASSERT_EQUAL_HEX16(expCurrentVal, INA226_regs[INA226_ALERT_REG]);
|
||||
|
||||
/* Make Alert is enable */
|
||||
TEST_ASSERT_EQUAL_HEX16(INA226_ALERT_MASK,
|
||||
INA226_regs[INA226_MASK_ENABLE_REG]);
|
||||
|
||||
/* Test with a missing device */
|
||||
TEST_ASSERT_EQUAL(POST_DEV_CFG_FAIL, INA226_fxnTable.cb_init(
|
||||
&ina226_invalid_dev,
|
||||
&fact_sdr_3v_ps_cfg, &alert_data));
|
||||
|
||||
/* Test with a missing bus */
|
||||
TEST_ASSERT_EQUAL(POST_DEV_CFG_FAIL, INA226_fxnTable.cb_init(
|
||||
&ina226_invalid_bus,
|
||||
&fact_sdr_3v_ps_cfg, &alert_data));
|
||||
|
||||
/* Test with NULL config*/
|
||||
TEST_ASSERT_EQUAL(
|
||||
POST_DEV_CFG_FAIL,
|
||||
INA226_fxnTable.cb_init(&ina226_invalid_bus, NULL, &alert_data));
|
||||
}
|
||||
|
||||
void test_get_status(void)
|
||||
{
|
||||
uint16_t busVoltageVal = 0;
|
||||
uint16_t expBusVoltageVal = 0;
|
||||
uint16_t shuntVoltageVal = 0;
|
||||
uint16_t expShuntVoltageVal = 0;
|
||||
uint16_t currentVal = 0;
|
||||
uint16_t expCurrentVal = 0;
|
||||
uint16_t powerVal = 0;
|
||||
uint16_t expPowerVal = 0;
|
||||
|
||||
INA226_regs[INA226_BUS_VOLT_REG] = 0x2580;
|
||||
TEST_ASSERT_EQUAL(
|
||||
true, INA226_fxnTable.cb_get_status(
|
||||
&sdr_fpga_ps, INA226_STATUS_BUS_VOLTAGE, &busVoltageVal));
|
||||
expBusVoltageVal =
|
||||
ina226_stub_get_busVlotage_status(INA226_regs[INA226_BUS_VOLT_REG]);
|
||||
TEST_ASSERT_EQUAL_HEX16(expBusVoltageVal, busVoltageVal);
|
||||
|
||||
INA226_regs[INA226_SHUNT_VOLT_REG] = 0x0168;
|
||||
TEST_ASSERT_EQUAL(
|
||||
true, INA226_fxnTable.cb_get_status(
|
||||
&sdr_fpga_ps, INA226_STATUS_SHUNT_VOLTAGE, &shuntVoltageVal));
|
||||
expShuntVoltageVal =
|
||||
ina226_stub_get_shuntVlotage_status(INA226_regs[INA226_SHUNT_VOLT_REG]);
|
||||
TEST_ASSERT_EQUAL_HEX16(expShuntVoltageVal, shuntVoltageVal);
|
||||
|
||||
INA226_regs[INA226_CURRENT_REG] = 0x1388;
|
||||
TEST_ASSERT_EQUAL(true, INA226_fxnTable.cb_get_status(&sdr_fpga_ps,
|
||||
INA226_STATUS_CURRENT,
|
||||
¤tVal));
|
||||
expCurrentVal =
|
||||
ina226_stub_get_current_status(INA226_regs[INA226_CURRENT_REG]);
|
||||
TEST_ASSERT_EQUAL_HEX16(expCurrentVal, currentVal);
|
||||
|
||||
INA226_regs[INA226_POWER_REG] = 0x02A8;
|
||||
TEST_ASSERT_EQUAL(true, INA226_fxnTable.cb_get_status(
|
||||
&sdr_fpga_ps, INA226_STATUS_POWER, &powerVal));
|
||||
expPowerVal = ina226_stub_get_power_status(INA226_regs[INA226_POWER_REG]);
|
||||
TEST_ASSERT_EQUAL_HEX16(expPowerVal, powerVal);
|
||||
|
||||
INA226_regs[INA226_POWER_REG] = 0x02A8;
|
||||
|
||||
/* Test with a invalid paramID */
|
||||
TEST_ASSERT_EQUAL(
|
||||
false, INA226_fxnTable.cb_get_status(
|
||||
&sdr_fpga_ps, INA226_INVALID_STATUS_PARAMID, &powerVal));
|
||||
|
||||
/* Test with a missing device */
|
||||
TEST_ASSERT_EQUAL(false, INA226_fxnTable.cb_get_status(&ina226_invalid_dev,
|
||||
INA226_STATUS_POWER,
|
||||
&powerVal));
|
||||
|
||||
/* Test with a missing bus */
|
||||
TEST_ASSERT_EQUAL(false, INA226_fxnTable.cb_get_status(&ina226_invalid_bus,
|
||||
INA226_STATUS_POWER,
|
||||
&powerVal));
|
||||
}
|
||||
|
||||
void test_get_config(void)
|
||||
{
|
||||
uint16_t currentVal = 0;
|
||||
uint16_t expCurrentVal = 0;
|
||||
INA226_regs[INA226_ALERT_REG] = 0x0000;
|
||||
|
||||
TEST_ASSERT_EQUAL(
|
||||
true, INA226_fxnTable.cb_get_config(
|
||||
&sdr_fpga_ps, INA226_CONFIG_CURRENT_LIM, ¤tVal));
|
||||
expCurrentVal = ina226_stub_get_currentLimit(INA226_regs[INA226_ALERT_REG]);
|
||||
TEST_ASSERT_EQUAL(expCurrentVal, currentVal);
|
||||
|
||||
/* Test with a invalid param id */
|
||||
TEST_ASSERT_EQUAL(
|
||||
false, INA226_fxnTable.cb_get_config(
|
||||
&sdr_fpga_ps, INA226_INVALID_CONFIG_PARAMID, ¤tVal));
|
||||
/* Test with a missing device */
|
||||
TEST_ASSERT_EQUAL(false, INA226_fxnTable.cb_get_config(
|
||||
&ina226_invalid_dev, INA226_CONFIG_CURRENT_LIM,
|
||||
¤tVal));
|
||||
|
||||
/* Test with a missing device */
|
||||
TEST_ASSERT_EQUAL(false, INA226_fxnTable.cb_get_config(
|
||||
&ina226_invalid_bus, INA226_CONFIG_CURRENT_LIM,
|
||||
¤tVal));
|
||||
}
|
||||
|
||||
void test_set_config(void)
|
||||
{
|
||||
uint16_t currentVal = 0x0BB8;
|
||||
uint16_t expCurrentVal = 0;
|
||||
INA226_regs[INA226_ALERT_REG] = 0x0000;
|
||||
TEST_ASSERT_EQUAL(
|
||||
true, INA226_fxnTable.cb_set_config(
|
||||
&sdr_fpga_ps, INA226_CONFIG_CURRENT_LIM, ¤tVal));
|
||||
expCurrentVal = ina226_stub_set_currentLimit(currentVal);
|
||||
TEST_ASSERT_EQUAL_HEX16(expCurrentVal, INA226_regs[INA226_ALERT_REG]);
|
||||
|
||||
/* Test with a invalid param id */
|
||||
TEST_ASSERT_EQUAL(
|
||||
false, INA226_fxnTable.cb_set_config(
|
||||
&sdr_fpga_ps, INA226_INVALID_CONFIG_PARAMID, ¤tVal));
|
||||
|
||||
/* Test with a missing device */
|
||||
TEST_ASSERT_EQUAL(false, INA226_fxnTable.cb_set_config(
|
||||
&ina226_invalid_dev, INA226_CONFIG_CURRENT_LIM,
|
||||
¤tVal));
|
||||
|
||||
/* Test with a missing device */
|
||||
TEST_ASSERT_EQUAL(false, INA226_fxnTable.cb_set_config(
|
||||
&ina226_invalid_bus, INA226_CONFIG_CURRENT_LIM,
|
||||
¤tVal));
|
||||
}
|
||||
|
||||
void test_invalid(void)
|
||||
{
|
||||
uint16_t currentVal = INA226_UPPER_BOUND_VAL;
|
||||
int16_t value = INA226_LOWER_BOUND_VAL;
|
||||
uint16_t expCurrentVal = 0;
|
||||
INA226_regs[INA226_ALERT_REG] = 0x0000;
|
||||
TEST_ASSERT_EQUAL(
|
||||
true, INA226_fxnTable.cb_set_config(
|
||||
&sdr_fpga_ps, INA226_CONFIG_CURRENT_LIM, ¤tVal));
|
||||
expCurrentVal = ina226_stub_set_currentLimit(currentVal);
|
||||
TEST_ASSERT_EQUAL(expCurrentVal, INA226_regs[INA226_ALERT_REG]);
|
||||
|
||||
expCurrentVal = 0;
|
||||
TEST_ASSERT_EQUAL(
|
||||
true, INA226_fxnTable.cb_set_config(&sdr_fpga_ps,
|
||||
INA226_CONFIG_CURRENT_LIM, &value));
|
||||
expCurrentVal = ina226_stub_set_currentLimit(value);
|
||||
TEST_ASSERT_EQUAL(expCurrentVal, INA226_regs[INA226_ALERT_REG]);
|
||||
}
|
||||
|
||||
void test_ocmp_ina226_alert_handler(void)
|
||||
{
|
||||
int16_t value = 0x0800;
|
||||
INA226_regs[INA226_CONFIG_REG] = 0;
|
||||
INA226_regs[INA226_CALIBRATION_REG] = 0;
|
||||
INA226_regs[INA226_ALERT_REG] = 0;
|
||||
INA226_regs[INA226_MASK_ENABLE_REG] = 0;
|
||||
AlertData alert_data = {
|
||||
.subsystem = 7,
|
||||
.componentId = 1,
|
||||
.deviceId = 0,
|
||||
};
|
||||
AlertData *alert_data_cp = malloc(sizeof(AlertData));
|
||||
*alert_data_cp = alert_data;
|
||||
TEST_ASSERT_EQUAL(POST_DEV_CFG_DONE,
|
||||
INA226_fxnTable.cb_init(&sdr_fpga_ps, &fact_sdr_3v_ps_cfg,
|
||||
alert_data_cp));
|
||||
|
||||
sdr_fpga_ps.obj.alert_cb(INA226_EVT_SOL, value, alert_data_cp);
|
||||
sdr_fpga_ps.obj.alert_cb(INA226_EVT_SUL, value, alert_data_cp);
|
||||
sdr_fpga_ps.obj.alert_cb(INA226_EVT_BOL, value, alert_data_cp);
|
||||
sdr_fpga_ps.obj.alert_cb(INA226_EVT_BUL, value, alert_data_cp);
|
||||
sdr_fpga_ps.obj.alert_cb(INA226_EVT_POL, value, alert_data_cp);
|
||||
sdr_fpga_ps.obj.alert_cb(INA226_EVT_COL, value, alert_data_cp);
|
||||
sdr_fpga_ps.obj.alert_cb(INA226_EVT_CUL, value, alert_data_cp);
|
||||
|
||||
/* Test for memory check */
|
||||
sdr_fpga_ps.obj.alert_cb(INA226_EVT_COL, value, NULL);
|
||||
}
|
||||
Reference in New Issue
Block a user