Skip to content
Snippets Groups Projects
Commit ffb1ba6e authored by Francisco Acosta's avatar Francisco Acosta Committed by Francisco Acosta
Browse files

tests: add riotboot_hdr test

Unittest for riotboot_hdr submodule. If successful, it must
print 4 successful tests.
parent 00adbd69
No related branches found
No related tags found
No related merge requests found
include ../Makefile.tests_common
USEMODULE += riotboot_hdr
USEMODULE += embunit
HDR_LOG_LEVEL ?= LOG_NONE
CFLAGS += -DLOG_LEVEL=$(HDR_LOG_LEVEL)
include $(RIOTBASE)/Makefile.include
/*
* Copyright (C) 2018 Inria
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @ingroup tests
* @{
*
* @file
* @brief Tests for module riotboot_hdr
*
* @author Francisco Acosta <francisco.acosta@inria.fr>
*/
#include <stdio.h>
#include "riotboot/hdr.h"
#include "embUnit.h"
const riotboot_hdr_t riotboot_hdr_good = {
.magic_number = RIOTBOOT_MAGIC,
.version = 0x5bd19bff,
.start_addr = 0x00001100,
.chksum = 0x02eda672
};
const riotboot_hdr_t riotboot_hdr_bad_magic = {
.magic_number = 0x12345678,
.version = 0x5bd19bff,
.start_addr = 0x00001100,
.chksum = 0x02eda672
};
const riotboot_hdr_t riotboot_hdr_bad_chksum = {
.magic_number = RIOTBOOT_MAGIC,
.version = 0x5bd19bff,
.start_addr = 0x00001100,
.chksum = 0x02000000
};
static void test_riotboot_hdr_01(void)
{
int ret = riotboot_hdr_validate(&riotboot_hdr_good);
TEST_ASSERT_EQUAL_INT(0, ret);
}
static void test_riotboot_hdr_02(void)
{
int ret = riotboot_hdr_validate(&riotboot_hdr_bad_magic);
TEST_ASSERT_EQUAL_INT(-1, ret);
}
static void test_riotboot_hdr_03(void)
{
int ret = riotboot_hdr_validate(&riotboot_hdr_bad_chksum);
TEST_ASSERT_EQUAL_INT(-1, ret);
}
static void test_riotboot_hdr_04(void)
{
uint32_t chksum = riotboot_hdr_checksum(&riotboot_hdr_good);
TEST_ASSERT_EQUAL_INT(0x02eda672, chksum);
}
Test *tests_riotboot_hdr(void)
{
EMB_UNIT_TESTFIXTURES(fixtures) {
new_TestFixture(test_riotboot_hdr_01),
new_TestFixture(test_riotboot_hdr_02),
new_TestFixture(test_riotboot_hdr_03),
new_TestFixture(test_riotboot_hdr_04),
};
EMB_UNIT_TESTCALLER(riotboot_hdr_tests, NULL, NULL, fixtures);
return (Test *)&riotboot_hdr_tests;
}
int main(void)
{
TESTS_START();
TESTS_RUN(tests_riotboot_hdr());
TESTS_END();
return 0;
}
#!/usr/bin/env python3
# Copyright (C) 2018 Francisco Acosta <francisco.acosta@inria.fr>
#
# This file is subject to the terms and conditions of the GNU Lesser
# General Public License v2.1. See the file LICENSE in the top level
# directory for more details.
import sys
from testrunner import run
def testfunc(child):
child.expect(r"OK \(\d+ tests\)")
if __name__ == "__main__":
sys.exit(run(testfunc))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment