aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/comedi/drivers/tests/example_test.c
blob: fc65158b8e8ed76780fb921a148e962ba53496fc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// SPDX-License-Identifier: GPL-2.0+
/* vim: set ts=8 sw=8 noet tw=80 nowrap: */
/*
 *  comedi/drivers/tests/example_test.c
 *  Example set of unit tests.
 *
 *  COMEDI - Linux Control and Measurement Device Interface
 *  Copyright (C) 2016 Spencer E. Olson <olsonse@umich.edu>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 */

#include <linux/module.h>

#include "unittest.h"

/* *** BEGIN fake board data *** */
struct comedi_device {
	const char *board_name;
	int item;
};

static struct comedi_device dev = {
	.board_name = "fake_device",
};

/* *** END fake board data *** */

/* *** BEGIN fake data init *** */
void init_fake(void)
{
	dev.item = 10;
}

/* *** END fake data init *** */

void test0(void)
{
	init_fake();
	unittest(dev.item != 11, "negative result\n");
	unittest(dev.item == 10, "positive result\n");
}

/* **** BEGIN simple module entry/exit functions **** */
static int __init unittest_enter(void)
{
	const unittest_fptr unit_tests[] = {
		(unittest_fptr)test0,
		NULL,
	};

	exec_unittests("example", unit_tests);
	return 0;
}

static void __exit unittest_exit(void) { }

module_init(unittest_enter);
module_exit(unittest_exit);

MODULE_AUTHOR("Spencer Olson <olsonse@umich.edu>");
MODULE_DESCRIPTION("Comedi unit-tests example");
MODULE_LICENSE("GPL");
/* **** END simple module entry/exit functions **** */