diff options
Diffstat (limited to 'tests/libtest')
-rw-r--r-- | tests/libtest/.gitignore | 2 | ||||
-rw-r--r-- | tests/libtest/Makefile.am | 10 | ||||
-rw-r--r-- | tests/libtest/Makefile.inc | 4 | ||||
-rw-r--r-- | tests/libtest/chkhostname.c | 26 | ||||
-rw-r--r-- | tests/libtest/hostname.c | 32 | ||||
-rw-r--r-- | tests/libtest/sethostname.c | 28 |
6 files changed, 100 insertions, 2 deletions
diff --git a/tests/libtest/.gitignore b/tests/libtest/.gitignore index 3311a821e..cabcb671c 100644 --- a/tests/libtest/.gitignore +++ b/tests/libtest/.gitignore @@ -1,2 +1,2 @@ +chkhostname lib5[0-9][0-9] - diff --git a/tests/libtest/Makefile.am b/tests/libtest/Makefile.am index 70b0f12a4..2a0e3eaa4 100644 --- a/tests/libtest/Makefile.am +++ b/tests/libtest/Makefile.am @@ -53,6 +53,16 @@ endif EXTRA_DIST = test75.pl test307.pl test610.pl test613.pl test1013.pl \ test1022.pl Makefile.inc +if STATICLIB +# this means no shared option is enabled so we can disable the LD_PRELOAD +# attempt +libhostname_la_CFLAGS = -DDISABLE_PRELOAD +endif + +# we force our own host name, in order to make some tests machine independent +lib_LTLIBRARIES = libhostname.la +libhostname_la_SOURCES = sethostname.c + # Dependencies (may need to be overriden) LDADD = $(top_builddir)/lib/libcurl.la DEPENDENCIES = $(top_builddir)/lib/libcurl.la diff --git a/tests/libtest/Makefile.inc b/tests/libtest/Makefile.inc index 814c01e6c..28ed6831c 100644 --- a/tests/libtest/Makefile.inc +++ b/tests/libtest/Makefile.inc @@ -12,7 +12,9 @@ noinst_PROGRAMS = lib500 lib501 lib502 lib503 lib504 lib505 lib506 \ lib529 lib530 lib532 lib533 lib536 lib537 lib540 lib541 lib542 lib543 \ lib544 lib545 lib547 lib548 lib549 lib552 lib553 lib554 lib555 lib556 \ lib539 lib557 lib558 lib559 lib560 lib562 lib564 lib565 lib566 lib567 \ - lib568 lib569 lib570 lib571 lib572 lib573 + lib568 lib569 lib570 lib571 lib572 lib573 chkhostname + +chkhostname_SOURCES = chkhostname.c $(top_srcdir)/lib/curl_gethostname.c lib500_SOURCES = lib500.c $(SUPPORTFILES) diff --git a/tests/libtest/chkhostname.c b/tests/libtest/chkhostname.c new file mode 100644 index 000000000..686eb471a --- /dev/null +++ b/tests/libtest/chkhostname.c @@ -0,0 +1,26 @@ +#include "curl_gethostname.h" + +#include <stdio.h> + +#define HOSTNAME_MAX 1024 + +int main(int argc, char *argv[]) +{ + char buff[HOSTNAME_MAX]; + if (argc != 2) { + printf("Usage: %s EXPECTED_HOSTNAME\n", argv[0]); + return 1; + } + + if (Curl_gethostname(buff, HOSTNAME_MAX)) { + printf("Curl_gethostname() failed\n"); + return 1; + } + + /* compare the name returned by Curl_gethostname() with the expected one */ + if(strncmp(buff, argv[1], HOSTNAME_MAX)) { + printf("got unexpected host name back, LD_PRELOAD failed\n"); + return 1; + } + return 0; +} diff --git a/tests/libtest/hostname.c b/tests/libtest/hostname.c new file mode 100644 index 000000000..ca7fccaf8 --- /dev/null +++ b/tests/libtest/hostname.c @@ -0,0 +1,32 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + */ + +#include <string.h> +#include <unistd.h> + +#define HOSTNAME "curlhost" +#define HOSTNAME_LEN sizeof(HOSTNAME) + +/* + * we force our own host name, in order to make some tests machine independent + */ +int gethostname(char *name, size_t namelen) { + char buff[HOSTNAME_LEN + /* terminating zero */ 1]; + size_t max = (namelen < HOSTNAME_LEN) + ? namelen + : HOSTNAME_LEN; + + if(!name || !namelen) + return -1; + + strcpy(buff, HOSTNAME); + buff[max - 1] = '\0'; + strcpy(name, buff); + return 0; +}; diff --git a/tests/libtest/sethostname.c b/tests/libtest/sethostname.c new file mode 100644 index 000000000..667f689ae --- /dev/null +++ b/tests/libtest/sethostname.c @@ -0,0 +1,28 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + */ + +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#define GETHOSTNAME_ENV_VAR "CURL_GETHOSTNAME" + +/* + * we force our own host name, in order to make some tests machine independent + */ +int gethostname(char *name, size_t namelen) { + const char *force_hostname = getenv(GETHOSTNAME_ENV_VAR); + if(force_hostname) { + strncpy(name, force_hostname, namelen); + return 0; + } + + /* LD_PRELOAD used, but no hostname set, we'll just return a failure */ + return -1; +}; |