tests: add riotboot_hdr test
Unittest for riotboot_hdr submodule. If successful, it must print 4 successful tests.
This commit is contained in:
parent
00adbd69f6
commit
ffb1ba6e47
10
tests/riotboot_hdr/Makefile
Normal file
10
tests/riotboot_hdr/Makefile
Normal file
@ -0,0 +1,10 @@
|
||||
include ../Makefile.tests_common
|
||||
|
||||
USEMODULE += riotboot_hdr
|
||||
USEMODULE += embunit
|
||||
|
||||
HDR_LOG_LEVEL ?= LOG_NONE
|
||||
|
||||
CFLAGS += -DLOG_LEVEL=$(HDR_LOG_LEVEL)
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
||||
93
tests/riotboot_hdr/main.c
Normal file
93
tests/riotboot_hdr/main.c
Normal file
@ -0,0 +1,93 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
18
tests/riotboot_hdr/tests/01-run.py
Executable file
18
tests/riotboot_hdr/tests/01-run.py
Executable file
@ -0,0 +1,18 @@
|
||||
#!/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))
|
||||
Loading…
x
Reference in New Issue
Block a user