Test: use static data in test_ctf_writer
authorMichael Jeanson <mjeanson@efficios.com>
Wed, 9 Aug 2017 22:35:56 +0000 (18:35 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 21 Aug 2017 21:02:22 +0000 (17:02 -0400)
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
configure.ac
include/Makefile.am
include/babeltrace/compat/utsname-internal.h [deleted file]
tests/lib/test_ctf_writer.c

index 62863c0ddff08892a15d084c615c1b603db75a16..a13b36527976bc6dec3492790cfd15efda81ead5 100644 (file)
@@ -262,7 +262,6 @@ AC_CHECK_FUNCS([ \
        dup2 \
        ftruncate \
        gethostbyname \
-       gethostname \
        gettimeofday \
        localtime_r \
        memchr \
@@ -283,7 +282,6 @@ AC_CHECK_FUNCS([ \
        strtoul \
        strtoull \
        tzset \
-       uname \
 ])
 
 # AC_FUNC_MALLOC causes problems when cross-compiling.
index f1f86fcb69f28cc11690b9672b10c3fd1f4823f9..a0dd70802c8fae0fe01e5720f1f262e396506357 100644 (file)
@@ -97,7 +97,6 @@ noinst_HEADERS = \
        babeltrace/compat/time-internal.h \
        babeltrace/compat/unistd-internal.h \
        babeltrace/compat/utc-internal.h \
-       babeltrace/compat/utsname-internal.h \
        babeltrace/compat/uuid-internal.h \
        babeltrace/compiler-internal.h \
        babeltrace/ctf-ir/attributes-internal.h \
diff --git a/include/babeltrace/compat/utsname-internal.h b/include/babeltrace/compat/utsname-internal.h
deleted file mode 100644 (file)
index 8ca4ea7..0000000
+++ /dev/null
@@ -1,111 +0,0 @@
-
-#ifndef UTSNAME_H
-#define UTSNAME_H
-
-/*
- * Copyright 2011 Martin T. Sandsmark <sandsmark@samfundet.no>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifdef __MINGW32__
-
-#include <winsock2.h>
-#include <windows.h>
-#include <stdio.h>
-
-#define UTSNAME_LENGTH 257
-struct utsname {
-       char sysname[UTSNAME_LENGTH];
-       char nodename[UTSNAME_LENGTH];
-       char release[UTSNAME_LENGTH];
-       char version[UTSNAME_LENGTH];
-       char machine[UTSNAME_LENGTH];
-};
-
-static inline
-int uname(struct utsname *name)
-{
-       OSVERSIONINFO versionInfo;
-       SYSTEM_INFO sysInfo;
-       int ret = 0;
-
-       /* Get Windows version info */
-       memset(&versionInfo, 0, sizeof(OSVERSIONINFO));
-       versionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
-       GetVersionEx(&versionInfo);
-
-       /* Get hardware info */
-       ZeroMemory(&sysInfo, sizeof(SYSTEM_INFO));
-       GetSystemInfo(&sysInfo);
-
-       /* Fill the sysname */
-       strcpy(name->sysname, "Windows");
-
-       /* Fill the release */
-       snprintf(name->release, UTSNAME_LENGTH, "%lu",
-                       versionInfo.dwBuildNumber);
-
-       /* Fill the version */
-       snprintf(name->version, UTSNAME_LENGTH, "%lu.%lu",
-                       versionInfo.dwMajorVersion,
-                       versionInfo.dwMinorVersion);
-
-       /* Fill ithe nodename */
-       if (gethostname(name->nodename, UTSNAME_LENGTH) != 0) {
-               if (WSAGetLastError() == WSANOTINITIALISED) {
-                       /* WinSock not initialized */
-                       WSADATA WSAData;
-                       WSAStartup(MAKEWORD(1, 0), &WSAData);
-                       gethostname(name->nodename, UTSNAME_LENGTH);
-                       WSACleanup();
-               } else {
-                       ret = -1;
-                       goto end;
-               }
-       }
-
-       /* Fill the machine */
-       switch(sysInfo.wProcessorArchitecture) {
-       case PROCESSOR_ARCHITECTURE_AMD64:
-               strcpy(name->machine, "x86_64");
-               break;
-       case PROCESSOR_ARCHITECTURE_IA64:
-               strcpy(name->machine, "ia64");
-               break;
-       case PROCESSOR_ARCHITECTURE_INTEL:
-               strcpy(name->machine, "x86");
-               break;
-       case PROCESSOR_ARCHITECTURE_UNKNOWN:
-       default:
-               strcpy(name->machine, "unknown");
-       }
-
-end:
-       return ret;
-}
-#else /* __MINGW32__ */
-#include <sys/utsname.h>
-#endif /* __MINGW32__ */
-
-#endif //UTSNAME_H
index a2fb43f94b7d2956ae64dd3dbb31d903cf035ef9..bf1ff958e0bd53bb726f9d9939e579a93ea60e90 100644 (file)
@@ -36,7 +36,6 @@
 #include <unistd.h>
 #include <babeltrace/compat/stdlib-internal.h>
 #include <stdio.h>
-#include <babeltrace/compat/utsname-internal.h>
 #include <babeltrace/compat/limits-internal.h>
 #include <babeltrace/compat/stdio-internal.h>
 #include <string.h>
 
 #define NR_TESTS 623
 
+struct bt_utsname {
+       char sysname[BABELTRACE_HOST_NAME_MAX];
+       char nodename[BABELTRACE_HOST_NAME_MAX];
+       char release[BABELTRACE_HOST_NAME_MAX];
+       char version[BABELTRACE_HOST_NAME_MAX];
+       char machine[BABELTRACE_HOST_NAME_MAX];
+};
+
 static int64_t current_time = 42;
 static unsigned int packet_resize_test_length = PACKET_RESIZE_TEST_DEF_LENGTH;
 
@@ -2851,8 +2858,8 @@ int main(int argc, char **argv)
        const int is_absolute = 0xFF;
        char *metadata_string;
        struct bt_ctf_writer *writer;
-       struct utsname name;
-       char hostname[BABELTRACE_HOST_NAME_MAX];
+       struct bt_utsname name = {"GNU/Linux", "testhost", "4.4.0-87-generic",
+               "#110-Ubuntu SMP Tue Jul 18 12:55:35 UTC 2017", "x86_64"};
        struct bt_ctf_clock *clock, *ret_clock;
        struct bt_ctf_clock_class *ret_clock_class;
        struct bt_ctf_stream_class *stream_class, *ret_stream_class;
@@ -2913,13 +2920,9 @@ int main(int argc, char **argv)
                "bt_ctf_trace_get_native_byte_order returns a correct endianness");
 
        /* Add environment context to the trace */
-       ret = gethostname(hostname, sizeof(hostname));
-       if (ret < 0) {
-               return ret;
-       }
-       ok(bt_ctf_writer_add_environment_field(writer, "host", hostname) == 0,
+       ok(bt_ctf_writer_add_environment_field(writer, "host", name.nodename) == 0,
                "Add host (%s) environment field to writer instance",
-               hostname);
+               name.nodename);
        ok(bt_ctf_writer_add_environment_field(NULL, "test_field",
                "test_value"),
                "bt_ctf_writer_add_environment_field error with NULL writer");
@@ -3043,12 +3046,6 @@ int main(int argc, char **argv)
                "bt_ctf_trace_get_environment_field_value successfully replaces an existing field");
        BT_PUT(obj);
 
-       /* On Solaris, uname() can return any positive value on success */
-       if (uname(&name) < 0) {
-               perror("uname");
-               return -1;
-       }
-
        ok(bt_ctf_writer_add_environment_field(writer, "sysname", name.sysname)
                == 0, "Add sysname (%s) environment field to writer instance",
                name.sysname);
This page took 0.028128 seconds and 4 git commands to generate.