1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * comedi/drivers/tests/comedi_example_test.c
4 * Example set of unit tests.
5 *
6 * COMEDI - Linux Control and Measurement Device Interface
7 * Copyright (C) 2016 Spencer E. Olson <olsonse@umich.edu>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 */
19
20#include <linux/module.h>
21
22#include "unittest.h"
23
24/* *** BEGIN fake board data *** */
25struct comedi_device {
26 const char *board_name;
27 int item;
28};
29
30static struct comedi_device dev = {
31 .board_name = "fake_device",
32};
33
34/* *** END fake board data *** */
35
36/* *** BEGIN fake data init *** */
37static void init_fake(void)
38{
39 dev.item = 10;
40}
41
42/* *** END fake data init *** */
43
44static void test0(void)
45{
46 init_fake();
47 unittest(dev.item != 11, "negative result\n");
48 unittest(dev.item == 10, "positive result\n");
49}
50
51/* **** BEGIN simple module entry/exit functions **** */
52static int __init unittest_enter(void)
53{
54 static const unittest_fptr unit_tests[] = {
55 test0,
56 NULL,
57 };
58
59 exec_unittests(name: "example", unit_tests);
60 return 0;
61}
62
63static void __exit unittest_exit(void) { }
64
65module_init(unittest_enter);
66module_exit(unittest_exit);
67
68MODULE_AUTHOR("Spencer Olson <olsonse@umich.edu>");
69MODULE_DESCRIPTION("Comedi unit-tests example");
70MODULE_LICENSE("GPL");
71/* **** END simple module entry/exit functions **** */
72

source code of linux/drivers/comedi/drivers/tests/comedi_example_test.c