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.
36 * lnet/klnds/ptllnd/wirecheck.c
38 * Author: PJ Kirner <pjkirner@clusterfs.com>
42 #include <sys/types.h>
47 #include <lnet/api-support.h>
49 /* This ghastly hack to allows me to include lib-types.h It doesn't affect any
50 * assertions generated here (but fails-safe if it ever does) */
55 #include <lnet/lib-types.h>
56 #include <lnet/ptllnd_wire.h>
59 #define strnlen(s, i) strlen(s)
62 #define BLANK_LINE() \
69 printf (" /* "c" */\n"); \
73 #define STRINGIFY(a) #a
75 #define CHECK_DEFINE(a) \
77 printf (" CLASSERT ("#a" == "STRINGIFY(a)");\n"); \
80 #define CHECK_VALUE(a) \
82 printf (" CLASSERT ("#a" == %d);\n", a); \
85 #define CHECK_MEMBER_OFFSET(s,m) \
87 CHECK_VALUE((int)offsetof(s, m)); \
90 #define CHECK_MEMBER_SIZEOF(s,m) \
92 CHECK_VALUE((int)sizeof(((s *)0)->m)); \
95 #define CHECK_MEMBER(s,m) \
97 CHECK_MEMBER_OFFSET(s, m); \
98 CHECK_MEMBER_SIZEOF(s, m); \
101 #define CHECK_STRUCT(s) \
104 COMMENT ("Checks for struct "#s); \
105 CHECK_VALUE((int)sizeof(s)); \
109 system_string (char *cmdline, char *str, int len)
122 int fd = fileno(stdout);
124 rc = dup2(fds[1], fd);
128 exit(system(cmdline));
130 } else if ((int)pid < 0) {
133 FILE *f = fdopen (fds[0], "r");
140 if (fgets(str, len, f) == NULL)
143 if (waitpid(pid, &rc, 0) != pid)
146 if (!WIFEXITED(rc) ||
147 WEXITSTATUS(rc) != 0)
150 if (strnlen(str, len) == len)
153 if (str[strlen(str) - 1] == '\n')
154 str[strlen(str) - 1] = 0;
161 main (int argc, char **argv)
166 system_string("uname -a", unameinfo, sizeof(unameinfo));
167 system_string("gcc -v 2>&1 | tail -1", gccinfo, sizeof(gccinfo));
169 printf ("void kptllnd_assert_wire_constants (void)\n"
171 " /* Wire protocol assertions generated by 'wirecheck'\n"
174 "\n", unameinfo, gccinfo);
178 COMMENT ("Constants...");
179 CHECK_DEFINE (PTL_RESERVED_MATCHBITS);
180 CHECK_DEFINE (LNET_MSG_MATCHBITS);
182 CHECK_DEFINE (PTLLND_MSG_MAGIC);
183 CHECK_DEFINE (PTLLND_MSG_VERSION);
185 CHECK_DEFINE (PTLLND_RDMA_OK);
186 CHECK_DEFINE (PTLLND_RDMA_FAIL);
188 CHECK_DEFINE (PTLLND_MSG_TYPE_INVALID);
189 CHECK_DEFINE (PTLLND_MSG_TYPE_PUT);
190 CHECK_DEFINE (PTLLND_MSG_TYPE_GET);
191 CHECK_DEFINE (PTLLND_MSG_TYPE_IMMEDIATE);
192 CHECK_DEFINE (PTLLND_MSG_TYPE_NOOP);
193 CHECK_DEFINE (PTLLND_MSG_TYPE_HELLO);
194 CHECK_DEFINE (PTLLND_MSG_TYPE_NAK);
196 CHECK_STRUCT (kptl_msg_t);
197 CHECK_MEMBER (kptl_msg_t, ptlm_magic);
198 CHECK_MEMBER (kptl_msg_t, ptlm_version);
199 CHECK_MEMBER (kptl_msg_t, ptlm_type);
200 CHECK_MEMBER (kptl_msg_t, ptlm_credits);
201 CHECK_MEMBER (kptl_msg_t, ptlm_nob);
202 CHECK_MEMBER (kptl_msg_t, ptlm_cksum);
203 CHECK_MEMBER (kptl_msg_t, ptlm_srcnid);
204 CHECK_MEMBER (kptl_msg_t, ptlm_srcstamp);
205 CHECK_MEMBER (kptl_msg_t, ptlm_dstnid);
206 CHECK_MEMBER (kptl_msg_t, ptlm_dststamp);
207 CHECK_MEMBER (kptl_msg_t, ptlm_srcpid);
208 CHECK_MEMBER (kptl_msg_t, ptlm_dstpid);
209 CHECK_MEMBER (kptl_msg_t, ptlm_u.immediate);
210 CHECK_MEMBER (kptl_msg_t, ptlm_u.rdma);
211 CHECK_MEMBER (kptl_msg_t, ptlm_u.hello);
213 CHECK_STRUCT (kptl_immediate_msg_t);
214 CHECK_MEMBER (kptl_immediate_msg_t, kptlim_hdr);
215 CHECK_MEMBER (kptl_immediate_msg_t, kptlim_payload[13]);
217 CHECK_STRUCT (kptl_rdma_msg_t);
218 CHECK_MEMBER (kptl_rdma_msg_t, kptlrm_hdr);
219 CHECK_MEMBER (kptl_rdma_msg_t, kptlrm_matchbits);
221 CHECK_STRUCT (kptl_hello_msg_t);
222 CHECK_MEMBER (kptl_hello_msg_t, kptlhm_matchbits);
223 CHECK_MEMBER (kptl_hello_msg_t, kptlhm_max_msg_size);