diff --git a/tests/unittests/tests-luid/Makefile b/tests/unittests/tests-luid/Makefile new file mode 100644 index 0000000000..48422e909a --- /dev/null +++ b/tests/unittests/tests-luid/Makefile @@ -0,0 +1 @@ +include $(RIOTBASE)/Makefile.base diff --git a/tests/unittests/tests-luid/Makefile.include b/tests/unittests/tests-luid/Makefile.include new file mode 100644 index 0000000000..dd2d79e221 --- /dev/null +++ b/tests/unittests/tests-luid/Makefile.include @@ -0,0 +1 @@ +USEMODULE += luid diff --git a/tests/unittests/tests-luid/tests-luid.c b/tests/unittests/tests-luid/tests-luid.c new file mode 100644 index 0000000000..08af1de74b --- /dev/null +++ b/tests/unittests/tests-luid/tests-luid.c @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2019 ML!PA Consulting GmbH + * + * 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. + */ + +#include +#include +#include + +#include "tests-luid.h" + +static void test_luid_uniqe_eui64(void) +{ + eui64_t mac[3]; + + luid_get_eui64(&mac[0]); + luid_get_eui64(&mac[1]); + luid_get_eui64(&mac[2]); + TEST_ASSERT_EQUAL_INT(0, !memcmp(&mac[0], &mac[1], sizeof(mac[0]))); + TEST_ASSERT_EQUAL_INT(0, !memcmp(&mac[1], &mac[2], sizeof(mac[1]))); +} + +static void test_luid_uniqe_eui48(void) +{ + eui48_t mac[3]; + + luid_get_eui48(&mac[0]); + luid_get_eui48(&mac[1]); + luid_get_eui48(&mac[2]); + TEST_ASSERT_EQUAL_INT(0, !memcmp(&mac[0], &mac[1], sizeof(mac[0]))); + TEST_ASSERT_EQUAL_INT(0, !memcmp(&mac[1], &mac[2], sizeof(mac[1]))); +} + +static void test_luid_custom(void) +{ + uint8_t a[2][8]; + uint8_t b[2][8]; + + luid_custom(a[0], sizeof(a[0]), 0xfefe); + luid_custom(a[1], sizeof(a[1]), 0xfefe); + luid_custom(b[0], sizeof(b[0]), 0xbeef); + luid_custom(b[1], sizeof(b[1]), 0xbeef); + + TEST_ASSERT_EQUAL_INT(0, !memcmp(a[0], b[0], sizeof(a[0]))); + TEST_ASSERT_EQUAL_INT(0, !memcmp(a[1], b[1], sizeof(a[1]))); + TEST_ASSERT_EQUAL_INT(0, memcmp(a[0], a[0], sizeof(a[0]))); + TEST_ASSERT_EQUAL_INT(0, memcmp(b[1], b[1], sizeof(b[0]))); +} + +Test *tests_luid_tests(void) +{ + EMB_UNIT_TESTFIXTURES(fixtures) { + new_TestFixture(test_luid_uniqe_eui48), + new_TestFixture(test_luid_uniqe_eui64), + new_TestFixture(test_luid_custom), + }; + + EMB_UNIT_TESTCALLER(luid_tests, NULL, NULL, fixtures); + + return (Test *)&luid_tests; +} + +void tests_luid(void) +{ + TESTS_RUN(tests_luid_tests()); +} diff --git a/tests/unittests/tests-luid/tests-luid.h b/tests/unittests/tests-luid/tests-luid.h new file mode 100644 index 0000000000..0de07ccc3f --- /dev/null +++ b/tests/unittests/tests-luid/tests-luid.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2019 ML!PA Consulting GmbH + * + * 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. + */ + +/** + * @addtogroup unittests + * @{ + * + * @file + * @brief Unittests for the ``luid`` module + * + * @author Benjamin Valentin + */ +#ifndef TESTS_LUID_H +#define TESTS_LUID_H + +#include "embUnit.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief The entry point of this test suite. + */ +void tests_luid(void); + +/** + * @brief Generates tests for luid + * + * @return embUnit tests if successful, NULL if not. + */ +Test *tests_luid_tests(void); + +#ifdef __cplusplus +} +#endif + +#endif /* TESTS_LUID_H */ +/** @} */