Skip to content

Commit

Permalink
UART self test
Browse files Browse the repository at this point in the history
  • Loading branch information
openshwprojects committed Nov 27, 2024
1 parent 8f8f257 commit a2f3b02
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/selftest/selftest_cmd_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,56 @@ void Test_Events() {
SELFTEST_ASSERT(EVENT_ParseEventName(" ") == CMD_EVENT_NONE);
}

void Test_UART() {
int USED_BUFFER_SIZE = 123;
UART_InitReceiveRingBuffer(USED_BUFFER_SIZE);
byte next = 0;
for (int i = 0; i < 512; i++) {
SELFTEST_ASSERT(UART_GetDataSize() == 0);
UART_AppendByteToReceiveRingBuffer(next);
SELFTEST_ASSERT(UART_GetDataSize() == 1);
byte check = UART_GetByte(0);
SELFTEST_ASSERT(check == next);
UART_ConsumeBytes(1);
SELFTEST_ASSERT(UART_GetDataSize() == 0);
next++;
}
for (int i = 0; i < 66; i++) {
byte nn;
nn = next;
for (int j = 0; j < 10; j++) {
SELFTEST_ASSERT(UART_GetDataSize() == j);
UART_AppendByteToReceiveRingBuffer(nn);
SELFTEST_ASSERT(UART_GetDataSize() == j+1);
nn++;
}
nn = next;
for (int j = 0; j < 10; j++) {
byte check = UART_GetByte(0);
SELFTEST_ASSERT(check == nn);
UART_ConsumeBytes(1);
nn++;
}
SELFTEST_ASSERT(UART_GetDataSize() == 0);
next = nn;
}
for (int i = 0; i < USED_BUFFER_SIZE * 2; i++) {
UART_AppendByteToReceiveRingBuffer(next);

int reportedSize = (i+1);
// detect overflow
if (reportedSize > (USED_BUFFER_SIZE-1)) {
reportedSize = (USED_BUFFER_SIZE-1);
}
int realSize = UART_GetDataSize();
// is data size correctly reported?
SELFTEST_ASSERT(realSize == reportedSize);
next++;
}
}

void Test_Commands_Generic() {
Test_UART();
Test_Events();

// reset whole device
Expand Down

0 comments on commit a2f3b02

Please sign in to comment.