Commit 1b5c2c5c authored by Daniel Salzman's avatar Daniel Salzman

tests: adapt module tests to the new API

parent a519e5f9
......@@ -38,7 +38,7 @@
/libknot/test_ypscheme
/libknot/test_yptrafo
/modules/test_online_sign
/modules/test_onlinesign
/modules/test_rrl
/utils/test_cert
......
......@@ -49,10 +49,6 @@ check_PROGRAMS += \
libknot/test_ypscheme \
libknot/test_yptrafo
check_PROGRAMS += \
modules/test_online_sign \
modules/test_rrl
check_PROGRAMS += \
utils/test_cert \
utils/test_lookup
......@@ -82,6 +78,26 @@ check_PROGRAMS += \
test_zone_timers \
test_zonedb
if STATIC_MODULE_onlinesign
check_PROGRAMS += \
modules/test_onlinesign
else
if SHARED_MODULE_onlinesign
check_PROGRAMS += \
modules/test_onlinesign
endif
endif
if STATIC_MODULE_rrl
check_PROGRAMS += \
modules/test_rrl
else
if SHARED_MODULE_rrl
check_PROGRAMS += \
modules/test_rrl
endif
endif
utils_test_lookup_CPPFLAGS = \
$(AM_CPPFLAGS) \
$(libedit_CFLAGS)
......
/* Copyright (C) 2015 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -17,7 +17,7 @@
#include <tap/basic.h>
#include <assert.h>
#include "knot/modules/online_sign/nsec_next.h"
#include "knot/modules/onlinesign/nsec_next.h"
#include "libknot/consts.h"
#include "libknot/dname.h"
#include "libknot/errcode.h"
......
......@@ -147,8 +147,8 @@ int main(int argc, char *argv[])
sockaddr_set(&addr6, AF_INET6, "1122:3344:5566:7788::aabb", 0);
ret = 0;
for (unsigned i = 0; i < rate; ++i) {
if (rrl_query(rrl, &addr, &rq, zone) != KNOT_EOK ||
rrl_query(rrl, &addr6, &rq, zone) != KNOT_EOK) {
if (rrl_query(rrl, &addr, &rq, zone, NULL) != KNOT_EOK ||
rrl_query(rrl, &addr6, &rq, zone, NULL) != KNOT_EOK) {
ret = KNOT_ELIMIT;
break;
}
......@@ -157,11 +157,11 @@ int main(int argc, char *argv[])
#ifdef ENABLE_TIMED_TESTS
/* 5. limited request */
ret = rrl_query(rrl, &addr, &rq, zone);
ret = rrl_query(rrl, &addr, &rq, zone, NULL);
is_int(KNOT_ELIMIT, ret, "rrl: throttled IPv4 request");
/* 6. limited IPv6 request */
ret = rrl_query(rrl, &addr6, &rq, zone);
ret = rrl_query(rrl, &addr6, &rq, zone, NULL);
is_int(KNOT_ELIMIT, ret, "rrl: throttled IPv6 request");
#endif
......@@ -171,9 +171,9 @@ int main(int argc, char *argv[])
ret += rrl_setrate(0, 0); // 0
ret += rrl_rate(0); // 0
ret += rrl_setlocks(0,0); // -1
ret += rrl_query(0, 0, 0, 0); // -1
ret += rrl_query(rrl, 0, 0, 0); // -1
ret += rrl_query(rrl, (void*)0x1, 0, 0); // -1
ret += rrl_query(0, 0, 0, 0, NULL); // -1
ret += rrl_query(rrl, 0, 0, 0, NULL); // -1
ret += rrl_query(rrl, (void*)0x1, 0, 0, NULL); // -1
ret += rrl_destroy(0); // -1
is_int(-88, ret, "rrl: not crashed while executing functions on NULL context");
......
......@@ -23,6 +23,7 @@
#include "libknot/packet/wire.h"
#include "knot/nameserver/process_query.h"
#include "test_server.h"
#include "contrib/sockaddr.h"
#include "contrib/ucw/mempool.h"
/* Basic response check (4 TAP tests). */
......@@ -101,12 +102,13 @@ int main(int argc, char *argv[])
struct sockaddr_storage ss;
memset(&ss, 0, sizeof(struct sockaddr_storage));
sockaddr_set(&ss, AF_INET, "127.0.0.1", 53);
struct process_query_param param = {0};
param.remote = &ss;
param.server = &server;
knotd_qdata_params_t params = {
.remote = &ss,
.server = &server
};
/* Query processor (CH zone) */
knot_layer_begin(&proc, &param);
knot_layer_begin(&proc, &params);
knot_pkt_clear(query);
knot_pkt_put_question(query, IDSERVER_DNAME, KNOT_CLASS_CH, KNOT_RRTYPE_TXT);
exec_query(&proc, "CH TXT", query, KNOT_RCODE_NOERROR);
......
/* Copyright (C) 2014 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -25,10 +25,11 @@
#include "contrib/ucw/mempool.h"
/* Universal processing stage. */
int state_visit(int state, knot_pkt_t *pkt, struct query_data *qdata, void *ctx)
unsigned state_visit(unsigned state, knot_pkt_t *pkt, knotd_qdata_t *qdata,
knotd_mod_t *mod)
{
/* Visit current state */
bool *state_map = ctx;
bool *state_map = (bool *)mod;
state_map[state] = true;
return state + 1;
......@@ -36,14 +37,14 @@ int state_visit(int state, knot_pkt_t *pkt, struct query_data *qdata, void *ctx)
int main(int argc, char *argv[])
{
plan(4);
plan_lazy();
/* Create processing context. */
knot_mm_t mm;
mm_ctx_mempool(&mm, MM_DEFAULT_BLKSIZE);
/* Create a map of expected steps. */
bool state_map[QUERY_PLAN_STAGES] = { false };
bool state_map[KNOTD_STAGES] = { false };
/* Prepare query plan. */
struct query_plan *plan = query_plan_create(&mm);
......@@ -51,7 +52,7 @@ int main(int argc, char *argv[])
/* Register all stage visits. */
int ret = KNOT_EOK;
for (unsigned stage = QPLAN_BEGIN; stage < QUERY_PLAN_STAGES; ++stage) {
for (unsigned stage = KNOTD_STAGE_BEGIN; stage < KNOTD_STAGES; ++stage) {
ret = query_plan_step(plan, stage, state_visit, state_map);
if (ret != KNOT_EOK) {
break;
......@@ -61,7 +62,7 @@ int main(int argc, char *argv[])
/* Execute the plan. */
int state = 0, next_state = 0;
for (unsigned stage = QPLAN_BEGIN; stage < QUERY_PLAN_STAGES; ++stage) {
for (unsigned stage = KNOTD_STAGE_BEGIN; stage < KNOTD_STAGES; ++stage) {
struct query_step *step = NULL;
WALK_LIST(step, plan->stage[stage]) {
next_state = step->process(state, NULL, NULL, step->ctx);
......@@ -71,15 +72,15 @@ int main(int argc, char *argv[])
state = next_state;
}
}
ok(state == QUERY_PLAN_STAGES, "query_plan: executed all steps");
ok(state == KNOTD_STAGES, "query_plan: executed all steps");
/* Verify if all steps executed their callback. */
for (state = 0; state < QUERY_PLAN_STAGES; ++state) {
for (state = 0; state < KNOTD_STAGES; ++state) {
if (state_map[state] == false) {
break;
}
}
ok(state == QUERY_PLAN_STAGES, "query_plan: executed all callbacks");
ok(state == KNOTD_STAGES, "query_plan: executed all callbacks");
/* Free the query plan. */
query_plan_free(plan);
......
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