1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
7 #include <portals/api-support.h>
8 #include <portals/lib-types.h>
13 #define strnlen(s, i) strlen(s)
16 #define BLANK_LINE() \
23 printf (" /* "c" */\n"); \
26 #define STRINGIFY(a) #a
28 #define CHECK_DEFINE(a) \
30 printf (" LASSERT ("#a" == "STRINGIFY(a)");\n"); \
33 #define CHECK_VALUE(a) \
35 printf (" LASSERT ("#a" == %d);\n", a); \
38 #define CHECK_MEMBER_OFFSET(s,m) \
40 CHECK_VALUE((int)offsetof(s, m)); \
43 #define CHECK_MEMBER_SIZEOF(s,m) \
45 CHECK_VALUE((int)sizeof(((s *)0)->m)); \
48 #define CHECK_MEMBER(s,m) \
50 CHECK_MEMBER_OFFSET(s, m); \
51 CHECK_MEMBER_SIZEOF(s, m); \
54 #define CHECK_STRUCT(s) \
57 COMMENT ("Checks for struct "#s); \
58 CHECK_VALUE((int)sizeof(s)); \
62 check_ptl_handle_wire (void)
64 CHECK_STRUCT (ptl_handle_wire_t);
65 CHECK_MEMBER (ptl_handle_wire_t, wh_interface_cookie);
66 CHECK_MEMBER (ptl_handle_wire_t, wh_object_cookie);
70 check_ptl_magicversion (void)
72 CHECK_STRUCT (ptl_magicversion_t);
73 CHECK_MEMBER (ptl_magicversion_t, magic);
74 CHECK_MEMBER (ptl_magicversion_t, version_major);
75 CHECK_MEMBER (ptl_magicversion_t, version_minor);
81 CHECK_STRUCT (ptl_hdr_t);
82 CHECK_MEMBER (ptl_hdr_t, dest_nid);
83 CHECK_MEMBER (ptl_hdr_t, src_nid);
84 CHECK_MEMBER (ptl_hdr_t, dest_pid);
85 CHECK_MEMBER (ptl_hdr_t, src_pid);
86 CHECK_MEMBER (ptl_hdr_t, type);
87 CHECK_MEMBER (ptl_hdr_t, payload_length);
88 CHECK_MEMBER (ptl_hdr_t, msg);
92 CHECK_MEMBER (ptl_hdr_t, msg.ack.dst_wmd);
93 CHECK_MEMBER (ptl_hdr_t, msg.ack.match_bits);
94 CHECK_MEMBER (ptl_hdr_t, msg.ack.mlength);
98 CHECK_MEMBER (ptl_hdr_t, msg.put.ack_wmd);
99 CHECK_MEMBER (ptl_hdr_t, msg.put.match_bits);
100 CHECK_MEMBER (ptl_hdr_t, msg.put.hdr_data);
101 CHECK_MEMBER (ptl_hdr_t, msg.put.ptl_index);
102 CHECK_MEMBER (ptl_hdr_t, msg.put.offset);
106 CHECK_MEMBER (ptl_hdr_t, msg.get.return_wmd);
107 CHECK_MEMBER (ptl_hdr_t, msg.get.match_bits);
108 CHECK_MEMBER (ptl_hdr_t, msg.get.ptl_index);
109 CHECK_MEMBER (ptl_hdr_t, msg.get.src_offset);
110 CHECK_MEMBER (ptl_hdr_t, msg.get.sink_length);
114 CHECK_MEMBER (ptl_hdr_t, msg.reply.dst_wmd);
118 CHECK_MEMBER (ptl_hdr_t, msg.hello.incarnation);
119 CHECK_MEMBER (ptl_hdr_t, msg.hello.type);
123 system_string (char *cmdline, char *str, int len)
136 int fd = fileno(stdout);
138 rc = dup2(fds[1], fd);
142 exit(system(cmdline));
144 } else if ((int)pid < 0) {
147 FILE *f = fdopen (fds[0], "r");
154 if (fgets(str, len, f) == NULL)
157 if (waitpid(pid, &rc, 0) != pid)
160 if (!WIFEXITED(rc) ||
161 WEXITSTATUS(rc) != 0)
164 if (strnlen(str, len) == len)
167 if (str[strlen(str) - 1] == '\n')
168 str[strlen(str) - 1] = 0;
175 main (int argc, char **argv)
180 system_string("uname -a", unameinfo, sizeof(unameinfo));
181 system_string("gcc -v 2>&1 | tail -1", gccinfo, sizeof(gccinfo));
183 printf ("void lib_assert_wire_constants (void)\n"
185 " /* Wire protocol assertions generated by 'wirecheck'\n"
188 "\n", unameinfo, gccinfo);
192 COMMENT ("Constants...");
193 CHECK_DEFINE (PORTALS_PROTO_MAGIC);
194 CHECK_DEFINE (PORTALS_PROTO_VERSION_MAJOR);
195 CHECK_DEFINE (PORTALS_PROTO_VERSION_MINOR);
197 CHECK_VALUE (PTL_MSG_ACK);
198 CHECK_VALUE (PTL_MSG_PUT);
199 CHECK_VALUE (PTL_MSG_GET);
200 CHECK_VALUE (PTL_MSG_REPLY);
201 CHECK_VALUE (PTL_MSG_HELLO);
203 check_ptl_handle_wire ();
204 check_ptl_magicversion ();