Whamcloud - gitweb
LU-2989 build: some make targets are broken
[fs/lustre-release.git] / lnet / utils / wirecheck.c
index 77ad126..95d2aa6 100644 (file)
-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
+/*
+ * GPL HEADER START
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 only,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License version 2 for more details (a copy is included
+ * in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; If not, see
+ * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ *
+ * GPL HEADER END
  */
+/*
+ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Use is subject to license terms.
+ */
+/*
+ * This file is part of Lustre, http://www.lustre.org/
+ * Lustre is a trademark of Sun Microsystems, Inc.
+ */
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
 #include <stdio.h>
 #include <sys/types.h>
 #include <sys/wait.h>
-#include <portals/api-support.h>
-#include <portals/list.h>
-#include <portals/lib-types.h>
+#include <lnet/lib-lnet.h>
 
-extern size_t strnlen(const char *, size_t);
+#include <string.h>
 
-#define BLANK_LINE()                           \
-do {                                           \
-       printf ("\n");                          \
+#ifndef HAVE_STRNLEN
+#define strnlen(s, i) strlen(s)
+#endif
+
+#define BLANK_LINE()                            \
+do {                                            \
+        printf ("\n");                          \
 } while (0)
 
-#define COMMENT(c)                             \
-do {                                           \
-       printf ("        /* "c" */\n");         \
+#define COMMENT(c)                              \
+do {                                            \
+        printf ("        /* "c" */\n");         \
 } while (0)
 
 #define STRINGIFY(a) #a
 
-#define CHECK_DEFINE(a)                                                \
-do {                                                           \
-       printf ("        LASSERT ("#a" == "STRINGIFY(a)");\n"); \
+#define CHECK_DEFINE(a)                                                 \
+do {                                                                    \
+        printf ("        CLASSERT ("#a" == "STRINGIFY(a)");\n");        \
 } while (0)
 
-#define CHECK_VALUE(a)                                 \
-do {                                                   \
-       printf ("        LASSERT ("#a" == %d);\n", a);  \
+#define CHECK_VALUE(a)                                  \
+do {                                                    \
+        printf ("        CLASSERT ("#a" == %d);\n", a); \
 } while (0)
 
-#define CHECK_MEMBER_OFFSET(s,m)               \
-do {                                           \
-       CHECK_VALUE(offsetof(s, m));            \
+#define CHECK_MEMBER_OFFSET(s,m)                \
+do {                                            \
+        CHECK_VALUE((int)offsetof(s, m));       \
 } while (0)
 
-#define CHECK_MEMBER_SIZEOF(s,m)               \
-do {                                           \
-       CHECK_VALUE((int)sizeof(((s *)0)->m));  \
+#define CHECK_MEMBER_SIZEOF(s,m)                \
+do {                                            \
+        CHECK_VALUE((int)sizeof(((s *)0)->m));  \
 } while (0)
 
-#define CHECK_MEMBER(s,m)                      \
-do {                                           \
-       CHECK_MEMBER_OFFSET(s, m);              \
-       CHECK_MEMBER_SIZEOF(s, m);              \
+#define CHECK_MEMBER(s,m)                       \
+do {                                            \
+        CHECK_MEMBER_OFFSET(s, m);              \
+        CHECK_MEMBER_SIZEOF(s, m);              \
 } while (0)
 
 #define CHECK_STRUCT(s)                         \
 do {                                            \
         BLANK_LINE ();                          \
         COMMENT ("Checks for struct "#s);       \
-       CHECK_VALUE((int)sizeof(s));            \
+        CHECK_VALUE((int)sizeof(s));            \
 } while (0)
 
 void
-check_ptl_handle_wire (void)
+check_lnet_handle_wire (void)
 {
-       CHECK_STRUCT (ptl_handle_wire_t);
-       CHECK_MEMBER (ptl_handle_wire_t, wh_interface_cookie);
-       CHECK_MEMBER (ptl_handle_wire_t, wh_object_cookie);
+        CHECK_STRUCT (lnet_handle_wire_t);
+        CHECK_MEMBER (lnet_handle_wire_t, wh_interface_cookie);
+        CHECK_MEMBER (lnet_handle_wire_t, wh_object_cookie);
 }
 
 void
-check_ptl_magicversion (void)
+check_lnet_magicversion (void)
 {
-       CHECK_STRUCT (ptl_magicversion_t);
-       CHECK_MEMBER (ptl_magicversion_t, magic);
-       CHECK_MEMBER (ptl_magicversion_t, version_major);
-       CHECK_MEMBER (ptl_magicversion_t, version_minor);
+        CHECK_STRUCT (lnet_magicversion_t);
+        CHECK_MEMBER (lnet_magicversion_t, magic);
+        CHECK_MEMBER (lnet_magicversion_t, version_major);
+        CHECK_MEMBER (lnet_magicversion_t, version_minor);
 }
 
 void
-check_ptl_hdr (void)
+check_lnet_hdr (void)
 {
-       CHECK_STRUCT (ptl_hdr_t);
-       CHECK_MEMBER (ptl_hdr_t, dest_nid);
-       CHECK_MEMBER (ptl_hdr_t, src_nid);
-       CHECK_MEMBER (ptl_hdr_t, dest_pid);
-       CHECK_MEMBER (ptl_hdr_t, src_pid);
-       CHECK_MEMBER (ptl_hdr_t, type);
-       CHECK_MEMBER (ptl_hdr_t, payload_length);
-        CHECK_MEMBER (ptl_hdr_t, msg);
-        
+        CHECK_STRUCT (lnet_hdr_t);
+        CHECK_MEMBER (lnet_hdr_t, dest_nid);
+        CHECK_MEMBER (lnet_hdr_t, src_nid);
+        CHECK_MEMBER (lnet_hdr_t, dest_pid);
+        CHECK_MEMBER (lnet_hdr_t, src_pid);
+        CHECK_MEMBER (lnet_hdr_t, type);
+        CHECK_MEMBER (lnet_hdr_t, payload_length);
+        CHECK_MEMBER (lnet_hdr_t, msg);
+
         BLANK_LINE ();
         COMMENT ("Ack");
-        CHECK_MEMBER (ptl_hdr_t, msg.ack.dst_wmd);
-        CHECK_MEMBER (ptl_hdr_t, msg.ack.match_bits);
-        CHECK_MEMBER (ptl_hdr_t, msg.ack.mlength);
+        CHECK_MEMBER (lnet_hdr_t, msg.ack.dst_wmd);
+        CHECK_MEMBER (lnet_hdr_t, msg.ack.match_bits);
+        CHECK_MEMBER (lnet_hdr_t, msg.ack.mlength);
 
         BLANK_LINE ();
         COMMENT ("Put");
-       CHECK_MEMBER (ptl_hdr_t, msg.put.ack_wmd);
-       CHECK_MEMBER (ptl_hdr_t, msg.put.match_bits);
-       CHECK_MEMBER (ptl_hdr_t, msg.put.hdr_data);
-       CHECK_MEMBER (ptl_hdr_t, msg.put.ptl_index);
-       CHECK_MEMBER (ptl_hdr_t, msg.put.offset);
+        CHECK_MEMBER (lnet_hdr_t, msg.put.ack_wmd);
+        CHECK_MEMBER (lnet_hdr_t, msg.put.match_bits);
+        CHECK_MEMBER (lnet_hdr_t, msg.put.hdr_data);
+        CHECK_MEMBER (lnet_hdr_t, msg.put.ptl_index);
+        CHECK_MEMBER (lnet_hdr_t, msg.put.offset);
 
         BLANK_LINE ();
         COMMENT ("Get");
-       CHECK_MEMBER (ptl_hdr_t, msg.get.return_wmd);
-       CHECK_MEMBER (ptl_hdr_t, msg.get.match_bits);
-       CHECK_MEMBER (ptl_hdr_t, msg.get.ptl_index);
-       CHECK_MEMBER (ptl_hdr_t, msg.get.src_offset);
-       CHECK_MEMBER (ptl_hdr_t, msg.get.sink_length);
+        CHECK_MEMBER (lnet_hdr_t, msg.get.return_wmd);
+        CHECK_MEMBER (lnet_hdr_t, msg.get.match_bits);
+        CHECK_MEMBER (lnet_hdr_t, msg.get.ptl_index);
+        CHECK_MEMBER (lnet_hdr_t, msg.get.src_offset);
+        CHECK_MEMBER (lnet_hdr_t, msg.get.sink_length);
 
         BLANK_LINE ();
         COMMENT ("Reply");
-       CHECK_MEMBER (ptl_hdr_t, msg.reply.dst_wmd);
+        CHECK_MEMBER (lnet_hdr_t, msg.reply.dst_wmd);
 
         BLANK_LINE ();
         COMMENT ("Hello");
-       CHECK_MEMBER (ptl_hdr_t, msg.hello.incarnation);
-       CHECK_MEMBER (ptl_hdr_t, msg.hello.type);
+        CHECK_MEMBER (lnet_hdr_t, msg.hello.incarnation);
+        CHECK_MEMBER (lnet_hdr_t, msg.hello.type);
 }
 
 void
@@ -122,11 +159,11 @@ system_string (char *cmdline, char *str, int len)
         int   fds[2];
         int   rc;
         pid_t pid;
-        
+
         rc = pipe (fds);
         if (rc != 0)
                 abort ();
-        
+
         pid = fork ();
         if (pid == 0) {
                 /* child */
@@ -145,25 +182,25 @@ system_string (char *cmdline, char *str, int len)
 
                 if (f == NULL)
                         abort();
-                
+
                 close(fds[1]);
-                
+
                 if (fgets(str, len, f) == NULL)
                         abort();
-                
+
                 if (waitpid(pid, &rc, 0) != pid)
                         abort();
-                
+
                 if (!WIFEXITED(rc) ||
                     WEXITSTATUS(rc) != 0)
                         abort();
 
                 if (strnlen(str, len) == len)
                         str[len - 1] = 0;
-                
+
                 if (str[strlen(str) - 1] == '\n')
                         str[strlen(str) - 1] = 0;
-                
+
                 fclose(f);
         }
 }
@@ -171,37 +208,40 @@ system_string (char *cmdline, char *str, int len)
 int
 main (int argc, char **argv)
 {
-        char unameinfo[80];
-        char gccinfo[80];
-        
+        char unameinfo[256];
+        char gccinfo[256];
+
         system_string("uname -a", unameinfo, sizeof(unameinfo));
         system_string("gcc -v 2>&1 | tail -1", gccinfo, sizeof(gccinfo));
-        
-       printf ("void lib_assert_wire_constants (void)\n"
-               "{\n"
+
+        printf ("void lnet_assert_wire_constants (void)\n"
+                "{\n"
                 "        /* Wire protocol assertions generated by 'wirecheck'\n"
                 "         * running on %s\n"
                 "         * with %s */\n"
                 "\n", unameinfo, gccinfo);
-        
-       BLANK_LINE ();
-       
-       COMMENT ("Constants...");
-       CHECK_DEFINE (PORTALS_PROTO_MAGIC);
-       CHECK_DEFINE (PORTALS_PROTO_VERSION_MAJOR);
-       CHECK_DEFINE (PORTALS_PROTO_VERSION_MINOR);
-
-       CHECK_VALUE (PTL_MSG_ACK);
-       CHECK_VALUE (PTL_MSG_PUT);
-       CHECK_VALUE (PTL_MSG_GET);
-       CHECK_VALUE (PTL_MSG_REPLY);
-       CHECK_VALUE (PTL_MSG_HELLO);
-
-       check_ptl_handle_wire ();
-       check_ptl_magicversion ();
-       check_ptl_hdr ();
-       
-       printf ("}\n\n");
-       
-       return (0);
+
+        BLANK_LINE ();
+
+        COMMENT ("Constants...");
+
+        CHECK_DEFINE (LNET_PROTO_RA_MAGIC);
+
+        CHECK_DEFINE (LNET_PROTO_TCP_MAGIC);
+        CHECK_DEFINE (LNET_PROTO_TCP_VERSION_MAJOR);
+        CHECK_DEFINE (LNET_PROTO_TCP_VERSION_MINOR);
+
+        CHECK_VALUE (LNET_MSG_ACK);
+        CHECK_VALUE (LNET_MSG_PUT);
+        CHECK_VALUE (LNET_MSG_GET);
+        CHECK_VALUE (LNET_MSG_REPLY);
+        CHECK_VALUE (LNET_MSG_HELLO);
+
+        check_lnet_handle_wire ();
+        check_lnet_magicversion ();
+        check_lnet_hdr ();
+
+        printf ("}\n\n");
+
+        return (0);
 }