Issue 187 enable skipped ztest suites (#189)

* Fix some ztests that were skipped

* Expose bacapp_same_value()

* Fix bacapp, ptransfer tests

* Fix bugs in Load_Control object & tests

* refactor days functions from datetime module

* fix legacy ctests

* Add bacnet/basic/sys/days.[ch] to Zephyr build

* Update ztest to match from Zephyr v2.6.0; update ringbuf, datetime to build

* Fixup ztest test for object/acc

* Fix bvlc_address_from_ascii; enable/fix bvlc test

* Comment cleanup

* test/bacnet/basic/object/lc partially enabled

* Fix bacapp_decode_data_len return status on erroneous input

* fix ztest include fatal error

* fix ztest strsignal reference fatal error

* fix zassert_mem_equal reference syntax error

* fix zassert_mem_equal reference syntax error

Co-authored-by: Gregory Shue <gregory.shue@legrand.us>
Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
This commit is contained in:
Greg Shue
2021-08-16 15:29:40 -07:00
committed by GitHub
parent 541f4024fb
commit 8b8ef8f338
102 changed files with 3178 additions and 1208 deletions
+60 -9
View File
@@ -6,8 +6,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef __TC_UTIL_H__
#define __TC_UTIL_H__
#ifndef ZEPHYR_TESTSUITE_INCLUDE_TC_UTIL_H_
#define ZEPHYR_TESTSUITE_INCLUDE_TC_UTIL_H_
#include <zephyr.h>
@@ -92,6 +92,31 @@ static inline const char *TC_RESULT_TO_STR(int result)
}
}
static uint32_t tc_start_time;
static uint32_t tc_spend_time;
static inline void get_start_time_cyc(void)
{
/* Besides the ztest framework, some testcase will also call
* TC_START() in their code. But the caller thread cannot be
* in userspace.
*/
#if 0
if (!k_is_user_context()) {
tc_start_time = k_cycle_get_32();
}
#endif
}
static inline void test_time_ms(void)
{
#if 0
uint32_t spend_cycle = k_cycle_get_32() - tc_start_time;
tc_spend_time = k_cyc_to_ms_ceil32(spend_cycle);
#endif
}
#ifndef TC_ERROR
#define TC_ERROR(fmt, ...) \
do { \
@@ -105,7 +130,11 @@ static inline const char *TC_RESULT_TO_STR(int result)
#endif
#ifndef TC_START
#define TC_START(name) PRINT_DATA("starting test - %s\n", name)
#define TC_START(name) \
do { \
PRINT_DATA("START - %s\n", name); \
get_start_time_cyc(); \
} while (0)
#endif
#ifndef TC_END
@@ -114,10 +143,13 @@ static inline const char *TC_RESULT_TO_STR(int result)
#ifndef Z_TC_END_RESULT
/* prints result and the function name */
#define Z_TC_END_RESULT(result, func) \
do { \
TC_END(result, "%s - %s\n", TC_RESULT_TO_STR(result), func); \
PRINT_LINE; \
#define Z_TC_END_RESULT(result, func) \
do { \
test_time_ms(); \
TC_END(result, " %s - %s in %u.%u seconds\n", \
TC_RESULT_TO_STR(result), func, tc_spend_time/1000, \
tc_spend_time%1000); \
PRINT_LINE; \
} while (0)
#endif
@@ -126,6 +158,25 @@ static inline const char *TC_RESULT_TO_STR(int result)
Z_TC_END_RESULT((result), __func__)
#endif
#ifndef TC_SUITE_START
#define TC_SUITE_START(name) \
do { \
TC_PRINT("Running test suite %s\n", name); \
PRINT_LINE; \
} while (0)
#endif
#ifndef TC_SUITE_END
#define TC_SUITE_END(name, result) \
do { \
if (result == TC_PASS) { \
TC_PRINT("Test suite %s succeeded\n", name); \
} else { \
TC_PRINT("Test suite %s failed.\n", name); \
} \
} while (0)
#endif
#if defined(CONFIG_ARCH_POSIX)
#define TC_END_POST(result) posix_exit(result)
#else
@@ -157,7 +208,7 @@ static inline const char *TC_RESULT_TO_STR(int result)
#define TC_CMD_ITEM(name) cmd_##name
#else
#define TC_CMD_DEFINE(name) \
int cmd_##name(int argc, char *argv[]) \
int cmd_##name(int argc, char *argv[]) \
{ \
TC_START(__func__); \
name(); \
@@ -167,4 +218,4 @@ static inline const char *TC_RESULT_TO_STR(int result)
#define TC_CMD_ITEM(name) {STRINGIFY(name), cmd_##name, "none"}
#endif
#endif /* __TC_UTIL_H__ */
#endif /* ZEPHYR_TESTSUITE_INCLUDE_TC_UTIL_H_ */
+7 -7
View File
@@ -35,19 +35,19 @@
#include <tc_util.h>
#include <tinycrypt/constants.h>
static inline void show_str(const char *label, const u8_t *s, size_t len)
static inline void show_str(const char *label, const uint8_t *s, size_t len)
{
u32_t i;
uint32_t i;
TC_PRINT("%s = ", label);
for (i = 0U; i < (u32_t)len; ++i) {
for (i = 0U; i < (uint32_t)len; ++i) {
TC_PRINT("%02x", s[i]);
}
TC_PRINT("\n");
}
static inline
void fatal(u32_t testnum, const void *expected, size_t expectedlen,
void fatal(uint32_t testnum, const void *expected, size_t expectedlen,
const void *computed, size_t computedlen)
{
TC_ERROR("\tTest #%d Failed!\n", testnum);
@@ -57,11 +57,11 @@ void fatal(u32_t testnum, const void *expected, size_t expectedlen,
}
static inline
u32_t check_result(u32_t testnum, const void *expected,
uint32_t check_result(uint32_t testnum, const void *expected,
size_t expectedlen, const void *computed,
size_t computedlen, u32_t verbose)
size_t computedlen, uint32_t verbose)
{
u32_t result = TC_PASS;
uint32_t result = TC_PASS;
ARG_UNUSED(verbose);
+14 -16
View File
@@ -2,34 +2,29 @@
* Copyright (c) 2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*
* Modified from zephyr_v2.2.0 subsys/testsuite/ztest/include/ztest.h
* because:
* 1. This port will never be run in the Zephyr kernel.
* This repository is extended to be a Zephyr module for that.
* 2. This port will not support multiple CPUs or toolchains.
*
* Modifications:
* a. Code conditionally compiled on the following CPP symbols were deleted
* (as they were kernel-specific):
* KERNEL
*/
/**
* @file
*
* @brief Zephyr testing suite
* @brief Zephyr Testsuite
*
* From zephyr_v2.6.0 subsys/testsuite/ztest/include/ztest.h
* Note:
* 1. This port will never be run in the Zephyr kernel.
* This repository is extended to be a Zephyr module for that.
* 2. This port will not support multiple CPUs or toolchains.
*/
/**
* @brief Zephyr Tests
* @brief Zephyr Tests (ZTest)
* @defgroup all_tests Zephyr Tests
* @{
* @}
*/
#ifndef __ZTEST_H__
#define __ZTEST_H__
#ifndef ZEPHYR_TESTSUITE_INCLUDE_ZTEST_H_
#define ZEPHYR_TESTSUITE_INCLUDE_ZTEST_H_
/**
* @defgroup ztest Zephyr testing suite
@@ -39,6 +34,7 @@
#error "You need to add CONFIG_ZTEST to your config file."
#endif
#ifndef KERNEL
#define CONFIG_STDOUT_CONSOLE 1
#define CONFIG_ZTEST_ASSERT_VERBOSE 1
#define CONFIG_ZTEST_MOCKING
@@ -48,6 +44,7 @@
#define CONFIG_MP_NUM_CPUS 1
#define CONFIG_SYS_CLOCK_TICKS_PER_SEC 100
#define CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC 10000000
#define ARCH_STACK_PTR_ALIGN 8
/* FIXME: Properly integrate with Zephyr's arch specific code */
#define CONFIG_X86 1
#define CONFIG_PRINTK 1
@@ -59,6 +56,7 @@ typedef struct esf z_arch_esf_t;
#ifdef __cplusplus
}
#endif
#endif /* KERNEL */
#include <sys/printk.h>
#define PRINT printk
@@ -80,4 +78,4 @@ void test_main(void);
}
#endif
#endif /* __ZTEST_H__ */
#endif /* ZEPHYR_TESTSUITE_INCLUDE_ZTEST_H_ */
+32 -13
View File
@@ -10,8 +10,8 @@
* @brief Zephyr testing framework assertion macros
*/
#ifndef __ZTEST_ASSERT_H__
#define __ZTEST_ASSERT_H__
#ifndef ZEPHYR_TESTSUITE_ZTEST_ASSERT_H_
#define ZEPHYR_TESTSUITE_ZTEST_ASSERT_H_
#include <ztest.h>
#include <stdarg.h>
@@ -23,16 +23,20 @@
extern "C" {
#endif
const char *ztest_relative_filename(const char *file);
void ztest_test_fail(void);
#if CONFIG_ZTEST_ASSERT_VERBOSE == 0
static inline void z_zassert_(bool cond, const char *file, int line)
static inline bool z_zassert_(bool cond, const char *file, int line)
{
if (cond == false) {
PRINT("\n Assertion failed at %s:%d\n",
file, line);
ztest_relative_filename(file), line);
ztest_test_fail();
return false;
}
return true;
}
#define z_zassert(cond, default_msg, file, line, func, msg, ...) \
@@ -40,7 +44,7 @@ static inline void z_zassert_(bool cond, const char *file, int line)
#else /* CONFIG_ZTEST_ASSERT_VERBOSE != 0 */
static inline void z_zassert(bool cond,
static inline bool z_zassert(bool cond,
const char *default_msg,
const char *file,
int line, const char *func,
@@ -51,18 +55,20 @@ static inline void z_zassert(bool cond,
va_start(vargs, msg);
PRINT("\n Assertion failed at %s:%d: %s: %s\n",
file, line, func, default_msg);
ztest_relative_filename(file), line, func, default_msg);
vprintk(msg, vargs);
printk("\n");
va_end(vargs);
ztest_test_fail();
return false;
}
#if CONFIG_ZTEST_ASSERT_VERBOSE == 2
else {
PRINT("\n Assertion succeeded at %s:%d (%s)\n",
file, line, func);
ztest_relative_filename(file), line, func);
}
#endif
return true;
}
#endif /* CONFIG_ZTEST_ASSERT_VERBOSE */
@@ -83,14 +89,19 @@ static inline void z_zassert(bool cond,
* You probably don't need to call this macro directly. You should
* instead use zassert_{condition} macros below.
*
* Note that when CONFIG_MULTITHREADING=n macro returns from the function. It is
* then expected that in that case ztest asserts will be used only in the
* context of the test function.
*
* @param cond Condition to check
* @param msg Optional, can be NULL. Message to print if @a cond is false.
* @param default_msg Message to print if @a cond is false
*/
#define zassert(cond, default_msg, msg, ...) \
z_zassert(cond, msg ? ("(" default_msg ")") : (default_msg), \
__FILE__, __LINE__, __func__, msg ? msg : "", ##__VA_ARGS__)
#define zassert(cond, default_msg, msg, ...) do { \
bool _ret = z_zassert(cond, msg ? ("(" default_msg ")") : (default_msg), \
__FILE__, __LINE__, __func__, \
msg ? msg : "", ##__VA_ARGS__); \
} while (0)
/**
* @brief Assert that this function call won't be reached
@@ -115,6 +126,14 @@ static inline void z_zassert(bool cond,
#define zassert_false(cond, msg, ...) zassert(!(cond), #cond " is true", \
msg, ##__VA_ARGS__)
/**
* @brief Assert that @a cond is 0 (success)
* @param cond Condition to check
* @param msg Optional message to print if the assertion fails
*/
#define zassert_ok(cond, msg, ...) zassert(!(cond), #cond " is non-zero", \
msg, ##__VA_ARGS__)
/**
* @brief Assert that @a ptr is NULL
* @param ptr Pointer to compare
@@ -181,7 +200,7 @@ static inline void z_zassert(bool cond,
* @param msg Optional message to print if the assertion fails
*/
#define zassert_within(a, b, d, msg, ...) \
zassert(((a) > ((b) - (d))) && ((a) < ((b) + (d))), \
zassert(((a) >= ((b) - (d))) && ((a) <= ((b) + (d))), \
#a " not within " #b " +/- " #d, \
msg, ##__VA_ARGS__)
@@ -222,4 +241,4 @@ static inline void z_zassert(bool cond,
}
#endif
#endif /* __ZTEST_ASSERT_H__ */
#endif /* ZEPHYR_TESTSUITE_ZTEST_ASSERT_H_ */
+75
View File
@@ -0,0 +1,75 @@
/*
* Copyright (c) 2020 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ZEPHYR_INCLUDE_ZTEST_FATAL_HOOK_H_
#define ZEPHYR_INCLUDE_ZTEST_FATAL_HOOK_H_
#include <zephyr.h>
#if defined(CONFIG_ZTEST_FATAL_HOOK)
/**
* @brief Set the flag that treat fatal error happened as expected
*
* @details This is used for negative test cases which triggers a fatal
* error. Set the param true will still pass the test case when expected
* fatal error happened. For normal test case, set it false makes it back
* to normal behavior.
*
* @param valid flag indicate fault is expected
*/
__syscall void ztest_set_fault_valid(bool valid);
/* @brief A hook after fatal error handler
*
* @details This is a test case hook that can run code from test case, in
* order to deal with some special case when catching the expected fatal
* error.
*
* Usage: Define your own hook function in your test case code, and do what
* you want to do after fatal error handler.
*
* By default, it will do nothing before leaving error handler.
*/
void ztest_post_fatal_error_hook(unsigned int reason,
const z_arch_esf_t *pEsf);
#endif
#if defined(CONFIG_ZTEST_ASSERT_HOOK)
/**
* @brief Set the flag that treat assert fail happened as expected
*
* @details This is used for negative test cases which triggers a assert
* fail. Set the param true will still pass the test case when expected
* assert fail happened. For normal test case, set it false make it back
* to normal behavior.
*
* @param valid flag indicate assert is expected
*/
__syscall void ztest_set_assert_valid(bool valid);
/* @brief A hook after assert fault handler
*
* @details This is a test case hook that can run code from test case, in
* order to deal with some special case when catching the expected assert
* failed.
*
* Usage: Define your own hook function in your test case code, and do what
* you want to do after assert handler.
*
* By default, it will abort the thread which assert failed.
*/
void ztest_post_assert_fail_hook(void);
#endif
#if defined(CONFIG_ZTEST_FATAL_HOOK) || defined(CONFIG_ZTEST_ASSERT_HOOK)
#include <syscalls/ztest_error_hook.h>
#endif
#endif /* ZEPHYR_INCLUDE_ZTEST_FATAL_HOOK_H_ */
+80 -15
View File
@@ -10,8 +10,8 @@
* @brief Ztest mocking support
*/
#ifndef __ZTEST_MOCK_H__
#define __ZTEST_MOCK_H__
#ifndef ZEPHYR_TESTSUITE_ZTEST_MOCK_H_
#define ZEPHYR_TESTSUITE_ZTEST_MOCK_H_
/**
* @defgroup ztest_mock Ztest mocking support
@@ -33,9 +33,9 @@
* @param param Parameter for which the value should be set
* @param value Value for @a param
*/
#define ztest_expect_value(func, param, value) \
z_ztest_expect_value(STRINGIFY(func), STRINGIFY(param), \
(uintptr_t)(value))
#define ztest_expect_value(func, param, value) \
z_ztest_expect_value(STRINGIFY(func), STRINGIFY(param), \
(uintptr_t)(value))
/**
* @brief If @a param doesn't match the value set by ztest_expect_value(),
@@ -48,17 +48,75 @@
*
* @param param Parameter to check
*/
#define ztest_check_expected_value(param) \
z_ztest_check_expected_value(__func__, STRINGIFY(param), \
(uintptr_t)(param))
#define ztest_check_expected_value(param) \
z_ztest_check_expected_value(__func__, STRINGIFY(param), \
(uintptr_t)(param))
/**
* @brief Tell function @a func to expect the data @a data for @a param
*
* When using ztest_check_expected_data(), the data pointed to by
* @a param should be same @a data in this function. Only data pointer is stored
* by this function, so it must still be valid when ztest_check_expected_data is
* called.
*
* @param func Function in question
* @param param Parameter for which the data should be set
* @param data pointer for the data for parameter @a param
*/
#define ztest_expect_data(func, param, data) \
z_ztest_expect_data(STRINGIFY(func), STRINGIFY(param), (void *)(data))
/**
* @brief If data pointed by @a param don't match the data set by
* ztest_expect_data(), fail the test
*
* This will first check that @a param is expected to be null or non-null and
* then check whether the data pointed by parameter is equal to expected data.
* If either of these checks fail, the current test will fail. This
* must be called from the called function.
*
* @param param Parameter to check
* @param length Length of the data to compare
*/
#define ztest_check_expected_data(param, length) \
z_ztest_check_expected_data(__func__, STRINGIFY(param), \
(void *)(param), (length))
/**
* @brief Tell function @a func to return the data @a data for @a param
*
* When using ztest_return_data(), the data pointed to by @a param should be
* same @a data in this function. Only data pointer is stored by this function,
* so it must still be valid when ztest_copy_return_data is called.
*
* @param func Function in question
* @param param Parameter for which the data should be set
* @param data pointer for the data for parameter @a param
*/
#define ztest_return_data(func, param, data) \
z_ztest_return_data(STRINGIFY(func), STRINGIFY(param), (void *)(data))
/**
* @brief Copy the data set by ztest_return_data to the memory pointed by
* @a param
*
* This will first check that @a param is not null and then copy the data.
* This must be called from the called function.
*
* @param param Parameter to return data for
* @param length Length of the data to return
*/
#define ztest_copy_return_data(param, length) \
z_ztest_copy_return_data(__func__, STRINGIFY(param), \
(void *)(param), (length))
/**
* @brief Tell @a func that it should return @a value
*
* @param func Function that should return @a value
* @param value Value to return from @a func
*/
#define ztest_returns_value(func, value) \
#define ztest_returns_value(func, value) \
z_ztest_returns_value(STRINGIFY(func), (uintptr_t)(value))
/**
@@ -69,8 +127,7 @@
*
* @returns The value the current function should return
*/
#define ztest_get_return_value() \
z_ztest_get_return_value(__func__)
#define ztest_get_return_value() z_ztest_get_return_value(__func__)
/**
* @brief Get the return value as a pointer for current function
@@ -80,7 +137,7 @@
*
* @returns The value the current function should return as a `void *`
*/
#define ztest_get_return_value_ptr() \
#define ztest_get_return_value_ptr() \
((void *)z_ztest_get_return_value(__func__))
/**
@@ -100,7 +157,15 @@ int z_cleanup_mock(void);
void z_ztest_expect_value(const char *fn, const char *name, uintptr_t value);
void z_ztest_check_expected_value(const char *fn, const char *param,
uintptr_t value);
uintptr_t value);
void z_ztest_expect_data(const char *fn, const char *name, void *val);
void z_ztest_check_expected_data(const char *fn, const char *name, void *data,
uint32_t length);
void z_ztest_return_data(const char *fn, const char *name, void *val);
void z_ztest_copy_return_data(const char *fn, const char *name, void *data,
uint32_t length);
void z_ztest_returns_value(const char *fn, uintptr_t value);
uintptr_t z_ztest_get_return_value(const char *fn);
@@ -114,6 +179,6 @@ uintptr_t z_ztest_get_return_value(const char *fn);
#define z_init_mock()
#define z_cleanup_mock() 0
#endif /* CONFIG_ZTEST_MOCKING */
#endif /* CONFIG_ZTEST_MOCKING */
#endif /* __ZTEST_H__ */
#endif /* ZEPHYR_TESTSUITE_ZTEST_MOCK_H_ */
+39 -14
View File
@@ -9,26 +9,24 @@
*
* @brief Zephyr testing framework _test.
*
* Modified from zephyr_v2.2.0 subsys/testsuite/ztest/src/ztest.c
* because:
* From zephyr_v2.6.0 subsys/testsuite/ztest/src/ztest.c
* Note:
* 1. This port will never be run in the Zephyr kernel.
* This repository is extended to be a Zephyr module for that.
* 2. This port will not support multiple CPUs or toolchains.
*
* Modifications:
* a. Code conditionally compiled on the following CPP symbols were deleted
* (as they were kernel-specific):
* CONFIG_USERSPACE
* CONFIG_SMP
* KERNEL
* b. Inclusion of The following header files were removed as irrelevant.
* <app_memory/app_memdomain.h>
* c. syscall declarations and inclusions.
* 1. Added __ZEPHYR__ conditionals around:
* a. #include <app_memory/app_memdomain.h>
* b. syscall declarations and inclusions.
*/
#ifndef __ZTEST_TEST_H__
#define __ZTEST_TEST_H__
#ifndef ZEPHYR_TESTSUITE_ZTEST_TEST_H_
#define ZEPHYR_TESTSUITE_ZTEST_TEST_H_
#if 0 /* __ZEPHYR__ */
#include <app_memory/app_memdomain.h>
#endif /* __ZEPHYR__ */
#ifdef __cplusplus
extern "C" {
@@ -39,7 +37,7 @@ struct unit_test {
void (*test)(void);
void (*setup)(void);
void (*teardown)(void);
u32_t thread_options;
uint32_t thread_options;
};
void z_ztest_run_test_suite(const char *name, struct unit_test *suite);
@@ -145,6 +143,11 @@ static inline void unit_test_noop(void)
#define ztest_user_unit_test(fn) \
ztest_user_unit_test_setup_teardown(fn, unit_test_noop, unit_test_noop)
#if 0 /* __ZEPHYR__ */
__syscall void z_test_1cpu_start(void);
__syscall void z_test_1cpu_stop(void);
#endif /* __ZEPHYR__ */
/**
* @brief Define a SMP-unsafe test function
*
@@ -153,7 +156,12 @@ static inline void unit_test_noop(void)
*
* @param fn Test function
*/
#ifdef CONFIG_SMP
#define ztest_1cpu_unit_test(fn) \
ztest_unit_test_setup_teardown(fn, z_test_1cpu_start, z_test_1cpu_stop)
#else
#define ztest_1cpu_unit_test(fn) ztest_unit_test(fn)
#endif
/**
* @brief Define a SMP-unsafe test function that should run as a user thread
@@ -163,12 +171,24 @@ static inline void unit_test_noop(void)
*
* @param fn Test function
*/
#ifdef CONFIG_SMP
#define ztest_1cpu_user_unit_test(fn) \
ztest_user_unit_test_setup_teardown(fn, z_test_1cpu_start, z_test_1cpu_stop)
#else
#define ztest_1cpu_user_unit_test(fn) ztest_user_unit_test(fn)
#endif
/* definitions for use with testing application shared memory */
#ifdef CONFIG_USERSPACE
#define ZTEST_DMEM K_APP_DMEM(ztest_mem_partition)
#define ZTEST_BMEM K_APP_BMEM(ztest_mem_partition)
#define ZTEST_SECTION K_APP_DMEM_SECTION(ztest_mem_partition)
extern struct k_mem_partition ztest_mem_partition;
#else
#define ZTEST_DMEM
#define ZTEST_BMEM
#define ZTEST_SECTION .data
#endif
/**
* @brief Define a test suite
@@ -200,9 +220,14 @@ static inline void unit_test_noop(void)
/**
* @}
*/
#ifndef ZTEST_UNITTEST
#if 0 /* __ZEPHYR__ */
#include <syscalls/ztest_test.h>
#endif /* _ZEPHYR__ */
#endif
#ifdef __cplusplus
}
#endif
#endif /* __ZTEST_ASSERT_H__ */
#endif /* ZEPHYR_TESTSUITE_ZTEST_TEST_H_ */