From ff0c52cc4534bcc6ca9c52205dfc4dd4b105d12a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Sat, 1 Jun 2019 00:21:52 +0200 Subject: [PATCH] add debug lldb test and fix bug with functional header missing --- src/debug_lldb.cpp | 4 +-- tests/python_bindings/CMakeLists.txt | 6 +++++ .../Debug_lldb_tests/debug_lldb_test.cc | 27 +++++++++++++++++++ .../Debug_lldb_tests/debug_lldb_test.py | 21 +++++++++++++++ tests/python_bindings/test_suite.cc | 4 ++- tests/python_bindings/test_suite.h | 1 + 6 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 tests/python_bindings/Debug_lldb_tests/debug_lldb_test.cc create mode 100644 tests/python_bindings/Debug_lldb_tests/debug_lldb_test.py diff --git a/src/debug_lldb.cpp b/src/debug_lldb.cpp index 08f45e9..845181e 100644 --- a/src/debug_lldb.cpp +++ b/src/debug_lldb.cpp @@ -11,6 +11,7 @@ #include #include #include +#include extern char **environ; @@ -601,7 +602,6 @@ void Debug::LLDB::init_module(pybind11::module &api) { dbg .def(py::init([]() { return &(Debug::LLDB::get()); })) .def_readwrite("on_exit", &Debug::LLDB::on_exit) - // .def_readwrite("mutex", &Debug::LLDB::mutex) .def("continue_debug", &Debug::LLDB::continue_debug) .def("stop", &Debug::LLDB::stop) .def("kill", &Debug::LLDB::kill) @@ -642,7 +642,7 @@ void Debug::LLDB::init_module(pybind11::module &api) { py::arg("file_path"), py::arg("line_nr"), py::arg("line_count")) - .def(" write", &Debug::LLDB::write, + .def("write", &Debug::LLDB::write, py::arg("buffer")) ; diff --git a/tests/python_bindings/CMakeLists.txt b/tests/python_bindings/CMakeLists.txt index a49ce81..1c09093 100644 --- a/tests/python_bindings/CMakeLists.txt +++ b/tests/python_bindings/CMakeLists.txt @@ -27,3 +27,9 @@ add_test(pb_config_test pb_config_test) add_executable(pb_ctags_test Ctags_tests/ctags_test.cc $) target_link_libraries(pb_ctags_test test_suite) add_test(pb_ctags_test pb_ctags_test) + +if(LIBLLDB_FOUND AND NOT DEBIAN_STRETCH_FOUND) + add_executable(pb_debug_lldb_test Debug_lldb_tests/debug_lldb_test.cc $) + target_link_libraries(pb_debug_lldb_test test_suite) + add_test(pb_debug_lldb_test pb_debug_lldb_test) +endif() diff --git a/tests/python_bindings/Debug_lldb_tests/debug_lldb_test.cc b/tests/python_bindings/Debug_lldb_tests/debug_lldb_test.cc new file mode 100644 index 0000000..a999586 --- /dev/null +++ b/tests/python_bindings/Debug_lldb_tests/debug_lldb_test.cc @@ -0,0 +1,27 @@ +#include "test_suite.h" +#include + +int main() { + auto &config = Config::get(); + config.project.ctags_command = "ctags"; + auto suite_name = "Debug_lldb_tests"; + { + auto doTest = [&](auto test) { + auto test_suite = suite(suite_name); + auto build_path = test_suite.build_file_path / "tests" / "lldb_test_files" / "lldb_test_executable"; + { + auto module = py::module::import("debug_lldb_test"); + test_suite.has_assertion = false; + try { + module.attr(test)(build_path.c_str()); + test_suite.has_assertion = true; + } + catch(const std::exception &error) { + std::cout << error.what(); + } + } + }; + + doTest("start_on_exit"); + } +} diff --git a/tests/python_bindings/Debug_lldb_tests/debug_lldb_test.py b/tests/python_bindings/Debug_lldb_tests/debug_lldb_test.py new file mode 100644 index 0000000..09e05fa --- /dev/null +++ b/tests/python_bindings/Debug_lldb_tests/debug_lldb_test.py @@ -0,0 +1,21 @@ +from Jucipp import LLDB +from time import sleep +from jucipp_test import assert_equal + + +exited = False + +def on_exit(exit_code): + assert_equal(0, exit_code) + global exited + exited = True + +def start_on_exit(exec_path): + print(exec_path) + l = LLDB() + l.on_exit = [on_exit] + l.start(exec_path, "", []) + + while not exited: + sleep(0.1) + l.cancel() diff --git a/tests/python_bindings/test_suite.cc b/tests/python_bindings/test_suite.cc index c9c3666..f391509 100644 --- a/tests/python_bindings/test_suite.cc +++ b/tests/python_bindings/test_suite.cc @@ -11,7 +11,9 @@ suite::suite(const boost::filesystem::path &path) { if(!sys) { throw std::runtime_error("Unable to append sys path"); } - sys.attr("path").cast().append((test_file_path / path).string()); + auto sys_path = sys.attr("path").cast(); + sys_path.append((test_file_path / path).string()); + sys_path.append((test_file_path).string()); config.terminal.history_size = 100; } suite::~suite() { diff --git a/tests/python_bindings/test_suite.h b/tests/python_bindings/test_suite.h index 95370cd..0b13f8c 100644 --- a/tests/python_bindings/test_suite.h +++ b/tests/python_bindings/test_suite.h @@ -10,6 +10,7 @@ public: Glib::RefPtr app = Gtk::Application::create(); Config &config = Config::get(); boost::filesystem::path test_file_path = boost::filesystem::canonical(std::string(JUCI_TESTS_PATH) + "/python_bindings"); + boost::filesystem::path build_file_path = boost::filesystem::canonical(JUCI_BUILD_PATH); bool has_assertion = false; Plugins plugins; ~suite();