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