From 56a77f3a13ff8b32703756585760c890392950f0 Mon Sep 17 00:00:00 2001 From: Geoffrey Hunter Date: Fri, 24 Nov 2017 13:45:07 -0800 Subject: [PATCH] Pair of virtual serial ports are now being created by unit test executable. --- test/unit/CMakeLists.txt | 12 ++++++++++-- test/unit/TestUtil.hpp | 26 +++++++++++++++++--------- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index a6b287d..d9c403f 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -17,7 +17,9 @@ file(GLOB_RECURSE CppLinuxSerialUnitTests_SRC "*.cpp" "*.hpp") -add_executable(CppLinuxSerialUnitTests ${CppLinuxSerialUnitTests_SRC}) + + +add_executable(CppLinuxSerialUnitTests ${CppLinuxSerialUnitTests_SRC} "run.sh") target_link_libraries(CppLinuxSerialUnitTests LINK_PUBLIC CppLinuxSerial ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) @@ -30,4 +32,10 @@ add_custom_target( add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/CppLinuxSerialUnitTests.touch - COMMAND ${CMAKE_CURRENT_BINARY_DIR}/CppLinuxSerialUnitTests) \ No newline at end of file + COMMAND ${CMAKE_CURRENT_BINARY_DIR}/CppLinuxSerialUnitTests) + +add_custom_command(TARGET CppLinuxSerialUnitTests POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + ${CMAKE_CURRENT_SOURCE_DIR}/run.sh + $ + ) \ No newline at end of file diff --git a/test/unit/TestUtil.hpp b/test/unit/TestUtil.hpp index 1f79f64..7f36b92 100644 --- a/test/unit/TestUtil.hpp +++ b/test/unit/TestUtil.hpp @@ -136,19 +136,27 @@ namespace mn { void CreateVirtualSerialPortPair() { std::cout << "Creating virtual serial port pair..." << std::endl; - StartProcess("sudo socat -d -d pty,raw,echo=0,link=/dev/ttyS10 pty,raw,echo=0,link=/dev/ttyS11"); +// StartProcess("sudo socat -d -d pty,raw,echo=0,link=/dev/ttyS10 pty,raw,echo=0,link=/dev/ttyS11"); +// std::this_thread::sleep_for(1s); +// StartProcess("sudo chmod a+rw /dev/ttyS10"); +// StartProcess("sudo chmod a+rw /dev/ttyS11"); +// std::this_thread::sleep_for(1s); +// std::cout << "Finished creating virtual serial port pair." << std::endl; +// std::system("./run.sh"); + std::system("nohup sudo socat -d -d pty,raw,echo=0,link=/dev/ttyS10 pty,raw,echo=0,link=/dev/ttyS11 &"); std::this_thread::sleep_for(1s); - StartProcess("sudo chmod a+rw /dev/ttyS10"); - StartProcess("sudo chmod a+rw /dev/ttyS11"); - std::this_thread::sleep_for(1s); - std::cout << "Finished creating virtual serial port pair." << std::endl; + std::system("sudo chmod a+rw /dev/ttyS10"); + std::system("sudo chmod a+rw /dev/ttyS11"); } void CloseSerialPorts() { - for(const auto& filePointer : processes_) { - kill(filePointer.pid, SIGKILL); - pclose2(filePointer.fp, filePointer.pid); - } +// for(const auto& filePointer : processes_) { +// std::cout << "Sending SIGINT..." << std::endl; +// kill(filePointer.pid, SIGINT); +// std::cout << "Calling pclose2()..." << std::endl; +// pclose2(filePointer.fp, filePointer.pid); +// } + std::system("sudo pkill socat"); } std::vector processes_; -- libgit2 0.21.4