tap_updown_good \
api-test-coverage
+noinst_HEADERS = \
+ test-common.h
+
if BUILD_LIBNOZZLE
check_PROGRAMS = \
+ api_nozzle_open_test \
nozzle_test
-TESTS = $(check_PROGRAMS)
-
noinst_PROGRAMS = $(check_PROGRAMS)
+noinst_SCRIPTS = \
+ api-test-coverage
+
+TESTS = $(check_PROGRAMS)
+
check-local: check-api-test-coverage
check-api-test-coverage:
AM_CFLAGS += $(PTHREAD_CFLAGS) $(libnl_CFLAGS)
LIBS += $(top_builddir)/libnozzle/libnozzle.la $(PTHREAD_LIBS) $(libnl_LIBS)
+api_nozzle_open_test_SOURCES = api_nozzle_open.c \
+ test-common.c \
+ ../internals.c
+
nozzle_test_SOURCES = nozzle_test.c \
+ test-common.c \
../internals.c
endif
--- /dev/null
+/*
+ * Copyright (C) 2018 Red Hat, Inc. All rights reserved.
+ *
+ * Author: Fabio M. Di Nitto <fabbione@kronosnet.org>
+ *
+ * This software licensed under GPL-2.0+, LGPL-2.0+
+ */
+
+#include "config.h"
+
+#include <string.h>
+#include <errno.h>
+#include <limits.h>
+
+#include "test-common.h"
+
+/*
+ * use this one to randomize nozzle interface name
+ * for named creation test
+ */
+uint8_t randombyte = 0;
+
+static int test_iface(char *name, size_t size, const char *updownpath)
+{
+ nozzle_t nozzle;
+
+ nozzle=nozzle_open(name, size, updownpath);
+ if (!nozzle) {
+ printf("Unable to open nozzle.\n");
+ return -1;
+ }
+ printf("Created interface: %s\n", name);
+
+ if (is_if_in_system(name) > 0) {
+ printf("Found interface %s on the system\n", name);
+ } else {
+ printf("Unable to find interface %s on the system\n", name);
+ }
+
+ if (!nozzle_get_handle_by_name(name)) {
+ printf("Unable to find interface %s in nozzle db\n", name);
+ } else {
+ printf("Found interface %s in nozzle db\n", name);
+ }
+
+ nozzle_close(nozzle);
+
+ if (is_if_in_system(name) == 0)
+ printf("Successfully removed interface %s from the system\n", name);
+
+ return 0;
+}
+
+static int test(void)
+{
+ char device_name[2*IFNAMSIZ];
+ char fakepath[PATH_MAX];
+ size_t size = IFNAMSIZ;
+
+ memset(device_name, 0, sizeof(device_name));
+
+ printf("Creating random nozzle interface:\n");
+ if (test_iface(device_name, size, NULL) < 0) {
+ printf("Unable to create random interface\n");
+ return -1;
+ }
+
+#ifdef KNET_LINUX
+ printf("Creating kronostest%u nozzle interface:\n", randombyte);
+ snprintf(device_name, IFNAMSIZ, "kronostest%u", randombyte);
+ if (test_iface(device_name, size, NULL) < 0) {
+ printf("Unable to create kronostest%u interface\n", randombyte);
+ return -1;
+ }
+#endif
+#ifdef KNET_BSD
+ printf("Creating tap%u nozzle interface:\n", randombyte);
+ snprintf(device_name, IFNAMSIZ, "tap%u", randombyte);
+ if (test_iface(device_name, size, NULL) < 0) {
+ printf("Unable to create tap%u interface\n", randombyte);
+ return -1;
+ }
+
+ printf("Creating kronostest%u nozzle interface:\n", randombyte);
+ snprintf(device_name, IFNAMSIZ, "kronostest%u", randombyte);
+ if (test_iface(device_name, size, NULL) == 0) {
+ printf("BSD should not accept kronostest%u interface\n", randombyte);
+ return -1;
+ }
+#endif
+
+ printf("Testing ERROR conditions\n");
+
+ printf("Testing dev == NULL\n");
+ errno=0;
+ if ((test_iface(NULL, size, NULL) >= 0) || (errno != EINVAL)) {
+ printf("Something is wrong in nozzle_open sanity checks\n");
+ return -1;
+ }
+
+ printf("Testing size < IFNAMSIZ\n");
+ errno=0;
+ if ((test_iface(device_name, 1, NULL) >= 0) || (errno != EINVAL)) {
+ printf("Something is wrong in nozzle_open sanity checks\n");
+ return -1;
+ }
+
+ printf("Testing device_name size > IFNAMSIZ\n");
+ errno=0;
+ strcpy(device_name, "abcdefghilmnopqrstuvwz");
+ if ((test_iface(device_name, IFNAMSIZ, NULL) >= 0) || (errno != E2BIG)) {
+ printf("Something is wrong in nozzle_open sanity checks\n");
+ return -1;
+ }
+
+ printf("Testing updown path != abs\n");
+ errno=0;
+
+ memset(device_name, 0, IFNAMSIZ);
+ if ((test_iface(device_name, IFNAMSIZ, "foo") >= 0) || (errno != EINVAL)) {
+ printf("Something is wrong in nozzle_open sanity checks\n");
+ return -1;
+ }
+
+ memset(fakepath, 0, PATH_MAX);
+ memset(fakepath, '/', PATH_MAX - 2);
+
+ printf("Testing updown path > PATH_MAX\n");
+ errno=0;
+
+ memset(device_name, 0, IFNAMSIZ);
+ if ((test_iface(device_name, IFNAMSIZ, fakepath) >= 0) || (errno != E2BIG)) {
+ printf("Something is wrong in nozzle_open sanity checks\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+int main(void)
+{
+ need_root();
+
+ if (test() < 0)
+ return FAIL;
+
+ return PASS;
+}
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-#include <sys/types.h>
#include <errno.h>
-#include <ifaddrs.h>
#include <stdint.h>
#include <limits.h>
#include <sys/socket.h>
#include <net/if_dl.h>
#endif
-#include "libnozzle.h"
-#include "internals.h"
+#include "test-common.h"
char testipv4_1[1024];
char testipv4_2[1024];
*/
uint8_t randombyte = 0;
-static int is_if_in_system(char *name)
-{
- struct ifaddrs *ifap = NULL;
- struct ifaddrs *ifa;
- int found = 0;
-
- if (getifaddrs(&ifap) < 0) {
- printf("Unable to get interface list.\n");
- return -1;
- }
-
- ifa = ifap;
-
- while (ifa) {
- if (!strncmp(name, ifa->ifa_name, IFNAMSIZ)) {
- found = 1;
- break;
- }
- ifa=ifa->ifa_next;
- }
-
- freeifaddrs(ifap);
- return found;
-}
-
-static int test_iface(char *name, size_t size, const char *updownpath)
-{
- nozzle_t nozzle;
-
- nozzle=nozzle_open(name, size, updownpath);
- if (!nozzle) {
- printf("Unable to open knet.\n");
- return -1;
- }
- printf("Created interface: %s\n", name);
-
- if (is_if_in_system(name) > 0) {
- printf("Found interface %s on the system\n", name);
- } else {
- printf("Unable to find interface %s on the system\n", name);
- }
-
- if (!nozzle_get_handle_by_name(name)) {
- printf("Unable to find interface %s in nozzle db\n", name);
- } else {
- printf("Found interface %s in nozzle db\n", name);
- }
-
- nozzle_close(nozzle);
-
- if (is_if_in_system(name) == 0)
- printf("Successfully removed interface %s from the system\n", name);
-
- return 0;
-}
-
-static int check_nozzle_open_close(void)
-{
- char device_name[2*IFNAMSIZ];
- char fakepath[PATH_MAX];
- size_t size = IFNAMSIZ;
-
- memset(device_name, 0, sizeof(device_name));
-
- printf("Creating random nozzle interface:\n");
- if (test_iface(device_name, size, NULL) < 0) {
- printf("Unable to create random interface\n");
- return -1;
- }
-
-#ifdef KNET_LINUX
- printf("Creating kronostest%u nozzle interface:\n", randombyte);
- snprintf(device_name, IFNAMSIZ, "kronostest%u", randombyte);
- if (test_iface(device_name, size, NULL) < 0) {
- printf("Unable to create kronostest%u interface\n", randombyte);
- return -1;
- }
-#endif
-#ifdef KNET_BSD
- printf("Creating tap%u nozzle interface:\n", randombyte);
- snprintf(device_name, IFNAMSIZ, "tap%u", randombyte);
- if (test_iface(device_name, size, NULL) < 0) {
- printf("Unable to create tap%u interface\n", randombyte);
- return -1;
- }
-
- printf("Creating kronostest%u nozzle interface:\n", randombyte);
- snprintf(device_name, IFNAMSIZ, "kronostest%u", randombyte);
- if (test_iface(device_name, size, NULL) == 0) {
- printf("BSD should not accept kronostest%u interface\n", randombyte);
- return -1;
- }
-#endif
-
- printf("Testing ERROR conditions\n");
-
- printf("Testing dev == NULL\n");
- errno=0;
- if ((test_iface(NULL, size, NULL) >= 0) || (errno != EINVAL)) {
- printf("Something is wrong in nozzle_open sanity checks\n");
- return -1;
- }
-
- printf("Testing size < IFNAMSIZ\n");
- errno=0;
- if ((test_iface(device_name, 1, NULL) >= 0) || (errno != EINVAL)) {
- printf("Something is wrong in nozzle_open sanity checks\n");
- return -1;
- }
-
- printf("Testing device_name size > IFNAMSIZ\n");
- errno=0;
- strcpy(device_name, "abcdefghilmnopqrstuvwz");
- if ((test_iface(device_name, IFNAMSIZ, NULL) >= 0) || (errno != E2BIG)) {
- printf("Something is wrong in nozzle_open sanity checks\n");
- return -1;
- }
-
- printf("Testing updown path != abs\n");
- errno=0;
-
- memset(device_name, 0, IFNAMSIZ);
- if ((test_iface(device_name, IFNAMSIZ, "foo") >= 0) || (errno != EINVAL)) {
- printf("Something is wrong in nozzle_open sanity checks\n");
- return -1;
- }
-
- memset(fakepath, 0, PATH_MAX);
- memset(fakepath, '/', PATH_MAX - 2);
-
- printf("Testing updown path > PATH_MAX\n");
- errno=0;
-
- memset(device_name, 0, IFNAMSIZ);
- if ((test_iface(device_name, IFNAMSIZ, fakepath) >= 0) || (errno != E2BIG)) {
- printf("Something is wrong in nozzle_open sanity checks\n");
- return -1;
- }
-
- return 0;
-}
-
static int check_knet_multi_eth(void)
{
char device_name1[IFNAMSIZ];
int main(void)
{
- if (geteuid() != 0) {
- printf("This test requires root privileges\n");
- exit(77);
- }
+ need_root();
make_local_ips();
- if (check_nozzle_open_close() < 0)
- return -1;
-
if (check_knet_multi_eth() < 0)
return -1;
--- /dev/null
+/*
+ * Copyright (C) 2018 Red Hat, Inc. All rights reserved.
+ *
+ * Author: Fabio M. Di Nitto <fabbione@kronosnet.org>
+ *
+ * This software licensed under GPL-2.0+, LGPL-2.0+
+ */
+
+#include "config.h"
+
+#include <string.h>
+#include <sys/types.h>
+#include <ifaddrs.h>
+#include <limits.h>
+#include <unistd.h>
+#include <sys/types.h>
+
+#include "test-common.h"
+
+void need_root(void)
+{
+ if (geteuid() != 0) {
+ printf("This test requires root privileges\n");
+ exit(SKIP);
+ }
+}
+
+int is_if_in_system(char *name)
+{
+ struct ifaddrs *ifap = NULL;
+ struct ifaddrs *ifa;
+ int found = 0;
+
+ if (getifaddrs(&ifap) < 0) {
+ printf("Unable to get interface list.\n");
+ return -1;
+ }
+
+ ifa = ifap;
+
+ while (ifa) {
+ if (!strncmp(name, ifa->ifa_name, IFNAMSIZ)) {
+ found = 1;
+ break;
+ }
+ ifa=ifa->ifa_next;
+ }
+
+ freeifaddrs(ifap);
+ return found;
+}
--- /dev/null
+/*
+ * Copyright (C) 2018 Red Hat, Inc. All rights reserved.
+ *
+ * Authors: Fabio M. Di Nitto <fabbione@kronosnet.org>
+ *
+ * This software licensed under GPL-2.0+, LGPL-2.0+
+ */
+
+#ifndef __NOZZLE_TEST_COMMON_H__
+#define __NOZZLE_TEST_COMMON_H__
+
+#include "internals.h"
+#include "libnozzle.h"
+
+/*
+ * error codes from automake test-driver
+ */
+
+#define PASS 0
+#define SKIP 77
+#define ERROR 99
+#define FAIL -1
+
+/*
+ * common facilities
+ */
+
+void need_root(void);
+int is_if_in_system(char *name);
+
+#endif