1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
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
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
38 #include <sys/types.h>
40 #include <lnet/lib-lnet.h>
45 #define strnlen(s, i) strlen(s)
48 #define BLANK_LINE() \
55 printf (" /* "c" */\n"); \
58 #define STRINGIFY(a) #a
60 #define CHECK_DEFINE(a) \
62 printf (" CLASSERT ("#a" == "STRINGIFY(a)");\n"); \
65 #define CHECK_VALUE(a) \
67 printf (" CLASSERT ("#a" == %d);\n", a); \
70 #define CHECK_MEMBER_OFFSET(s,m) \
72 CHECK_VALUE((int)offsetof(s, m)); \
75 #define CHECK_MEMBER_SIZEOF(s,m) \
77 CHECK_VALUE((int)sizeof(((s *)0)->m)); \
80 #define CHECK_MEMBER(s,m) \
82 CHECK_MEMBER_OFFSET(s, m); \
83 CHECK_MEMBER_SIZEOF(s, m); \
86 #define CHECK_STRUCT(s) \
89 COMMENT ("Checks for struct "#s); \
90 CHECK_VALUE((int)sizeof(s)); \
94 check_lnet_handle_wire (void)
96 CHECK_STRUCT (lnet_handle_wire_t);
97 CHECK_MEMBER (lnet_handle_wire_t, wh_interface_cookie);
98 CHECK_MEMBER (lnet_handle_wire_t, wh_object_cookie);
102 check_lnet_magicversion (void)
104 CHECK_STRUCT (lnet_magicversion_t);
105 CHECK_MEMBER (lnet_magicversion_t, magic);
106 CHECK_MEMBER (lnet_magicversion_t, version_major);
107 CHECK_MEMBER (lnet_magicversion_t, version_minor);
111 check_lnet_hdr (void)
113 CHECK_STRUCT (lnet_hdr_t);
114 CHECK_MEMBER (lnet_hdr_t, dest_nid);
115 CHECK_MEMBER (lnet_hdr_t, src_nid);
116 CHECK_MEMBER (lnet_hdr_t, dest_pid);
117 CHECK_MEMBER (lnet_hdr_t, src_pid);
118 CHECK_MEMBER (lnet_hdr_t, type);
119 CHECK_MEMBER (lnet_hdr_t, payload_length);
120 CHECK_MEMBER (lnet_hdr_t, msg);
124 CHECK_MEMBER (lnet_hdr_t, msg.ack.dst_wmd);
125 CHECK_MEMBER (lnet_hdr_t, msg.ack.match_bits);
126 CHECK_MEMBER (lnet_hdr_t, msg.ack.mlength);
130 CHECK_MEMBER (lnet_hdr_t, msg.put.ack_wmd);
131 CHECK_MEMBER (lnet_hdr_t, msg.put.match_bits);
132 CHECK_MEMBER (lnet_hdr_t, msg.put.hdr_data);
133 CHECK_MEMBER (lnet_hdr_t, msg.put.ptl_index);
134 CHECK_MEMBER (lnet_hdr_t, msg.put.offset);
138 CHECK_MEMBER (lnet_hdr_t, msg.get.return_wmd);
139 CHECK_MEMBER (lnet_hdr_t, msg.get.match_bits);
140 CHECK_MEMBER (lnet_hdr_t, msg.get.ptl_index);
141 CHECK_MEMBER (lnet_hdr_t, msg.get.src_offset);
142 CHECK_MEMBER (lnet_hdr_t, msg.get.sink_length);
146 CHECK_MEMBER (lnet_hdr_t, msg.reply.dst_wmd);
150 CHECK_MEMBER (lnet_hdr_t, msg.hello.incarnation);
151 CHECK_MEMBER (lnet_hdr_t, msg.hello.type);
155 system_string (char *cmdline, char *str, int len)
168 int fd = fileno(stdout);
170 rc = dup2(fds[1], fd);
174 exit(system(cmdline));
176 } else if ((int)pid < 0) {
179 FILE *f = fdopen (fds[0], "r");
186 if (fgets(str, len, f) == NULL)
189 if (waitpid(pid, &rc, 0) != pid)
192 if (!WIFEXITED(rc) ||
193 WEXITSTATUS(rc) != 0)
196 if (strnlen(str, len) == len)
199 if (str[strlen(str) - 1] == '\n')
200 str[strlen(str) - 1] = 0;
207 main (int argc, char **argv)
212 system_string("uname -a", unameinfo, sizeof(unameinfo));
213 system_string("gcc -v 2>&1 | tail -1", gccinfo, sizeof(gccinfo));
215 printf ("void lnet_assert_wire_constants (void)\n"
217 " /* Wire protocol assertions generated by 'wirecheck'\n"
220 "\n", unameinfo, gccinfo);
224 COMMENT ("Constants...");
226 CHECK_DEFINE (LNET_PROTO_OPENIB_MAGIC);
227 CHECK_DEFINE (LNET_PROTO_RA_MAGIC);
229 CHECK_DEFINE (LNET_PROTO_TCP_MAGIC);
230 CHECK_DEFINE (LNET_PROTO_TCP_VERSION_MAJOR);
231 CHECK_DEFINE (LNET_PROTO_TCP_VERSION_MINOR);
233 CHECK_VALUE (LNET_MSG_ACK);
234 CHECK_VALUE (LNET_MSG_PUT);
235 CHECK_VALUE (LNET_MSG_GET);
236 CHECK_VALUE (LNET_MSG_REPLY);
237 CHECK_VALUE (LNET_MSG_HELLO);
239 check_lnet_handle_wire ();
240 check_lnet_magicversion ();