diff options
author | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2015-06-20 12:09:14 +0200 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2015-06-20 12:13:51 +0200 |
commit | 7f64118da5013d302824e9cfc89b6d89b87c90a8 (patch) | |
tree | a363958e0fc0b8f4a60ba89a6c364d54495e0e4a | |
parent | b54e6363867dd7cc94d097faca8e5f8336cfaaad (diff) | |
download | gnutls-7f64118da5013d302824e9cfc89b6d89b87c90a8.tar.gz |
tests: don't depend on gnulib
That dependency unfortunately causes many portability problems
on platforms where it should have worked out of the box.
-rw-r--r-- | tests/Makefile.am | 22 | ||||
-rw-r--r-- | tests/mini-dtls-fork.c | 10 | ||||
-rw-r--r-- | tests/mini-dtls-mtu.c | 15 | ||||
-rw-r--r-- | tests/mini-dtls-pthread.c | 12 | ||||
-rw-r--r-- | tests/mini-dtls-record-asym.c | 9 | ||||
-rw-r--r-- | tests/openpgp-auth.c | 11 | ||||
-rw-r--r-- | tests/openpgp-auth2.c | 1 | ||||
-rw-r--r-- | tests/pkcs12_simple.c | 12 | ||||
-rw-r--r-- | tests/rsa-encrypt-decrypt.c | 4 | ||||
-rw-r--r-- | tests/utils.c | 62 | ||||
-rw-r--r-- | tests/utils.h | 1 | ||||
-rw-r--r-- | tests/x509sign-verify.c | 4 | ||||
-rw-r--r-- | tests/x509sign-verify2.c | 10 |
13 files changed, 75 insertions, 98 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index 8aad0c6077..63ab1b2223 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -39,8 +39,6 @@ EXTRA_DIST = suppressions.valgrind eagain-common.h test-chains.h \ AM_CFLAGS = $(WARN_CFLAGS) $(WERROR_CFLAGS) AM_CPPFLAGS = \ - -I$(top_srcdir)/gl \ - -I$(top_builddir)/gl \ -I$(top_srcdir)/lib/includes \ -I$(top_builddir)/lib/includes \ -I$(top_srcdir)/libdane/includes \ @@ -52,7 +50,6 @@ AM_CPPFLAGS = \ AM_LDFLAGS = -no-install LDADD = ../lib/libgnutls.la \ - ../gl/libgnu.la \ libutils.la \ $(LTLIBGCRYPT) \ $(LIBSOCKET) $(INET_NTOP_LIB) $(INET_PTON_LIB) @@ -65,7 +62,6 @@ endif noinst_LTLIBRARIES = libutils.la libutils_la_SOURCES = utils.h utils.c -libutils_la_LIBADD = ../gl/libgnu.la ctests = mini-record-2 simple gc set_pkcs12_cred certder certuniqueid \ mpi certificate_set_x509_crl dn parse_ca moredn record-sizes \ @@ -127,6 +123,24 @@ endif endif +gc_CPPFLAGS = $(CPPFLAGS) \ + -I$(top_srcdir)/lib/minitasn1 \ + -I$(top_srcdir)/lib \ + -I$(top_srcdir)/gl \ + -I$(top_builddir)/gl + +mpi_CPPFLAGS = $(CPPFLAGS) \ + -I$(top_srcdir)/lib/minitasn1 \ + -I$(top_srcdir)/lib \ + -I$(top_srcdir)/gl \ + -I$(top_builddir)/gl + +pkcs12_s2k_CPPFLAGS = $(CPPFLAGS) \ + -I$(top_srcdir)/lib/minitasn1 \ + -I$(top_srcdir)/lib \ + -I$(top_srcdir)/gl \ + -I$(top_builddir)/gl + check_PROGRAMS = $(ctests) dist_check_SCRIPTS = rfc2253-escape-test diff --git a/tests/mini-dtls-fork.c b/tests/mini-dtls-fork.c index 14dcdc79e3..ec70f78231 100644 --- a/tests/mini-dtls-fork.c +++ b/tests/mini-dtls-fork.c @@ -33,10 +33,12 @@ #include <gnutls/dtls.h> #include <signal.h> #include <unistd.h> -#include <netinet/in.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <sys/wait.h> +#ifndef _WIN32 +# include <netinet/in.h> +# include <sys/types.h> +# include <sys/socket.h> +# include <sys/wait.h> +#endif #include "utils.h" #ifdef _WIN32 diff --git a/tests/mini-dtls-mtu.c b/tests/mini-dtls-mtu.c index 6d72a3dde9..6f52e336b8 100644 --- a/tests/mini-dtls-mtu.c +++ b/tests/mini-dtls-mtu.c @@ -31,9 +31,11 @@ #include <gnutls/dtls.h> #include <signal.h> #include <unistd.h> -#include <netinet/in.h> -#include <sys/types.h> -#include <sys/socket.h> +#ifndef _WIN32 +# include <netinet/in.h> +# include <sys/types.h> +# include <sys/socket.h> +#endif #include "utils.h" #define SERVER_MTU 500 @@ -285,8 +287,13 @@ static void server(int fd) void doit(void) { int fd[2]; + int err; - udp_socketpair(fd); + err = socketpair(AF_UNIX, SOCK_DGRAM, 0, fd); + if (err == -1) { + perror("socketpair"); + fail("socketpair"); + } child = fork(); if (child < 0) { diff --git a/tests/mini-dtls-pthread.c b/tests/mini-dtls-pthread.c index 62da039012..64cbba50f5 100644 --- a/tests/mini-dtls-pthread.c +++ b/tests/mini-dtls-pthread.c @@ -33,11 +33,13 @@ #include <gnutls/dtls.h> #include <signal.h> #include <unistd.h> -#include <netinet/in.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <sys/wait.h> -#include <pthread.h> +#ifndef _WIN32 +# include <netinet/in.h> +# include <sys/types.h> +# include <sys/socket.h> +# include <sys/wait.h> +# include <pthread.h> +#endif #include "utils.h" #ifdef _WIN32 diff --git a/tests/mini-dtls-record-asym.c b/tests/mini-dtls-record-asym.c index 7abd16fe67..9087dc5299 100644 --- a/tests/mini-dtls-record-asym.c +++ b/tests/mini-dtls-record-asym.c @@ -33,10 +33,6 @@ #include <gnutls/dtls.h> #include <signal.h> #include <unistd.h> -#include <netinet/in.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <sys/wait.h> #include "utils.h" #ifdef _WIN32 @@ -48,6 +44,11 @@ void doit(void) #else +#include <netinet/in.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/wait.h> + /* Tests whether packing multiple DTLS records in a single UDP packet * will be handled correctly, as well as an asymmetry in MTU sizes * between server and client. diff --git a/tests/openpgp-auth.c b/tests/openpgp-auth.c index bbbd2a85ec..bc79c223f2 100644 --- a/tests/openpgp-auth.c +++ b/tests/openpgp-auth.c @@ -27,13 +27,12 @@ #include <gnutls/openpgp.h> #include "utils.h" -#include <read-file.h> #include <unistd.h> #include <stdlib.h> -#include <sys/types.h> -#include <sys/socket.h> #if !defined(_WIN32) +# include <sys/types.h> +# include <sys/socket.h> #include <sys/wait.h> #endif #include <string.h> @@ -48,9 +47,9 @@ static const char priv_key_file[] = "../guile/tests/openpgp-sec.asc"; static const char *key_id = NULL; static gnutls_datum_t stored_cli_cert = { NULL, 0 }; -static void log_message(int level, const char *message) +static void log_message(int level, const char *msg) { - fprintf(stderr, "[%5d|%2d] %s", getpid(), level, message); + fprintf(stderr, "[%5d|%2d] %s", getpid(), level, msg); } static @@ -107,7 +106,7 @@ void check_loaded_key(gnutls_certificate_credentials_t cred) gnutls_openpgp_privkey_deinit(key); } -void doit() +void doit(void) { int err, i; int sockets[2]; diff --git a/tests/openpgp-auth2.c b/tests/openpgp-auth2.c index 1666b121b5..11fb6d578b 100644 --- a/tests/openpgp-auth2.c +++ b/tests/openpgp-auth2.c @@ -29,7 +29,6 @@ #include <gnutls/openpgp.h> #include "utils.h" -#include <read-file.h> #include <unistd.h> #include <stdlib.h> diff --git a/tests/pkcs12_simple.c b/tests/pkcs12_simple.c index f182860aaa..59738bd4f6 100644 --- a/tests/pkcs12_simple.c +++ b/tests/pkcs12_simple.c @@ -25,8 +25,8 @@ #include <config.h> #endif +#include <stdio.h> #include <stdlib.h> -#include <read-file.h> #include <gnutls/pkcs12.h> #include <gnutls/x509.h> #include "utils.h" @@ -41,8 +41,6 @@ void doit(void) #ifdef ENABLE_NON_SUITEB_CURVES const char *filename, *password = "1234"; gnutls_pkcs12_t pkcs12; - unsigned char *file_data; - size_t file_size; gnutls_datum_t data; gnutls_x509_crt_t *chain, *extras; unsigned int chain_size = 0, extras_size = 0, i; @@ -71,12 +69,10 @@ void doit(void) ("Reading PKCS#12 blob from `%s' using password `%s'.\n", filename, password); - file_data = (void *) read_binary_file(filename, &file_size); - if (file_data == NULL) + ret = gnutls_load_file(filename, &data); + if (ret < 0) fail("cannot open file"); - data.data = file_data; - data.size = file_size; ret = gnutls_pkcs12_import(pkcs12, &data, GNUTLS_X509_FMT_DER, 0); if (ret < 0) fail("pkcs12_import failed %d: %s\n", ret, @@ -146,7 +142,7 @@ void doit(void) gnutls_strerror(ret)); gnutls_x509_privkey_deinit(pkey); - free(file_data); + free(data.data); gnutls_global_deinit(); #else diff --git a/tests/rsa-encrypt-decrypt.c b/tests/rsa-encrypt-decrypt.c index 2519720a62..c303b53d04 100644 --- a/tests/rsa-encrypt-decrypt.c +++ b/tests/rsa-encrypt-decrypt.c @@ -30,9 +30,9 @@ #include <stdlib.h> #include <string.h> #include <sys/types.h> -#include <netinet/in.h> -#include <sys/socket.h> #ifndef _WIN32 +# include <netinet/in.h> +# include <sys/socket.h> # include <arpa/inet.h> #endif #include <unistd.h> diff --git a/tests/utils.c b/tests/utils.c index 5a7c6c036c..d6c54a0a1d 100644 --- a/tests/utils.c +++ b/tests/utils.c @@ -30,9 +30,17 @@ #include <time.h> #include <unistd.h> #include <errno.h> -#include <netinet/in.h> +#ifndef _WIN32 +# include <netinet/in.h> +# include <sys/socket.h> +#else +#ifdef _WIN32 +# include <windows.h> /* for Sleep */ +# include <winbase.h> +#endif + +#endif #include <sys/types.h> -#include <sys/socket.h> #include "utils.h" @@ -178,53 +186,3 @@ int main(int argc, char *argv[]) return error_count ? 1 : 0; } -static int udp_socket(void) -{ - int on = 1; - struct sockaddr_in addr = { - .sin_family = AF_INET, - .sin_addr = {htonl(INADDR_LOOPBACK)}, - .sin_port = 0 - }; - int fd; - - fd = socket(AF_INET, SOCK_DGRAM, 0); - setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char*)&on, sizeof(on)); -#if defined(SO_REUSEPORT) - setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, (char*)&on, sizeof(on)); -#endif - - if (bind(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) { - perror("bind"); - exit(EXIT_FAILURE); - } - - return fd; -} - -static void udp_connect(int fd1, int fd2) -{ - struct sockaddr_in addr; - socklen_t addrlen = sizeof(addr); - - if (getsockname(fd1, &addr, &addrlen) < 0) { - perror("getsockname"); - exit(EXIT_FAILURE); - } - - if (connect(fd2, &addr, addrlen) < 0) { - perror("connect"); - exit(EXIT_FAILURE); - } -} - -int udp_socketpair(int *fd) -{ - fd[0] = udp_socket(); - fd[1] = udp_socket(); - - udp_connect(fd[0], fd[1]); - udp_connect(fd[1], fd[0]); - - return 0; -} diff --git a/tests/utils.h b/tests/utils.h index b3f50fde13..e5949a7249 100644 --- a/tests/utils.h +++ b/tests/utils.h @@ -57,7 +57,6 @@ extern void escapeprint(const char *str, size_t len); extern void hexprint(const void *str, size_t len); extern void binprint(const void *str, size_t len); -int udp_socketpair(int *fd); void sec_sleep(int sec); /* This must be implemented elsewhere. */ diff --git a/tests/x509sign-verify.c b/tests/x509sign-verify.c index e1510b3ef1..c5850e03b1 100644 --- a/tests/x509sign-verify.c +++ b/tests/x509sign-verify.c @@ -30,9 +30,9 @@ #include <stdlib.h> #include <string.h> #include <sys/types.h> -#include <netinet/in.h> -#include <sys/socket.h> #ifndef _WIN32 +# include <netinet/in.h> +# include <sys/socket.h> # include <arpa/inet.h> #endif #include <unistd.h> diff --git a/tests/x509sign-verify2.c b/tests/x509sign-verify2.c index 5978657ab1..58395699e7 100644 --- a/tests/x509sign-verify2.c +++ b/tests/x509sign-verify2.c @@ -29,13 +29,13 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <sys/types.h> -#include <netinet/in.h> -#include <sys/socket.h> #ifndef _WIN32 -#include <arpa/inet.h> +# include <sys/types.h> +# include <netinet/in.h> +# include <sys/socket.h> +# include <arpa/inet.h> +# include <unistd.h> #endif -#include <unistd.h> #include <gnutls/gnutls.h> #include <gnutls/x509.h> #include <gnutls/abstract.h> |