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/list.h>
9 #include <portals/lib-types.h>
11 extern size_t strnlen(const char *, size_t);
13 #define BLANK_LINE() \
20 printf (" /* "c" */\n"); \
23 #define STRINGIFY(a) #a
25 #define CHECK_DEFINE(a) \
27 printf (" LASSERT ("#a" == "STRINGIFY(a)");\n"); \
30 #define CHECK_VALUE(a) \
32 printf (" LASSERT ("#a" == %d);\n", a); \
35 #define CHECK_MEMBER_OFFSET(s,m) \
37 CHECK_VALUE((int)offsetof(s, m)); \
40 #define CHECK_MEMBER_SIZEOF(s,m) \
42 CHECK_VALUE((int)sizeof(((s *)0)->m)); \
45 #define CHECK_MEMBER(s,m) \
47 CHECK_MEMBER_OFFSET(s, m); \
48 CHECK_MEMBER_SIZEOF(s, m); \
51 #define CHECK_STRUCT(s) \
54 COMMENT ("Checks for struct "#s); \
55 CHECK_VALUE((int)sizeof(s)); \
59 check_ptl_handle_wire (void)
61 CHECK_STRUCT (ptl_handle_wire_t);
62 CHECK_MEMBER (ptl_handle_wire_t, wh_interface_cookie);
63 CHECK_MEMBER (ptl_handle_wire_t, wh_object_cookie);
67 check_ptl_magicversion (void)
69 CHECK_STRUCT (ptl_magicversion_t);
70 CHECK_MEMBER (ptl_magicversion_t, magic);
71 CHECK_MEMBER (ptl_magicversion_t, version_major);
72 CHECK_MEMBER (ptl_magicversion_t, version_minor);
78 CHECK_STRUCT (ptl_hdr_t);
79 CHECK_MEMBER (ptl_hdr_t, dest_nid);
80 CHECK_MEMBER (ptl_hdr_t, src_nid);
81 CHECK_MEMBER (ptl_hdr_t, dest_pid);
82 CHECK_MEMBER (ptl_hdr_t, src_pid);
83 CHECK_MEMBER (ptl_hdr_t, type);
84 CHECK_MEMBER (ptl_hdr_t, payload_length);
85 CHECK_MEMBER (ptl_hdr_t, msg);
89 CHECK_MEMBER (ptl_hdr_t, msg.ack.dst_wmd);
90 CHECK_MEMBER (ptl_hdr_t, msg.ack.match_bits);
91 CHECK_MEMBER (ptl_hdr_t, msg.ack.mlength);
95 CHECK_MEMBER (ptl_hdr_t, msg.put.ack_wmd);
96 CHECK_MEMBER (ptl_hdr_t, msg.put.match_bits);
97 CHECK_MEMBER (ptl_hdr_t, msg.put.hdr_data);
98 CHECK_MEMBER (ptl_hdr_t, msg.put.ptl_index);
99 CHECK_MEMBER (ptl_hdr_t, msg.put.offset);
103 CHECK_MEMBER (ptl_hdr_t, msg.get.return_wmd);
104 CHECK_MEMBER (ptl_hdr_t, msg.get.match_bits);
105 CHECK_MEMBER (ptl_hdr_t, msg.get.ptl_index);
106 CHECK_MEMBER (ptl_hdr_t, msg.get.src_offset);
107 CHECK_MEMBER (ptl_hdr_t, msg.get.sink_length);
111 CHECK_MEMBER (ptl_hdr_t, msg.reply.dst_wmd);
115 CHECK_MEMBER (ptl_hdr_t, msg.hello.incarnation);
116 CHECK_MEMBER (ptl_hdr_t, msg.hello.type);
120 system_string (char *cmdline, char *str, int len)
133 int fd = fileno(stdout);
135 rc = dup2(fds[1], fd);
139 exit(system(cmdline));
141 } else if ((int)pid < 0) {
144 FILE *f = fdopen (fds[0], "r");
151 if (fgets(str, len, f) == NULL)
154 if (waitpid(pid, &rc, 0) != pid)
157 if (!WIFEXITED(rc) ||
158 WEXITSTATUS(rc) != 0)
161 if (strnlen(str, len) == len)
164 if (str[strlen(str) - 1] == '\n')
165 str[strlen(str) - 1] = 0;
172 main (int argc, char **argv)
177 system_string("uname -a", unameinfo, sizeof(unameinfo));
178 system_string("gcc -v 2>&1 | tail -1", gccinfo, sizeof(gccinfo));
180 printf ("void lib_assert_wire_constants (void)\n"
182 " /* Wire protocol assertions generated by 'wirecheck'\n"
185 "\n", unameinfo, gccinfo);
189 COMMENT ("Constants...");
190 CHECK_DEFINE (PORTALS_PROTO_MAGIC);
191 CHECK_DEFINE (PORTALS_PROTO_VERSION_MAJOR);
192 CHECK_DEFINE (PORTALS_PROTO_VERSION_MINOR);
194 CHECK_VALUE (PTL_MSG_ACK);
195 CHECK_VALUE (PTL_MSG_PUT);
196 CHECK_VALUE (PTL_MSG_GET);
197 CHECK_VALUE (PTL_MSG_REPLY);
198 CHECK_VALUE (PTL_MSG_HELLO);
200 check_ptl_handle_wire ();
201 check_ptl_magicversion ();