1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /* vim: set ts=8 sw=8 noet tw=80 nowrap: */
4 * comedi/drivers/tests/unittest.h
5 * Simple framework for unittests for comedi drivers.
7 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 2016 Spencer E. Olson <olsonse@umich.edu>
9 * based of parts of drivers/of/unittest.c
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
22 #ifndef _COMEDI_DRIVERS_TESTS_UNITTEST_H
23 #define _COMEDI_DRIVERS_TESTS_UNITTEST_H
25 static struct unittest_results {
30 typedef void *(*unittest_fptr)(void);
32 #define unittest(result, fmt, ...) ({ \
33 bool failed = !(result); \
35 ++unittest_results.failed; \
36 pr_err("FAIL %s():%i " fmt, __func__, __LINE__, \
39 ++unittest_results.passed; \
40 pr_debug("pass %s():%i " fmt, __func__, __LINE__, \
47 * Execute an array of unit tests.
48 * @name: Name of set of unit tests--will be shown at INFO log level.
49 * @unit_tests: A null-terminated list of unit tests to execute.
51 static inline void exec_unittests(const char *name,
52 const unittest_fptr *unit_tests)
54 pr_info("begin comedi:\"%s\" unittests\n", name);
56 for (; (*unit_tests) != NULL; ++unit_tests)
59 pr_info("end of comedi:\"%s\" unittests - %i passed, %i failed\n", name,
60 unittest_results.passed, unittest_results.failed);
63 #endif /* _COMEDI_DRIVERS_TESTS_UNITTEST_H */