mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-27 10:22:08 +00:00
UT for ocmp_debug
This commit is contained in:
@@ -6,10 +6,10 @@
|
||||
* 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 "inc/ocmp_wrappers/ocmp_debugi2c.h"
|
||||
|
||||
#include "common/inc/global/ocmp_frame.h"
|
||||
#include "common/inc/global/Framework.h"
|
||||
#include "common/inc/ocmp_wrappers/ocmp_debugi2c.h"
|
||||
#include "inc/common/global_header.h"
|
||||
#include "inc/common/i2cbus.h"
|
||||
#include "inc/devices/debug_oci2c.h"
|
||||
|
||||
@@ -178,10 +178,12 @@ $(PATHB)Test_ocmp_cat24c04$(TARGET_EXTENSION): $(STD_FILES) $(TEST_OCMP_CAT24C04
|
||||
TEST_OCMP_LTC4275_SRC=$(OCWARE_ROOT)/src/devices/ocmp_wrappers/ocmp_ltc4275.c $(OCWARE_ROOT)/src/devices/ltc4275.c $(OCWARE_ROOT)/src/devices/i2cbus.c $(OCWARE_ROOT)/src/post/post_util.c fake/fake_GPIO.c fake/fake_I2C.c fake/fake_ThreadedISR.c fake/fake_ltc4275.c stub/stub_GateMutex.c $(OCWARE_ROOT)/platform/oc-sdr/cfg/OC_CONNECT_GBC.c
|
||||
$(PATHB)Test_ocmp_ltc4275$(TARGET_EXTENSION): $(STD_FILES) $(TEST_OCMP_LTC4275_SRC) $(INC_M)
|
||||
|
||||
|
||||
TEST_LTC4274_SRC=$(OCWARE_ROOT)/src/devices/ltc4274.c $(OCWARE_ROOT)/src/devices/i2cbus.c fake/fake_GPIO.c fake/fake_I2C.c fake/fake_ThreadedISR.c fake/fake_ltc4274.c stub/stub_GateMutex.c $(OCWARE_ROOT)/src/post/post_util.c $(OCWARE_ROOT)/platform/oc-sdr/cfg/OC_CONNECT_GBC.c
|
||||
$(PATHB)Test_ltc4274$(TARGET_EXTENSION): $(STD_FILES) $(TEST_LTC4274_SRC) $(INC_M)
|
||||
|
||||
TEST_OCMP_DEBUGI2C_SRC=$(OCWARE_ROOT)/src/devices/ocmp_wrappers/ocmp_debugi2c.c $(OCWARE_ROOT)/src/devices/i2cbus.c fake/fake_GPIO.c fake/fake_I2C.c fake/fake_ThreadedISR.c fake/fake_debugI2C.c $(OCWARE_ROOT)/platform/oc-sdr/cfg/OC_CONNECT_GBC.c
|
||||
$(PATHB)Test_ocmp_debugi2c$(TARGET_EXTENSION): $(STD_FILES) $(TEST_OCMP_DEBUGI2C_SRC)
|
||||
|
||||
$(PATHB)%$(TARGET_EXTENSION):
|
||||
$(C_COMPILER) $(CFLAGS) $(INC_DIRS) $(SYMBOLS) $^ -o $@
|
||||
$(COV_CMDS)
|
||||
|
||||
29
firmware/ec/test/fake/fake_debugI2C.c
Normal file
29
firmware/ec/test/fake/fake_debugI2C.c
Normal file
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* 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_debugI2c.h"
|
||||
|
||||
S_I2C_Cfg I2C_INVALID_DEV = {
|
||||
.bus = DEBUG_I2C_INVALID_BUS,
|
||||
};
|
||||
|
||||
S_OCI2C s_oci2c = { .slaveAddress = DEBUG_I2C_SLAVE_ADDR,
|
||||
.reg_address = DEBUG_I2C_REG_ADDR,
|
||||
.reg_value = DEBUG_I2C_REG_VALUE,
|
||||
.number_of_bytes = DEBUG_I2C_NO_OF_BYTES };
|
||||
|
||||
S_OCI2C s_oci2c_invalid = { .slaveAddress = DEBUG_I2C_INVALID_SLAVE_ADDR,
|
||||
.reg_address = DEBUG_I2C_REG_ADDR,
|
||||
.reg_value = DEBUG_I2C_REG_VALUE,
|
||||
.number_of_bytes = DEBUG_I2C_NO_OF_BYTES };
|
||||
|
||||
uint8_t DEBUG_I2C_regs[] = {
|
||||
[DEBUG_I2C_INTERRUPT_STATUS] = 0x00,
|
||||
[DEBUG_I2C_INTERRUPT_MASK] = 0x00,
|
||||
[DEBUG_I2C_END] = 0x00,
|
||||
};
|
||||
35
firmware/ec/test/include/test_debugI2c.h
Normal file
35
firmware/ec/test/include/test_debugI2c.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* 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_DEBUG_I2C_H
|
||||
#define _TEST_DEBUG_I2C_H
|
||||
|
||||
#include "common/inc/ocmp_wrappers/ocmp_debugi2c.h"
|
||||
#include "fake/fake_GPIO.h"
|
||||
#include "fake/fake_I2C.h"
|
||||
#include "inc/devices/debug_oci2c.h"
|
||||
#include <string.h>
|
||||
#include <ti/sysbios/knl/Task.h>
|
||||
#include "unity.h"
|
||||
|
||||
#define DEBUG_I2C_DEFAULT_VALUE 0x00
|
||||
#define DEBUG_I2C_INVALID_BUS 10
|
||||
#define DEBUG_I2C_INVALID_SLAVE_ADDR 0x48
|
||||
#define DEBUG_I2C_NO_OF_BYTES 1
|
||||
#define DEBUG_I2C_READ_WRITE_VALUE 0x5A
|
||||
#define DEBUG_I2C_REG_ADDR 0x01
|
||||
#define DEBUG_I2C_REG_VALUE 12
|
||||
#define DEBUG_I2C_SLAVE_ADDR 0x2F
|
||||
|
||||
typedef enum DEBUGI2CRegs {
|
||||
DEBUG_I2C_INTERRUPT_STATUS = 0x00,
|
||||
DEBUG_I2C_INTERRUPT_MASK,
|
||||
DEBUG_I2C_END = 0xFF,
|
||||
} DEBUGI2CRegs;
|
||||
|
||||
#endif
|
||||
Binary file not shown.
69
firmware/ec/test/suites/Test_ocmp_debugi2c.c
Normal file
69
firmware/ec/test/suites/Test_ocmp_debugi2c.c
Normal file
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* 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_debugI2c.h"
|
||||
|
||||
extern S_I2C_Cfg debug_I2C1;
|
||||
extern S_I2C_Cfg I2C_INVALID_DEV;
|
||||
extern S_OCI2C s_oci2c;
|
||||
extern S_OCI2C s_oci2c_invalid;
|
||||
extern S_OCI2C s_oci2c_2byte;
|
||||
extern uint8_t DEBUG_I2C_regs[DEBUG_I2C_END];
|
||||
/* ============================= Fake Functions ============================= */
|
||||
unsigned int s_task_sleep_ticks;
|
||||
xdc_Void ti_sysbios_knl_Task_sleep__E(xdc_UInt32 nticks)
|
||||
{
|
||||
s_task_sleep_ticks += nticks;
|
||||
}
|
||||
/* ============================= Boilerplate ================================ */
|
||||
void suite_setUp(void)
|
||||
{
|
||||
fake_I2C_init();
|
||||
fake_I2C_registerDevSimple(debug_I2C1.bus, s_oci2c.slaveAddress,
|
||||
&DEBUG_I2C_regs, sizeof(DEBUG_I2C_regs),
|
||||
sizeof(DEBUG_I2C_regs[0]), sizeof(uint8_t),
|
||||
FAKE_I2C_DEV_LITTLE_ENDIAN);
|
||||
}
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
memset(DEBUG_I2C_regs, 0, sizeof(DEBUG_I2C_regs));
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void suite_tearDown(void)
|
||||
{
|
||||
fake_I2C_deinit(); /* This will automatically unregister devices */
|
||||
}
|
||||
/* ================================ Tests =================================== */
|
||||
void test_i2c_read(void)
|
||||
{
|
||||
DEBUG_I2C_regs[DEBUG_I2C_INTERRUPT_MASK] = DEBUG_I2C_READ_WRITE_VALUE;
|
||||
TEST_ASSERT_EQUAL(true, i2c_read(&debug_I2C1, &s_oci2c));
|
||||
TEST_ASSERT_EQUAL_HEX8(DEBUG_I2C_READ_WRITE_VALUE, s_oci2c.reg_value);
|
||||
|
||||
/* Invalid bus */
|
||||
TEST_ASSERT_EQUAL(false, i2c_read(&I2C_INVALID_DEV, &s_oci2c));
|
||||
TEST_ASSERT_EQUAL(false, i2c_read(&debug_I2C1, &s_oci2c_invalid));
|
||||
}
|
||||
|
||||
void test_i2c_write(void)
|
||||
{
|
||||
DEBUG_I2C_regs[DEBUG_I2C_INTERRUPT_MASK] = DEBUG_I2C_DEFAULT_VALUE;
|
||||
s_oci2c.reg_value = DEBUG_I2C_READ_WRITE_VALUE;
|
||||
TEST_ASSERT_EQUAL(true, i2c_write(&debug_I2C1, &s_oci2c));
|
||||
TEST_ASSERT_EQUAL_HEX8(DEBUG_I2C_READ_WRITE_VALUE,
|
||||
DEBUG_I2C_regs[DEBUG_I2C_INTERRUPT_MASK]);
|
||||
|
||||
/* Invalid bus */
|
||||
TEST_ASSERT_EQUAL(false, i2c_write(&I2C_INVALID_DEV, &s_oci2c));
|
||||
TEST_ASSERT_EQUAL(false, i2c_write(&debug_I2C1, &s_oci2c_invalid));
|
||||
}
|
||||
Reference in New Issue
Block a user