mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-27 10:22:08 +00:00
Merge pull request #242 from Telecominfraproject/UT_ocmp_dat
UT for ocmp_dat-xxr5a-pp.c
This commit is contained in:
@@ -96,6 +96,8 @@ static bool _set_config(void *driver, unsigned int param_id, const void *data)
|
||||
}
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
||||
static ePostCode _probe(void *driver, POSTData *postData)
|
||||
{
|
||||
/* TODO: perhaps GPIO should provide probe/test function? for now we'll
|
||||
@@ -130,6 +132,7 @@ static ePostCode _init(void *driver, const void *config,
|
||||
_set_attenuation(driver, cfg_atten->attenuation);
|
||||
return POST_DEV_CFG_DONE;
|
||||
}
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
const Driver_fxnTable DATXXR5APP_fxnTable = {
|
||||
/* Message handlers */
|
||||
|
||||
@@ -193,6 +193,9 @@ $(PATHB)Test_ocmp_fe$(TARGET_EXTENSION): $(STD_FILES) $(TEST_OCMP_FE_SRC)
|
||||
TEST_OCMP_DEBUGOCGPIO_SRC=$(OCWARE_ROOT)/src/devices/ocmp_wrappers/ocmp_debugocgpio.c $(OCWARE_ROOT)/src/drivers/OcGpio.c fake/fake_GPIO.c fake/fake_I2C.c fake/fake_ThreadedISR.c fake/fake_debugocgpio.c fake/fake_SX1509_register.c fake/fake_PCA9557.c stub/stub_GateMutex.c $(OCWARE_ROOT)/src/drivers/GpioPCA9557.c $(OCWARE_ROOT)/src/devices/pca9557.c $(OCWARE_ROOT)/src/drivers/GpioSX1509.c $(OCWARE_ROOT)/src/devices/sx1509.c $(OCWARE_ROOT)/src/devices/i2cbus.c $(OCWARE_ROOT)/src/helpers/memory.c $(OCWARE_ROOT)/platform/oc-sdr/cfg/OC_CONNECT_GBC.c $(OCWARE_ROOT)/platform/oc-sdr/cfg/OC_CONNECT_SDR.c
|
||||
$(PATHB)Test_ocmp_debugocgpio$(TARGET_EXTENSION): $(STD_FILES) $(TEST_OCMP_DEBUGOCGPIO_SRC)
|
||||
|
||||
TEST_OCMP_DATXXR5A_SRC=$(OCWARE_ROOT)/src/devices/ocmp_wrappers/ocmp_dat-xxr5a-pp.c $(OCWARE_ROOT)/src/drivers/PinGroup.c $(OCWARE_ROOT)/src/devices/i2cbus.c fake/fake_I2C.c fake/fake_ThreadedISR.c fake/fake_dat.c fake/fake_PCA9557.c $(OCWARE_ROOT)/src/helpers/memory.c stub/stub_GateMutex.c $(OCWARE_ROOT)/src/drivers/GpioPCA9557.c $(OCWARE_ROOT)/src/devices/pca9557.c $(OCWARE_ROOT)/platform/oc-sdr/cfg/OC_CONNECT_FE.c
|
||||
$(PATHB)Test_ocmp_dat-xxr5a$(TARGET_EXTENSION): $(STD_FILES) $(TEST_OCMP_DATXXR5A_SRC)
|
||||
|
||||
$(PATHB)%$(TARGET_EXTENSION):
|
||||
$(C_COMPILER) $(CFLAGS) $(INC_DIRS) $(SYMBOLS) $^ -o $@
|
||||
$(COV_CMDS)
|
||||
|
||||
43
firmware/ec/test/fake/fake_dat.c
Normal file
43
firmware/ec/test/fake/fake_dat.c
Normal file
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* 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_dat.h"
|
||||
OcGpio_Port fe_ch1_gain_io = {
|
||||
.fn_table = &GpioPCA9557_fnTable,
|
||||
.cfg =
|
||||
&(PCA9557_Cfg){
|
||||
.i2c_dev = { OC_CONNECT1_I2C2, RFFE_CHANNEL1_IO_TX_ATTEN_ADDR },
|
||||
},
|
||||
.object_data = &(PCA9557_Obj){},
|
||||
};
|
||||
|
||||
OcGpio_Port fe_ch1_gain_io_invalid = {
|
||||
.fn_table = &GpioPCA9557_fnTable,
|
||||
.cfg =
|
||||
&(PCA9557_Cfg){
|
||||
.i2c_dev = { OC_CONNECT1_I2C4, RFFE_CHANNEL1_INVALID_SLAVE_ADDR },
|
||||
},
|
||||
.object_data = &(PCA9557_Obj){},
|
||||
};
|
||||
|
||||
Fe_Gain_Cfg fe_ch1_gain_invalid = {
|
||||
/* CH1_TX_ATTN_16DB */
|
||||
.pin_tx_attn_16db = { &fe_ch1_gain_io_invalid, 1 },
|
||||
/* CH1_TX_ATTN_P5DB */
|
||||
.pin_tx_attn_p5db = { &fe_ch1_gain_io_invalid, 2 },
|
||||
/* CH1_TX_ATTN_1DB */
|
||||
.pin_tx_attn_1db = { &fe_ch1_gain_io_invalid, 3 },
|
||||
/* CH1_TX_ATTN_2DB */
|
||||
.pin_tx_attn_2db = { &fe_ch1_gain_io_invalid, 4 },
|
||||
/* CH1_TX_ATTN_4DB */
|
||||
.pin_tx_attn_4db = { &fe_ch1_gain_io_invalid, 5 },
|
||||
/* CH1_TX_ATTN_8DB */
|
||||
.pin_tx_attn_8db = { &fe_ch1_gain_io_invalid, 6 },
|
||||
/* CH1_TX_ATTN_ENB */
|
||||
.pin_tx_attn_enb = { &fe_ch1_gain_io_invalid, 7 },
|
||||
};
|
||||
63
firmware/ec/test/include/test_dat.h
Normal file
63
firmware/ec/test/include/test_dat.h
Normal file
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* 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_DAT_H
|
||||
#define _TEST_DAT_H
|
||||
|
||||
#include "common/inc/global/Framework.h"
|
||||
#include "common/inc/global/OC_CONNECT1.h"
|
||||
#include "common/inc/ocmp_wrappers/ocmp_dat-xxr5a-pp.h"
|
||||
#include "drivers/GpioPCA9557.h"
|
||||
#include "drivers/PinGroup.h"
|
||||
#include "fake/fake_GPIO.h"
|
||||
#include "fake/fake_I2C.h"
|
||||
#include "fake/fake_ThreadedISR.h"
|
||||
#include "helpers/array.h"
|
||||
#include "helpers/attribute.h"
|
||||
#include "inc/devices/dat-xxr5a-pp.h"
|
||||
#include "inc/subsystem/rffe/rffe_ctrl.h"
|
||||
#include "include/test_PCA9557.h"
|
||||
#include <string.h>
|
||||
#include <ti/sysbios/knl/Task.h>
|
||||
#include "unity.h"
|
||||
|
||||
#define DAT_AATN_VALUE_0 0
|
||||
#define DAT_AATN_VALUE_1 1
|
||||
#define DAT_AATN_VALUE_2 2
|
||||
#define DAT_AATN_VALUE_4 4
|
||||
#define DAT_AATN_VALUE_8 8
|
||||
#define DAT_AATN_VALUE_16 16
|
||||
#define DAT_AATN_VALUE_32 32
|
||||
#define DAT_AATN_VALUE_41 41
|
||||
#define DAT_AATN_VALUE_51 51
|
||||
#define DAT_AATN_VALUE_63 63
|
||||
#define DAT_AATN_VALUE_64 64
|
||||
#define DAT_ATTN0_OUTPUT_VALUE_GET 0x00
|
||||
#define DAT_ATTN1_OUTPUT_VALUE_GET 0x04
|
||||
#define DAT_ATTN1_OUTPUT_VALUE_SET 0x7E
|
||||
#define DAT_ATTN2_OUTPUT_VALUE_GET 0x08
|
||||
#define DAT_ATTN4_OUTPUT_VALUE_GET 0x10
|
||||
#define DAT_ATTN8_OUTPUT_VALUE_GET 0x20
|
||||
#define DAT_ATTN16_OUTPUT_VALUE_GET 0x40
|
||||
#define DAT_ATTN32_OUTPUT_VALUE_GET 0x02
|
||||
#define DAT_ATTN41_OUTPUT_VALUE_GET 0x26
|
||||
#define DAT_ATTN51_OUTPUT_VALUE_GET 0x4E
|
||||
#define DAT_ATTN63_OUTPUT_VALUE_GET 0x7E
|
||||
#define DAT_ATTN64_OUTPUT_VALUE_GET 0x7E
|
||||
#define DAT_DEFAULT_VALUE 0xFF
|
||||
#define DAT_INIT_DIR_CONFIG_VALUE 0x00
|
||||
#define DAT_INIT_POLARITY_VALUE 0x00
|
||||
#define DAT_INIT_OUTPUT_VALUE 0x7E
|
||||
#define DAT_INVALID_PARAM 40
|
||||
#define RFFE_CHANNEL1_INVALID_SLAVE_ADDR 0x51
|
||||
|
||||
typedef enum DatConfig {
|
||||
DAT_CONFIG_ATTENUATION = 0,
|
||||
} DatConfig;
|
||||
|
||||
#endif
|
||||
189
firmware/ec/test/suites/Test_ocmp_dat-xxr5a.c
Normal file
189
firmware/ec/test/suites/Test_ocmp_dat-xxr5a.c
Normal file
@@ -0,0 +1,189 @@
|
||||
/**
|
||||
* 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_dat.h"
|
||||
/* ======================== Constants & variables =========================== */
|
||||
extern const DATR5APP_Config fact_ch1_tx_gain_cfg;
|
||||
extern Fe_Gain_Cfg fe_ch1_gain;
|
||||
extern Fe_Gain_Cfg fe_ch1_gain_invalid;
|
||||
extern uint8_t PCA9557_regs[PCA9557_REGS_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(OC_CONNECT1_I2C2, RFFE_CHANNEL1_IO_TX_ATTEN_ADDR,
|
||||
PCA9557_regs, sizeof(PCA9557_regs),
|
||||
sizeof(PCA9557_regs[0]), sizeof(uint8_t),
|
||||
FAKE_I2C_DEV_LITTLE_ENDIAN);
|
||||
}
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
memset(PCA9557_regs, 0, sizeof(PCA9557_regs));
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void suite_tearDown(void)
|
||||
{
|
||||
fake_I2C_deinit(); /* This will automatically unregister devices */
|
||||
}
|
||||
|
||||
void test_init(void)
|
||||
{
|
||||
PCA9557_regs[PCA9557_REGS_OUTPUT_VALUE] = DAT_DEFAULT_VALUE;
|
||||
PCA9557_regs[PCA9557_REGS_POLARITY] = DAT_DEFAULT_VALUE;
|
||||
PCA9557_regs[PCA9557_REGS_DIR_CONFIG] = DAT_DEFAULT_VALUE;
|
||||
TEST_ASSERT_EQUAL(
|
||||
POST_DEV_CFG_DONE,
|
||||
DATXXR5APP_fxnTable.cb_init(&fe_ch1_gain, &fact_ch1_tx_gain_cfg, NULL));
|
||||
TEST_ASSERT_EQUAL_HEX8(DAT_INIT_OUTPUT_VALUE,
|
||||
PCA9557_regs[PCA9557_REGS_OUTPUT_VALUE]);
|
||||
TEST_ASSERT_EQUAL_HEX8(DAT_INIT_POLARITY_VALUE,
|
||||
PCA9557_regs[PCA9557_REGS_POLARITY]);
|
||||
TEST_ASSERT_EQUAL_HEX8(DAT_INIT_DIR_CONFIG_VALUE,
|
||||
PCA9557_regs[PCA9557_REGS_DIR_CONFIG]);
|
||||
|
||||
/* Invalid cfg Test */
|
||||
TEST_ASSERT_EQUAL(POST_DEV_CFG_FAIL,
|
||||
DATXXR5APP_fxnTable.cb_init(&fe_ch1_gain_invalid,
|
||||
&fact_ch1_tx_gain_cfg, NULL));
|
||||
}
|
||||
|
||||
void test_probe(void)
|
||||
{
|
||||
// TODO:Tracked as issue #117
|
||||
}
|
||||
|
||||
void test_set_get_config(void)
|
||||
{
|
||||
int16_t atten = DAT_AATN_VALUE_1;
|
||||
int16_t readValue = DAT_DEFAULT_VALUE;
|
||||
|
||||
PCA9557_regs[PCA9557_REGS_OUTPUT_VALUE] = DAT_ATTN1_OUTPUT_VALUE_SET;
|
||||
TEST_ASSERT_EQUAL(true, DATXXR5APP_fxnTable.cb_set_config(
|
||||
&fe_ch1_gain, DAT_CONFIG_ATTENUATION, &atten));
|
||||
TEST_ASSERT_EQUAL(true,
|
||||
DATXXR5APP_fxnTable.cb_get_config(
|
||||
&fe_ch1_gain, DAT_CONFIG_ATTENUATION, &readValue));
|
||||
TEST_ASSERT_EQUAL(DAT_AATN_VALUE_1, readValue);
|
||||
TEST_ASSERT_EQUAL_HEX8(DAT_ATTN1_OUTPUT_VALUE_GET,
|
||||
PCA9557_regs[PCA9557_REGS_OUTPUT_VALUE]);
|
||||
|
||||
atten = DAT_AATN_VALUE_0;
|
||||
TEST_ASSERT_EQUAL(true, DATXXR5APP_fxnTable.cb_set_config(
|
||||
&fe_ch1_gain, DAT_CONFIG_ATTENUATION, &atten));
|
||||
TEST_ASSERT_EQUAL(true,
|
||||
DATXXR5APP_fxnTable.cb_get_config(
|
||||
&fe_ch1_gain, DAT_CONFIG_ATTENUATION, &readValue));
|
||||
TEST_ASSERT_EQUAL(DAT_AATN_VALUE_0, readValue);
|
||||
TEST_ASSERT_EQUAL_HEX8(DAT_ATTN0_OUTPUT_VALUE_GET,
|
||||
PCA9557_regs[PCA9557_REGS_OUTPUT_VALUE]);
|
||||
|
||||
atten = DAT_AATN_VALUE_2;
|
||||
TEST_ASSERT_EQUAL(true, DATXXR5APP_fxnTable.cb_set_config(
|
||||
&fe_ch1_gain, DAT_CONFIG_ATTENUATION, &atten));
|
||||
TEST_ASSERT_EQUAL(true,
|
||||
DATXXR5APP_fxnTable.cb_get_config(
|
||||
&fe_ch1_gain, DAT_CONFIG_ATTENUATION, &readValue));
|
||||
TEST_ASSERT_EQUAL(DAT_AATN_VALUE_2, readValue);
|
||||
TEST_ASSERT_EQUAL_HEX8(DAT_ATTN2_OUTPUT_VALUE_GET,
|
||||
PCA9557_regs[PCA9557_REGS_OUTPUT_VALUE]);
|
||||
|
||||
atten = DAT_AATN_VALUE_4;
|
||||
TEST_ASSERT_EQUAL(true, DATXXR5APP_fxnTable.cb_set_config(
|
||||
&fe_ch1_gain, DAT_CONFIG_ATTENUATION, &atten));
|
||||
TEST_ASSERT_EQUAL(true,
|
||||
DATXXR5APP_fxnTable.cb_get_config(
|
||||
&fe_ch1_gain, DAT_CONFIG_ATTENUATION, &readValue));
|
||||
TEST_ASSERT_EQUAL(DAT_AATN_VALUE_4, readValue);
|
||||
TEST_ASSERT_EQUAL_HEX8(DAT_ATTN4_OUTPUT_VALUE_GET,
|
||||
PCA9557_regs[PCA9557_REGS_OUTPUT_VALUE]);
|
||||
|
||||
atten = DAT_AATN_VALUE_8;
|
||||
TEST_ASSERT_EQUAL(true, DATXXR5APP_fxnTable.cb_set_config(
|
||||
&fe_ch1_gain, DAT_CONFIG_ATTENUATION, &atten));
|
||||
TEST_ASSERT_EQUAL(true,
|
||||
DATXXR5APP_fxnTable.cb_get_config(
|
||||
&fe_ch1_gain, DAT_CONFIG_ATTENUATION, &readValue));
|
||||
TEST_ASSERT_EQUAL(DAT_AATN_VALUE_8, readValue);
|
||||
TEST_ASSERT_EQUAL_HEX8(DAT_ATTN8_OUTPUT_VALUE_GET,
|
||||
PCA9557_regs[PCA9557_REGS_OUTPUT_VALUE]);
|
||||
|
||||
atten = DAT_AATN_VALUE_16;
|
||||
TEST_ASSERT_EQUAL(true, DATXXR5APP_fxnTable.cb_set_config(
|
||||
&fe_ch1_gain, DAT_CONFIG_ATTENUATION, &atten));
|
||||
TEST_ASSERT_EQUAL(true,
|
||||
DATXXR5APP_fxnTable.cb_get_config(
|
||||
&fe_ch1_gain, DAT_CONFIG_ATTENUATION, &readValue));
|
||||
TEST_ASSERT_EQUAL(DAT_AATN_VALUE_16, readValue);
|
||||
TEST_ASSERT_EQUAL_HEX8(DAT_ATTN16_OUTPUT_VALUE_GET,
|
||||
PCA9557_regs[PCA9557_REGS_OUTPUT_VALUE]);
|
||||
|
||||
atten = DAT_AATN_VALUE_32;
|
||||
TEST_ASSERT_EQUAL(true, DATXXR5APP_fxnTable.cb_set_config(
|
||||
&fe_ch1_gain, DAT_CONFIG_ATTENUATION, &atten));
|
||||
TEST_ASSERT_EQUAL(true,
|
||||
DATXXR5APP_fxnTable.cb_get_config(
|
||||
&fe_ch1_gain, DAT_CONFIG_ATTENUATION, &readValue));
|
||||
TEST_ASSERT_EQUAL(DAT_AATN_VALUE_32, readValue);
|
||||
TEST_ASSERT_EQUAL_HEX8(DAT_ATTN32_OUTPUT_VALUE_GET,
|
||||
PCA9557_regs[PCA9557_REGS_OUTPUT_VALUE]);
|
||||
|
||||
atten = DAT_AATN_VALUE_41;
|
||||
TEST_ASSERT_EQUAL(true, DATXXR5APP_fxnTable.cb_set_config(
|
||||
&fe_ch1_gain, DAT_CONFIG_ATTENUATION, &atten));
|
||||
TEST_ASSERT_EQUAL(true,
|
||||
DATXXR5APP_fxnTable.cb_get_config(
|
||||
&fe_ch1_gain, DAT_CONFIG_ATTENUATION, &readValue));
|
||||
TEST_ASSERT_EQUAL(DAT_AATN_VALUE_41, readValue);
|
||||
TEST_ASSERT_EQUAL_HEX8(DAT_ATTN41_OUTPUT_VALUE_GET,
|
||||
PCA9557_regs[PCA9557_REGS_OUTPUT_VALUE]);
|
||||
|
||||
atten = DAT_AATN_VALUE_51;
|
||||
TEST_ASSERT_EQUAL(true, DATXXR5APP_fxnTable.cb_set_config(
|
||||
&fe_ch1_gain, DAT_CONFIG_ATTENUATION, &atten));
|
||||
TEST_ASSERT_EQUAL(true,
|
||||
DATXXR5APP_fxnTable.cb_get_config(
|
||||
&fe_ch1_gain, DAT_CONFIG_ATTENUATION, &readValue));
|
||||
TEST_ASSERT_EQUAL(DAT_AATN_VALUE_51, readValue);
|
||||
TEST_ASSERT_EQUAL_HEX8(DAT_ATTN51_OUTPUT_VALUE_GET,
|
||||
PCA9557_regs[PCA9557_REGS_OUTPUT_VALUE]);
|
||||
|
||||
atten = DAT_AATN_VALUE_63;
|
||||
TEST_ASSERT_EQUAL(true, DATXXR5APP_fxnTable.cb_set_config(
|
||||
&fe_ch1_gain, DAT_CONFIG_ATTENUATION, &atten));
|
||||
TEST_ASSERT_EQUAL(true,
|
||||
DATXXR5APP_fxnTable.cb_get_config(
|
||||
&fe_ch1_gain, DAT_CONFIG_ATTENUATION, &readValue));
|
||||
TEST_ASSERT_EQUAL(DAT_AATN_VALUE_63, readValue);
|
||||
TEST_ASSERT_EQUAL_HEX8(DAT_ATTN63_OUTPUT_VALUE_GET,
|
||||
PCA9557_regs[PCA9557_REGS_OUTPUT_VALUE]);
|
||||
|
||||
/* Invalid Parameter */
|
||||
TEST_ASSERT_EQUAL(false, DATXXR5APP_fxnTable.cb_set_config(
|
||||
&fe_ch1_gain, DAT_INVALID_PARAM, &atten));
|
||||
TEST_ASSERT_EQUAL(false, DATXXR5APP_fxnTable.cb_get_config(
|
||||
&fe_ch1_gain, DAT_INVALID_PARAM, &atten));
|
||||
/* out of bound value */
|
||||
atten = DAT_AATN_VALUE_64;
|
||||
/* TODO: The below function should return false. The attenuation range is 0
|
||||
to 63(ie 0.5dB to 31.5dB). Fix is needed for this. Tracked as issue #118 */
|
||||
TEST_ASSERT_EQUAL(true, DATXXR5APP_fxnTable.cb_set_config(
|
||||
&fe_ch1_gain, DAT_CONFIG_ATTENUATION, &atten));
|
||||
TEST_ASSERT_EQUAL_HEX8(DAT_ATTN64_OUTPUT_VALUE_GET,
|
||||
PCA9557_regs[PCA9557_REGS_OUTPUT_VALUE]);
|
||||
}
|
||||
Reference in New Issue
Block a user