diff --git a/CMakeLists.txt b/CMakeLists.txt index 7003130638d6d435ed7781e4d038c352b3c55c86..1ffe67f9d89fbfb59bbdcc395a4bf711f2d4e208 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,8 +20,6 @@ file(GLOB CORE_HEADERS src/*.h) set(Python_ADDITIONAL_VERSIONS 3.7) find_package (PythonLibs REQUIRED) -#find_package(PkgConfig) -#pkg_check_modules(PC_JSON-C REQUIRED json-c) include_directories(${PYTHON_INCLUDE_DIR}) add_library(${PROJECT_NAME} SHARED ${CORE_SRCS} ${CORE_UNIX_SRCS}) @@ -37,16 +35,9 @@ target_link_libraries(${PROJECT_NAME} dap_core) target_include_directories(${PROJECT_NAME} PUBLIC src/ ) -file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/src/libdapConnector.py - DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/) - -file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/test/main_test.py - DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/) - -if(BUILD_DAP_TESTS) +if(BUILD_DAP_PYTHON_TESTS) + add_subdirectory(test) file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/test/main_test.py - DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/) - enable_testing() - #add_subdirectory(test) + DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/test/) endif() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..bca400efd1cb6cb428b41dd287cc76411982b26e --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,19 @@ +project(TPO C) +cmake_minimum_required(VERSION 2.8) + +set(CMAKE_VERBOSE_MAKEFILE ON) +set(CMAKE_COLOR_MAKEFILE ON) +set(CMAKE_C_STANDARD 11) + +set(Python_ADDITIONAL_VERSIONS 3.7) +find_package (PythonLibs REQUIRED) +include_directories(${PYTHON_INCLUDE_DIR} include/) + +file(GLOB TPO_INCLUDES include/*.h) +file(GLOB TPO_SRCS src/*.c) + +add_library(${PROJECT_NAME} SHARED ${TPO_INCLUDES} ${TPO_SRCS} ) + +target_link_libraries(${PROJECT_NAME} ${PYTHON_LIBRARIES}) + +target_link_libraries(${PROJECT_NAME} dap_python_module) diff --git a/test/include/tpo.h b/test/include/tpo.h new file mode 100644 index 0000000000000000000000000000000000000000..d71f3b4ee74e8ac6c04ef96440f436feb73b9948 --- /dev/null +++ b/test/include/tpo.h @@ -0,0 +1,49 @@ +#define PY_SSIZE_T_CLEAN +#include "Python.h" +#include "libdap-python.h" + +#ifdef __cplusplus +extern "C" { +#endif + +PyObject *TPO_init(PyObject *self, PyObject *args); +PyObject *TPO_deinit(PyObject *self, PyObject *args); + +static PyMethodDef TPOPythonMethods[] = { + {"init", TPO_init, METH_VARARGS, "Initialization of the python-cellframe interface DAP (Deus Applicaions Prototypes)"}, + {"deinit", TPO_deinit, METH_VARARGS, "Deinitialization of the python-cellframe interface DAP (Deus Applicaions Prototypes)"}, + {"setLogLevel", (PyCFunction)dap_set_log_level, METH_VARARGS, "Setting the logging level"}, + {"logIt", (PyCFunction)dap_log_it, METH_VARARGS, "The wrapper of the log_it function for the libdap library"}, + {"logItDebug", (PyCFunction)dap_log_it_debug, METH_VARARGS, "The log_it wrapper for the libdap library displays information with the logging level DEBUG"}, + {"logItInfo", (PyCFunction)dap_log_it_info, METH_VARARGS, "The log_it wrapper for the libdap library displays information with the logging level INFO"}, + {"logItNotice", (PyCFunction)dap_log_it_notice, METH_VARARGS, "The log_it wrapper for the libdap library displays information with the logging level NOTICE"}, + {"logItMessage", (PyCFunction)dap_log_it_message, METH_VARARGS, "The log_it wrapper for the libdap library displays information with the logging level MESSAGE"}, + {"logItDap", (PyCFunction)dap_log_it_dap, METH_VARARGS, "The log_it wrapper for the libdap library displays information with the logging level DAP"}, + {"logItWarning", (PyCFunction)dap_log_it_warning, METH_VARARGS, "The log_it wrapper for the libdap library displays information with the logging level WARNING"}, + {"logItAtt", (PyCFunction)dap_log_it_att, METH_VARARGS, "The log_it wrapper for the libdap library displays information with the logging level ATT"}, + {"logItError", (PyCFunction)dap_log_it_error, METH_VARARGS, "The log_it wrapper for the libdap library displays information with the logging level ERROR"}, + {"logItCritical", (PyCFunction)dap_log_it_critical, METH_VARARGS, "The log_it wrapper for the libdap library displays information with the logging level CRITICAL"}, + {"configGetItem", (PyCFunction)py_m_dap_config_get_item, METH_VARARGS, ""}, + {"configGetItemDefault", (PyCFunction)py_m_dap_config_get_item_default, METH_VARARGS, ""}, + //{"deinit", dap_server_core_deinit, METH_NOARGS, "Deinitialization of the DAP (Deus Applicaions Prototypes) server core library"}, + //{"loop", dap_server_core_loop, METH_VARARGS, ""}, + //{"listen", dap_server_core_listen, METH_VARARGS, ""}, + {NULL, NULL, 0, NULL} +}; + +static struct PyModuleDef TPOModule = { + PyModuleDef_HEAD_INIT, + "libTPO", /* name of module */ + NULL, /* module documentation, may be NULL */ + -1, /* size of per-interpreter state of the module, + or -1 if the module keeps state in global variables. */ + TPOPythonMethods +}; + +PyMODINIT_FUNC PyInit_libTPO(void); + + +#ifdef __cplusplus +} +#endif + diff --git a/test/main_test.py b/test/main_test.py index 793739ffe904345c79c79460d2825e594ae26185..f56c995df04184baa79a580d4ff58b0d7c0db7b6 100644 --- a/test/main_test.py +++ b/test/main_test.py @@ -1,4 +1,4 @@ -from libdapConnector import * +from libTPO import * import os import sys @@ -11,32 +11,24 @@ print("Start main test") app_name = "TestAPP" print("Create config file") create_config_file(app_name) +path = os.getcwd() - -json_string = """{ - "modules": "", - "dap": { - "config_dir": \""""+os.getcwd()+"""\", - "log_level": \""""+LogLevel.L_DEBUG.name+"""\", - "application_name": \""""+app_name+"""\" - } - }""" -init(json_string) -logIt(LogLevel.L_INFO, "Initialization of the DAP done") -setLogLevel(LogLevel.L_DEBUG) -logIt(LogLevel.L_INFO,"Level logging ""DEBUG"" done") -logIt(LogLevel.L_DEBUG, "Test. Outputting a string using the log_it function in the libdap library") -logIt(LogLevel.L_INFO,"Outputting a string using the log_it function done") +init(app_name, app_name, path, "DEBUG") +logIt(INFO, "Initialization of the DAP done") +setLogLevel(DEBUG) +logIt(INFO,"Level logging ""DEBUG"" done") +logIt(DEBUG, "Test. Outputting a string using the log_it function in the libdap library") +logIt(INFO,"Outputting a string using the log_it function done") res1 = configGetItem("server", "listen_address") -logIt(LogLevel.L_INFO, "Output [server] 'listen_address' = "+res1+"\n") +logIt(INFO, "Output [server] 'listen_address' = "+res1+"\n") res2 = configGetItemDefault("server1", "listen_address", "8.8.8.8") -logIt(LogLevel.L_INFO, "Output default value '8.8.8.8' [server1] 'listen_address' = "+res2+"\n") -logIt(LogLevel.L_INFO, "TEST. Get default config done") -deInit() -logIt(LogLevel.L_INFO, "Deinitialization done") +logIt(INFO, "Output default value '8.8.8.8' [server1] 'listen_address' = "+res2+"\n") +logIt(INFO, "TEST. Get default config done") +deinit() +logIt(INFO, "Deinitialization done") os.remove(app_name+".cfg") -logIt(LogLevel.L_INFO, "Dellete config file") -logIt(LogLevel.L_INFO, "Main test done"); +logIt(INFO, "Dellete config file") +logIt(INFO, "Main test done"); sys.exit(0) diff --git a/test/src/tpo.c b/test/src/tpo.c new file mode 100644 index 0000000000000000000000000000000000000000..602eba1b2a09dbe1f0cf4be2520a15a735f27a07 --- /dev/null +++ b/test/src/tpo.c @@ -0,0 +1,62 @@ +#include "tpo.h" + +PyObject *TPO_init(PyObject *self, PyObject *args){ + const char *app_name, *file_name_log, *config_dir, *s_log_level; + if (!PyArg_ParseTuple(args, "s|s|s|s", &app_name, &file_name_log, &config_dir, &s_log_level)){ + return NULL; + } + if (dap_common_init(app_name, file_name_log) != 0){ + return NULL; + } + dap_config_init(config_dir); + if ((g_config = dap_config_open(app_name) ) == NULL){ + return NULL; + } + + if (strcmp(s_log_level, "DEBUG") == 0 ){ + dap_log_level_set(L_DEBUG); + } else if (strcmp(s_log_level, "INFO") == 0) { + dap_log_level_set(L_INFO); + } else if (strcmp(s_log_level, "NOTICE") == 0) { + dap_log_level_set(L_NOTICE); + }else if (strcmp(s_log_level, "MESSAGE") == 0) { + dap_log_level_set(L_MSG); + }else if (strcmp(s_log_level, "DAP") == 0) { + dap_log_level_set(L_DAP); + }else if (strcmp(s_log_level, "WARNING") == 0) { + dap_log_level_set(L_WARNING); + }else if (strcmp(s_log_level, "ATT") == 0) { + dap_log_level_set(L_ATT); + }else if (strcmp(s_log_level, "ERROR") == 0) { + dap_log_level_set(L_ERROR); + } else if (strcmp(s_log_level, "CRITICAL") == 0) { + dap_log_level_set(L_CRITICAL); + } else { + dap_log_level_set(L_DEBUG); + } + return PyLong_FromLong(0); +} +PyObject *TPO_deinit(PyObject *self, PyObject *args){ + dap_config_close(g_config); + dap_config_deinit(); + return PyLong_FromLong(0); +} + +PyMODINIT_FUNC PyInit_libTPO(void){ + + if (PyType_Ready(&DapObject_DapObjectType) < 0 ) + return NULL; + + PyObject *module = PyModule_Create(&TPOModule); + PyModule_AddObject(module, "DEBUG", PyLong_FromLong(L_DEBUG)); + PyModule_AddObject(module, "INFO", PyLong_FromLong(L_INFO)); + PyModule_AddObject(module, "NOTICE", PyLong_FromLong(L_NOTICE)); + PyModule_AddObject(module, "MESSAGE", PyLong_FromLong(L_MSG)); + PyModule_AddObject(module, "DAP", PyLong_FromLong(L_DAP)); + PyModule_AddObject(module, "WARNING", PyLong_FromLong(L_WARNING)); + PyModule_AddObject(module, "ATT", PyLong_FromLong(L_ATT)); + PyModule_AddObject(module, "ERROR", PyLong_FromLong(L_ERROR)); + PyModule_AddObject(module, "CRITICAL", PyLong_FromLong(L_CRITICAL)); + return module; +} +