Whamcloud - gitweb
- merge 0.7rc1 from b_devel to HEAD (20030612 merge point)
[fs/lustre-release.git] / lnet / utils / wirecheck.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  */
4 #include <stdio.h>
5 #include <portals/api-support.h>
6 #include <portals/list.h>
7 #include <portals/lib-types.h>
8
9 #define BLANK_LINE()                            \
10 do {                                            \
11         printf ("\n");                          \
12 } while (0)
13
14 #define COMMENT(c)                              \
15 do {                                            \
16         printf ("        /* "c" */\n");         \
17 } while (0)
18
19 #define STRINGIFY(a) #a
20
21 #define CHECK_DEFINE(a)                                         \
22 do {                                                            \
23         printf ("        LASSERT ("#a" == "STRINGIFY(a)");\n"); \
24 } while (0)
25
26 #define CHECK_VALUE(a)                                  \
27 do {                                                    \
28         printf ("        LASSERT ("#a" == %d);\n", a);  \
29 } while (0)
30
31 #define CHECK_MEMBER_OFFSET(s,m)                \
32 do {                                            \
33         CHECK_VALUE(offsetof(s, m));            \
34 } while (0)
35
36 #define CHECK_MEMBER_SIZEOF(s,m)                \
37 do {                                            \
38         CHECK_VALUE((int)sizeof(((s *)0)->m));  \
39 } while (0)
40
41 #define CHECK_MEMBER(s,m)                       \
42 do {                                            \
43         CHECK_MEMBER_OFFSET(s, m);              \
44         CHECK_MEMBER_SIZEOF(s, m);              \
45 } while (0)
46
47 #define CHECK_STRUCT(s)                         \
48 do {                                            \
49         BLANK_LINE ();                          \
50         COMMENT ("Checks for struct "#s);       \
51         CHECK_VALUE((int)sizeof(s));            \
52 } while (0)
53
54 void
55 check_ptl_handle_wire (void)
56 {
57         CHECK_STRUCT (ptl_handle_wire_t);
58         CHECK_MEMBER (ptl_handle_wire_t, wh_interface_cookie);
59         CHECK_MEMBER (ptl_handle_wire_t, wh_object_cookie);
60 }
61
62 void
63 check_ptl_magicversion (void)
64 {
65         CHECK_STRUCT (ptl_magicversion_t);
66         CHECK_MEMBER (ptl_magicversion_t, magic);
67         CHECK_MEMBER (ptl_magicversion_t, version_major);
68         CHECK_MEMBER (ptl_magicversion_t, version_minor);
69 }
70
71 void
72 check_ptl_hdr (void)
73 {
74         CHECK_STRUCT (ptl_hdr_t);
75         CHECK_MEMBER (ptl_hdr_t, dest_nid);
76         CHECK_MEMBER (ptl_hdr_t, src_nid);
77         CHECK_MEMBER (ptl_hdr_t, dest_pid);
78         CHECK_MEMBER (ptl_hdr_t, src_pid);
79         CHECK_MEMBER (ptl_hdr_t, type);
80
81         BLANK_LINE ();
82         COMMENT ("Ack");
83         CHECK_MEMBER (ptl_hdr_t, msg.ack.mlength);
84         CHECK_MEMBER (ptl_hdr_t, msg.ack.dst_wmd);
85         CHECK_MEMBER (ptl_hdr_t, msg.ack.match_bits);
86         CHECK_MEMBER (ptl_hdr_t, msg.ack.length);
87
88         BLANK_LINE ();
89         COMMENT ("Put");
90         CHECK_MEMBER (ptl_hdr_t, msg.put.ptl_index);
91         CHECK_MEMBER (ptl_hdr_t, msg.put.ack_wmd);
92         CHECK_MEMBER (ptl_hdr_t, msg.put.match_bits);
93         CHECK_MEMBER (ptl_hdr_t, msg.put.length);
94         CHECK_MEMBER (ptl_hdr_t, msg.put.offset);
95         CHECK_MEMBER (ptl_hdr_t, msg.put.hdr_data);
96
97         BLANK_LINE ();
98         COMMENT ("Get");
99         CHECK_MEMBER (ptl_hdr_t, msg.get.ptl_index);
100         CHECK_MEMBER (ptl_hdr_t, msg.get.return_wmd);
101         CHECK_MEMBER (ptl_hdr_t, msg.get.match_bits);
102         CHECK_MEMBER (ptl_hdr_t, msg.get.length);
103         CHECK_MEMBER (ptl_hdr_t, msg.get.src_offset);
104         CHECK_MEMBER (ptl_hdr_t, msg.get.return_offset);
105         CHECK_MEMBER (ptl_hdr_t, msg.get.sink_length);
106
107         BLANK_LINE ();
108         COMMENT ("Reply");
109         CHECK_MEMBER (ptl_hdr_t, msg.reply.dst_wmd);
110         CHECK_MEMBER (ptl_hdr_t, msg.reply.dst_offset);
111         CHECK_MEMBER (ptl_hdr_t, msg.reply.length);
112 }
113
114 int
115 main (int argc, char **argv)
116 {
117         printf ("void lib_assert_wire_constants (void)\n"
118                 "{\n");
119
120         COMMENT ("Wire protocol assertions generated by 'wirecheck'");
121         BLANK_LINE ();
122         
123         COMMENT ("Constants...");
124         CHECK_DEFINE (PORTALS_PROTO_MAGIC);
125         CHECK_DEFINE (PORTALS_PROTO_VERSION_MAJOR);
126         CHECK_DEFINE (PORTALS_PROTO_VERSION_MINOR);
127
128         CHECK_VALUE (PTL_MSG_ACK);
129         CHECK_VALUE (PTL_MSG_PUT);
130         CHECK_VALUE (PTL_MSG_GET);
131         CHECK_VALUE (PTL_MSG_REPLY);
132         CHECK_VALUE (PTL_MSG_HELLO);
133
134         check_ptl_handle_wire ();
135         check_ptl_magicversion ();
136         check_ptl_hdr ();
137         
138         printf ("}\n\n");
139         
140         return (0);
141 }