Skip to content

Commit c750504

Browse files
committed
fix tests
1 parent 44c7b3f commit c750504

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

.devcontainer/devcontainer.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
},
1717
"runArgs": [
1818
"--network",
19-
"host"
19+
"host",
20+
"--privileged",
21+
"--device",
22+
"/dev/bus/usb:/dev/bus/usb",
23+
"--device=/dev/ttyUSB0:/dev/ttyUSB0",
24+
"--group-add=dialout"
2025
]
2126
}

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,4 @@ add_custom_command(TARGET serial_tests POST_BUILD
7878
COMMENT "Copy shared library next to test binary")
7979

8080
enable_testing()
81-
add_test(NAME SerialEchoTest COMMAND serial_tests /dev/ttyACM0)
81+
add_test(NAME SerialEchoTest COMMAND serial_tests /dev/ttyUSB0)

tests/serial_test.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@
3232
#include <cstring>
3333
#include <iostream>
3434
#include <string>
35+
#include <thread>
36+
#include <chrono>
3537

3638
int main(int argc, char *argv[]) {
37-
const char *port = argc > 1 ? argv[1] : "/dev/ttyACM0"; // default path
39+
const char *port = argc > 1 ? argv[1] : "/dev/ttyUSB0"; // default path
3840
const std::string testMsg = "HELLO";
3941

4042
intptr_t handle = serialOpen((void *)port, 115200, 8, 0, 0);
@@ -43,6 +45,11 @@ int main(int argc, char *argv[]) {
4345
return 1;
4446
}
4547

48+
// Opening a serial connection toggles DTR on most Arduino boards, which
49+
// triggers a reset. Give the micro-controller a moment to reboot before we
50+
// start talking to it, otherwise the first bytes might be lost.
51+
std::this_thread::sleep_for(std::chrono::seconds(2));
52+
4653
// Send message
4754
int written =
4855
serialWrite(handle, (void *)testMsg.c_str(), testMsg.size(), 100, 1);

0 commit comments

Comments
 (0)