Whamcloud - gitweb
LU-16763 kunit: consolidate kernel unit testing
[fs/lustre-release.git] / lustre / kunit / obd_test.c
1 // SPDX-License-Identifier: GPL-2.0
2
3 /*
4  * Copyright (c) 2023, Amazon and/or its affiliates. All rights reserved.
5  * Use is subject to license terms.
6  *
7  */
8
9 /*
10  * This file is part of Lustre, http://www.lustre.org/
11  *
12  * lustre/kunit/obd_test.c
13  *
14  * Simple OBD device for:
15  *   1) testing OBD device lifecycle management
16  *   2) demonstrating a simple OBD device
17  *
18  * Author: Timothy Day <timday@amazon.com>
19  *
20  */
21
22 #include <linux/module.h>
23
24 #include <obd_class.h>
25
26 static int verbose;
27 module_param(verbose, int, 0644);
28 MODULE_PARM_DESC(verbose, "Set the logging level for the module");
29
30 static int obd_test_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
31 {
32         if (verbose >= 1)
33                 pr_info("Lustre: OBD: %s", __func__);
34
35         if (verbose >= 2) {
36                 int obd_minor_found;
37
38                 pr_info("Lustre: OBD: obd_name: %s, obd_num: %i, obd_uuid: %s",
39                        obd->obd_name, obd->obd_minor, obd->obd_uuid.uuid);
40
41                 obd_minor_found = class_name2dev(obd->obd_name);
42                 pr_info("Lustre: OBD: class_name2dev(): %i, %s",
43                        obd_minor_found,
44                        obd_minor_found == obd->obd_minor ? "PASS" : "FAIL");
45
46                 obd_minor_found = class_uuid2dev(&obd->obd_uuid);
47                 pr_info("Lustre: OBD: class_uuid2dev(): %i, %s",
48                        obd_minor_found,
49                        obd_minor_found == obd->obd_minor ? "PASS" : "FAIL");
50
51                 obd_minor_found = class_name2obd(obd->obd_name)->obd_minor;
52                 pr_info("Lustre: OBD: class_name2obd(): %i, %s",
53                        obd_minor_found,
54                        obd_minor_found == obd->obd_minor ? "PASS" : "FAIL");
55
56                 obd_minor_found = class_uuid2obd(&obd->obd_uuid)->obd_minor;
57                 pr_info("Lustre: OBD: class_uuid2obd(): %i, %s",
58                        obd_minor_found,
59                        obd_minor_found == obd->obd_minor ? "PASS" : "FAIL");
60         }
61
62         return 0;
63 }
64
65 static int obd_test_cleanup(struct obd_device *obd)
66 {
67         if (verbose >= 1)
68                 pr_info("Lustre: OBD: %s", __func__);
69
70         return 0;
71 }
72
73 static const struct obd_ops obd_test_obd_ops = {
74         .o_owner       = THIS_MODULE,
75         .o_setup       = obd_test_setup,
76         .o_cleanup     = obd_test_cleanup,
77 };
78
79 static int __init obd_test_init(void)
80 {
81         return class_register_type(&obd_test_obd_ops, NULL, false,
82                                    "obd_test", NULL);
83 }
84
85 static void __exit obd_test_exit(void)
86 {
87         class_unregister_type("obd_test");
88 }
89
90 MODULE_AUTHOR("Amazon, Inc. <timday@amazon.com>");
91 MODULE_DESCRIPTION("Lustre OBD test module");
92 MODULE_VERSION(LUSTRE_VERSION_STRING);
93 MODULE_LICENSE("GPL");
94
95 module_init(obd_test_init);
96 module_exit(obd_test_exit);