Skip to content
Snippets Groups Projects
Commit 257b55c9 authored by Daniel Salzman's avatar Daniel Salzman
Browse files

tests-extra: add support for libknot control interface

parent 8e90439f
Branches
Tags
No related merge requests found
"""Libknot server control interface wrapper.
Example:
import json
from libknot.control import *
ctl = KnotCtl()
ctl.connect("/var/run/knot/knot.sock")
......@@ -25,35 +28,56 @@ Example:
from ctypes import cdll, c_void_p, c_int, c_char_p, c_uint, byref
from enum import IntEnum
LIB = cdll.LoadLibrary('libknot.so')
CTL_ALLOC = None
CTL_FREE = None
CTL_SET_TIMEOUT = None
CTL_CONNECT = None
CTL_CLOSE = None
CTL_SEND = None
CTL_RECEIVE = None
CTL_ERROR = None
def load_lib(path="libknot.so"):
"""Loads the libknot library."""
LIB = cdll.LoadLibrary(path)
CTL_ALLOC = LIB.knot_ctl_alloc
CTL_ALLOC.restype = c_void_p
global CTL_ALLOC
CTL_ALLOC = LIB.knot_ctl_alloc
CTL_ALLOC.restype = c_void_p
CTL_FREE = LIB.knot_ctl_free
CTL_FREE.argtypes = [c_void_p]
global CTL_FREE
CTL_FREE = LIB.knot_ctl_free
CTL_FREE.argtypes = [c_void_p]
CTL_SET_TIMEOUT = LIB.knot_ctl_set_timeout
CTL_SET_TIMEOUT.argtypes = [c_void_p, c_int]
global CTL_SET_TIMEOUT
CTL_SET_TIMEOUT = LIB.knot_ctl_set_timeout
CTL_SET_TIMEOUT.argtypes = [c_void_p, c_int]
CTL_CONNECT = LIB.knot_ctl_connect
CTL_CONNECT.restype = c_int
CTL_CONNECT.argtypes = [c_void_p, c_char_p]
global CTL_CONNECT
CTL_CONNECT = LIB.knot_ctl_connect
CTL_CONNECT.restype = c_int
CTL_CONNECT.argtypes = [c_void_p, c_char_p]
CTL_CLOSE = LIB.knot_ctl_close
CTL_CLOSE.argtypes = [c_void_p]
global CTL_CLOSE
CTL_CLOSE = LIB.knot_ctl_close
CTL_CLOSE.argtypes = [c_void_p]
CTL_SEND = LIB.knot_ctl_send
CTL_SEND.restype = c_int
CTL_SEND.argtypes = [c_void_p, c_uint, c_void_p]
global CTL_SEND
CTL_SEND = LIB.knot_ctl_send
CTL_SEND.restype = c_int
CTL_SEND.argtypes = [c_void_p, c_uint, c_void_p]
CTL_RECEIVE = LIB.knot_ctl_receive
CTL_RECEIVE.restype = c_int
CTL_RECEIVE.argtypes = [c_void_p, c_void_p, c_void_p]
global CTL_RECEIVE
CTL_RECEIVE = LIB.knot_ctl_receive
CTL_RECEIVE.restype = c_int
CTL_RECEIVE.argtypes = [c_void_p, c_void_p, c_void_p]
CTL_ERROR = LIB.knot_strerror
CTL_ERROR.restype = c_char_p
CTL_ERROR.argtypes = [c_int]
global CTL_ERROR
CTL_ERROR = LIB.knot_strerror
CTL_ERROR.restype = c_char_p
CTL_ERROR.argtypes = [c_int]
class KnotCtlType(IntEnum):
......@@ -114,6 +138,8 @@ class KnotCtl(object):
"""Libknot server control interface."""
def __init__(self):
if not CTL_ALLOC:
load_lib()
self.obj = CTL_ALLOC()
def __del__(self):
......
#!/usr/bin/env python3
import sys
from dnstest.utils import Skip
import dnstest.params as params
try:
sys.path.append(params.repo_binary("python"))
import libknot.control
libknot.control.load_lib(params.libknot_lib)
except:
raise Skip("libknot not available")
......@@ -50,6 +50,8 @@ gdb_bin = get_binary("KNOT_TEST_GDB", "gdb")
vgdb_bin = get_binary("KNOT_TEST_VGDB", "vgdb")
# KNOT_TEST_LIBTOOL - libtool script.
libtool_bin = get_binary("KNOT_TEST_LIBTOOL", repo_binary("libtool"))
# KNOT_TEST_LIBKNOT - libknot library.
libknot_lib = get_binary("KNOT_TEST_LIBKNOT", repo_binary("src/.libs/libknot.so"))
# KNOT_TEST_KNOT - Knot binary.
knot_bin = get_binary("KNOT_TEST_KNOT", repo_binary("src/knotd"))
# KNOT_TEST_KNOTC - Knot control binary.
......
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