Skip to content

Commit

Permalink
#45: Tests for error_handler
Browse files Browse the repository at this point in the history
  • Loading branch information
aul12 committed Dec 29, 2022
1 parent 1a23005 commit d9fce8f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
10 changes: 6 additions & 4 deletions Src/Application/error_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,22 @@
#include <avr/wdt.h>
#include <stdbool.h>

enum { DDRL_INIT = 0xFF };
enum { GROUP_MASK = 0x0FU };

void error_handler_init(void) {
DDRL = 0xFF;
DDRL = DDRL_INIT;
PORTL = 0;
}

void error_handler_handle_error(error_group_t group, uint8_t error_id) {
uint8_t code = (error_id & 0x0F) << 4 | (group & 0x0F);
PORTL = code;
error_handler_handle_warning(group, error_id);
while (true) {
wdt_reset();
}
}

void error_handler_handle_warning(error_group_t group, uint8_t error_id) {
uint8_t code = (error_id & 0x0F) << 4 | (group & 0x0F);
uint8_t code = ((uint8_t) error_id & GROUP_MASK) << 4U | (group & GROUP_MASK);
PORTL = code;
}
8 changes: 8 additions & 0 deletions Tests/LowLevel/Application/error_handler.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
#include <Mock/avr/io.hpp>
#include <gtest/gtest.h>

extern "C" {
#include <Application/error_handler.h>
}

TEST(TEST_NAME, init) {
error_handler_init();
EXPECT_EQ(DDRL, 0xFF);
EXPECT_EQ(PORTL, 0x00);
}

TEST(TEST_NAME, handle_warning) {
error_handler_handle_warning(static_cast<error_group_t>(6), 11);
EXPECT_EQ(PORTL, 16 * 11 + 6);
}

0 comments on commit d9fce8f

Please sign in to comment.