Commit b90e6c71 authored by Marek Vavruša's avatar Marek Vavruša

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.
parent 8f6e74cd
......@@ -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))
......
......@@ -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" $< > $@
......
......@@ -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,
},
})
......
......@@ -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 [#]_)."
......
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)
......@@ -6,6 +6,7 @@
# Check return code of kresd. Passed test have to call quit().
tests_config := \
basic \
hints \
predict
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment