Permalink
Browse files

testsuite: decouple from utils.c

Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
  • Loading branch information...
1 parent fca3cfb commit 4d69fc8b89a5b36ee1e521da74d9d38095557184 @fabbione committed Mar 23, 2011
Showing with 74 additions and 81 deletions.
  1. +1 −1 libtap/Makefile.am
  2. +6 −18 tests/Makefile.am
  3. +3 −3 tests/khandle_test.c
  4. +21 −19 tests/listener_test.c
  5. +3 −2 tests/lookup_bench.c
  6. +23 −21 tests/netutils_test.c
  7. +12 −12 tests/ping_test.c
  8. +5 −5 tests/timediff_test.c
View
2 libtap/Makefile.am
@@ -31,7 +31,7 @@ noinst_PROGRAMS = $(check_PROGRAMS)
check_PROGRAMS = tap_test
-tap_test_SOURCES = $(sources) ../utils.c
+tap_test_SOURCES = $(sources)
tap_test_CPPFLAGS = -DTEST \
-DABSBUILDDIR=\"$(abs_builddir)\"
View
24 tests/Makefile.am
@@ -33,26 +33,14 @@ AM_LDFLAGS = \
$(top_builddir)/libknet/libknet.a \
$(top_builddir)/libvty/libvty.a
-ping_test_SOURCES = \
- ping_test.c \
- ../utils.c
+ping_test_SOURCES = ping_test.c
-khandle_test_SOURCES = \
- khandle_test.c \
- ../utils.c
+khandle_test_SOURCES = khandle_test.c
-lookup_bench_SOURCES = \
- lookup_bench.c \
- ../utils.c
+lookup_bench_SOURCES = lookup_bench.c
-listener_test_SOURCES = \
- listener_test.c \
- ../utils.c
+listener_test_SOURCES = listener_test.c
-netutils_test_SOURCES = \
- netutils_test.c \
- ../utils.c
+netutils_test_SOURCES = netutils_test.c
-timediff_test_SOURCES = \
- timediff_test.c \
- ../utils.c
+timediff_test_SOURCES = timediff_test.c
View
6 tests/khandle_test.c
@@ -1,12 +1,12 @@
#include "config.h"
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
#include "libknet.h"
-#include "utils.h"
#define HOST_LIST_SIZE 8192
#define HOST_LIST_LOOP 64
@@ -27,7 +27,7 @@ int main(int argc, char *argv[])
sock = socket(AF_UNIX, SOCK_STREAM, 0);
if (sock < 0) {
- log_error("Unable to create new socket");
+ printf("Unable to create new socket\n");
exit(EXIT_FAILURE);
}
@@ -48,7 +48,7 @@ int main(int argc, char *argv[])
printf("Loop count: %u times\n", (unsigned int) search.param1);
if (knet_handle_free(knet_h) != 0) {
- log_error("Unable to free knet_handle");
+ printf("Unable to free knet_handle\n");
exit(EXIT_FAILURE);
}
View
40 tests/listener_test.c
@@ -1,10 +1,12 @@
#include "config.h"
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
#include <stdlib.h>
#include <sys/epoll.h>
#include "libknet-private.h"
-#include "utils.h"
#define KNET_TEST_PORT 50000
@@ -18,7 +20,7 @@ static void test_add_listener(void)
listener = malloc(sizeof(struct knet_listener));
if (listener == NULL) {
- log_error("Unable to create listener");
+ printf("Unable to create listener\n");
exit(EXIT_FAILURE);
}
@@ -31,7 +33,7 @@ static void test_add_listener(void)
address->sin_addr.s_addr = INADDR_ANY;
if (knet_listener_add(knet_h, listener) != 0) {
- log_error("Unable to add listener");
+ printf("Unable to add listener\n");
exit(EXIT_FAILURE);
}
}
@@ -41,7 +43,7 @@ static void test_add_host(void)
struct knet_host *host;
if (knet_host_add(knet_h, 1) != 0) {
- log_error("Unable to add host to knet_handle");
+ printf("Unable to add host to knet_handle\n");
exit(EXIT_FAILURE);
}
@@ -61,16 +63,16 @@ int main(int argc, char *argv[])
sock = socket(AF_UNIX, SOCK_STREAM, 0);
if (sock < 0) {
- log_error("Unable to create new socket");
+ printf("Unable to create new socket\n");
exit(EXIT_FAILURE);
}
if ((knet_h = knet_handle_new(sock, 1)) == NULL) {
- log_error("Unable to create new knet_handle_t");
+ printf("Unable to create new knet_handle_t\n");
exit(EXIT_FAILURE);
}
- log_info("Adding listener to handle");
+ printf("Adding listener to handle\n");
test_add_listener();
memset(&ev, 0, sizeof(struct epoll_event));
@@ -79,52 +81,52 @@ int main(int argc, char *argv[])
err = epoll_ctl(knet_h->epollfd, EPOLL_CTL_ADD, listener->sock, &ev);
if (err != -1) {
- log_error("Listener file descriptor not found in epollfd");
+ printf("Listener file descriptor not found in epollfd\n");
exit(EXIT_FAILURE);
}
- log_error("Listener file descriptor was added to epollfd");
+ printf("Listener file descriptor was added to epollfd\n");
- log_info("Adding host to handle");
+ printf("Adding host to handle\n");
test_add_host();
err = knet_listener_remove(knet_h, listener);
if (err != -EBUSY) {
- log_error("Listener socket should be in use");
+ printf("Listener socket should be in use\n");
exit(EXIT_FAILURE);
}
- log_error("Unable to remove listener with active links");
+ printf("Unable to remove listener with active links\n");
- log_info("Removing host from handle");
+ printf("Removing host from handle\n");
err = knet_host_remove(knet_h, 1);
if (err != 0) {
- log_error("Unable to remove host from knet_handle");
+ printf("Unable to remove host from knet_handle\n");
exit(EXIT_FAILURE);
}
- log_info("Removing listener");
+ printf("Removing listener\n");
err = knet_listener_remove(knet_h, listener);
if (err != 0) {
- log_error("Unable to remove listener from knet_handle");
+ printf("Unable to remove listener from knet_handle\n");
exit(EXIT_FAILURE);
}
/* don't try this at home :) */
err = epoll_ctl(knet_h->epollfd, EPOLL_CTL_DEL, listener->sock, &ev);
if (err != -1) {
- log_error("Listener file was present in epollfd");
+ printf("Listener file was present in epollfd\n");
exit(EXIT_FAILURE);
}
- log_error("Listener file descriptor was removed from epollfd");
+ printf("Listener file descriptor was removed from epollfd\n");
if (knet_handle_free(knet_h) != 0) {
- log_error("Unable to free knet_handle");
+ printf("Unable to free knet_handle\n");
exit(EXIT_FAILURE);
}
View
5 tests/lookup_bench.c
@@ -1,12 +1,13 @@
#include "config.h"
+#include <stdio.h>
#include <stdlib.h>
#include <time.h>
+#include <string.h>
#include "libknet.h"
#include "libknet-private.h"
#include "netutils.h"
-#include "utils.h"
#define KNET_PORT 50000
#define KNET_BENCH_LOOPNUM 100000000
@@ -21,7 +22,7 @@ int main(int argc, char *argv[])
head = malloc(sizeof(struct knet_link));
if (head == NULL) {
- log_error("Unable to create knet_link");
+ printf("Unable to create knet_link\n");
exit(EXIT_FAILURE);
}
View
44 tests/netutils_test.c
@@ -1,12 +1,14 @@
#include "config.h"
+#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
+#include <string.h>
+#include <errno.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include "netutils.h"
-#include "utils.h"
static void check_ipv4(void)
{
@@ -17,7 +19,7 @@ static void check_ipv4(void)
memset(&addr, 0, sizeof(struct sockaddr_in));
memset(&addrck, 0, sizeof(struct sockaddr_in));
- log_info("Checking strtoaddr on 192.168.0.1:50000");
+ printf("Checking strtoaddr on 192.168.0.1:50000\n");
addrck.sin_family = AF_INET;
addrck.sin_addr.s_addr = htonl(0xc0a80001); /* 192.168.0.1 */
@@ -27,35 +29,35 @@ static void check_ipv4(void)
(struct sockaddr *) &addr, sizeof(struct sockaddr_in));
if (err != 0) {
- log_error("Unable to convert 192.168.0.1:50000");
+ printf("Unable to convert 192.168.0.1:50000\n");
exit(EXIT_FAILURE);
}
if (memcmp(&addr, &addrck, sizeof(struct sockaddr_in)) != 0) {
errno = EINVAL;
- log_error("Check on 192.168.0.1:50000 failed");
+ printf("Check on 192.168.0.1:50000 failed\n");
exit(EXIT_FAILURE);
}
- log_info("Checking addrtostr on 192.168.0.1:50000");
+ printf("Checking addrtostr on 192.168.0.1:50000\n");
err = addrtostr((struct sockaddr *) &addrck,
sizeof(struct sockaddr_in), buf);
if (err != 0) {
- log_error("Unable to convert 192.168.0.1:50000");
+ printf("Unable to convert 192.168.0.1:50000\n");
exit(EXIT_FAILURE);
}
if (strcmp(buf[0], "192.168.0.1") != 0) {
errno = EINVAL;
- log_error("Wrong address conversion: %s", buf[0]);
+ printf("Wrong address conversion: %s\n", buf[0]);
exit(EXIT_FAILURE);
}
if (strcmp(buf[1], "50000") != 0) {
errno = EINVAL;
- log_error("Wrong port conversion: %s", buf[1]);
+ printf("Wrong port conversion: %s\n", buf[1]);
exit(EXIT_FAILURE);
}
@@ -71,7 +73,7 @@ static void check_ipv6(void)
memset(&addr, 0, sizeof(struct sockaddr_in6));
memset(&addrck, 0, sizeof(struct sockaddr_in6));
- log_info("Checking strtoaddr on [fd00::1]:50000");
+ printf("Checking strtoaddr on [fd00::1]:50000\n");
addrck.sin6_family = AF_INET6;
addrck.sin6_addr.s6_addr16[0] = htons(0xfd00); /* fd00::1 */
@@ -82,35 +84,35 @@ static void check_ipv6(void)
(struct sockaddr *) &addr, sizeof(struct sockaddr_in6));
if (err != 0) {
- log_error("Unable to convert [fd00::1]:50000");
+ printf("Unable to convert [fd00::1]:50000\n");
exit(EXIT_FAILURE);
}
if (memcmp(&addr, &addrck, sizeof(struct sockaddr_in6)) != 0) {
errno = EINVAL;
- log_error("Check on 192.168.0.1:50000 failed");
+ printf("Check on 192.168.0.1:50000 failed\n");
exit(EXIT_FAILURE);
}
- log_info("Checking addrtostr on [fd00::1]:50000");
+ printf("Checking addrtostr on [fd00::1]:50000\n");
err = addrtostr((struct sockaddr *) &addrck,
sizeof(struct sockaddr_in6), buf);
if (err != 0) {
- log_error("Unable to convert 192.168.0.1:50000");
+ printf("Unable to convert 192.168.0.1:50000\n");
exit(EXIT_FAILURE);
}
if (strcmp(buf[0], "fd00::1") != 0) {
errno = EINVAL;
- log_error("Wrong address conversion: %s", buf[0]);
+ printf("Wrong address conversion: %s\n", buf[0]);
exit(EXIT_FAILURE);
}
if (strcmp(buf[1], "50000") != 0) {
errno = EINVAL;
- log_error("Wrong port conversion: %s", buf[1]);
+ printf("Wrong port conversion: %s\n", buf[1]);
exit(EXIT_FAILURE);
}
@@ -122,23 +124,23 @@ static void check_resolve(void)
int err;
struct sockaddr_in addr;
- log_info("Checking host resolution");
+ printf("Checking host resolution\n");
err = strtoaddr("localhost", "50000",
(struct sockaddr *) &addr, sizeof(struct sockaddr_in));
if (err == 0) {
errno = EINVAL;
- log_error("Host resolution should not be enabled");
+ printf("Host resolution should not be enabled\n");
exit(EXIT_FAILURE);
}
- log_info("Checking port resolution");
+ printf("Checking port resolution\n");
err = strtoaddr("127.0.0.1", "ssh",
(struct sockaddr *) &addr, sizeof(struct sockaddr_in));
if (err == 0) {
errno = EINVAL;
- log_error("Port resolution should not be enabled");
+ printf("Port resolution should not be enabled\n");
exit(EXIT_FAILURE);
}
}
@@ -163,15 +165,15 @@ int main(int argc, char *argv[])
sizeof(struct sockaddr_storage));
if (err != 0) {
- log_error("Unable to convert strings to sockaddr");
+ printf("Unable to convert strings to sockaddr\n");
exit(EXIT_FAILURE);
}
err = addrtostr((struct sockaddr *) &address,
sizeof(struct sockaddr_storage), buf);
if (err != 0) {
- log_error("Unable to convert sockaddr to strings");
+ printf("Unable to convert sockaddr to strings\n");
exit(EXIT_FAILURE);
}
View
24 tests/ping_test.c
@@ -1,5 +1,6 @@
#include "config.h"
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@@ -8,7 +9,6 @@
#include <arpa/inet.h>
#include "libknet.h"
-#include "utils.h"
static int knet_sock[2];
static knet_handle_t knet_h;
@@ -54,7 +54,7 @@ static void argv_to_hosts(int argc, char *argv[])
listener = malloc(sizeof(struct knet_listener));
if (listener == NULL) {
- log_error("Unable to create listener");
+ printf("Unable to create listener\n");
exit(EXIT_FAILURE);
}
@@ -66,20 +66,20 @@ static void argv_to_hosts(int argc, char *argv[])
err = tok_inaddrport(argv[1], address);
if (err < 0) {
- log_error("Unable to convert ip address: %s", argv[1]);
+ printf("Unable to convert ip address: %s\n", argv[1]);
exit(EXIT_FAILURE);
}
err = knet_listener_add(knet_h, listener);
if (err != 0) {
- log_error("Unable to start knet listener");
+ printf("Unable to start knet listener\n");
exit(EXIT_FAILURE);
}
for (i = 2; i < argc; i++) {
if (knet_host_add(knet_h, i - 1) != 0) {
- log_error("Unable to add new knet_host");
+ printf("Unable to add new knet_host\n");
exit(EXIT_FAILURE);
}
@@ -96,7 +96,7 @@ static void argv_to_hosts(int argc, char *argv[])
(struct sockaddr_in *) &host->link[0].address);
if (err < 0) {
- log_error("Unable to convert ip address: %s", argv[i]);
+ printf("Unable to convert ip address: %s", argv[i]);
exit(EXIT_FAILURE);
}
@@ -134,7 +134,7 @@ static void sigint_handler(int signum)
err = knet_handle_free(knet_h);
if (err != 0) {
- log_error("Unable to cleanup before exit");
+ printf("Unable to cleanup before exit\n");
exit(EXIT_FAILURE);
}
}
@@ -156,19 +156,19 @@ int main(int argc, char *argv[])
}
if (socketpair(AF_UNIX, SOCK_STREAM, IPPROTO_IP, knet_sock) != 0) {
- log_error("Unable to create socket");
+ printf("Unable to create socket\n");
exit(EXIT_FAILURE);
}
knet_h = NULL;
if (signal(SIGINT, sigint_handler) == SIG_ERR) {
- log_error("Unable to configure SIGINT handler");
+ printf("Unable to configure SIGINT handler\n");
exit(EXIT_FAILURE);
}
if ((knet_h = knet_handle_new(knet_sock[0], 1)) == NULL) {
- log_error("Unable to create new knet_handle_t");
+ printf("Unable to create new knet_handle_t\n");
exit(EXIT_FAILURE);
}
@@ -178,7 +178,7 @@ int main(int argc, char *argv[])
while (1) {
knet_host_foreach(knet_h, print_link, &print_search);
- log_info("Sending 'Hello World!' frame");
+ printf("Sending 'Hello World!' frame\n");
write(knet_sock[1], "Hello World!", 13);
tv.tv_sec = 5;
@@ -194,7 +194,7 @@ int main(int argc, char *argv[])
/* usleep(500000); */
if (len < 0) {
- log_error("Unable select over knet_handle_t");
+ printf("Unable select over knet_handle_t\n");
exit(EXIT_FAILURE);
} else if (FD_ISSET(knet_sock[1], &rfds)) {
len = read(knet_sock[1], buff, sizeof(buff));
View
10 tests/timediff_test.c
@@ -1,9 +1,9 @@
#include "config.h"
+#include <stdio.h>
#include <time.h>
#include <stdlib.h>
-#include "utils.h"
#include "libknet-private.h"
#define timespec_set(x, sec, nsec) \
@@ -22,20 +22,20 @@ static void check_timespec_diff(void)
timespec_set(end, start.tv_sec, start.tv_nsec + 10000);
timespec_diff(start, end, &diff);
- log_info("Checking 10000 == %llu", diff);
+ printf("Checking 10000 == %llu\n", diff);
if (diff != 10000) {
- log_error("Failure!");
+ printf("Failure!\n");
exit(EXIT_FAILURE);
}
timespec_set(end, start.tv_sec + 5, start.tv_nsec - 5000);
timespec_diff(start, end, &diff);
- log_info("Checking 4999995000 == %llu", diff);
+ printf("Checking 4999995000 == %llu\n", diff);
if (diff != 4999995000llu) {
- log_error("Failure!");
+ printf("Failure!\n");
exit(EXIT_FAILURE);
}
}

0 comments on commit 4d69fc8

Please sign in to comment.