[PATCH 03/13] testsuite: Add test for getnameinfo().

Christian Mauderer christian.mauderer at embedded-brains.de
Thu Apr 21 08:49:43 UTC 2016


From: Christian Mauderer <Christian.Mauderer at embedded-brains.de>

---
 testsuites/libtests/Makefile.am                    |   1 +
 testsuites/libtests/configure.ac                   |   1 +
 testsuites/libtests/libnetworking01/Makefile.am    |  22 +++
 testsuites/libtests/libnetworking01/init.c         | 161 +++++++++++++++++++++
 .../libtests/libnetworking01/libnetworking01.doc   |  24 +++
 .../libtests/libnetworking01/libnetworking01.scn   |   9 ++
 6 files changed, 218 insertions(+)
 create mode 100644 testsuites/libtests/libnetworking01/Makefile.am
 create mode 100644 testsuites/libtests/libnetworking01/init.c
 create mode 100644 testsuites/libtests/libnetworking01/libnetworking01.doc
 create mode 100644 testsuites/libtests/libnetworking01/libnetworking01.scn

diff --git a/testsuites/libtests/Makefile.am b/testsuites/libtests/Makefile.am
index d775c77..4be862e 100644
--- a/testsuites/libtests/Makefile.am
+++ b/testsuites/libtests/Makefile.am
@@ -23,6 +23,7 @@ _SUBDIRS += block13
 _SUBDIRS += rbheap01
 _SUBDIRS += flashdisk01
 _SUBDIRS += capture01
+_SUBDIRS += libnetworking01
 
 _SUBDIRS += bspcmdline01 cpuuse devfs01 devfs02 devfs03 devfs04 \
     deviceio01 devnullfatal01 dumpbuf01 gxx01 top\
