Added tests for I2C periherials
This commit is contained in:
parent
a6c5a32442
commit
514c90cefe
7 changed files with 186 additions and 0 deletions
|
|
@ -4,6 +4,7 @@
|
||||||
IMPORT_TEST_GROUP(simple_test);
|
IMPORT_TEST_GROUP(simple_test);
|
||||||
IMPORT_TEST_GROUP(tg_ADC);
|
IMPORT_TEST_GROUP(tg_ADC);
|
||||||
IMPORT_TEST_GROUP(tg_wwdg);
|
IMPORT_TEST_GROUP(tg_wwdg);
|
||||||
|
IMPORT_TEST_GROUP(tg_I2C);
|
||||||
IMPORT_TEST_GROUP(test_RegEdit);
|
IMPORT_TEST_GROUP(test_RegEdit);
|
||||||
IMPORT_TEST_GROUP(test_blink);
|
IMPORT_TEST_GROUP(test_blink);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
project(Tests)
|
project(Tests)
|
||||||
|
|
||||||
# TEST_DIRS
|
# TEST_DIRS
|
||||||
|
add_subdirectory(I2C)
|
||||||
add_subdirectory(wwdg)
|
add_subdirectory(wwdg)
|
||||||
add_subdirectory(blink)
|
add_subdirectory(blink)
|
||||||
add_subdirectory(MockRegEdit)
|
add_subdirectory(MockRegEdit)
|
||||||
|
|
@ -20,6 +21,7 @@ add_executable(AllTests
|
||||||
target_link_libraries(AllTests
|
target_link_libraries(AllTests
|
||||||
${CPPUTEST_LIBRARIES}
|
${CPPUTEST_LIBRARIES}
|
||||||
# TEST_LINKS
|
# TEST_LINKS
|
||||||
|
test_I2C
|
||||||
test_wwdg
|
test_wwdg
|
||||||
test_blink
|
test_blink
|
||||||
test_ADC
|
test_ADC
|
||||||
|
|
|
||||||
23
tests/I2C/CMakeLists.txt
Normal file
23
tests/I2C/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
# File: tests/I2C/CMakeLists.txt
|
||||||
|
|
||||||
|
add_subdirectory(mocks)
|
||||||
|
add_subdirectory(fakes)
|
||||||
|
add_subdirectory(stubs)
|
||||||
|
|
||||||
|
# TEST_RUNNER
|
||||||
|
add_library(test_I2C
|
||||||
|
test_I2C.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(test_I2C
|
||||||
|
${CPPUTEST_LIBRARIES}
|
||||||
|
I2C
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(test_I2C PUBLIC
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}
|
||||||
|
#Next comes the shared and non-module specific test depencencies.
|
||||||
|
${CMAKE_SOURCE_DIR}/tests/shared/mocks/
|
||||||
|
${CMAKE_SOURCE_DIR}/tests/shared/fakes/
|
||||||
|
${CMAKE_SOURCE_DIR}/tests/shared/stubs/
|
||||||
|
)
|
||||||
0
tests/I2C/fakes/CMakeLists.txt
Normal file
0
tests/I2C/fakes/CMakeLists.txt
Normal file
0
tests/I2C/mocks/CMakeLists.txt
Normal file
0
tests/I2C/mocks/CMakeLists.txt
Normal file
0
tests/I2C/stubs/CMakeLists.txt
Normal file
0
tests/I2C/stubs/CMakeLists.txt
Normal file
160
tests/I2C/test_I2C.cpp
Normal file
160
tests/I2C/test_I2C.cpp
Normal file
|
|
@ -0,0 +1,160 @@
|
||||||
|
/*
|
||||||
|
* Author: username
|
||||||
|
* Date: todays_date
|
||||||
|
* filename: test_I2C.c
|
||||||
|
* description: module_purpose
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "CppUTest/CommandLineTestRunner.h"
|
||||||
|
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#include "I2C.h"
|
||||||
|
#include "I2C_internal.h"
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_GROUP(tg_I2C)
|
||||||
|
{
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
void teardown()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint32_t clockspeed;
|
||||||
|
uint16_t mode;
|
||||||
|
uint16_t dutycycle;
|
||||||
|
uint16_t ownaddress1;
|
||||||
|
uint16_t ack;
|
||||||
|
uint16_t ack_address;
|
||||||
|
} i2c_config;
|
||||||
|
*/
|
||||||
|
|
||||||
|
TEST(tg_I2C, GetBusReturnsNonNullOnValidIndecies)
|
||||||
|
{
|
||||||
|
i2c_bus_typedef_p i2cbus_ptr = I2C_GetBus(0);
|
||||||
|
CHECK_TRUE_TEXT(i2cbus_ptr != nullptr, "The pointer should have been valid but was nullptr.");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(tg_I2C, GetBusReturnsNullOnInvalid)
|
||||||
|
{
|
||||||
|
|
||||||
|
i2c_bus_typedef_p i2cbus_ptr = I2C_GetBus(I2C_BUS_QTY + 1);
|
||||||
|
CHECK_EQUAL_TEXT(nullptr, i2cbus_ptr, "The pointer should be null for invalid indecies.");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(tg_I2C, BusFailsOnInvalidconfig)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(tg_I2C, CreateI2CBus_10Bit)
|
||||||
|
{
|
||||||
|
i2c_config i2c1_config = {
|
||||||
|
.clockspeed = I2C_STD_SPEED,
|
||||||
|
.mode = I2C_MODE_MASTER,
|
||||||
|
.dutycycle = 0,
|
||||||
|
.ownaddress = 0,
|
||||||
|
.ack = true,
|
||||||
|
.ack_address = 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
i2c_bus_typedef_p i2c1_ptr = I2C_GetBus(0);
|
||||||
|
|
||||||
|
bool ret = i2c1_ptr->Init(i2c1_ptr, &i2c1_config);
|
||||||
|
CHECK_TRUE(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TEST_GROUP(tg_I2C_internal)
|
||||||
|
{
|
||||||
|
i2c_config config;
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
config.clockspeed = 0;
|
||||||
|
config.mode = 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
void teardown()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST(tg_I2C_internal, i2c_configchecksclockspeed)
|
||||||
|
{
|
||||||
|
bool ret = false;
|
||||||
|
|
||||||
|
for(config.clockspeed = 0; config.clockspeed < I2C_INVALID_SPEED; config.clockspeed++){
|
||||||
|
ret = is_i2c_config_valid(&config);
|
||||||
|
CHECK_TRUE(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
config.clockspeed = I2C_INVALID_SPEED;
|
||||||
|
ret = is_i2c_config_valid(&config);
|
||||||
|
CHECK_FALSE_TEXT(ret, "config check accepted invalid i2c clockspeed!");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(tg_I2C_internal, i2c_configchecksmode)
|
||||||
|
{
|
||||||
|
bool ret = false;
|
||||||
|
|
||||||
|
for(config.mode = 0; config.mode < I2C_MODE_INVALID; config.mode++){
|
||||||
|
ret = is_i2c_config_valid(&config);
|
||||||
|
CHECK_TRUE(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
config.mode = I2C_MODE_INVALID;
|
||||||
|
ret = is_i2c_config_valid(&config);
|
||||||
|
CHECK_FALSE_TEXT(ret, "config check accepted invalid i2c mode!");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(tg_I2C_internal, i2c_configchecksdutycycle)
|
||||||
|
{
|
||||||
|
bool ret = false;
|
||||||
|
|
||||||
|
for(config.dutycycle= 0; config.dutycycle < I2C_DUTYCYCLE_INVALID; config.dutycycle++){
|
||||||
|
ret = is_i2c_config_valid(&config);
|
||||||
|
CHECK_TRUE(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
config.dutycycle= I2C_DUTYCYCLE_INVALID;
|
||||||
|
ret = is_i2c_config_valid(&config);
|
||||||
|
CHECK_FALSE_TEXT(ret, "config check accepted invalid i2c dutycycle!");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(tg_I2C_internal, is10bitaddresschecksCorrectly)
|
||||||
|
{
|
||||||
|
bool ret = false;
|
||||||
|
|
||||||
|
CHECK_FALSE_TEXT(ret, "check");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(tg_I2C_internal, is7bitaddresschecksCorrectly)
|
||||||
|
{
|
||||||
|
bool ret = false;
|
||||||
|
|
||||||
|
CHECK_FALSE_TEXT(ret, "check");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Loading…
Add table
Reference in a new issue