2015-04-11 07:44:37 +08:00
|
|
|
/* tc_utilities.h - testcase utilities header file */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2012-2015 Wind River Systems, Inc.
|
|
|
|
*
|
2017-01-19 09:01:01 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2015-04-11 07:44:37 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __TC_UTIL_H__
|
|
|
|
#define __TC_UTIL_H__
|
|
|
|
|
2015-10-21 19:36:59 +08:00
|
|
|
#include <zephyr.h>
|
2015-04-11 07:44:37 +08:00
|
|
|
|
|
|
|
#include <string.h>
|
2018-08-09 14:18:18 +08:00
|
|
|
#include <shell/legacy_shell.h>
|
2015-04-11 07:44:37 +08:00
|
|
|
|
2016-06-23 21:47:00 +08:00
|
|
|
#if defined(CONFIG_STDOUT_CONSOLE)
|
|
|
|
#include <stdio.h>
|
|
|
|
#define PRINT_DATA(fmt, ...) printf(fmt, ##__VA_ARGS__)
|
|
|
|
#else
|
|
|
|
#include <misc/printk.h>
|
2015-04-11 07:44:37 +08:00
|
|
|
#define PRINT_DATA(fmt, ...) printk(fmt, ##__VA_ARGS__)
|
2016-06-23 21:47:00 +08:00
|
|
|
#endif /* CONFIG_STDOUT_CONSOLE */
|
2015-04-11 07:44:37 +08:00
|
|
|
|
2017-11-28 17:51:06 +08:00
|
|
|
#if defined CONFIG_ARCH_POSIX
|
|
|
|
#include "posix_board_if.h"
|
|
|
|
#endif
|
|
|
|
|
2016-05-25 12:02:02 +08:00
|
|
|
/**
|
2018-05-07 11:37:10 +08:00
|
|
|
* @def TC_PRINT_RUNID
|
2016-05-25 12:02:02 +08:00
|
|
|
* @brief Report a Run ID
|
|
|
|
*
|
|
|
|
* When the CPP symbol \c TC_RUNID is defined (for example, from the
|
|
|
|
* compile environment), print the defined string ``RunID:
|
|
|
|
* <TC_RUNID>`` when called (TC_END_REPORT() will also call it).
|
|
|
|
*
|
|
|
|
* This is used mainly when automating the execution and running of
|
|
|
|
* multiple test cases, to verify that the expected image is being
|
|
|
|
* executed (as sometimes the targets fail to flash or reset
|
|
|
|
* properly).
|
|
|
|
*
|
|
|
|
* TC_RUNID is any string, that will be converted to a string literal.
|
|
|
|
*/
|
|
|
|
#define __str(x) #x
|
|
|
|
#define _str(x) __str(x)
|
|
|
|
#ifdef TC_RUNID
|
|
|
|
#define TC_PRINT_RUNID PRINT_DATA("RunID: " _str(TC_RUNID) "\n")
|
|
|
|
#else
|
|
|
|
#define TC_PRINT_RUNID do {} while (0)
|
|
|
|
#endif
|
|
|
|
|
2016-08-22 19:51:46 +08:00
|
|
|
#define PRINT_LINE \
|
2015-04-11 07:44:37 +08:00
|
|
|
PRINT_DATA( \
|
|
|
|
"============================================================" \
|
|
|
|
"=======\n")
|
|
|
|
|
|
|
|
/* stack size and priority for test suite task */
|
|
|
|
#define TASK_STACK_SIZE (1024 * 2)
|
|
|
|
|
|
|
|
#define FMT_ERROR "%s - %s@%d. "
|
|
|
|
|
|
|
|
#define TC_PASS 0
|
|
|
|
#define TC_FAIL 1
|
2018-04-22 11:26:19 +08:00
|
|
|
#define TC_SKIP 2
|
2015-04-11 07:44:37 +08:00
|
|
|
|
2018-06-29 05:09:28 +08:00
|
|
|
static __unused const char *TC_RESULT_STR[] = {
|
|
|
|
[TC_PASS] = "PASS",
|
|
|
|
[TC_FAIL] = "FAIL",
|
|
|
|
[TC_SKIP] = "SKIP",
|
|
|
|
};
|
|
|
|
|
|
|
|
#define TC_RESULT_TO_STR(result) TC_RESULT_STR[result]
|
|
|
|
|
2015-04-11 07:44:37 +08:00
|
|
|
#define TC_ERROR(fmt, ...) \
|
|
|
|
do { \
|
2018-06-29 05:09:28 +08:00
|
|
|
PRINT_DATA(FMT_ERROR, "FAIL", __func__, __LINE__); \
|
2015-04-11 07:44:37 +08:00
|
|
|
PRINT_DATA(fmt, ##__VA_ARGS__); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define TC_PRINT(fmt, ...) PRINT_DATA(fmt, ##__VA_ARGS__)
|
2017-08-17 00:52:07 +08:00
|
|
|
#define TC_START(name) PRINT_DATA("starting test - %s\n", name)
|
2015-04-11 07:44:37 +08:00
|
|
|
#define TC_END(result, fmt, ...) PRINT_DATA(fmt, ##__VA_ARGS__)
|
|
|
|
|
|
|
|
/* prints result and the function name */
|
2016-10-28 08:19:31 +08:00
|
|
|
#define _TC_END_RESULT(result, func) \
|
|
|
|
do { \
|
2018-06-29 05:09:28 +08:00
|
|
|
TC_END(result, "%s - %s\n", TC_RESULT_TO_STR(result), func); \
|
2017-08-17 00:52:07 +08:00
|
|
|
PRINT_LINE; \
|
2015-04-11 07:44:37 +08:00
|
|
|
} while (0)
|
2016-08-22 19:51:46 +08:00
|
|
|
#define TC_END_RESULT(result) \
|
2016-10-28 08:19:31 +08:00
|
|
|
_TC_END_RESULT((result), __func__)
|
2015-04-11 07:44:37 +08:00
|
|
|
|
2018-02-01 16:18:07 +08:00
|
|
|
#if defined(CONFIG_ARCH_POSIX)
|
|
|
|
#define TC_END_POST(result) posix_exit(result)
|
|
|
|
#else
|
|
|
|
#define TC_END_POST(result)
|
|
|
|
#endif /* CONFIG_ARCH_POSIX */
|
2017-11-28 17:51:06 +08:00
|
|
|
|
2015-04-11 07:44:37 +08:00
|
|
|
#define TC_END_REPORT(result) \
|
|
|
|
do { \
|
|
|
|
PRINT_LINE; \
|
2016-05-25 12:02:02 +08:00
|
|
|
TC_PRINT_RUNID; \
|
2015-04-11 07:44:37 +08:00
|
|
|
TC_END(result, \
|
2016-08-22 19:51:46 +08:00
|
|
|
"PROJECT EXECUTION %s\n", \
|
2016-10-28 08:19:31 +08:00
|
|
|
(result) == TC_PASS ? "SUCCESSFUL" : "FAILED"); \
|
2018-02-01 16:18:07 +08:00
|
|
|
TC_END_POST(result); \
|
2015-04-11 07:44:37 +08:00
|
|
|
} while (0)
|
|
|
|
|
2016-11-08 09:38:51 +08:00
|
|
|
#define TC_CMD_DEFINE(name) \
|
|
|
|
int cmd_##name(int argc, char *argv[]) \
|
|
|
|
{ \
|
|
|
|
TC_START(__func__); \
|
|
|
|
name(); \
|
|
|
|
TC_END_RESULT(TC_PASS); \
|
|
|
|
return 0; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define TC_CMD_ITEM(name) {STRINGIFY(name), cmd_##name, "none"}
|
2015-04-11 07:44:37 +08:00
|
|
|
#endif /* __TC_UTIL_H__ */
|