From: Marek VavrusÌŒa Date: Thu, 23 Nov 2017 08:59:31 +0000 (-0800) Subject: added basic config test for consts, depend on knot >= 2.4, cleanup X-Git-Tag: v1.5.1~15^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b90e6c71225c65e426c347646dfb593c37fbf6cc;p=thirdparty%2Fknot-resolver.git added basic config test for consts, depend on knot >= 2.4, cleanup The library now depends on libknot >= 2.4.0 (in Debian stable), this allows us to remove a dead code and sed-ing of the kres.lua Added a basic config tests to check that constants still work, and basic interface to rrsets still works after the change. --- diff --git a/Makefile b/Makefile index 58093eb87..8d9644cae 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ BUILD_CFLAGS += --coverage endif # Dependencies -KNOT_MINVER := 2.3.1 +KNOT_MINVER := 2.4.0 $(eval $(call find_lib,libknot,$(KNOT_MINVER),yes)) $(eval $(call find_lib,libdnssec,$(KNOT_MINVER),yes)) $(eval $(call find_lib,libzscanner,$(KNOT_MINVER),yes)) diff --git a/daemon/daemon.mk b/daemon/daemon.mk index 516cb40ee..09717d22b 100644 --- a/daemon/daemon.mk +++ b/daemon/daemon.mk @@ -60,14 +60,9 @@ ifneq ($(SED),) $(INSTALL) -m 0644 doc/kresd.8 $(DESTDIR)$(MANDIR)/man8/ endif daemon-clean: kresd-clean - @$(RM) daemon/lua/*.inc daemon/lua/kres.lua daemon/lua/trust_anchors.lua \ + @$(RM) daemon/lua/*.inc daemon/lua/trust_anchors.lua \ daemon/lua/zonefile.lua -KNOT_RRSET_TXT_DUMP := \ - $(shell pkg-config libknot --atleast-version=2.4.0 && echo true || echo false) -daemon/lua/kres.lua: daemon/lua/kres.lua.in - @$(call quiet,SED,$<) -e "s|@KNOT_RRSET_TXT_DUMP@|$(KNOT_RRSET_TXT_DUMP)|g" $< > $@ - daemon/lua/trust_anchors.lua: daemon/lua/trust_anchors.lua.in @$(call quiet,SED,$<) -e "s|@ETCDIR@|$(ETCDIR)|g" $< > $@ diff --git a/daemon/lua/kres.lua.in b/daemon/lua/kres.lua similarity index 90% rename from daemon/lua/kres.lua.in rename to daemon/lua/kres.lua index d45e9dc1f..7ea3d1b34 100644 --- a/daemon/lua/kres.lua.in +++ b/daemon/lua/kres.lua @@ -175,37 +175,19 @@ ffi.metatype( knot_rrset_t, { -- Dump the rrset in presentation format (dig-like). txt_dump = function(rr, style) - if @KNOT_RRSET_TXT_DUMP@ then - local bufsize = 1024 - local dump = ffi.new('char *[1]', C.malloc(bufsize)) - -- ^ one pointer to a string - local size = ffi.new('size_t[1]', { bufsize }) -- one size_t = bufsize + local bufsize = 1024 + local dump = ffi.new('char *[1]', C.malloc(bufsize)) + -- ^ one pointer to a string + local size = ffi.new('size_t[1]', { bufsize }) -- one size_t = bufsize - local ret = knot.knot_rrset_txt_dump(rr, dump, size, - style or knot.KNOT_DUMP_STYLE_DEFAULT) - local result = nil - if ret >= 0 then - result = ffi.string(dump[0], ret) - end - C.free(dump[0]) - return result - else - -- different _txt_dump ABI -> use old "binary" method - local function hex_encode(str) - return (str:gsub('.', function (c) - return string.format('%02X', string.byte(c)) - end)) - end - local result = '' - local i - for i = 0, rr.rrs.rr_count - 1 do - local rr1 = rr:get(i) - local rdata = hex_encode(rr1.rdata) - result = result .. string.format('%s %d IN TYPE%d \\# %d %s\n', - kres.dname2str(rr1.owner), rr1.ttl, rr1.type, #rr1.rdata, rdata) - end - return result + local ret = knot.knot_rrset_txt_dump(rr, dump, size, + style or knot.KNOT_DUMP_STYLE_DEFAULT) + local result = nil + if ret >= 0 then + result = ffi.string(dump[0], ret) end + C.free(dump[0]) + return result end, }, }) diff --git a/doc/build.rst b/doc/build.rst index e9dde5381..d67766c4d 100644 --- a/doc/build.rst +++ b/doc/build.rst @@ -39,7 +39,7 @@ The following is a list of software required to build Knot DNS Resolver from sou "C compiler", "*all*", "*(build only)* [#]_" "`pkg-config`_", "*all*", "*(build only)* [#]_" "hexdump or xxd", "``daemon``", "*(build only)*" - "libknot_ 2.3.1+", "*all*", "Knot DNS library (requires autotools, GnuTLS and Jansson)." + "libknot_ 2.4.0+", "*all*", "Knot DNS library (requires autotools, GnuTLS and Jansson)." "LuaJIT_ 2.0+", "``daemon``", "Embedded scripting language." "libuv_ 1.7+", "``daemon``", "Multiplatform I/O and services (libuv_ 1.0 with limitations [#]_)." diff --git a/tests/config/basic/test.cfg b/tests/config/basic/test.cfg new file mode 100644 index 000000000..19f21d13a --- /dev/null +++ b/tests/config/basic/test.cfg @@ -0,0 +1,26 @@ +dofile('./test_utils.lua') -- load test utilities + +-- test if constants work properly +function test_constants() + assert.same(1, kres.class.IN) + assert.same(1, kres.class['IN']) + assert.same(2, kres.type.NS) + assert.same(2, kres.type.TYPE2) + assert.same(nil, kres.type.BADTYPE) + assert.same(2, kres.rcode.SERVFAIL) +end + +-- test if rrsets interfaces work +function test_rrsets() + local rr = {owner = '\3com', ttl = 1, type = kres.type.TXT, rdata = '\5hello'} + local rr_text = tostring(kres.rr2str(rr)) + assert.same('com. 1 TXT "hello"', rr_text:gsub('%s+', ' ')) +end + +-- run test after processed config file +-- default config will be used and we can test it. +event.after(0, function (ev) + test(test_constants) + test(test_rrsets) + quit() +end) diff --git a/tests/config/test_config.mk b/tests/config/test_config.mk index 4f26dc982..8d9f1e03f 100644 --- a/tests/config/test_config.mk +++ b/tests/config/test_config.mk @@ -6,6 +6,7 @@ # Check return code of kresd. Passed test have to call quit(). tests_config := \ + basic \ hints \ predict