/* SPDX-License-Identifier: GPL-2.0 */ /* * kselftest.h: low-level kselftest framework to include from * selftest programs. When possible, please use * kselftest_harness.h instead. * * Copyright (c) 2014 Shuah Khan <shuahkh@osg.samsung.com> * Copyright (c) 2014 Samsung Electronics Co., Ltd. * * Using this API consists of first counting how many tests your code * has to run, and then starting up the reporting: * * ksft_print_header(); * ksft_set_plan(total_number_of_tests); * * For each test, report any progress, debugging, etc with: * * ksft_print_msg(fmt, ...); * ksft_perror(msg); * * and finally report the pass/fail/skip/xfail/xpass state of the test * with one of: * * ksft_test_result(condition, fmt, ...); * ksft_test_result_report(result, fmt, ...); * ksft_test_result_pass(fmt, ...); * ksft_test_result_fail(fmt, ...); * ksft_test_result_skip(fmt, ...); * ksft_test_result_xfail(fmt, ...); * ksft_test_result_xpass(fmt, ...); * ksft_test_result_error(fmt, ...); * ksft_test_result_code(exit_code, test_name, fmt, ...); * * When all tests are finished, clean up and exit the program with one of: * * ksft_finished(); * ksft_exit(condition); * ksft_exit_pass(); * ksft_exit_fail(); * * If the program wants to report details on why the entire program has * failed, it can instead exit with a message (this is usually done when * the program is aborting before finishing all tests): * * ksft_exit_fail_msg(fmt, ...); * ksft_exit_fail_perror(msg); *
*/ #ifndef __KSELFTEST_H #define __KSELFTEST_H
staticinlinevoid ksft_print_header(void)
{ /* * Force line buffering; If stdout is not connected to a terminal, it * will otherwise default to fully buffered, which can cause output * duplication if there is content in the buffer when fork()ing. If * there is a crash, line buffering also means the most recent output * line will be visible.
*/
setvbuf(stdout, NULL, _IOLBF, 0);
if (!(getenv("KSFT_TAP_LEVEL")))
printf("TAP version 13\n");
}
/** * ksft_test_result() - Report test success based on truth of condition * * @condition: if true, report test success, otherwise failure.
*/ #define ksft_test_result(condition, fmt, ...) do { \ if (!!(condition)) \
ksft_test_result_pass(fmt, ##__VA_ARGS__);\ else \
ksft_test_result_fail(fmt, ##__VA_ARGS__);\
} while (0)
/* TODO: how does "error" differ from "fail" or "skip"? */ staticinline __printf(1, 2) void ksft_test_result_error(constchar *msg, ...)
{ int saved_errno = errno;
va_list args;
/** * ksft_exit() - Exit selftest based on truth of condition * * @condition: if true, exit self test with success, otherwise fail.
*/ #define ksft_exit(condition) do { \ if (!!(condition)) \
ksft_exit_pass(); \ else \
ksft_exit_fail(); \
} while (0)
/** * ksft_finished() - Exit selftest with success if all tests passed
*/ #define ksft_finished() \
ksft_exit(ksft_plan == \
ksft_cnt.ksft_pass + \
ksft_cnt.ksft_xfail + \
ksft_cnt.ksft_xskip)
/* * FIXME: several tests misuse ksft_exit_skip so produce * something sensible if some tests have already been run * or a plan has been printed. Those tests should use * ksft_test_result_skip or ksft_exit_fail_msg instead.
*/ if (ksft_plan || ksft_test_num()) {
ksft_cnt.ksft_xskip++;
printf("ok %u # SKIP ", 1 + ksft_test_num());
} else {
printf("1..0 # SKIP ");
} if (msg) {
errno = saved_errno;
vprintf(msg, args);
va_end(args);
} if (ksft_test_num())
ksft_print_cnts(); exit(KSFT_SKIP);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.