4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2014, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
41 #include <sys/types.h>
43 #include <linux/lnet/lnet-types.h>
46 #define strnlen(s, i) strlen(s)
49 #define BLANK_LINE() \
56 printf (" /* "c" */\n"); \
59 #define STRINGIFY(a) #a
61 #define CHECK_BUILD_TEST(a) \
62 printf(" BUILD_BUG_ON("#a");\n")
64 #define CHECK_DEFINE(a) \
66 printf (" BUILD_BUG_ON("#a" != "STRINGIFY(a)");\n"); \
69 #define CHECK_VALUE(a) \
71 printf (" BUILD_BUG_ON("#a" != %d);\n", a); \
74 #define CHECK_MEMBER_OFFSET(s,m) \
76 CHECK_VALUE((int)offsetof(s, m)); \
79 #define CHECK_MEMBER_SIZEOF(s,m) \
81 CHECK_VALUE((int)sizeof(((s *)0)->m)); \
84 #define CHECK_MEMBER_IS_FLEXIBLE(s, m) \
86 CHECK_MEMBER_OFFSET(s, m); \
87 CHECK_BUILD_TEST(offsetof(struct s, m) != sizeof(struct s)); \
90 #define CHECK_MEMBER(s,m) \
92 CHECK_MEMBER_OFFSET(s, m); \
93 CHECK_MEMBER_SIZEOF(s, m); \
96 #define CHECK_STRUCT(s) \
99 COMMENT ("Checks for struct "#s); \
100 CHECK_VALUE((int)sizeof(s)); \
104 check_lnet_handle_wire(void)
106 CHECK_STRUCT(struct lnet_handle_wire);
107 CHECK_MEMBER(struct lnet_handle_wire, wh_interface_cookie);
108 CHECK_MEMBER(struct lnet_handle_wire, wh_object_cookie);
112 check_lnet_magicversion (void)
114 CHECK_STRUCT(struct lnet_magicversion);
115 CHECK_MEMBER(struct lnet_magicversion, magic);
116 CHECK_MEMBER(struct lnet_magicversion, version_major);
117 CHECK_MEMBER(struct lnet_magicversion, version_minor);
121 check_lnet_hdr_nid4(void)
123 CHECK_STRUCT(struct _lnet_hdr_nid4);
124 CHECK_MEMBER(struct _lnet_hdr_nid4, dest_nid);
125 CHECK_MEMBER(struct _lnet_hdr_nid4, src_nid);
126 CHECK_MEMBER(struct _lnet_hdr_nid4, dest_pid);
127 CHECK_MEMBER(struct _lnet_hdr_nid4, src_pid);
128 CHECK_MEMBER(struct _lnet_hdr_nid4, type);
129 CHECK_MEMBER(struct _lnet_hdr_nid4, payload_length);
130 CHECK_MEMBER(struct _lnet_hdr_nid4, msg);
134 CHECK_MEMBER(struct _lnet_hdr_nid4, msg.ack.dst_wmd);
135 CHECK_MEMBER(struct _lnet_hdr_nid4, msg.ack.match_bits);
136 CHECK_MEMBER(struct _lnet_hdr_nid4, msg.ack.mlength);
140 CHECK_MEMBER(struct _lnet_hdr_nid4, msg.put.ack_wmd);
141 CHECK_MEMBER(struct _lnet_hdr_nid4, msg.put.match_bits);
142 CHECK_MEMBER(struct _lnet_hdr_nid4, msg.put.hdr_data);
143 CHECK_MEMBER(struct _lnet_hdr_nid4, msg.put.ptl_index);
144 CHECK_MEMBER(struct _lnet_hdr_nid4, msg.put.offset);
148 CHECK_MEMBER(struct _lnet_hdr_nid4, msg.get.return_wmd);
149 CHECK_MEMBER(struct _lnet_hdr_nid4, msg.get.match_bits);
150 CHECK_MEMBER(struct _lnet_hdr_nid4, msg.get.ptl_index);
151 CHECK_MEMBER(struct _lnet_hdr_nid4, msg.get.src_offset);
152 CHECK_MEMBER(struct _lnet_hdr_nid4, msg.get.sink_length);
156 CHECK_MEMBER(struct _lnet_hdr_nid4, msg.reply.dst_wmd);
160 CHECK_MEMBER(struct _lnet_hdr_nid4, msg.hello.incarnation);
161 CHECK_MEMBER(struct _lnet_hdr_nid4, msg.hello.type);
165 check_lnet_ni_status(void)
168 COMMENT("Checks for struct lnet_ni_status and related constants");
170 CHECK_DEFINE(LNET_NI_STATUS_INVALID);
171 CHECK_DEFINE(LNET_NI_STATUS_UP);
172 CHECK_DEFINE(LNET_NI_STATUS_DOWN);
174 CHECK_STRUCT(struct lnet_ni_status);
175 CHECK_MEMBER(struct lnet_ni_status, ns_nid);
176 CHECK_MEMBER(struct lnet_ni_status, ns_status);
177 CHECK_MEMBER(struct lnet_ni_status, ns_msg_size);
179 CHECK_STRUCT(struct lnet_ni_large_status);
180 CHECK_MEMBER(struct lnet_ni_large_status, ns_status);
181 CHECK_MEMBER(struct lnet_ni_large_status, ns_nid);
185 check_lnet_ping_info(void)
188 COMMENT("Checks for struct lnet_ping_info and related constants");
190 CHECK_DEFINE(LNET_PROTO_PING_MAGIC);
191 CHECK_VALUE(LNET_PING_FEAT_INVAL);
192 CHECK_VALUE(LNET_PING_FEAT_BASE);
193 CHECK_VALUE(LNET_PING_FEAT_NI_STATUS);
194 CHECK_VALUE(LNET_PING_FEAT_RTE_DISABLED);
195 CHECK_VALUE(LNET_PING_FEAT_MULTI_RAIL);
196 CHECK_VALUE(LNET_PING_FEAT_DISCOVERY);
197 CHECK_VALUE(LNET_PING_FEAT_LARGE_ADDR);
198 CHECK_VALUE(LNET_PING_FEAT_PRIMARY_LARGE);
199 CHECK_VALUE(LNET_PING_FEAT_BITS);
201 CHECK_STRUCT(struct lnet_ping_info);
202 CHECK_MEMBER(struct lnet_ping_info, pi_magic);
203 CHECK_MEMBER(struct lnet_ping_info, pi_features);
204 CHECK_MEMBER(struct lnet_ping_info, pi_pid);
205 CHECK_MEMBER(struct lnet_ping_info, pi_nnis);
206 CHECK_MEMBER_IS_FLEXIBLE(struct lnet_ping_info, pi_ni);
210 system_string(char *cmdline, char *str, int len)
223 int fd = fileno(stdout);
225 rc = dup2(fds[1], fd);
229 exit(system(cmdline));
231 } else if ((int)pid < 0) {
234 FILE *f = fdopen (fds[0], "r");
241 if (fgets(str, len, f) == NULL)
244 if (waitpid(pid, &rc, 0) != pid)
247 if (!WIFEXITED(rc) ||
248 WEXITSTATUS(rc) != 0)
251 if (strnlen(str, len) == len)
254 if (str[strlen(str) - 1] == '\n')
255 str[strlen(str) - 1] = 0;
262 main (int argc, char **argv)
267 system_string("uname -a", unameinfo, sizeof(unameinfo));
268 system_string("gcc -v 2>&1 | tail -1", gccinfo, sizeof(gccinfo));
270 printf ("void lnet_assert_wire_constants (void)\n"
272 " /* Wire protocol assertions generated by 'wirecheck'\n"
275 "\n", unameinfo, gccinfo);
279 COMMENT ("Constants...");
281 CHECK_DEFINE (LNET_PROTO_RA_MAGIC);
283 CHECK_DEFINE (LNET_PROTO_TCP_MAGIC);
284 CHECK_DEFINE (LNET_PROTO_TCP_VERSION_MAJOR);
285 CHECK_DEFINE (LNET_PROTO_TCP_VERSION_MINOR);
287 CHECK_VALUE (LNET_MSG_ACK);
288 CHECK_VALUE (LNET_MSG_PUT);
289 CHECK_VALUE (LNET_MSG_GET);
290 CHECK_VALUE (LNET_MSG_REPLY);
291 CHECK_VALUE (LNET_MSG_HELLO);
293 check_lnet_handle_wire();
294 check_lnet_magicversion();
295 check_lnet_hdr_nid4();
296 check_lnet_ni_status();
297 check_lnet_ping_info();