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 (c) 2003, 2010, Oracle and/or its affiliates. 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.
42 #include <sys/types.h>
44 #include <lnet/lib-lnet.h>
49 #define strnlen(s, i) strlen(s)
52 #define BLANK_LINE() \
59 printf (" /* "c" */\n"); \
62 #define STRINGIFY(a) #a
64 #define CHECK_DEFINE(a) \
66 printf (" CLASSERT ("#a" == "STRINGIFY(a)");\n"); \
69 #define CHECK_VALUE(a) \
71 printf (" CLASSERT ("#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(s,m) \
86 CHECK_MEMBER_OFFSET(s, m); \
87 CHECK_MEMBER_SIZEOF(s, m); \
90 #define CHECK_STRUCT(s) \
93 COMMENT ("Checks for struct "#s); \
94 CHECK_VALUE((int)sizeof(s)); \
98 check_lnet_handle_wire (void)
100 CHECK_STRUCT (lnet_handle_wire_t);
101 CHECK_MEMBER (lnet_handle_wire_t, wh_interface_cookie);
102 CHECK_MEMBER (lnet_handle_wire_t, wh_object_cookie);
106 check_lnet_magicversion (void)
108 CHECK_STRUCT (lnet_magicversion_t);
109 CHECK_MEMBER (lnet_magicversion_t, magic);
110 CHECK_MEMBER (lnet_magicversion_t, version_major);
111 CHECK_MEMBER (lnet_magicversion_t, version_minor);
115 check_lnet_hdr (void)
117 CHECK_STRUCT (lnet_hdr_t);
118 CHECK_MEMBER (lnet_hdr_t, dest_nid);
119 CHECK_MEMBER (lnet_hdr_t, src_nid);
120 CHECK_MEMBER (lnet_hdr_t, dest_pid);
121 CHECK_MEMBER (lnet_hdr_t, src_pid);
122 CHECK_MEMBER (lnet_hdr_t, type);
123 CHECK_MEMBER (lnet_hdr_t, payload_length);
124 CHECK_MEMBER (lnet_hdr_t, msg);
128 CHECK_MEMBER (lnet_hdr_t, msg.ack.dst_wmd);
129 CHECK_MEMBER (lnet_hdr_t, msg.ack.match_bits);
130 CHECK_MEMBER (lnet_hdr_t, msg.ack.mlength);
134 CHECK_MEMBER (lnet_hdr_t, msg.put.ack_wmd);
135 CHECK_MEMBER (lnet_hdr_t, msg.put.match_bits);
136 CHECK_MEMBER (lnet_hdr_t, msg.put.hdr_data);
137 CHECK_MEMBER (lnet_hdr_t, msg.put.ptl_index);
138 CHECK_MEMBER (lnet_hdr_t, msg.put.offset);
142 CHECK_MEMBER (lnet_hdr_t, msg.get.return_wmd);
143 CHECK_MEMBER (lnet_hdr_t, msg.get.match_bits);
144 CHECK_MEMBER (lnet_hdr_t, msg.get.ptl_index);
145 CHECK_MEMBER (lnet_hdr_t, msg.get.src_offset);
146 CHECK_MEMBER (lnet_hdr_t, msg.get.sink_length);
150 CHECK_MEMBER (lnet_hdr_t, msg.reply.dst_wmd);
154 CHECK_MEMBER (lnet_hdr_t, msg.hello.incarnation);
155 CHECK_MEMBER (lnet_hdr_t, msg.hello.type);
159 system_string (char *cmdline, char *str, int len)
172 int fd = fileno(stdout);
174 rc = dup2(fds[1], fd);
178 exit(system(cmdline));
180 } else if ((int)pid < 0) {
183 FILE *f = fdopen (fds[0], "r");
190 if (fgets(str, len, f) == NULL)
193 if (waitpid(pid, &rc, 0) != pid)
196 if (!WIFEXITED(rc) ||
197 WEXITSTATUS(rc) != 0)
200 if (strnlen(str, len) == len)
203 if (str[strlen(str) - 1] == '\n')
204 str[strlen(str) - 1] = 0;
211 main (int argc, char **argv)
216 system_string("uname -a", unameinfo, sizeof(unameinfo));
217 system_string("gcc -v 2>&1 | tail -1", gccinfo, sizeof(gccinfo));
219 printf ("void lnet_assert_wire_constants (void)\n"
221 " /* Wire protocol assertions generated by 'wirecheck'\n"
224 "\n", unameinfo, gccinfo);
228 COMMENT ("Constants...");
230 CHECK_DEFINE (LNET_PROTO_RA_MAGIC);
232 CHECK_DEFINE (LNET_PROTO_TCP_MAGIC);
233 CHECK_DEFINE (LNET_PROTO_TCP_VERSION_MAJOR);
234 CHECK_DEFINE (LNET_PROTO_TCP_VERSION_MINOR);
236 CHECK_VALUE (LNET_MSG_ACK);
237 CHECK_VALUE (LNET_MSG_PUT);
238 CHECK_VALUE (LNET_MSG_GET);
239 CHECK_VALUE (LNET_MSG_REPLY);
240 CHECK_VALUE (LNET_MSG_HELLO);
242 check_lnet_handle_wire ();
243 check_lnet_magicversion ();