linux/drivers/staging/comedi/drivers/tests/example_test.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0+
   2/* vim: set ts=8 sw=8 noet tw=80 nowrap: */
   3/*
   4 *  comedi/drivers/tests/example_test.c
   5 *  Example set of unit tests.
   6 *
   7 *  COMEDI - Linux Control and Measurement Device Interface
   8 *  Copyright (C) 2016 Spencer E. Olson <olsonse@umich.edu>
   9 *
  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.
  14 *
  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.
  19 */
  20
  21#include <linux/module.h>
  22
  23#include "unittest.h"
  24
  25/* *** BEGIN fake board data *** */
  26struct comedi_device {
  27        const char *board_name;
  28        int item;
  29};
  30
  31static struct comedi_device dev = {
  32        .board_name = "fake_device",
  33};
  34
  35/* *** END fake board data *** */
  36
  37/* *** BEGIN fake data init *** */
  38void init_fake(void)
  39{
  40        dev.item = 10;
  41}
  42
  43/* *** END fake data init *** */
  44
  45void test0(void)
  46{
  47        init_fake();
  48        unittest(dev.item != 11, "negative result\n");
  49        unittest(dev.item == 10, "positive result\n");
  50}
  51
  52/* **** BEGIN simple module entry/exit functions **** */
  53static int __init unittest_enter(void)
  54{
  55        const unittest_fptr unit_tests[] = {
  56                (unittest_fptr)test0,
  57                NULL,
  58        };
  59
  60        exec_unittests("example", unit_tests);
  61        return 0;
  62}
  63
  64static void __exit unittest_exit(void) { }
  65
  66module_init(unittest_enter);
  67module_exit(unittest_exit);
  68
  69MODULE_AUTHOR("Spencer Olson <olsonse@umich.edu>");
  70MODULE_DESCRIPTION("Comedi unit-tests example");
  71MODULE_LICENSE("GPL");
  72/* **** END simple module entry/exit functions **** */
  73