From 69c6d0694b17fec92e12e86bed4d1afd57b04882 Mon Sep 17 00:00:00 2001 From: "W.C.A. Wijngaards" Date: Fri, 29 Nov 2013 15:41:06 +0100 Subject: [PATCH 01/10] fix issue #38: install, uninstall, libtool, configureoutsidesrcdir, the dist compiles. library version set to 0:0:0. --- Makefile.in | 13 +++++++++++++ README.md | 13 ++++++++++--- configure.ac | 32 +++++++++++++++++++++++++++--- depcomp | 1 - doc/Makefile.in | 25 ++++++++++++++++++++++-- src/Makefile.in | 43 +++++++++++++++++++++++++++++++++++------ src/example/Makefile.in | 16 ++++++++++++++- src/test/Makefile.in | 8 +++++++- 8 files changed, 134 insertions(+), 17 deletions(-) delete mode 120000 depcomp diff --git a/Makefile.in b/Makefile.in index b6c9558a..31ed9521 100644 --- a/Makefile.in +++ b/Makefile.in @@ -20,6 +20,14 @@ default: all : default +install: all + cd src && $(MAKE) $@ + cd doc && $(MAKE) $@ + +uninstall: + cd src && $(MAKE) $@ + cd doc && $(MAKE) $@ + doc: cd doc && $(MAKE) $@ @@ -44,13 +52,16 @@ $(distdir): mkdir -p $(distdir)/src/getdns mkdir -p $(distdir)/src/test mkdir -p $(distdir)/src/example + mkdir -p $(distdir)/doc cp $(srcdir)/configure.ac $(distdir) cp $(srcdir)/configure $(distdir) cp $(srcdir)/Makefile.in $(distdir) cp $(srcdir)/install-sh $(distdir) cp $(srcdir)/config.sub $(distdir) cp $(srcdir)/config.guess $(distdir) + cp $(srcdir)/ltmain.sh $(distdir) cp $(srcdir)/src/Makefile.in $(distdir)/src + cp $(srcdir)/src/Doxyfile.in $(distdir)/src cp $(srcdir)/src/*.[ch] $(distdir)/src cp $(srcdir)/src/getdns/*.in $(distdir)/src/getdns cp $(srcdir)/src/getdns/*.h $(distdir)/src/getdns @@ -59,6 +70,8 @@ $(distdir): cp $(srcdir)/src/test/*.can $(distdir)/src/test cp $(srcdir)/src/example/Makefile.in $(distdir)/src/example cp $(srcdir)/src/example/*.c $(distdir)/src/example + cp $(srcdir)/doc/Makefile.in $(distdir)/doc + cp $(srcdir)/doc/*.in $(distdir)/doc distcheck: $(distdir).tar.gz gzip -cd $(distdir).tar.gz | tar xvf - diff --git a/README.md b/README.md index 83bcd51e..843dc94b 100644 --- a/README.md +++ b/README.md @@ -49,18 +49,25 @@ External Dependencies External dependencies are linked outside the getdns API build tree (we rely on configure to find them). We would like to keep the dependency tree short. * [libevent](http://libevent.org) version 2.0.21 stable +Sometimes called libevent2 * [libldns from NL](https://www.nlnetlabs.nl/projects/ldns/) version 1.6.16 (ldns may require openssl headers and libraries) * [libunbound from NL](http://www.nlnetlabs.nl/projects/unbound/) svn revision 3012, configure must be run with the --with-libevent option (recommended to also use --with-libunbound-only). +* [libexpat](http://expat.sourceforge.net/) for libunbound. * [libidn from the FSF](http://www.gnu.org/software/libidn/) version 1. * Doxygen is used to generate documentation, while this is not technically necessary for the build it makes things a lot more pleasant. -Assuming that the getdns sources are in a diretory named getdns in your home directory, to build libunbound (note that the svn checkout may take a while): +You have to install the library and also the library-devel (or -dev) for your +package management system to install the compile time files. If you checked +out our git; the configure script is built with autoreconf --install. + +Assuming that the getdns sources are in a diretory named getdns in your home directory, to build libunbound: ``` # mkdir unbound # cd unbound -# svn checkout -r 3012 http://unbound.nlnetlabs.nl/svn -# cd svn/trunk +# svn export -r 3012 http://unbound.nlnetlabs.nl/svn/trunk +# cd trunk # ./configure --with-libevent --with-libunbound-only +### add --disable-gost --disable-ecdsa if elliptic curves are disabled for you. # make # make install ``` diff --git a/configure.ac b/configure.ac index 01fb2afe..6446c720 100644 --- a/configure.ac +++ b/configure.ac @@ -5,7 +5,7 @@ # @configure_input@ # -AC_PREREQ([2.68]) +AC_PREREQ([2.56]) AC_INIT([getdns], [0.1.0], [melinda.shore@nomountain.net]) AC_CONFIG_SRCDIR([src/getdns/getdns.h]) # AM_INIT_AUTOMAKE @@ -24,6 +24,34 @@ esac AC_PROG_CC AC_PROG_CPP +# always use ./libtool unless override from commandline (libtool=mylibtool) +if test -z "$libtool"; then + libtool="`pwd`/libtool" +fi +AC_SUBST(libtool) +AC_PROG_LIBTOOL +AC_PROG_INSTALL + +dnl Add option to disable the evil rpath. Check whether to use rpath or not. +dnl Adds the --disable-rpath option. Uses trick to edit the ./libtool. +AC_DEFUN([ACX_ARG_RPATH], +[ +AC_ARG_ENABLE(rpath, + [ --disable-rpath disable hardcoded rpath (default=enabled)], + enable_rpath=$enableval, enable_rpath=yes) +if test "x$enable_rpath" = xno; then + dnl AC_MSG_RESULT([Fixing libtool for -rpath problems.]) + AC_CONFIG_COMMANDS([disable-rpath], [ + sed < libtool > libtool-2 \ + 's/^hardcode_libdir_flag_spec.*$'/'hardcode_libdir_flag_spec=" -D__LIBTOOL_RPATH_SED__ "/' + mv libtool-2 libtool + chmod 755 libtool + libtool="./libtool" + ]) +fi +]) +ACX_ARG_RPATH + # Checks for libraries. found_all_libs=1 AC_MSG_NOTICE([Checking for dependencies libevent, ldns]) @@ -66,6 +94,4 @@ AC_CONFIG_FILES([Makefile src/Makefile src/getdns/Makefile src/example/Makefile if [ test -n "$DOXYGEN" ] then AC_CONFIG_FILES([src/Doxyfile]) fi - -AC_CONFIG_SUBDIRS([src/ src/getdns/ src/example/ src/test/ doc/]) AC_OUTPUT diff --git a/depcomp b/depcomp deleted file mode 120000 index 61f3df73..00000000 --- a/depcomp +++ /dev/null @@ -1 +0,0 @@ -/usr/local/share/automake-1.12/depcomp \ No newline at end of file diff --git a/doc/Makefile.in b/doc/Makefile.in index 1e705add..101cc9e0 100644 --- a/doc/Makefile.in +++ b/doc/Makefile.in @@ -10,21 +10,42 @@ distdir = $(tarname)-$(version) prefix = @prefix@ exec_prefix = @exec_prefix@ bindir = @bindir@ +# datarootdir is here to please some checkers +datarootdir=@datarootdir@ +mandir = @mandir@ +INSTALL = @INSTALL@ srcdir = @srcdir@ VPATH = @srcdir@ DOCDIRS = html latex man +MANPAGES = libgetdns.3 getdns_address.3 default: all all: doc -doc: +doc: $(MANPAGES) cd ../src && doxygen +libgetdns.3: libgetdns.3.in + cp $< $@ + +getdns_address.3: getdns_address.3.in + cp $< $@ + +install: $(MANPAGES) + $(INSTALL) -m 755 -d $(DESTDIR)$(mandir) + $(INSTALL) -m 755 -d $(DESTDIR)$(mandir)/man3 + $(INSTALL) -m 644 libgetdns.3 $(DESTDIR)$(mandir)/man3 + $(INSTALL) -m 644 getdns_address.3 $(DESTDIR)$(mandir)/man3 + +uninstall: + rm -f $(DESTDIR)$(mandir)/man3/libgetdns.3 + rm -f $(DESTDIR)$(mandir)/man3/getdns_address.3 + clean: - rm -rf $(DOCDIRS) + rm -rf $(DOCDIRS) $(MANPAGES) distclean : clean rm -f Makefile config.status config.log diff --git a/src/Makefile.in b/src/Makefile.in index 33fd5d59..abe998c7 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -7,9 +7,23 @@ version = @PACKAGE_VERSION@ tarname = @PACKAGE_TARNAME@ distdir = $(tarname)-$(version) +# current:revision:age +# (binary-api-number):(which-binary-api-version):(how-many-nrs-backwardscompat) +# if api unchanged: no changes +# if api broken: current++ ; revision = 0; age = 0 +# if programs compiled against existing library work and link with new +# version of library with new binary api: revision++; age++ +libversion = 0:0:0 + prefix = @prefix@ exec_prefix = @exec_prefix@ bindir = @bindir@ +libdir = @libdir@ +includedir = @includedir@ +# datarootdir is here to please some checkers +datarootdir=@datarootdir@ +INSTALL = @INSTALL@ +LIBTOOL = @libtool@ srcdir = @srcdir@ VPATH = @srcdir@ @@ -17,27 +31,44 @@ VPATH = @srcdir@ CC=gcc CFLAGS=@CFLAGS@ -Wall -g -fPIC -I$(srcdir)/ -I/usr/local/include -std=c99 LDFLAGS=@LDFLAGS@ -levent_core -lldns -lunbound -lidn -# PROGRAMS=example-simple-answers example-tree example-all-functions example-synchronous +GETDNS_OBJ=sync.lo context.lo list.lo dict.lo convert.lo general.lo \ + hostname.lo service.lo request-internal.lo validate_dnssec.lo \ + util-internal.lo getdns_error.lo .SUFFIXES: .c .o .a .lo .h .c.o: $(CC) $(CFLAGS) -c $< -o $@ +.c.lo: + $(LIBTOOL) --quiet --tag=CC --mode=compile $(CC) $(CFLAGS) -c $< -o $@ + default: all -all: libgetdns.so +all: libgetdns.la cd test && $(MAKE) $@ cd example && $(MAKE) $@ -libgetdns.so: sync.o context.o list.o dict.o convert.o general.o hostname.o service.o request-internal.o \ - validate_dnssec.o util-internal.o getdns_error.o - $(CC) $(CFLAGS) -shared -o $@ $? $(LDFLAGS) +install: libgetdns.la + $(INSTALL) -m 755 -d $(DESTDIR)$(includedir) + $(INSTALL) -m 755 -d $(DESTDIR)$(includedir)/getdns + $(INSTALL) -m 644 $(srcdir)/getdns/getdns.h $(DESTDIR)$(includedir)/getdns/getdns.h + $(INSTALL) -m 755 -d $(DESTDIR)$(libdir) + $(LIBTOOL) --mode=install cp libgetdns.la $(DESTDIR)$(libdir) + $(LIBTOOL) --mode=finish $(DESTDIR)$(libdir) + +uninstall: + rm -f $(DESTDIR)$(includedir)/getdns/getdns.h + $(LIBTOOL) --mode=uninstall rm -f $(DESTDIR)$(libdir)/libgetdns.la + +libgetdns.la: $(GETDNS_OBJ) + $(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) -o $@ $(GETDNS_OBJ) $(LDFLAGS) -rpath $(libdir) -version-info $(libversion) -no-undefined clean: cd test && $(MAKE) $@ cd example && $(MAKE) $@ - rm -f *.o $(PROGRAMS) libgetdns.so + rm -f *.o *.lo $(PROGRAMS) libgetdns.la + rm -rf .libs distclean : clean cd test && $(MAKE) $@ diff --git a/src/example/Makefile.in b/src/example/Makefile.in index 8ee83bd3..96d5d537 100644 --- a/src/example/Makefile.in +++ b/src/example/Makefile.in @@ -10,13 +10,14 @@ distdir = $(tarname)-$(version) prefix = @prefix@ exec_prefix = @exec_prefix@ bindir = @bindir@ +LIBTOOL = @libtool@ srcdir = @srcdir@ VPATH = @srcdir@ CC=gcc CFLAGS=@CFLAGS@ -Wall -g -fPIC -I$(srcdir)/ -I$(srcdir)/../ -I/usr/local/include -std=c99 -LDFLAGS=@LDFLAGS@ -L. -L$(srcdir)/.. -L/usr/local/lib +LDFLAGS=@LDFLAGS@ -L. -L.. -L/usr/local/lib LDLIBS=-lgetdns -lldns -levent_core -lunbound PROGRAMS=example_simple_answers example_tree example_all_functions example_synchronous @@ -29,8 +30,21 @@ default: all all: $(PROGRAMS) +example_simple_answers: example_simple_answers.o + $(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ example_simple_answers.o + +example_tree: example_tree.o + $(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ example_tree.o + +example_all_functions: example_all_functions.o + $(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ example_all_functions.o + +example_synchronous: example_synchronous.o + $(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ example_synchronous.o + clean: rm -f *.o $(PROGRAMS) + rm -rf .libs distclean : clean rm -f Makefile config.status config.log diff --git a/src/test/Makefile.in b/src/test/Makefile.in index d4964d4a..35df2342 100644 --- a/src/test/Makefile.in +++ b/src/test/Makefile.in @@ -10,13 +10,14 @@ distdir = $(tarname)-$(version) prefix = @prefix@ exec_prefix = @exec_prefix@ bindir = @bindir@ +LIBTOOL = @libtool@ srcdir = @srcdir@ VPATH = @srcdir@ CC=gcc CFLAGS=@CFLAGS@ -Wall -g -fPIC -I$(srcdir)/ -I$(srcdir)/../ -I/usr/local/include -std=c99 $(cflags) -LDFLAGS=@LDFLAGS@ -L. -L$(srcdir)/.. -L/usr/local/lib +LDFLAGS=@LDFLAGS@ -L. -L.. -L/usr/local/lib LDLIBS=-lgetdns -lldns -levent_core -lunbound PROGRAMS=tests_dict tests_list tests_stub_async tests_stub_sync @@ -30,15 +31,20 @@ default: all all: $(PROGRAMS) tests_dict: tests_dict.o testmessages.o + $(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ tests_dict.o testmessages.o tests_list: tests_list.o testmessages.o + $(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ tests_list.o testmessages.o tests_stub_async: tests_stub_async.o testmessages.o + $(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ tests_stub_async.o testmessages.o tests_stub_sync: tests_stub_sync.o + $(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ tests_stub_sync.o clean: rm -f *.o $(PROGRAMS) + rm -rf .libs distclean : clean rm -f Makefile config.status config.log From b392679ce4137e72e29b88ee6d0d925b0963e3ca Mon Sep 17 00:00:00 2001 From: "W.C.A. Wijngaards" Date: Fri, 29 Nov 2013 16:24:39 +0100 Subject: [PATCH 02/10] make test and a testscript and output comparisons. --- Makefile.in | 5 +- src/Makefile.in | 5 +- src/test/Makefile.in | 6 +- src/test/tests_dict.good | 85 ++++++++++++++++++++++++ src/test/tests_list.good | 78 ++++++++++++++++++++++ src/test/tests_stub_async.c | 2 +- src/test/tests_stub_async.good | 72 ++++++++++++++++++++ src/test/tests_stub_sync.good | 116 +++++++++++++++++++++++++++++++++ src/test/testscript.sh | 51 +++++++++++++++ 9 files changed, 416 insertions(+), 4 deletions(-) create mode 100644 src/test/tests_dict.good create mode 100644 src/test/tests_list.good create mode 100644 src/test/tests_stub_async.good create mode 100644 src/test/tests_stub_sync.good create mode 100755 src/test/testscript.sh diff --git a/Makefile.in b/Makefile.in index 31ed9521..d4212263 100644 --- a/Makefile.in +++ b/Makefile.in @@ -31,6 +31,9 @@ uninstall: doc: cd doc && $(MAKE) $@ +test: + cd src && $(MAKE) $@ + clean: cd src && $(MAKE) $@ cd doc && $(MAKE) $@ @@ -95,4 +98,4 @@ Makefile: Makefile.in config.status configure.status: configure ./config.status --recheck -.PHONY: all distclean clean default doc +.PHONY: all distclean clean default doc test diff --git a/src/Makefile.in b/src/Makefile.in index abe998c7..8ff1f827 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -64,6 +64,9 @@ uninstall: libgetdns.la: $(GETDNS_OBJ) $(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) -o $@ $(GETDNS_OBJ) $(LDFLAGS) -rpath $(libdir) -version-info $(libversion) -no-undefined +test: libgetdns.la + cd test && $(MAKE) $@ + clean: cd test && $(MAKE) $@ cd example && $(MAKE) $@ @@ -105,4 +108,4 @@ Makefile: Makefile.in ../config.status configure.status: configure cd .. && ./config.status --recheck -.PHONY: clean +.PHONY: clean test diff --git a/src/test/Makefile.in b/src/test/Makefile.in index 35df2342..f58331d4 100644 --- a/src/test/Makefile.in +++ b/src/test/Makefile.in @@ -42,6 +42,10 @@ tests_stub_async: tests_stub_async.o testmessages.o tests_stub_sync: tests_stub_sync.o $(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ tests_stub_sync.o +test: + ./testscript.sh + @echo "All tests OK" + clean: rm -f *.o $(PROGRAMS) rm -rf .libs @@ -79,4 +83,4 @@ Makefile: Makefile.in ../../config.status configure.status: configure cd ../.. && ./config.status --recheck -.PHONY: clean +.PHONY: clean test diff --git a/src/test/tests_dict.good b/src/test/tests_dict.good new file mode 100644 index 00000000..4ea6186c --- /dev/null +++ b/src/test/tests_dict.good @@ -0,0 +1,85 @@ +TESTPROG tests_dict START +TESTCASE tests_dict:tst_create BEGIN + tests_dict:tst_create: getdns_dict_create + tests_dict:tst_create: getdns_dict_destroy(dict) + tests_dict:tst_create: getdns_dict_destroy(NULL) +TESTCASE tests_dict:tst_create END +TESTCASE tests_dict:tst_bindatasetget BEGIN + tests_dict:tst_bindatasetget: getdns_dict_get_bindata() empty dict + tests_dict:tst_bindatasetget: line 63: getdns_dict_get_bindata(NULL, key, &ans_bdata),retval = 305 + tests_dict:tst_bindatasetget: line 69: getdns_dict_get_bindata(dict, key, NULL),retval = 305 + tests_dict:tst_bindatasetget: getdns_dict_get_bindata(dict, NULL, &ans_bindata) + tests_dict:tst_bindatasetget: line 74: getdns_dict_get_bindata,retval = 305 + tests_dict:tst_bindatasetget: getdns_dict_get_bindata(dict, key, &ans_bdata) + tests_dict:tst_bindatasetget: line 80: getdns_list_get_bindata,retval = 306 + tests_dict:tst_bindatasetget: getdns_dict_set_bindata(dict, key, bindata) + tests_dict:tst_bindatasetget: line 101: getdns_dict_set_bindata,retval=0,key=foo + tests_dict:tst_bindatasetget: getdns_dict_get_bindata(dict, key, &ans_bdata) + tests_dict:tst_bindatasetget: line 108: getdns_dict_get_bindata,retval=0,key=foo,data=foobar +TESTCASE tests_dict:tst_bindatasetget END +TESTCASE tests_dict:tst_dictsetget BEGIN + tests_dict:tst_dictsetget: getdns_dict_get_dict() empty dict + tests_dict:tst_dictsetget: line 148: getdns_dict_get_dict(NULL, key, &ansdict),retval = 305 + tests_dict:tst_dictsetget: line 154: getdns_dict_get_dict(dict, key, NULL),retval = 305 + tests_dict:tst_dictsetget: getdns_dict_get_dict(dict, NULL, &ansdict) + tests_dict:tst_dictsetget: line 159: getdns_dict_get_dict,retval = 305 + tests_dict:tst_dictsetget: getdns_dict_get_dict(dict, key, &ansdict) + tests_dict:tst_dictsetget: line 165: getdns_list_get_dict,retval = 305 + tests_dict:tst_dictsetget: getdns_dict_set_dict(dict, key, newdict) + tests_dict:tst_dictsetget: line 185: getdns_dict_set_dict,retval=0,key=foo + tests_dict:tst_dictsetget: getdns_dict_get_dict(dict, key, &ansdict) + tests_dict:tst_dictsetget: line 195: getdns_dict_get_dict,retval=0,key=foo,int1=42,int2=52 +TESTCASE tests_dict:tst_dictsetget END +TESTCASE tests_dict:tst_intsetget BEGIN + tests_dict:tst_intsetget: getdns_dict_get_int() empty dict + tests_dict:tst_intsetget: line 410: getdns_dict_get_int(NULL, key, &ans_int),retval = 305 + tests_dict:tst_intsetget: line 416: getdns_dict_get_int(dict, key, NULL),retval = 305 + tests_dict:tst_intsetget: getdns_dict_get_int(dict, NULL, &ans_int) + tests_dict:tst_intsetget: line 421: getdns_dict_get_int,retval = 305 + tests_dict:tst_intsetget: getdns_dict_get_int(dict, key, &ans_int) + tests_dict:tst_intsetget: line 427: getdns_list_get_int,retval = 306 + tests_dict:tst_intsetget: getdns_dict_set_int(dict, key, newint) + tests_dict:tst_intsetget: line 445: getdns_dict_set_int,retval=0,key=foo,int=42 + tests_dict:tst_intsetget: getdns_dict_get_int(dict, key, &ans_int) + tests_dict:tst_intsetget: line 451: getdns_dict_get_int,retval=0,key=foo,int=42 + tests_dict:tst_intsetget: getdns_dict_set_int(dict, key, newint) + tests_dict:tst_intsetget: line 459: getdns_dict_set_int,retval=0,key=bar,int=52 + tests_dict:tst_intsetget: getdns_dict_get_int(dict, key, &ans_int) + tests_dict:tst_intsetget: line 465: getdns_dict_get_int,retval=0,key=bar,int=52 + tests_dict:tst_intsetget: getdns_dict_get_data_type(dict, key, &dtype) + tests_dict:tst_intsetget: line 472: getdns_dict_get_data_type,retval=0,key=bar,dtype=2 +TESTCASE tests_dict:tst_intsetget END +TESTCASE tests_dict:tst_listsetget BEGIN + tests_dict:tst_listsetget: getdns_dict_get_list() empty dict + tests_dict:tst_listsetget: line 324: getdns_dict_get_list(NULL, key, &anslist),retval = 305 + tests_dict:tst_listsetget: line 330: getdns_dict_get_list(dict, key, NULL),retval = 305 + tests_dict:tst_listsetget: getdns_dict_get_list(dict, NULL, &anslist) + tests_dict:tst_listsetget: line 335: getdns_dict_get_list,retval = 305 + tests_dict:tst_listsetget: getdns_dict_get_list(dict, key, &anslist) + tests_dict:tst_listsetget: line 341: getdns_list_get_list,retval = 306 + tests_dict:tst_listsetget: getdns_dict_set_list(dict, key, newlist) + tests_dict:tst_listsetget: line 363: getdns_dict_set_list,retval=0,key=foo + tests_dict:tst_listsetget: getdns_dict_get_list(dict, key, &anslist) + tests_dict:tst_listsetget: line 373: getdns_dict_get_list,retval=0,key=foo,int1=42,int2=52 +TESTCASE tests_dict:tst_listsetget END +TESTCASE tests_dict:tst_getnames BEGIN + tests_dict:tst_getnames: getdns_dict_get_names(NULL, &list) + tests_dict:tst_getnames: getdns_dict_get_names(dict, NULL) + tests_dict:tst_getnames: getdns_dict_get_names(dict, &list), empty dictionary + list item 0: NOTIMPLEMENTED list item 1: NOTIMPLEMENTED list item 2: NOTIMPLEMENTED list item 3: NOTIMPLEMENTEDTESTCASE tests_dict:tst_getnames END +TESTCASE tests_dict:tst_copy BEGIN + tests_dict:tst_copy: empty list cases + tests_dict:tst_copy: dict1 populate +{ + "bar": 52, + "foo": 42, + "quz": 62 +} + tests_dict:tst_copy: getdns_dict_copy(dict1, &dict2) +{ + "bar": 52, + "foo": 42, + "quz": 62 +} +TESTCASE tests_dict:tst_copy END +TESTPROG tests_dict END diff --git a/src/test/tests_list.good b/src/test/tests_list.good new file mode 100644 index 00000000..009e66be --- /dev/null +++ b/src/test/tests_list.good @@ -0,0 +1,78 @@ +TESTPROG tests_list START +TESTCASE tests_list:tst_create BEGIN + tests_list:tst_create: getdns_list_create + tests_list:tst_create: getdns_list_destroy(list) + tests_list:tst_create: getdns_list_destroy(NULL) + tests_list:tst_create: getdns_add_item(list) past block size + tests_list:tst_create: getdns_list_get_length(list) + tests_list:tst_create: list length = 12 + tests_list:tst_create: getdns_list_get_length() + tests_list:tst_create: NUll, 12, retval = 304 + tests_list:tst_create: NUll, NULL, retval = 304 + tests_list:tst_create: list, NULL, retval = 304 +TESTCASE tests_list:tst_create END +TESTCASE tests_list:tst_bindatasetget BEGIN + tests_list:tst_bindatasetget: getdns_list_get_bindata() empty list + tests_list:tst_bindatasetget: getdns_list_get_bindata(NULL, index, &ans_bindata),retval = 304 + tests_list:tst_bindatasetget: getdns_list_get_bindata(list, index, NULL),retval = 304 + tests_list:tst_bindatasetget: getdns_list_get_bindata(list, 0, &ans_bindata) + tests_list:tst_bindatasetget: getdns_list_get_bindata,retval = 304 + tests_list:tst_bindatasetget: getdns_list_get_bindata(list, 1, &ans_bindata) + tests_list:tst_bindatasetget: getdns_list_get_bindata,retval = 304 + tests_list:tst_bindatasetget: getdns_list_set_bindata() empty list + tests_list:tst_bindatasetget: getdns_list_set_bindata(NULL, index, ans_bindata),retval = 304 + tests_list:tst_bindatasetget: getdns_list_set_bindata(list, 0, ans_bindata) + tests_list:tst_bindatasetget: getdns_list_set_bindata,retval = 304 + tests_list:tst_bindatasetget: getdns_list_set_bindata(list, 1, ans_bindata) + tests_list:tst_bindatasetget: getdns_list_set_bindata,retval = 304 + tests_list:tst_bindatasetget: getdns_list_set/get_bindata,retval = 0, bindata->data = 7,foobar +TESTCASE tests_list:tst_bindatasetget END +TESTCASE tests_list:tst_dictsetget BEGIN + tests_list:tst_dictsetget: getdns_list_get_dict() empty list + tests_list:tst_dictsetget: getdns_list_get_dict(NULL, index, &dict),retval = 304 + tests_list:tst_dictsetget: getdns_list_get_dict(list, index, NULL),retval = 304 + tests_list:tst_dictsetget: getdns_list_get_dict(list, 0, &dict) + tests_list:tst_dictsetget: getdns_list_get_dict,retval = 304 + tests_list:tst_dictsetget: getdns_list_get_dict(list, 1, &dict) + tests_list:tst_dictsetget: getdns_list_get_dict,retval = 304 + tests_list:tst_dictsetget: getdns_list_set_dict() empty list + tests_list:tst_dictsetget: getdns_list_set_dict(NULL, index, dict),retval = 304 + tests_list:tst_dictsetget: getdns_list_set_dict(list, 0, dict) + tests_list:tst_dictsetget: getdns_list_set_dict,retval = 304 + tests_list:tst_dictsetget: getdns_list_set_dict(list, 1, dict) + tests_list:tst_dictsetget: getdns_list_set_dict,retval = 304 + tests_list:tst_dictsetget: getdns_list_set/get_dict,retval=0, ans=42 +TESTCASE tests_list:tst_dictsetget END +TESTCASE tests_list:tst_intsetget BEGIN + tests_list:tst_intsetget: getdns_list_get_int() empty list + tests_list:tst_intsetget: getdns_list_get_int(NULL, index, &ans_int),retval = 304 + tests_list:tst_intsetget: getdns_list_get_int(list, index, NULL),retval = 304 + tests_list:tst_intsetget: getdns_list_get_int(list, 0, &ans_int) + tests_list:tst_intsetget: getdns_list_get_int,retval = 304 + tests_list:tst_intsetget: getdns_list_get_int(list, 1, &ans_int) + tests_list:tst_intsetget: getdns_list_get_int,retval = 304 + tests_list:tst_intsetget: getdns_list_set_int() empty list + tests_list:tst_intsetget: getdns_list_set_int(NULL, index, ans_int),retval = 304 + tests_list:tst_intsetget: getdns_list_set_int(list, 0, ans_int) + tests_list:tst_intsetget: getdns_list_set_int,retval = 304 + tests_list:tst_intsetget: getdns_list_set_int(list, 1, ans_int) + tests_list:tst_intsetget: getdns_list_set_int,retval = 304 + tests_list:tst_intsetget: getdns_list_set/get_int,retval = 0, ans = 42 +TESTCASE tests_list:tst_intsetget END +TESTCASE tests_list:tst_listsetget BEGIN + tests_list:tst_listsetget: getdns_list_get_list() empty list + tests_list:tst_listsetget: getdns_list_get_list(NULL, index, &ans_list),retval = 304 + tests_list:tst_listsetget: getdns_list_get_list(list, index, NULL),retval = 304 + tests_list:tst_listsetget: getdns_list_get_list(list, 0, &ans_list) + tests_list:tst_listsetget: getdns_list_get_list,retval = 304 + tests_list:tst_listsetget: getdns_list_get_list(list, 1, &ans_list) + tests_list:tst_listsetget: getdns_list_get_list,retval = 304 + tests_list:tst_listsetget: getdns_list_set_list() empty list + tests_list:tst_listsetget: getdns_list_set_list(NULL, index, ans_list),retval = 304 + tests_list:tst_listsetget: getdns_list_set_list(list, 0, ans_list) + tests_list:tst_listsetget: getdns_list_set_list,retval = 304 + tests_list:tst_listsetget: getdns_list_set_list(list, 1, ans_list) + tests_list:tst_listsetget: getdns_list_set_list,retval = 304 + tests_list:tst_listsetget: getdns_list_set/get_list,retval = 0, ans[0] = 42 +TESTCASE tests_list:tst_listsetget END +TESTPROG tests_list END diff --git a/src/test/tests_stub_async.c b/src/test/tests_stub_async.c index d03d5931..287ce8a4 100644 --- a/src/test/tests_stub_async.c +++ b/src/test/tests_stub_async.c @@ -42,7 +42,7 @@ this_callbackfn(struct getdns_context_t *this_context, { if (this_callback_type == GETDNS_CALLBACK_COMPLETE) { /* This is a callback with data */ char *res = getdns_pretty_print_dict(this_response); - fprintf(stdout, "%s", res); + fprintf(stdout, "%s\n", res); getdns_dict_destroy(this_response); free(res); diff --git a/src/test/tests_stub_async.good b/src/test/tests_stub_async.good new file mode 100644 index 00000000..6f90de20 --- /dev/null +++ b/src/test/tests_stub_async.good @@ -0,0 +1,72 @@ +{ + "answer_type": 800, + "canonical_name": , + "just_address_answers": + [ + , + , + + ], + "replies_full": + [ + + ], + "replies_tree": + [ + { + "additional": [], + "answer": + [ + { + "class": 1, + "name": , + "rdata": + { + "ipv4_address": , + "rdata_raw": + }, + "ttl": 300, + "type": 1 + }, + { + "class": 1, + "name": , + "rdata": + { + "ipv4_address": , + "rdata_raw": + }, + "ttl": 300, + "type": 1 + }, + { + "class": 1, + "name": , + "rdata": + { + "ipv4_address": , + "rdata_raw": + }, + "ttl": 300, + "type": 1 + } + ], + "answer_type": 800, + "authority": [], + "canonical_name": , + "header": + { + "id": 0, + "opcode": 0, + "qr": 1 + }, + "question": + { + "qclass": 1, + "qname": , + "qtype": 1 + } + } + ], + "status": 900 +} diff --git a/src/test/tests_stub_sync.good b/src/test/tests_stub_sync.good new file mode 100644 index 00000000..f736c265 --- /dev/null +++ b/src/test/tests_stub_sync.good @@ -0,0 +1,116 @@ +The packet { + "answer_type": 800, + "canonical_name": , + "just_address_answers": + [ + , + , + + ], + "replies_full": + [ + + ], + "replies_tree": + [ + { + "additional": [], + "answer": + [ + { + "class": 1, + "name": , + "rdata": + { + "ipv4_address": , + "rdata_raw": + }, + "ttl": 264, + "type": 1 + }, + { + "class": 1, + "name": , + "rdata": + { + "ipv4_address": , + "rdata_raw": + }, + "ttl": 264, + "type": 1 + }, + { + "class": 1, + "name": , + "rdata": + { + "ipv4_address": , + "rdata_raw": + }, + "ttl": 264, + "type": 1 + } + ], + "answer_type": 800, + "authority": [], + "canonical_name": , + "header": + { + "id": 0, + "opcode": 0, + "qr": 1 + }, + "question": + { + "qclass": 1, + "qname": , + "qtype": 1 + } + } + ], + "status": 900 +} +The packet { + "answer_type": 800, + "canonical_name": , + "just_address_answers": [], + "replies_full": + [ + + ], + "replies_tree": + [ + { + "additional": [], + "answer": [], + "answer_type": 800, + "authority": + [ + { + "class": 1, + "name": , + "rdata": + { + "rdata_raw": + }, + "ttl": 40, + "type": 6 + } + ], + "canonical_name": , + "header": + { + "id": 0, + "opcode": 0, + "qr": 1 + }, + "question": + { + "qclass": 1, + "qname": , + "qtype": 33 + } + } + ], + "status": 900 +} diff --git a/src/test/testscript.sh b/src/test/testscript.sh new file mode 100755 index 00000000..d87bab28 --- /dev/null +++ b/src/test/testscript.sh @@ -0,0 +1,51 @@ +#!/bin/sh + +# run $1 > $2 and exit on failure to execute +function runit () { + echo -n "Test $1:" + ./$1 > $2 + if test $? -ne 0; then + echo " failed (execution failed)" + exit 1 + fi +} + +# check output files $1 and $2, exit on failure +function diffit () { + if diff $1 $2; then + echo " OK" + else + echo " failed (differences above)" + exit 1 + fi +} + +# check output of program $1, known_good must be in $1.good +function checkoutput () { + runit $1 output + diffit output $1.good +} + +# filter out TTL and bindata stuff from $1 to $2 +function filterout() { + sed -e '/"ttl"/d' -e '/"ipv4_address"/d' -e '/"ipv6_address"/d' -e '/"rdata_raw"/d' -e '/$2 +} + +# like checkoutput but removes addresses and TTLs and bindata +# this makes the test almost useless, but it tests runtime lookup +# and the structure of the answer format, against the live internet. +function checkpacket () { + runit $1 output + cp $1.good output.good + filterout output output2 + filterout output.good output2.good + diffit output2 output2.good +} + +checkoutput tests_dict +checkoutput tests_list +checkpacket tests_stub_async +checkpacket tests_stub_sync + +rm -f output output.good output2 output2.good +exit 0 From c349bdb70facde3899a334fabd45fdfc047ee668 Mon Sep 17 00:00:00 2001 From: "W.C.A. Wijngaards" Date: Fri, 29 Nov 2013 16:33:01 +0100 Subject: [PATCH 03/10] OpenBSD port: search in libevent_core and libevent --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 6446c720..17a67058 100644 --- a/configure.ac +++ b/configure.ac @@ -55,7 +55,7 @@ ACX_ARG_RPATH # Checks for libraries. found_all_libs=1 AC_MSG_NOTICE([Checking for dependencies libevent, ldns]) -AC_CHECK_LIB([event_core], [event_base_new], [], [found_all_libs=0]) +AC_SEARCH_LIBS([event_base_new], [event_core event], [], [found_all_libs=0]) AC_CHECK_LIB([ldns], [ldns_dname_new_frm_str], [], [found_all_libs=0]) AC_CHECK_LIB([idn], [idna_to_ascii_8z], [], [found_all_libs=0]) From be9e180b28f7396b79dd6b0bca4383ecd84a709b Mon Sep 17 00:00:00 2001 From: "W.C.A. Wijngaards" Date: Fri, 29 Nov 2013 17:03:01 +0100 Subject: [PATCH 04/10] Searches, --with-libidn, libunbound, libldns. --- configure.ac | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/configure.ac b/configure.ac index 17a67058..cc7022e9 100644 --- a/configure.ac +++ b/configure.ac @@ -52,6 +52,64 @@ fi ]) ACX_ARG_RPATH +# search to set include and library paths right +# find libidn +AC_ARG_WITH(libidn, AC_HELP_STRING([--with-libidn=pathname], + [path to libidn (default: search /usr/local ..)]), + [], [withval="yes"]) +if test x_$withval = x_yes; then + for dir in /usr/local /opt/local /usr/pkg /usr/sfw; do + if test -f "$dir/include/idna.h"; then + CPPFLAGS="$CPPFLAGS -I$dir/include" + LDFLAGS="$LDFLAGS -L$dir/lib" + AC_MSG_NOTICE([Found libidn in $dir]) + break + fi + done +fi +if test x_$withval != x_no; then + CPPFLAGS="$CPPFLAGS -I$withval/include" + LDFLAGS="$LDFLAGS -L$withval/lib" +fi + +# find libldns +AC_ARG_WITH(libldns, AC_HELP_STRING([--with-libldns=pathname], + [path to libldns (default: search /usr/local ..)]), + [], [withval="yes"]) +if test x_$withval = x_yes; then + for dir in /usr/local /opt/local /usr/pkg /usr/sfw; do + if test -f "$dir/include/ldns/ldns.h"; then + CPPFLAGS="$CPPFLAGS -I$dir/include" + LDFLAGS="$LDFLAGS -L$dir/lib" + AC_MSG_NOTICE([Found libldns in $dir]) + break + fi + done +fi +if test x_$withval != x_no; then + CPPFLAGS="$CPPFLAGS -I$withval/include" + LDFLAGS="$LDFLAGS -L$withval/lib" +fi + +# find libunbound +AC_ARG_WITH(libunbound, AC_HELP_STRING([--with-libunbound=pathname], + [path to libunbound (default: search /usr/local ..)]), + [], [withval="yes"]) +if test x_$withval = x_yes; then + for dir in /usr/local /opt/local /usr/pkg /usr/sfw; do + if test -f "$dir/include/unbound.h"; then + CPPFLAGS="$CPPFLAGS -I$dir/include" + LDFLAGS="$LDFLAGS -L$dir/lib" + AC_MSG_NOTICE([Found libunbound in $dir]) + break + fi + done +fi +if test x_$withval != x_no; then + CPPFLAGS="$CPPFLAGS -I$withval/include" + LDFLAGS="$LDFLAGS -L$withval/lib" +fi + # Checks for libraries. found_all_libs=1 AC_MSG_NOTICE([Checking for dependencies libevent, ldns]) From 552cb4bfcac4acc97661217bad3c5dcfc4abbc34 Mon Sep 17 00:00:00 2001 From: "W.C.A. Wijngaards" Date: Fri, 29 Nov 2013 17:10:09 +0100 Subject: [PATCH 05/10] Put -g-O2 back by reorder tests, fixup lib search --- configure.ac | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/configure.ac b/configure.ac index cc7022e9..d0b44bc0 100644 --- a/configure.ac +++ b/configure.ac @@ -12,6 +12,9 @@ AC_CONFIG_SRCDIR([src/getdns/getdns.h]) # LT_INIT AC_CONFIG_MACRO_DIR([m4]) +AC_PROG_CC +AC_PROG_CPP + # Checks for programs. AC_CANONICAL_HOST case "$host_os" in @@ -21,9 +24,6 @@ case "$host_os" in ;; esac -AC_PROG_CC -AC_PROG_CPP - # always use ./libtool unless override from commandline (libtool=mylibtool) if test -z "$libtool"; then libtool="`pwd`/libtool" @@ -60,16 +60,17 @@ AC_ARG_WITH(libidn, AC_HELP_STRING([--with-libidn=pathname], if test x_$withval = x_yes; then for dir in /usr/local /opt/local /usr/pkg /usr/sfw; do if test -f "$dir/include/idna.h"; then - CPPFLAGS="$CPPFLAGS -I$dir/include" + CFLAGS="$CFLAGS -I$dir/include" LDFLAGS="$LDFLAGS -L$dir/lib" AC_MSG_NOTICE([Found libidn in $dir]) break fi done -fi -if test x_$withval != x_no; then - CPPFLAGS="$CPPFLAGS -I$withval/include" - LDFLAGS="$LDFLAGS -L$withval/lib" +else + if test x_$withval != x_no; then + CFLAGS="$CFLAGS -I$withval/include" + LDFLAGS="$LDFLAGS -L$withval/lib" + fi fi # find libldns @@ -79,16 +80,17 @@ AC_ARG_WITH(libldns, AC_HELP_STRING([--with-libldns=pathname], if test x_$withval = x_yes; then for dir in /usr/local /opt/local /usr/pkg /usr/sfw; do if test -f "$dir/include/ldns/ldns.h"; then - CPPFLAGS="$CPPFLAGS -I$dir/include" + CFLAGS="$CFLAGS -I$dir/include" LDFLAGS="$LDFLAGS -L$dir/lib" AC_MSG_NOTICE([Found libldns in $dir]) break fi done -fi -if test x_$withval != x_no; then - CPPFLAGS="$CPPFLAGS -I$withval/include" - LDFLAGS="$LDFLAGS -L$withval/lib" +else + if test x_$withval != x_no; then + CFLAGS="$CFLAGS -I$withval/include" + LDFLAGS="$LDFLAGS -L$withval/lib" + fi fi # find libunbound @@ -98,16 +100,17 @@ AC_ARG_WITH(libunbound, AC_HELP_STRING([--with-libunbound=pathname], if test x_$withval = x_yes; then for dir in /usr/local /opt/local /usr/pkg /usr/sfw; do if test -f "$dir/include/unbound.h"; then - CPPFLAGS="$CPPFLAGS -I$dir/include" + CFLAGS="$CFLAGS -I$dir/include" LDFLAGS="$LDFLAGS -L$dir/lib" AC_MSG_NOTICE([Found libunbound in $dir]) break fi done -fi -if test x_$withval != x_no; then - CPPFLAGS="$CPPFLAGS -I$withval/include" - LDFLAGS="$LDFLAGS -L$withval/lib" +else + if test x_$withval != x_no; then + CFLAGS="$CFLAGS -I$withval/include" + LDFLAGS="$LDFLAGS -L$withval/lib" + fi fi # Checks for libraries. From 48b54c3579d57c03ccfa02270a7650cdf931f1a3 Mon Sep 17 00:00:00 2001 From: "W.C.A. Wijngaards" Date: Fri, 29 Nov 2013 18:07:43 +0100 Subject: [PATCH 06/10] compile tests when needed. --- src/test/Makefile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/Makefile.in b/src/test/Makefile.in index f58331d4..8a2c3529 100644 --- a/src/test/Makefile.in +++ b/src/test/Makefile.in @@ -42,7 +42,7 @@ tests_stub_async: tests_stub_async.o testmessages.o tests_stub_sync: tests_stub_sync.o $(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ tests_stub_sync.o -test: +test: all ./testscript.sh @echo "All tests OK" From f217ab674e81b4b3d0b5bbb2fdaaf2bd6a721bd2 Mon Sep 17 00:00:00 2001 From: "W.C.A. Wijngaards" Date: Sat, 30 Nov 2013 11:25:50 +0100 Subject: [PATCH 07/10] Compile and test succeeds on OpenBSD --- Makefile.in | 2 ++ src/Makefile.in | 2 +- src/test/testscript.sh | 10 +++++----- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Makefile.in b/Makefile.in index d4212263..3700736d 100644 --- a/Makefile.in +++ b/Makefile.in @@ -70,6 +70,8 @@ $(distdir): cp $(srcdir)/src/getdns/*.h $(distdir)/src/getdns cp $(srcdir)/src/test/Makefile.in $(distdir)/src/test cp $(srcdir)/src/test/*.[ch] $(distdir)/src/test + cp $(srcdir)/src/test/*.sh $(distdir)/src/test + cp $(srcdir)/src/test/*.good $(distdir)/src/test cp $(srcdir)/src/test/*.can $(distdir)/src/test cp $(srcdir)/src/example/Makefile.in $(distdir)/src/example cp $(srcdir)/src/example/*.c $(distdir)/src/example diff --git a/src/Makefile.in b/src/Makefile.in index 8ff1f827..2d9a3bd7 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -29,7 +29,7 @@ srcdir = @srcdir@ VPATH = @srcdir@ CC=gcc -CFLAGS=@CFLAGS@ -Wall -g -fPIC -I$(srcdir)/ -I/usr/local/include -std=c99 +CFLAGS=@CFLAGS@ -Wall -fPIC -I$(srcdir)/ -I/usr/local/include -std=c99 LDFLAGS=@LDFLAGS@ -levent_core -lldns -lunbound -lidn GETDNS_OBJ=sync.lo context.lo list.lo dict.lo convert.lo general.lo \ hostname.lo service.lo request-internal.lo validate_dnssec.lo \ diff --git a/src/test/testscript.sh b/src/test/testscript.sh index d87bab28..980a1bd2 100755 --- a/src/test/testscript.sh +++ b/src/test/testscript.sh @@ -1,7 +1,7 @@ #!/bin/sh # run $1 > $2 and exit on failure to execute -function runit () { +function runit { echo -n "Test $1:" ./$1 > $2 if test $? -ne 0; then @@ -11,7 +11,7 @@ function runit () { } # check output files $1 and $2, exit on failure -function diffit () { +function diffit { if diff $1 $2; then echo " OK" else @@ -21,20 +21,20 @@ function diffit () { } # check output of program $1, known_good must be in $1.good -function checkoutput () { +function checkoutput { runit $1 output diffit output $1.good } # filter out TTL and bindata stuff from $1 to $2 -function filterout() { +function filterout { sed -e '/"ttl"/d' -e '/"ipv4_address"/d' -e '/"ipv6_address"/d' -e '/"rdata_raw"/d' -e '/$2 } # like checkoutput but removes addresses and TTLs and bindata # this makes the test almost useless, but it tests runtime lookup # and the structure of the answer format, against the live internet. -function checkpacket () { +function checkpacket { runit $1 output cp $1.good output.good filterout output output2 From 0761834cf55accfef52a7a01ed0b7c69ccef09e1 Mon Sep 17 00:00:00 2001 From: "W.C.A. Wijngaards" Date: Sat, 30 Nov 2013 12:32:17 +0100 Subject: [PATCH 08/10] Fix shell portability, test succeeds on NetBSD. --- src/test/testscript.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/test/testscript.sh b/src/test/testscript.sh index 980a1bd2..bfd7c5de 100755 --- a/src/test/testscript.sh +++ b/src/test/testscript.sh @@ -1,7 +1,7 @@ #!/bin/sh # run $1 > $2 and exit on failure to execute -function runit { +runit () { echo -n "Test $1:" ./$1 > $2 if test $? -ne 0; then @@ -11,7 +11,7 @@ function runit { } # check output files $1 and $2, exit on failure -function diffit { +diffit () { if diff $1 $2; then echo " OK" else @@ -21,20 +21,20 @@ function diffit { } # check output of program $1, known_good must be in $1.good -function checkoutput { +checkoutput () { runit $1 output diffit output $1.good } # filter out TTL and bindata stuff from $1 to $2 -function filterout { +filterout () { sed -e '/"ttl"/d' -e '/"ipv4_address"/d' -e '/"ipv6_address"/d' -e '/"rdata_raw"/d' -e '/$2 } # like checkoutput but removes addresses and TTLs and bindata # this makes the test almost useless, but it tests runtime lookup # and the structure of the answer format, against the live internet. -function checkpacket { +checkpacket () { runit $1 output cp $1.good output.good filterout output output2 From 64c057b82dae41228984abcbc66774592b563853 Mon Sep 17 00:00:00 2001 From: "W.C.A. Wijngaards" Date: Sat, 30 Nov 2013 13:53:57 +0100 Subject: [PATCH 09/10] Portable with event1.x, test succeeds on FreeBSD --- Makefile.in | 3 +-- configure.ac | 3 ++- src/context.c | 8 ++++++-- src/general.c | 22 +++++++++++++++++++++- src/request-internal.c | 8 +++++++- src/sync.c | 7 ++++++- src/test/tests_stub_async.c | 7 ++++++- 7 files changed, 49 insertions(+), 9 deletions(-) diff --git a/Makefile.in b/Makefile.in index 3700736d..e052d610 100644 --- a/Makefile.in +++ b/Makefile.in @@ -63,8 +63,7 @@ $(distdir): cp $(srcdir)/config.sub $(distdir) cp $(srcdir)/config.guess $(distdir) cp $(srcdir)/ltmain.sh $(distdir) - cp $(srcdir)/src/Makefile.in $(distdir)/src - cp $(srcdir)/src/Doxyfile.in $(distdir)/src + cp $(srcdir)/src/*.in $(distdir)/src cp $(srcdir)/src/*.[ch] $(distdir)/src cp $(srcdir)/src/getdns/*.in $(distdir)/src/getdns cp $(srcdir)/src/getdns/*.h $(distdir)/src/getdns diff --git a/configure.ac b/configure.ac index d0b44bc0..06ca9eb9 100644 --- a/configure.ac +++ b/configure.ac @@ -141,7 +141,7 @@ if test -z "$DOXYGEN"; fi # Checks for header files. -AC_CHECK_HEADERS([inttypes.h netinet/in.h stdint.h stdlib.h string.h]) +AC_CHECK_HEADERS([inttypes.h netinet/in.h stdint.h stdlib.h string.h event2/event.h]) # Checks for typedefs, structures, and compiler characteristics. AC_HEADER_STDBOOL @@ -155,4 +155,5 @@ AC_CONFIG_FILES([Makefile src/Makefile src/getdns/Makefile src/example/Makefile if [ test -n "$DOXYGEN" ] then AC_CONFIG_FILES([src/Doxyfile]) fi +AC_CONFIG_HEADER([src/config.h]) AC_OUTPUT diff --git a/src/context.c b/src/context.c index b66642f2..18ec3b48 100644 --- a/src/context.c +++ b/src/context.c @@ -28,9 +28,13 @@ * THE SOFTWARE. */ +#include "config.h" +#ifdef HAVE_EVENT2_EVENT_H +# include +#else +# include +#endif #include - -#include #include #include #include diff --git a/src/general.c b/src/general.c index 8f4f1e39..d33c01cb 100644 --- a/src/general.c +++ b/src/general.c @@ -34,10 +34,18 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include "config.h" +#ifdef HAVE_EVENT2_EVENT_H +# include +#else +# include +# define evutil_socket_t int +# define event_free free +# define evtimer_new(b, cb, arg) event_new((b), -1, 0, (cb), (arg)) +#endif #include #include #include -#include #include #include "context.h" #include "types-internal.h" @@ -67,6 +75,18 @@ typedef struct netreq_cb_data char *bogus; } netreq_cb_data; +#ifndef HAVE_EVENT2_EVENT_H +static struct event * +event_new(struct event_base *b, evutil_socket_t fd, short ev, void* cb, void *arg) +{ + struct event* e = (struct event*)calloc(1, sizeof(struct event)); + if(!e) return NULL; + event_set(e, fd, ev, cb, arg); + event_base_set(b, e); + return e; +} +#endif /* no event2 */ + /* cancel, cleanup and send timeout to callback */ static void ub_resolve_timeout(evutil_socket_t fd, short what, void *arg) diff --git a/src/request-internal.c b/src/request-internal.c index c7bee15f..ab1db272 100644 --- a/src/request-internal.c +++ b/src/request-internal.c @@ -33,10 +33,16 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include "config.h" +#ifdef HAVE_EVENT2_EVENT_H +# include +#else +# include +# define event_free free +#endif #include "types-internal.h" #include "util-internal.h" #include -#include /* useful macros */ #define gd_malloc(sz) context->malloc(sz) diff --git a/src/sync.c b/src/sync.c index de265b04..bcd82650 100644 --- a/src/sync.c +++ b/src/sync.c @@ -33,8 +33,13 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include "config.h" +#ifdef HAVE_EVENT2_EVENT_H +# include +#else +# include +#endif #include -#include #include #include "context.h" #include "general.h" diff --git a/src/test/tests_stub_async.c b/src/test/tests_stub_async.c index 287ce8a4..9c7bbac2 100644 --- a/src/test/tests_stub_async.c +++ b/src/test/tests_stub_async.c @@ -26,12 +26,17 @@ * THE SOFTWARE. */ +#include "config.h" +#ifdef HAVE_EVENT2_EVENT_H +# include +#else +# include +#endif #include #include #include #include "testmessages.h" #include -#include /* Set up the callback function, which will also do the processing of the results */ void From 997fbec46ff6741a3e2d8ccfd19b7147d5e81720 Mon Sep 17 00:00:00 2001 From: "W.C.A. Wijngaards" Date: Mon, 2 Dec 2013 14:20:03 +0100 Subject: [PATCH 10/10] Link with -levent if detected, fix examples. --- src/Makefile.in | 2 +- src/example/Makefile.in | 2 +- src/example/example_simple_answers.c | 7 ++++++- src/example/example_tree.c | 7 ++++++- src/test/Makefile.in | 2 +- 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/Makefile.in b/src/Makefile.in index 2d9a3bd7..a495df69 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -30,7 +30,7 @@ VPATH = @srcdir@ CC=gcc CFLAGS=@CFLAGS@ -Wall -fPIC -I$(srcdir)/ -I/usr/local/include -std=c99 -LDFLAGS=@LDFLAGS@ -levent_core -lldns -lunbound -lidn +LDFLAGS=@LDFLAGS@ @LIBS@ GETDNS_OBJ=sync.lo context.lo list.lo dict.lo convert.lo general.lo \ hostname.lo service.lo request-internal.lo validate_dnssec.lo \ util-internal.lo getdns_error.lo diff --git a/src/example/Makefile.in b/src/example/Makefile.in index 96d5d537..036feb4b 100644 --- a/src/example/Makefile.in +++ b/src/example/Makefile.in @@ -18,7 +18,7 @@ VPATH = @srcdir@ CC=gcc CFLAGS=@CFLAGS@ -Wall -g -fPIC -I$(srcdir)/ -I$(srcdir)/../ -I/usr/local/include -std=c99 LDFLAGS=@LDFLAGS@ -L. -L.. -L/usr/local/lib -LDLIBS=-lgetdns -lldns -levent_core -lunbound +LDLIBS=-lgetdns @LIBS@ PROGRAMS=example_simple_answers example_tree example_all_functions example_synchronous .SUFFIXES: .c .o .a .lo .h diff --git a/src/example/example_simple_answers.c b/src/example/example_simple_answers.c index 8b92a2af..1d60e728 100644 --- a/src/example/example_simple_answers.c +++ b/src/example/example_simple_answers.c @@ -26,13 +26,18 @@ * THE SOFTWARE. */ +#include "../config.h" #include #include #include #include #include #include -#include +#ifdef HAVE_EVENT2_EVENT_H +# include +#else +# include +#endif #define UNUSED_PARAM(x) ((void)(x)) diff --git a/src/example/example_tree.c b/src/example/example_tree.c index 45e7a231..3f4a0865 100644 --- a/src/example/example_tree.c +++ b/src/example/example_tree.c @@ -1,10 +1,15 @@ +#include "../config.h" #include #include #include #include #include #include -#include +#ifdef HAVE_EVENT2_EVENT_H +# include +#else +# include +#endif #define UNUSED_PARAM(x) ((void)(x)) diff --git a/src/test/Makefile.in b/src/test/Makefile.in index 8a2c3529..83b4d427 100644 --- a/src/test/Makefile.in +++ b/src/test/Makefile.in @@ -18,7 +18,7 @@ VPATH = @srcdir@ CC=gcc CFLAGS=@CFLAGS@ -Wall -g -fPIC -I$(srcdir)/ -I$(srcdir)/../ -I/usr/local/include -std=c99 $(cflags) LDFLAGS=@LDFLAGS@ -L. -L.. -L/usr/local/lib -LDLIBS=-lgetdns -lldns -levent_core -lunbound +LDLIBS=-lgetdns @LIBS@ PROGRAMS=tests_dict tests_list tests_stub_async tests_stub_sync .SUFFIXES: .c .o .a .lo .h