Skip to content

Commit

Permalink
Fix linuxsysfs itest failing when serial device is connected (openhab…
Browse files Browse the repository at this point in the history
…#3782)

This fixes that some linuxsysfs tests always fail on Linux whenever a real serial device is connected.
Due to the changes in openhab#3290 the tests would also scan the actual devices causing tests to fail due to unexpected results.

Signed-off-by: Wouter Born <[email protected]>
  • Loading branch information
wborn authored Aug 27, 2023
1 parent 5daf4ff commit 9cc7b58
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ public class SysfsUsbSerialScanner implements UsbSerialScanner {

private static final String SYSFS_TTY_DEVICES_DIRECTORY_DEFAULT = "/sys/class/tty";
private static final String DEV_DIRECTORY_DEFAULT = "/dev";
private static final String DEV_SERIAL_BY_ID_DIRECTORY = DEV_DIRECTORY_DEFAULT + "/serial/by-id";
private static final String SERIAL_BY_ID_DIRECTORY = "/serial/by-id";

private String sysfsTtyDevicesDirectory = SYSFS_TTY_DEVICES_DIRECTORY_DEFAULT;
private String devDirectory = DEV_DIRECTORY_DEFAULT;
private String devSerialByIdDirectory = DEV_DIRECTORY_DEFAULT + SERIAL_BY_ID_DIRECTORY;

private static final String SYSFS_FILENAME_USB_VENDOR_ID = "idVendor";
private static final String SYSFS_FILENAME_USB_PRODUCT_ID = "idProduct";
Expand Down Expand Up @@ -151,7 +152,7 @@ private Set<SerialPortInfo> getSerialPortInfos() throws IOException {
}

// optionally compute links and their corresponding SerialInfo :
Path devSerialDir = Path.of(DEV_SERIAL_BY_ID_DIRECTORY);
Path devSerialDir = Path.of(devSerialByIdDirectory);
if (exists(devSerialDir) && isDirectory(devSerialDir) && isReadable(devSerialDir)) {
// browse serial/by-id directory :
try (DirectoryStream<Path> directoryStream = newDirectoryStream(devSerialDir)) {
Expand Down Expand Up @@ -284,6 +285,7 @@ private void extractConfiguration(Map<String, Object> config) {
if (configurationIsChanged) {
sysfsTtyDevicesDirectory = newSysfsTtyDevicesDirectory;
devDirectory = newDevDirectory;
devSerialByIdDirectory = devDirectory + SERIAL_BY_ID_DIRECTORY;
}

if (!canPerformScans()) {
Expand Down

0 comments on commit 9cc7b58

Please sign in to comment.