source: rtems/testsuites/libtests/networking01/init.c @ 97417bb

5
Last change on this file since 97417bb was 97417bb, checked in by Sebastian Huber <sebastian.huber@…>, on 08/07/18 at 05:09:55

tests: Remove CONFIGURE_MAXIMUM_DRIVERS

This configuration is superfluous in these tests.

  • Property mode set to 100644
File size: 3.8 KB
Line 
1/*
2 * Copyright (c) 2016 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Dornierstr. 4
6 *  82178 Puchheim
7 *  Germany
8 *  <rtems@embedded-brains.de>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.org/license/LICENSE.
13 */
14
15#ifdef HAVE_CONFIG_H
16#include "config.h"
17#endif
18
19#include <sys/socket.h>
20#include <netdb.h>
21#include <string.h>
22#include <netinet/in.h>
23
24#include <rtems.h>
25#include <tmacros.h>
26
27const char rtems_test_name[] = "NETWORKING 1";
28
29/* forward declarations to avoid warnings */
30static rtems_task Init(rtems_task_argument argument);
31
32static void fill_sa(struct sockaddr *sa, sa_family_t family)
33{
34  memset(sa, 0, sizeof(*sa));
35  sa->sa_len = sizeof(*sa);
36  sa->sa_family = family;
37}
38
39static void fill_sa_in(struct sockaddr_in *sa_in,
40  in_addr_t addr, in_port_t port)
41{
42  fill_sa((struct sockaddr *)sa_in, AF_INET);
43  sa_in->sin_port = htons(port);
44  sa_in->sin_addr.s_addr = htonl(addr);
45}
46
47static void test_getnameinfo(
48  const struct sockaddr *sa,
49  int flags,
50  bool ask_node,
51  bool ask_service,
52  int expected_returnvalue,
53  const char *expected_node,
54  const char *expected_service
55)
56{
57  char node[] = "255.255.255.255";
58  char service[] = "65535";
59  socklen_t salen = sa->sa_len;
60  int rv;
61
62  char *node_p = node;
63  char *service_p = service;
64  size_t node_l = sizeof(node);
65  size_t service_l = sizeof(service);
66
67  if(ask_node == false) {
68    node_p = NULL;
69    node_l = 0;
70  }
71
72  if(ask_service == false) {
73    service_p = NULL;
74    service_l = 0;
75  }
76
77  rv = getnameinfo(sa, salen, node_p, node_l, service_p, service_l, flags);
78  rtems_test_assert(rv == expected_returnvalue);
79
80  if(expected_node != NULL) {
81    rtems_test_assert(strcmp(expected_node, node) == 0);
82  }
83
84  if(expected_service != NULL) {
85    rtems_test_assert(strcmp(expected_service, service) == 0);
86  }
87}
88
89static void test(void)
90{
91  struct sockaddr sa;
92  struct sockaddr_in sa_in;
93  struct sockaddr *sa_in_p = (struct sockaddr *) &sa_in;
94
95  const in_addr_t ip1_num = 0x7F000001u;
96  const char ip1_string[] = "127.0.0.1";
97
98  const in_addr_t ip2_num = 0xC0A86464u;
99  const char ip2_string[] = "192.168.100.100";
100
101  const in_port_t port1_num = 7u;
102  const char port1_string[] = "7";
103
104  const in_port_t port2_num = 65534u;
105  const char port2_string[] = "65534";
106
107
108  puts("Try AF_INET6");
109  fill_sa(&sa, AF_INET6);
110  test_getnameinfo(&sa, 0, true, true, EAI_FAMILY, NULL, NULL);
111
112  puts("force node name");
113  fill_sa_in(&sa_in, ip1_num, port1_num);
114  test_getnameinfo(sa_in_p, NI_NAMEREQD, true, true, EAI_NONAME, NULL, NULL);
115
116  puts("force service name");
117  fill_sa_in(&sa_in, ip1_num, port1_num);
118  test_getnameinfo(sa_in_p, NI_NAMEREQD, true, true, EAI_NONAME, NULL, NULL);
119
120  puts("get node only");
121  fill_sa_in(&sa_in, ip1_num, port1_num);
122  test_getnameinfo(sa_in_p, 0, true, false, 0, ip1_string, NULL);
123
124  puts("get service only");
125  fill_sa_in(&sa_in, ip1_num, port1_num);
126  test_getnameinfo(sa_in_p, 0, false, true, 0, NULL, port1_string);
127
128  puts("get node and service");
129  fill_sa_in(&sa_in, ip1_num, port1_num);
130  test_getnameinfo(sa_in_p, 0, true, true, 0, ip1_string, port1_string);
131
132  puts("get node and service with maximum number of characters for IP");
133  fill_sa_in(&sa_in, ip2_num, port2_num);
134  test_getnameinfo(sa_in_p, 0, true, true, 0, ip2_string, port2_string);
135}
136
137static rtems_task Init(rtems_task_argument argument)
138{
139  TEST_BEGIN();
140  test();
141  TEST_END();
142
143  rtems_test_exit(0);
144}
145
146#define CONFIGURE_INIT
147
148#define CONFIGURE_MICROSECONDS_PER_TICK 10000
149
150#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
151#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
152
153#define CONFIGURE_MAXIMUM_TASKS (1)
154
155#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
156
157#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
158
159#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT
160
161#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.