This commit is contained in:
2024-06-04 18:45:10 +02:00
commit 58fe6ef3b1
30 changed files with 1625 additions and 0 deletions

11
Firmware/test/README Normal file
View File

@@ -0,0 +1,11 @@
This directory is intended for PIO Unit Testing and project tests.
Unit Testing is a software testing method by which individual units of
source code, sets of one or more MCU program modules together with associated
control data, usage procedures, and operating procedures, are tested to
determine whether they are fit for use. Unit testing finds problems early
in the development cycle.
More information about PIO Unit Testing:
- https://docs.platformio.org/page/plus/unit-testing.html

41
Firmware/test/test_demo.c Normal file
View File

@@ -0,0 +1,41 @@
#include <stdint.h>
#include <unity.h>
#include <util/delay.h>
#include "fifo.h"
#include "unittest_transport.h"
void test_fifo(void)
{
uint8_t buf[3];
fifo_t f;
fifo_init(&f, buf, sizeof(buf));
fifo_put(&f, 0x11);
fifo_put(&f, 0x22);
fifo_put(&f, 0x33);
TEST_ASSERT_EQUAL(0x11, fifo_get_nowait(&f));
TEST_ASSERT_EQUAL(0x22, fifo_get_nowait(&f));
TEST_ASSERT_EQUAL(0x33, fifo_get_nowait(&f));
}
int main()
{
// NOTE!!! Wait for >2 secs
// if board doesn't support software reset via Serial.DTR/RTS
_delay_ms(2000);
DDRB |= 0x2;
PORTB &= ~0x2;
UNITY_BEGIN(); // IMPORTANT LINE!
RUN_TEST(test_fifo);
UNITY_END(); // stop unit testing
PORTB |= 0x2;
DDRB |= 0x4;
PORTB &= ~0x4;
while (1)
;
}

View File

@@ -0,0 +1,32 @@
#ifndef UNITTEST_TRANSPORT_H
#define UNITTEST_TRANSPORT_H
#include <avr/io.h>
#include <stdint.h>
#include "uart.h"
void unittest_uart_begin()
{
// Set Baudrate according to datasheet (16MHz -> 115200 Baud, U2X=1)
UBRR0 = 0x10;
UCSR0B |= (1<<TXEN0);
// Reset Complete-Flags
UCSR0A = (1 << RXC0) | (1 << TXC0) | (1 << U2X0);
}
void unittest_uart_putchar(char c)
{
loop_until_bit_is_set(UCSR0A, UDRE0);
UDR0 = c;
}
void unittest_uart_flush()
{
}
void unittest_uart_end()
{
}
#endif