diff --git a/testsuites/libtests/configure.ac b/testsuites/libtests/configure.ac
index 5ac2dfd..d0b7d6f 100644
--- a/testsuites/libtests/configure.ac
+++ b/testsuites/libtests/configure.ac
@@ -79,6 +79,7 @@ AM_CONDITIONAL(DLTESTS,[test x"$TEST_LIBDL" = x"yes"])
 
 # Explicitly list all Makefiles here
 AC_CONFIG_FILES([Makefile
+libnetworking01/Makefile
 libfdt01/Makefile
 defaultconfig01/Makefile
 pwdgrp02/Makefile
diff --git a/testsuites/libtests/libnetworking01/Makefile.am b/testsuites/libtests/libnetworking01/Makefile.am
new file mode 100644
index 0000000..9d25c75
--- /dev/null
+++ b/testsuites/libtests/libnetworking01/Makefile.am
@@ -0,0 +1,22 @@
+
+rtems_tests_PROGRAMS = libnetworking01
+libnetworking01_SOURCES = init.c
+
+dist_rtems_tests_DATA = libnetworking01.scn
+dist_rtems_tests_DATA += libnetworking01.doc
+
+include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP at .cfg
+include $(top_srcdir)/../automake/compile.am
+include $(top_srcdir)/../automake/leaf.am
+
+AM_CPPFLAGS += -I$(top_srcdir)/../support/include
+AM_CPPFLAGS += -I$(top_srcdir)/termios04
+
+LINK_OBJS = $(libnetworking01_OBJECTS)
+LINK_LIBS = $(libnetworking01_LDLIBS)
+
+libnetworking01$(EXEEXT): $(libnetworking01_OBJECTS) $(libnetworking01_DEPENDENCIES)
+	@rm -f libnetworking01$(EXEEXT)
+	$(make-exe)
+
+include $(top_srcdir)/../automake/local.am
diff --git a/testsuites/libtests/libnetworking01/init.c b/testsuites/libtests/libnetworking01/init.c
new file mode 100644
index 0000000..c6edca4
--- /dev/null
+++ b/testsuites/libtests/libnetworking01/init.c
@@ -0,0 +1,161 @@
+/*
+ * Copyright (c) 2016 embedded brains GmbH.  All rights reserved.
+ *
+ *  embedded brains GmbH
+ *  Dornierstr. 4
+ *  82178 Puchheim
+ *  Germany
+ *  <rtems at embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/socket.h>
+#include <netdb.h>
+#include <string.h>
+#include <netinet/in.h>
+
+#include <rtems.h>
+#include <tmacros.h>
+
+const char rtems_test_name[] = "LIBNETWORKING 1";
+
+/* forward declarations to avoid warnings */
+static rtems_task Init(rtems_task_argument argument);
+
+static void fill_sa(struct sockaddr *sa, sa_family_t family)
+{
+  memset(sa, 0, sizeof(struct sockaddr));
+  sa->sa_len = sizeof(struct sockaddr);
+  sa->sa_family = family;
+}
+
+static void fill_sa_in(struct sockaddr_in *sa_in,
+  in_addr_t addr, in_port_t port)
+{
+  fill_sa((struct sockaddr *)sa_in, AF_INET);
+  sa_in->sin_port = port;
+  sa_in->sin_addr.s_addr = addr;
+}
+
+static void test_getnameinfo(
+  const struct sockaddr *sa,
+  int flags,
+  bool ask_node,
+  bool ask_service,
+  int expected_returnvalue,
+  const char *expected_node,
+  const char *expected_service
+)
+{
+  char node[] = "255.255.255.255";
+  char service[] = "65535";
+  socklen_t salen = sa->sa_len;
+  int rv;
+
+  char *node_p = node;
+  char *service_p = service;
+  size_t node_l = sizeof(node);
+  size_t service_l = sizeof(service);
+
+  if(ask_node == false) {
+    node_p = NULL;
+    node_l = 0;
+  }
+
+  if(ask_service == false) {
+    service_p = NULL;
+    service_l = 0;
+  }
+
+  rv = getnameinfo(sa, salen, node_p, node_l, service_p, service_l, flags);
+  rtems_test_assert(rv == expected_returnvalue);
+
+  if(expected_node != NULL) {
+    rtems_test_assert(strcmp(expected_node, node) == 0);
+  }
+
+  if(expected_service != NULL) {
+    rtems_test_assert(strcmp(expected_service, service) == 0);
+  }
+}
+
+static void test(void)
+{
+  struct sockaddr sa;
+  struct sockaddr_in sa_in;
+  struct sockaddr *sa_in_p = (struct sockaddr *) &sa_in;
+
+  const in_addr_t ip1_num = 0x7F000001u;
+  const char ip1_string[] = "127.0.0.1";
+
+  const in_addr_t ip2_num = 0xC0A86464u;
+  const char ip2_string[] = "192.168.100.100";
+
+  const in_port_t port1_num = 7u;
+  const char port1_string[] = "7";
+
+  const in_port_t port2_num = 65534u;
+  const char port2_string[] = "65534";
+
+
+  printk("Try AF_INET6\n");
+  fill_sa(&sa, AF_INET6);
+  test_getnameinfo(&sa, 0, true, true, EAI_FAMILY, NULL, NULL);
+
+  printk("force node name\n");
+  fill_sa_in(&sa_in, ip1_num, port1_num);
+  test_getnameinfo(sa_in_p, NI_NAMEREQD, true, true, EAI_NONAME, NULL, NULL);
+
+  printk("force service name\n");
+  fill_sa_in(&sa_in, ip1_num, port1_num);
+  test_getnameinfo(sa_in_p, NI_NAMEREQD, true, true, EAI_NONAME, NULL, NULL);
+
+  printk("get node only\n");
+  fill_sa_in(&sa_in, ip1_num, port1_num);
+  test_getnameinfo(sa_in_p, 0, true, false, 0, ip1_string, NULL);
+
+  printk("get service only\n");
+  fill_sa_in(&sa_in, ip1_num, port1_num);
+  test_getnameinfo(sa_in_p, 0, false, true, 0, NULL, port1_string);
+
+  printk("get node and service\n");
+  fill_sa_in(&sa_in, ip1_num, port1_num);
+  test_getnameinfo(sa_in_p, 0, true, true, 0, ip1_string, port1_string);
+
+  printk("get node and service with maximum number of characters for IP\n");
+  fill_sa_in(&sa_in, ip2_num, port2_num);
+  test_getnameinfo(sa_in_p, 0, true, true, 0, ip2_string, port2_string);
+}
+
+static rtems_task Init(rtems_task_argument argument)
+{
+  TEST_BEGIN();
+  test();
+  TEST_END();
+
+  rtems_test_exit(0);
+}
+
+#define CONFIGURE_INIT
+
+#define CONFIGURE_MICROSECONDS_PER_TICK 10000
+
+#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+
+#define CONFIGURE_MAXIMUM_DRIVERS 2
+
+#define CONFIGURE_MAXIMUM_TASKS (1)
+
+#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
+
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+
+#include <rtems/confdefs.h>
diff --git a/testsuites/libtests/libnetworking01/libnetworking01.doc b/testsuites/libtests/libnetworking01/libnetworking01.doc
new file mode 100644
index 0000000..1bc87d2
--- /dev/null
+++ b/testsuites/libtests/libnetworking01/libnetworking01.doc
@@ -0,0 +1,24 @@
+#
+# Copyright (c) 2016 embedded brains GmbH.  All rights reserved.
+#
+#  embedded brains GmbH
+#  Dornierstr. 4
+#  82178 Puchheim
+#  Germany
+#  <rtems at embedded-brains.de>
+#
+# The license and distribution terms for this file may be
+# found in the file LICENSE in this distribution or at
+# http://www.rtems.org/license/LICENSE.
+
+This file describes the directives and concepts tested by this test set.
+
+test set name: libnetworking
+
+directives:
+
++ getnameinfo()
+
+concepts:
+
++ Try to get some valid and invalid name infos.
diff --git a/testsuites/libtests/libnetworking01/libnetworking01.scn b/testsuites/libtests/libnetworking01/libnetworking01.scn
new file mode 100644
index 0000000..75e8457
--- /dev/null
+++ b/testsuites/libtests/libnetworking01/libnetworking01.scn
@@ -0,0 +1,9 @@
+*** BEGIN OF TEST LIBNETWORKING 1 ***
+Try AF_INET6
+force node name
+force service name
+get node only
+get service only
+get node and service
+get node and service with maximum number of characters for IP
+*** END OF TEST LIBNETWORKING 1 ***
-- 
1.8.4.5




More information about the devel mailing list