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