Commit 56a77f3a13ff8b32703756585760c890392950f0

Authored by Geoffrey Hunter
1 parent 2e35cebd

Pair of virtual serial ports are now being created by unit test executable.

test/unit/CMakeLists.txt
@@ -17,7 +17,9 @@ file(GLOB_RECURSE CppLinuxSerialUnitTests_SRC @@ -17,7 +17,9 @@ file(GLOB_RECURSE CppLinuxSerialUnitTests_SRC
17 "*.cpp" 17 "*.cpp"
18 "*.hpp") 18 "*.hpp")
19 19
20 -add_executable(CppLinuxSerialUnitTests ${CppLinuxSerialUnitTests_SRC}) 20 +
  21 +
  22 +add_executable(CppLinuxSerialUnitTests ${CppLinuxSerialUnitTests_SRC} "run.sh")
21 23
22 target_link_libraries(CppLinuxSerialUnitTests LINK_PUBLIC CppLinuxSerial ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) 24 target_link_libraries(CppLinuxSerialUnitTests LINK_PUBLIC CppLinuxSerial ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
23 25
@@ -30,4 +32,10 @@ add_custom_target( @@ -30,4 +32,10 @@ add_custom_target(
30 32
31 add_custom_command( 33 add_custom_command(
32 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/CppLinuxSerialUnitTests.touch 34 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/CppLinuxSerialUnitTests.touch
33 - COMMAND ${CMAKE_CURRENT_BINARY_DIR}/CppLinuxSerialUnitTests)  
34 \ No newline at end of file 35 \ No newline at end of file
  36 + COMMAND ${CMAKE_CURRENT_BINARY_DIR}/CppLinuxSerialUnitTests)
  37 +
  38 +add_custom_command(TARGET CppLinuxSerialUnitTests POST_BUILD
  39 + COMMAND ${CMAKE_COMMAND} -E copy_if_different
  40 + ${CMAKE_CURRENT_SOURCE_DIR}/run.sh
  41 + $<TARGET_FILE_DIR:CppLinuxSerialUnitTests>
  42 + )
35 \ No newline at end of file 43 \ No newline at end of file
test/unit/TestUtil.hpp
@@ -136,19 +136,27 @@ namespace mn { @@ -136,19 +136,27 @@ namespace mn {
136 136
137 void CreateVirtualSerialPortPair() { 137 void CreateVirtualSerialPortPair() {
138 std::cout << "Creating virtual serial port pair..." << std::endl; 138 std::cout << "Creating virtual serial port pair..." << std::endl;
139 - StartProcess("sudo socat -d -d pty,raw,echo=0,link=/dev/ttyS10 pty,raw,echo=0,link=/dev/ttyS11"); 139 +// StartProcess("sudo socat -d -d pty,raw,echo=0,link=/dev/ttyS10 pty,raw,echo=0,link=/dev/ttyS11");
  140 +// std::this_thread::sleep_for(1s);
  141 +// StartProcess("sudo chmod a+rw /dev/ttyS10");
  142 +// StartProcess("sudo chmod a+rw /dev/ttyS11");
  143 +// std::this_thread::sleep_for(1s);
  144 +// std::cout << "Finished creating virtual serial port pair." << std::endl;
  145 +// std::system("./run.sh");
  146 + std::system("nohup sudo socat -d -d pty,raw,echo=0,link=/dev/ttyS10 pty,raw,echo=0,link=/dev/ttyS11 &");
140 std::this_thread::sleep_for(1s); 147 std::this_thread::sleep_for(1s);
141 - StartProcess("sudo chmod a+rw /dev/ttyS10");  
142 - StartProcess("sudo chmod a+rw /dev/ttyS11");  
143 - std::this_thread::sleep_for(1s);  
144 - std::cout << "Finished creating virtual serial port pair." << std::endl; 148 + std::system("sudo chmod a+rw /dev/ttyS10");
  149 + std::system("sudo chmod a+rw /dev/ttyS11");
145 } 150 }
146 151
147 void CloseSerialPorts() { 152 void CloseSerialPorts() {
148 - for(const auto& filePointer : processes_) {  
149 - kill(filePointer.pid, SIGKILL);  
150 - pclose2(filePointer.fp, filePointer.pid);  
151 - } 153 +// for(const auto& filePointer : processes_) {
  154 +// std::cout << "Sending SIGINT..." << std::endl;
  155 +// kill(filePointer.pid, SIGINT);
  156 +// std::cout << "Calling pclose2()..." << std::endl;
  157 +// pclose2(filePointer.fp, filePointer.pid);
  158 +// }
  159 + std::system("sudo pkill socat");
152 } 160 }
153 161
154 std::vector<ProcessInfo> processes_; 162 std::vector<ProcessInfo> processes_;