diff --git a/tests/riotboot_hdr/Makefile b/tests/riotboot_hdr/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..68cbbd8c116b68a3245d5b42748b9abe14266f48 --- /dev/null +++ b/tests/riotboot_hdr/Makefile @@ -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 diff --git a/tests/riotboot_hdr/main.c b/tests/riotboot_hdr/main.c new file mode 100644 index 0000000000000000000000000000000000000000..109dff56bbe7ab59c1a8a729fe8cdfd56a7e2c76 --- /dev/null +++ b/tests/riotboot_hdr/main.c @@ -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; +} diff --git a/tests/riotboot_hdr/tests/01-run.py b/tests/riotboot_hdr/tests/01-run.py new file mode 100755 index 0000000000000000000000000000000000000000..8d71a331effdf6f987248b253a86b76ba966cc8a --- /dev/null +++ b/tests/riotboot_hdr/tests/01-run.py @@ -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))