Whamcloud - gitweb
LU-1347 build: remove the vim/emacs modelines
[fs/lustre-release.git] / lnet / selftest / module.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  */
30 /*
31  * This file is part of Lustre, http://www.lustre.org/
32  * Lustre is a trademark of Sun Microsystems, Inc.
33  */
34
35 #define DEBUG_SUBSYSTEM S_LNET
36
37 #include "selftest.h"
38
39
40 #define LST_INIT_NONE           0
41 #define LST_INIT_RPC            1
42 #define LST_INIT_FW             2
43 #define LST_INIT_CONSOLE        3
44
45 extern int lstcon_console_init(void);
46 extern int lstcon_console_fini(void);
47
48 static int lst_init_step = LST_INIT_NONE;
49
50 void
51 lnet_selftest_fini (void)
52 {
53         switch (lst_init_step) {
54 #ifdef __KERNEL__
55                 case LST_INIT_CONSOLE:
56                         lstcon_console_fini();
57 #endif
58                 case LST_INIT_FW:
59                         sfw_shutdown();
60                 case LST_INIT_RPC:
61                         srpc_shutdown();
62                 case LST_INIT_NONE:
63                         break;
64                 default:
65                         LBUG();
66         }
67         return;
68 }
69
70
71 void
72 lnet_selftest_structure_assertion(void)
73 {
74         CLASSERT(sizeof(srpc_msg_t) == 160);
75         CLASSERT(sizeof(srpc_test_reqst_t) == 70);
76         CLASSERT(offsetof(srpc_msg_t, msg_body.tes_reqst.tsr_concur) == 72);
77         CLASSERT(offsetof(srpc_msg_t, msg_body.tes_reqst.tsr_ndest) == 78);
78         CLASSERT(sizeof(srpc_stat_reply_t) == 136);
79         CLASSERT(sizeof(srpc_stat_reqst_t) == 28);
80 }
81
82 int
83 lnet_selftest_init (void)
84 {
85         int     rc;
86
87         rc = srpc_startup();
88         if (rc != 0) {
89                 CERROR("LST can't startup rpc\n");
90                 goto error;
91         }
92         lst_init_step = LST_INIT_RPC;
93
94         rc = sfw_startup();
95         if (rc != 0) {
96                 CERROR("LST can't startup framework\n");
97                 goto error;
98         }
99         lst_init_step = LST_INIT_FW;
100
101 #ifdef __KERNEL__
102         rc = lstcon_console_init();
103         if (rc != 0) {
104                 CERROR("LST can't startup console\n");
105                 goto error;
106         }
107         lst_init_step = LST_INIT_CONSOLE;  
108 #endif
109
110         return 0;
111 error:
112         lnet_selftest_fini();
113         return rc;
114 }
115
116 #ifdef __KERNEL__
117
118 MODULE_DESCRIPTION("LNet Selftest");
119 MODULE_LICENSE("GPL");
120
121 cfs_module(lnet, "0.9.0", lnet_selftest_init, lnet_selftest_fini);
122
123 #else
124
125 int
126 selftest_wait_events (void)
127 {
128         int evts = 0;
129
130         for (;;) {
131                 /* Consume all pending events */
132                 while (srpc_check_event(0))
133                         evts++;
134                 evts += stt_check_events();
135                 evts += swi_check_events();
136                 if (evts != 0) break;
137
138                 /* Nothing happened, block for events */
139                 evts += srpc_check_event(stt_poll_interval());
140                 /* We may have blocked, check for expired timers */
141                 evts += stt_check_events();
142                 if (evts == 0) /* timed out and still no event */
143                         break;
144         }
145
146         return evts;
147 }
148
149 #endif