Compare commits
3 commits
d1b6c828cb
...
7b1f76c470
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7b1f76c470 | ||
|
|
a118d621c8 | ||
|
|
0eb4acc3f5 |
9 changed files with 177 additions and 65 deletions
|
|
@ -13,16 +13,30 @@
|
||||||
uint16_t fake_data[FAKESIZE];
|
uint16_t fake_data[FAKESIZE];
|
||||||
int fake_index = 0;
|
int fake_index = 0;
|
||||||
|
|
||||||
|
static bool is_setup = false;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void ADC_SetPin(uint8_t pin_num)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ADC_Setup(void)
|
||||||
|
{
|
||||||
|
is_setup = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
void ADC_Init(uint8_t pin_num)
|
void ADC_Init(uint8_t pin_num)
|
||||||
{
|
{
|
||||||
mock_c()->actualCall("ADC_Init")
|
mock_c()->actualCall("ADC_Init")
|
||||||
->withUnsignedIntParameters("pin_num", pin_num);
|
->withUnsignedIntParameters("pin_num", pin_num);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ADC_Enable(uint8_t pin_num)
|
void ADC_Enable(void)
|
||||||
{
|
{
|
||||||
mock_c()->actualCall("ADC_Enable")
|
mock_c()->actualCall("ADC_Enable");
|
||||||
->withUnsignedIntParameters("pin_num", pin_num);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ADC_Disable()
|
void ADC_Disable()
|
||||||
|
|
@ -62,3 +76,9 @@ int MockADC_GetIndex(void)
|
||||||
{
|
{
|
||||||
return fake_index;
|
return fake_index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool MockADC_IsSetup(void)
|
||||||
|
{
|
||||||
|
return is_setup;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,18 +13,18 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
/**
|
|
||||||
* A function that adds two to a number
|
void ADC_Setup(void);
|
||||||
* @param a The first argument
|
void ADC_SetPin(uint8_t pin_num);
|
||||||
*/
|
|
||||||
void ADC_Init(uint8_t pin_num);
|
void ADC_Init(uint8_t pin_num);
|
||||||
void ADC_Enable(uint8_t pin_num);
|
void ADC_Enable(void);
|
||||||
void ADC_Disable();
|
void ADC_Disable(void);
|
||||||
|
|
||||||
extern uint16_t (*ADC_ReadValue)(uint8_t pin_num);
|
extern uint16_t (*ADC_ReadValue)(uint8_t pin_num);
|
||||||
|
|
||||||
void MockADC_PushValue(uint16_t value);
|
void MockADC_PushValue(uint16_t value);
|
||||||
void MockADC_ZeroIndex(void);
|
void MockADC_ZeroIndex(void);
|
||||||
int MockADC_GetIndex(void);
|
int MockADC_GetIndex(void);
|
||||||
|
bool MockADC_IsSetup(void);
|
||||||
|
|
||||||
#endif //MOCKADC_H
|
#endif //MOCKADC_H
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,6 @@ int main(int argc, char **argv)
|
||||||
_delay_ms(2500);
|
_delay_ms(2500);
|
||||||
ZCD_Poll();
|
ZCD_Poll();
|
||||||
TriacOut_SetupPins();
|
TriacOut_SetupPins();
|
||||||
TriacOut_SetAllHigh();
|
|
||||||
|
|
||||||
Load_HandleLoadPortA(ADC_LOAD1, 1);
|
Load_HandleLoadPortA(ADC_LOAD1, 1);
|
||||||
Load_HandleLoadPortB(ADC_LOAD2, 3);
|
Load_HandleLoadPortB(ADC_LOAD2, 3);
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,9 @@
|
||||||
|
|
||||||
void ZCD_Setup(void)
|
void ZCD_Setup(void)
|
||||||
{
|
{
|
||||||
ADC_Init(7);
|
ADC_Init(ZCD_PIN);
|
||||||
ADC_Enable(7);
|
ADC_SetPin(ZCD_PIN);
|
||||||
|
ADC_Enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZCD_IsTriggered()
|
bool ZCD_IsTriggered()
|
||||||
|
|
|
||||||
|
|
@ -37,28 +37,52 @@ TEST(test_ADC, FirstTest)
|
||||||
CHECK(true);
|
CHECK(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ADCStoresPortState(void){
|
|
||||||
mock().expectOneCall("RegEdit_ReadReg")
|
|
||||||
.withPointerParameter("reg", (void *) &PORTA.OUT)
|
|
||||||
.andReturnValue(0xFF);
|
|
||||||
|
|
||||||
mock().expectOneCall("RegEdit_ReadReg")
|
TEST(test_ADC, ADC_SetupSetsRegisters)
|
||||||
.withPointerParameter("reg", (void *) &PORTA.DIR)
|
{
|
||||||
.andReturnValue(0xFF);
|
//Clears control register A for ADC0
|
||||||
|
mock().expectOneCall("RegEdit_SetNum")
|
||||||
|
.withPointerParameter("reg", (void *) &ADC0.CTRLA)
|
||||||
|
.withUnsignedIntParameter("num", 0x00);
|
||||||
|
|
||||||
|
//Sets The sample accumulation number to 32.
|
||||||
|
mock().expectOneCall("RegEdit_SetNum")
|
||||||
|
.withPointerParameter("reg", (void *) &ADC0.CTRLB)
|
||||||
|
.withUnsignedIntParameter("num", 0x5);
|
||||||
|
|
||||||
|
//Sets the voltage reference to VDD or VCC.
|
||||||
|
mock().expectOneCall("RegEdit_SetBit")
|
||||||
|
.withPointerParameter("reg", (void *) &ADC0.CTRLC)
|
||||||
|
.withUnsignedIntParameter("bit_num", 4);
|
||||||
|
|
||||||
|
//Sets the pre-scalar for the adc sample rate.
|
||||||
|
mock().expectOneCall("RegEdit_SetBit")
|
||||||
|
.withPointerParameter("reg", (void *) &ADC0.CTRLC)
|
||||||
|
.withUnsignedIntParameter("bit_num", 2);
|
||||||
|
|
||||||
|
//Setup an Initalization delay.
|
||||||
|
mock().expectOneCall("RegEdit_OR_Num")
|
||||||
|
.withPointerParameter("reg", (void *) &ADC0.CTRLD)
|
||||||
|
.withUnsignedIntParameter("num", (2<<5));
|
||||||
|
|
||||||
|
//Set the bit for ADC variation during readings.
|
||||||
|
mock().expectOneCall("RegEdit_SetBit")
|
||||||
|
.withPointerParameter("reg", (void *) &ADC0.CTRLD)
|
||||||
|
.withUnsignedIntParameter("bit_num", 4);
|
||||||
|
|
||||||
|
ADC_Setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(test_ADC, ADC_InitPortAPin7UsesCorrectRegisters)
|
TEST(test_ADC, ADC_InitPortAPin7UsesCorrectRegisters)
|
||||||
{
|
{
|
||||||
ADCStoresPortState();
|
|
||||||
|
|
||||||
//Check for setting the direction to input.
|
//Check for setting the direction to input.
|
||||||
mock().expectOneCall("RegEdit_SetBit")
|
mock().expectOneCall("RegEdit_ClearBit")
|
||||||
.withPointerParameter("reg", (void *) &PORTA.DIRCLR)
|
.withPointerParameter("reg", (void *) &PORTA.DIR)
|
||||||
.withUnsignedIntParameter("bit_num", 7);
|
.withUnsignedIntParameter("bit_num", 7);
|
||||||
|
|
||||||
//Check that the pullup is off
|
//Check that the pullup is off
|
||||||
mock().expectOneCall("RegEdit_SetBit")
|
mock().expectOneCall("RegEdit_ClearBit")
|
||||||
.withPointerParameter("reg", (void *) &PORTA.OUTCLR)
|
.withPointerParameter("reg", (void *) &PORTA.OUT)
|
||||||
.withUnsignedIntParameter("bit_num", 7);
|
.withUnsignedIntParameter("bit_num", 7);
|
||||||
|
|
||||||
//Set the ISC(input sense config) to disable digital input
|
//Set the ISC(input sense config) to disable digital input
|
||||||
|
|
@ -74,16 +98,14 @@ TEST(test_ADC, ADC_InitPortAPin7UsesCorrectRegisters)
|
||||||
TEST(test_ADC, ADC_InitPortAPin0UsesCorrectRegisters)
|
TEST(test_ADC, ADC_InitPortAPin0UsesCorrectRegisters)
|
||||||
{
|
{
|
||||||
|
|
||||||
ADCStoresPortState();
|
|
||||||
|
|
||||||
//Check for setting the direction to input.
|
//Check for setting the direction to input.
|
||||||
mock().expectOneCall("RegEdit_SetBit")
|
mock().expectOneCall("RegEdit_ClearBit")
|
||||||
.withPointerParameter("reg", (void *) &PORTA.DIRCLR)
|
.withPointerParameter("reg", (void *) &PORTA.DIR)
|
||||||
.withUnsignedIntParameter("bit_num", 0);
|
.withUnsignedIntParameter("bit_num", 0);
|
||||||
|
|
||||||
//Check that the pullup is off
|
//Check that the pullup is off
|
||||||
mock().expectOneCall("RegEdit_SetBit")
|
mock().expectOneCall("RegEdit_ClearBit")
|
||||||
.withPointerParameter("reg", (void *) &PORTA.OUTCLR)
|
.withPointerParameter("reg", (void *) &PORTA.OUT)
|
||||||
.withUnsignedIntParameter("bit_num", 0);
|
.withUnsignedIntParameter("bit_num", 0);
|
||||||
|
|
||||||
//Set the ISC(input sense config) to disable digital input
|
//Set the ISC(input sense config) to disable digital input
|
||||||
|
|
@ -92,6 +114,7 @@ TEST(test_ADC, ADC_InitPortAPin0UsesCorrectRegisters)
|
||||||
.withPointerParameter("reg", (void *) &PORTA.PIN0CTRL)
|
.withPointerParameter("reg", (void *) &PORTA.PIN0CTRL)
|
||||||
.withUnsignedIntParameter("bit_num", PORT_ISC_INPUT_DISABLE_gc);
|
.withUnsignedIntParameter("bit_num", PORT_ISC_INPUT_DISABLE_gc);
|
||||||
|
|
||||||
|
|
||||||
ADC_Init(0);
|
ADC_Init(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -101,51 +124,45 @@ TEST(test_ADC, ADC_InitDoesNothingOnHighPinNumbers)
|
||||||
ADC_Init(8);
|
ADC_Init(8);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(test_ADC, ADC_EnableSuccessOnPin7)
|
TEST(test_ADC, ADC_EnablePasses)
|
||||||
{
|
{
|
||||||
|
|
||||||
//Set the MUXPOS or the ADC pin stuff.
|
|
||||||
mock().expectOneCall("RegEdit_OR_Num")
|
|
||||||
.withPointerParameter("reg", (void *) &ADC0.MUXPOS)
|
|
||||||
.withUnsignedIntParameter("num", ADC_MUXPOS_AIN7_gc);
|
|
||||||
|
|
||||||
mock().expectOneCall("RegEdit_SetBit")
|
mock().expectOneCall("RegEdit_SetBit")
|
||||||
.withPointerParameter("reg", (void *) &ADC0.CTRLA)
|
.withPointerParameter("reg", (void *) &ADC0.CTRLA)
|
||||||
.withUnsignedIntParameter("bit_num", 0);
|
.withUnsignedIntParameter("bit_num", 0);
|
||||||
|
|
||||||
ADC_Enable(7);
|
ADC_Enable();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST(test_ADC, ADC_EnableNothingOnHighPinNumbers)
|
|
||||||
{
|
|
||||||
|
|
||||||
mock().expectNoCall("RegEdit_SetBit");
|
|
||||||
ADC_Enable(8);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(test_ADC, ADC_DisablePasses)
|
TEST(test_ADC, ADC_DisablePasses)
|
||||||
{
|
{
|
||||||
//Clears the muxpos register
|
|
||||||
mock().expectOneCall("RegEdit_ClearRegister")
|
|
||||||
.withPointerParameter("reg", (void *) &ADC0.MUXPOS);
|
|
||||||
|
|
||||||
mock().expectOneCall("RegEdit_ClearBit")
|
mock().expectOneCall("RegEdit_ClearBit")
|
||||||
.withPointerParameter("reg", (void *) &ADC0.CTRLA)
|
.withPointerParameter("reg", (void *) &ADC0.CTRLA)
|
||||||
.withUnsignedIntParameter("bit_num", 0);
|
.withUnsignedIntParameter("bit_num", 0);
|
||||||
|
|
||||||
mock().expectOneCall("RegEdit_SetNum")
|
|
||||||
.withPointerParameter("reg", (void*) &PORTA.OUT)
|
|
||||||
.ignoreOtherParameters();
|
|
||||||
|
|
||||||
mock().expectOneCall("RegEdit_SetNum")
|
|
||||||
.withPointerParameter("reg", (void*) &PORTA.DIR)
|
|
||||||
.ignoreOtherParameters();
|
|
||||||
|
|
||||||
ADC_Disable();
|
ADC_Disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(test_ADC, ADC_SetPinSetsRightRegisters)
|
||||||
|
{
|
||||||
|
//It clears existing MUXPOS register values.
|
||||||
|
mock().expectOneCall("RegEdit_ClearRegister")
|
||||||
|
.withPointerParameter("reg", (void *) &ADC0.MUXPOS);
|
||||||
|
|
||||||
|
//It Correctly sets the pin number.
|
||||||
|
mock().expectOneCall("RegEdit_SetNum")
|
||||||
|
.withPointerParameter("reg", (void *) &ADC0.MUXPOS)
|
||||||
|
.withUnsignedIntParameter("num", 4);
|
||||||
|
|
||||||
|
ADC_SetPin(4);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TEST(test_ADC, ADC_SetPinFailsOnInvalidPin)
|
||||||
|
{
|
||||||
|
ADC_SetPin(8);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static uint16_t ADC_ReadValueFake(uint8_t pin_num)
|
static uint16_t ADC_ReadValueFake(uint8_t pin_num)
|
||||||
|
|
|
||||||
|
|
@ -30,17 +30,16 @@ TEST_GROUP(test_MockADC)
|
||||||
TEST(test_MockADC, ADC_InitExpects)
|
TEST(test_MockADC, ADC_InitExpects)
|
||||||
{
|
{
|
||||||
mock().expectOneCall("ADC_Init")
|
mock().expectOneCall("ADC_Init")
|
||||||
.withUnsignedIntParameter("pin_num", 0x2);
|
.withUnsignedIntParameter("pin_num", 7);
|
||||||
|
|
||||||
ADC_Init(0x2);
|
ADC_Init(7);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(test_MockADC, ADC_EnableExpects)
|
TEST(test_MockADC, ADC_EnableExpects)
|
||||||
{
|
{
|
||||||
mock().expectOneCall("ADC_Enable")
|
mock().expectOneCall("ADC_Enable");
|
||||||
.withUnsignedIntParameter("pin_num", 0x2);
|
|
||||||
|
|
||||||
ADC_Enable(0x2);
|
ADC_Enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -84,3 +83,12 @@ TEST(test_MockADC, MockADC_PushValueDoesntOverflowArray)
|
||||||
CHECK_TRUE(MockADC_GetIndex() <= 255);
|
CHECK_TRUE(MockADC_GetIndex() <= 255);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(test_MockADC, MockADC_SetupSetsGlobal)
|
||||||
|
{
|
||||||
|
CHECK_FALSE(MockADC_IsSetup());
|
||||||
|
|
||||||
|
ADC_Setup();
|
||||||
|
|
||||||
|
CHECK_TRUE(MockADC_IsSetup());
|
||||||
|
}
|
||||||
|
|
|
||||||
12
tests/load/CMakeLists.txt
Normal file
12
tests/load/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
# TEST_RUNNER
|
||||||
|
add_library(test_load
|
||||||
|
test_load.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(test_load
|
||||||
|
${CPPUTEST_LIBRARIES}/libCppUTest.a
|
||||||
|
${CPPUTEST_LIBRARIES}/libCppUTestExt.a
|
||||||
|
load
|
||||||
|
MockADC
|
||||||
|
MockRegEdit
|
||||||
|
)
|
||||||
56
tests/load/test_load.cpp
Normal file
56
tests/load/test_load.cpp
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
/*
|
||||||
|
* Author: Jake G
|
||||||
|
* Date: 2024
|
||||||
|
* filename: test_load.cpp
|
||||||
|
* description:
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "CppUTest/CommandLineTestRunner.h"
|
||||||
|
#include "CppUTestExt/MockSupport.h"
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
|
||||||
|
//This define allows us to dircetly include the device header without error.
|
||||||
|
#define _AVR_IO_H_
|
||||||
|
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#include <iotn404.h> //ATtiny404 header fille.
|
||||||
|
#include "load.h"
|
||||||
|
#include "MockADC.h"
|
||||||
|
#include "MockADC.h"
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_GROUP(test_load)
|
||||||
|
{
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
void teardown()
|
||||||
|
{
|
||||||
|
mock().checkExpectations();
|
||||||
|
mock().clear();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST(test_load, LoadPass)
|
||||||
|
{
|
||||||
|
CHECK_TRUE(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(test_load, PortAHandlerSuccess)
|
||||||
|
{
|
||||||
|
mock().expectOneCall("ADC_Init")
|
||||||
|
.withUnsignedIntParameter("pin_num", 4);
|
||||||
|
|
||||||
|
mock().expectOneCall("ADC_Enable");
|
||||||
|
mock().expectOneCall("ADC_ReadValue_Impl")
|
||||||
|
.withUnsignedIntParameter("pin_num", 4);
|
||||||
|
mock().expectOneCall("ADC_Disable");
|
||||||
|
mock().expectOneCall("RegEdit_ClearBit")
|
||||||
|
.withPointerParameter("reg", (void *) &PORTA.OUT)
|
||||||
|
.withUnsignedIntParameter("bit_num", 7);
|
||||||
|
|
||||||
|
Load_HandleLoadPortA(4, 7);
|
||||||
|
}
|
||||||
|
|
@ -38,8 +38,7 @@ static void ZCDSetupExpectations(void)
|
||||||
mock().expectOneCall("ADC_Init")
|
mock().expectOneCall("ADC_Init")
|
||||||
.withUnsignedIntParameter("pin_num", 7);
|
.withUnsignedIntParameter("pin_num", 7);
|
||||||
|
|
||||||
mock().expectOneCall("ADC_Enable")
|
mock().expectOneCall("ADC_Enable");
|
||||||
.withUnsignedIntParameter("pin_num", 7);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue