Skip to content

Commit 4a7f89a

Browse files
committed
Changes from OpenBSD ... cross compiled linux
1 parent 091f12d commit 4a7f89a

File tree

70 files changed

+909
-270
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+909
-270
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ autom4te.cache
3131
stamp-h1
3232
.deps
3333
.libs
34+
.ccls-cache
3435

3536
Makefile
3637

de.ibapl.spsw.api.tests/pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>de.ibapl.spsw</groupId>
77
<artifactId>spsw-project</artifactId>
8-
<version>3.0.2-SNAPSHOT</version>
8+
<version>3.1.0-SNAPSHOT</version>
99
</parent>
1010

1111
<artifactId>de.ibapl.spsw.api.test</artifactId>
@@ -15,7 +15,7 @@
1515
<dependency>
1616
<groupId>de.ibapl.spsw</groupId>
1717
<artifactId>de.ibapl.spsw.api</artifactId>
18-
<version>3.0.2-SNAPSHOT</version>
18+
<version>3.1.0-SNAPSHOT</version>
1919
</dependency>
2020
<dependency>
2121
<groupId>org.junit.jupiter</groupId>

de.ibapl.spsw.api.tests/src/main/java/de/ibapl/spsw/tests/AbstractOnePortTest.java

+77-52
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
*/
2222
package de.ibapl.spsw.tests;
2323

24-
import de.ibapl.jnhw.libloader.MultiarchTupelBuilder;
2524
import de.ibapl.spsw.api.DataBits;
2625
import de.ibapl.spsw.api.FlowControl;
2726
import de.ibapl.spsw.api.Parity;
@@ -48,6 +47,7 @@
4847
import java.util.List;
4948
import java.util.Set;
5049
import java.util.concurrent.Future;
50+
import java.util.concurrent.TimeUnit;
5151
import java.util.logging.Level;
5252
import org.junit.jupiter.api.Assertions;
5353
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -59,8 +59,7 @@
5959
import static org.junit.jupiter.api.Assertions.fail;
6060
import static org.junit.jupiter.api.Assumptions.assumeTrue;
6161
import org.junit.jupiter.api.Test;
62-
import org.junit.jupiter.api.condition.EnabledOnOs;
63-
import org.junit.jupiter.api.condition.OS;
62+
import org.junit.jupiter.api.Timeout;
6463
import org.junit.jupiter.params.ParameterizedTest;
6564
import org.junit.jupiter.params.provider.EnumSource;
6665
import org.junit.jupiter.params.provider.MethodSource;
@@ -93,36 +92,22 @@ public void testFlowControl() throws Exception {
9392

9493
testFlowControl(EnumSet.of(FlowControl.XON_XOFF_IN));
9594
testFlowControl(EnumSet.of(FlowControl.XON_XOFF_OUT));
96-
}
97-
98-
@BaselineTest
99-
@Test
100-
@EnabledOnOs({OS.LINUX})
101-
public void testFlowControl_LINUX() throws Exception {
102-
assumeWTest();
103-
LOG.log(Level.INFO, "run testFlowControl");
104-
openDefault();
105-
106-
IllegalArgumentException iae = assertThrows(IllegalArgumentException.class, () -> {
107-
testFlowControl(EnumSet.of(FlowControl.RTS_CTS_IN));
108-
});
109-
assertEquals("Can only set RTS/CTS for both in and out", iae.getMessage());
110-
iae = assertThrows(IllegalArgumentException.class, () -> {
111-
testFlowControl(EnumSet.of(FlowControl.RTS_CTS_OUT));
112-
});
113-
assertEquals("Can only set RTS/CTS for both in and out", iae.getMessage());
114-
}
115-
116-
@BaselineTest
117-
@Test
118-
@EnabledOnOs({OS.WINDOWS})
119-
public void testFlowControl_WINDOWS() throws Exception {
120-
assumeWTest();
121-
LOG.log(Level.INFO, "run testFlowControl");
122-
openDefault();
123-
124-
testFlowControl(EnumSet.of(FlowControl.RTS_CTS_IN));
125-
testFlowControl(EnumSet.of(FlowControl.RTS_CTS_OUT));
95+
switch (MULTIARCHTUPEL_BUILDER.getOS()) {
96+
case WINDOWS:
97+
testFlowControl(EnumSet.of(FlowControl.RTS_CTS_IN));
98+
testFlowControl(EnumSet.of(FlowControl.RTS_CTS_OUT));
99+
break;
100+
case LINUX:
101+
default:
102+
IllegalArgumentException iae = assertThrows(IllegalArgumentException.class, () -> {
103+
testFlowControl(EnumSet.of(FlowControl.RTS_CTS_IN));
104+
});
105+
assertEquals("Can only set RTS/CTS for both in and out", iae.getMessage());
106+
iae = assertThrows(IllegalArgumentException.class, () -> {
107+
testFlowControl(EnumSet.of(FlowControl.RTS_CTS_OUT));
108+
});
109+
assertEquals("Can only set RTS/CTS for both in and out", iae.getMessage());
110+
}
126111
}
127112

128113
@BaselineTest
@@ -539,14 +524,30 @@ public void testWriteSingleByteTimeout() throws Exception {
539524
private final static int _16MB = 1024 * 1024 * 16;
540525
private final static int _1MB = 1024 * 1024; // Too much for FTDI on Windows there is nothing sent...
541526
private final static int _256kB = 1024 * 256;
527+
private final static int _8kB = 1024 * 8;
542528

543529
@BaselineTest
544530
@Test
531+
@Timeout(unit = TimeUnit.MINUTES, value = 1)
532+
public void testWrite8kBChunkInfiniteWrite() throws Exception {
533+
writeChunk(_8kB, Speed._230400_BPS, 0);
534+
}
535+
536+
@BaselineTest
537+
@Test
538+
public void write8kBChunk() throws Exception {
539+
writeChunk(_8kB, Speed._230400_BPS, 1000 + 2 * SerialPortConfiguration.calculateMillisForCharacters(_8kB,
540+
Speed._230400_BPS, DataBits.DB_8, StopBits.SB_1, Parity.NONE));
541+
}
542+
543+
@NotSupportedByAllDevices
544+
@Test
545+
@Timeout(unit = TimeUnit.MINUTES, value = 1)
545546
public void testWrite256kBChunkInfiniteWrite() throws Exception {
546547
writeChunk(_256kB, Speed._230400_BPS, 0);
547548
}
548549

549-
@BaselineTest
550+
@NotSupportedByAllDevices
550551
@Test
551552
public void write256kBChunk() throws Exception {
552553
writeChunk(_256kB, Speed._230400_BPS, 1000 + 2 * SerialPortConfiguration.calculateMillisForCharacters(_256kB,
@@ -555,6 +556,7 @@ public void write256kBChunk() throws Exception {
555556

556557
@NotSupportedByAllDevices
557558
@Test
559+
@Timeout(unit = TimeUnit.MINUTES, value = 2)
558560
public void testWrite1MBChunkInfiniteWrite() throws Exception {
559561
writeChunk(_1MB, Speed._1000000_BPS, 0);
560562
}
@@ -574,6 +576,7 @@ public void write1MBChunk() throws Exception {
574576
*/
575577
@NotSupportedByAllDevices
576578
@Test
579+
@Timeout(unit = TimeUnit.MINUTES, value = 4)
577580
public void testWrite16MBChunkInfiniteWrite() throws Exception {
578581
writeChunk(_16MB, Speed._1000000_BPS, 0);
579582
}
@@ -593,11 +596,10 @@ public void write16MBChunk() throws Exception {
593596

594597
public void writeChunk(int chunksize, Speed speed, int writeTimeout) throws Exception {
595598
assumeWTest();
596-
LOG.log(Level.INFO, "run testWriteBytesTimeout writeTO: {0} speed: {1} chunksize: {2}", new Object[]{writeTimeout, speed, chunksize});
597-
if (writeTimeout == -1) {
598-
LOG.log(Level.INFO, "infinite timeout");
599+
if (writeTimeout == SerialPortSocket.INFINITE_TIMEOUT) {
600+
LOG.log(Level.INFO, "run testWriteBytesTimeout writeTO: INFINITE_TIMEOUT speed: {1} chunksize: {2}", new Object[]{speed, chunksize});
599601
} else {
600-
LOG.log(Level.INFO, "timeout in ms:" + writeTimeout);
602+
LOG.log(Level.INFO, "run testWriteBytesTimeout writeTO: {0} speed: {1} chunksize: {2}", new Object[]{writeTimeout, speed, chunksize});
601603
}
602604

603605
// Set a high speed to speed up things
@@ -607,9 +609,13 @@ public void writeChunk(int chunksize, Speed speed, int writeTimeout) throws Exce
607609
byte[] data = new byte[chunksize];
608610
int dataWritten = 0;
609611
try {
610-
assertTimeoutPreemptively(Duration.ofMillis(writeSpc.calculateMillisForCharacters(data.length * 2)), () -> {
612+
if (writeTimeout == SerialPortSocket.INFINITE_TIMEOUT) {
611613
writeSpc.getOutputStream().write(data);
612-
});
614+
} else {
615+
assertTimeoutPreemptively(Duration.ofMillis(writeSpc.calculateMillisForCharacters(data.length * 2)), () -> {
616+
writeSpc.getOutputStream().write(data);
617+
});
618+
}
613619
dataWritten = data.length;
614620
} catch (TimeoutIOException e) {
615621
dataWritten = e.bytesTransferred;
@@ -815,11 +821,20 @@ public void testBreak() throws Exception {
815821
public void testParity(Parity p) throws Exception {
816822
LOG.log(Level.INFO, "run testParity({0}) - BaselineTest", p);
817823
openDefault();
818-
if ((p == Parity.SPACE || p == Parity.MARK) && (de.ibapl.jnhw.libloader.OS.FREE_BSD == MULTIARCHTUPEL_BUILDER.getOS())) {
819-
Assertions.assertThrows(IllegalArgumentException.class, () -> readSpc.setParity(p));
820-
} else {
821-
readSpc.setParity(p);
822-
assertEquals(p, readSpc.getParity());
824+
switch (MULTIARCHTUPEL_BUILDER.getOS()) {
825+
case FREE_BSD:
826+
case DARWIN:
827+
case OPEN_BSD:
828+
if (p == Parity.SPACE || p == Parity.MARK) {
829+
Assertions.assertThrows(IllegalArgumentException.class, () -> readSpc.setParity(p));
830+
} else {
831+
readSpc.setParity(p);
832+
assertEquals(p, readSpc.getParity());
833+
}
834+
break;
835+
default:
836+
readSpc.setParity(p);
837+
assertEquals(p, readSpc.getParity());
823838
}
824839
}
825840

@@ -833,7 +848,14 @@ public void testSpeed() throws Exception {
833848
for (Speed b : Speed.values()) {
834849
try {
835850
readSpc.setSpeed(b);
836-
assertEquals(b, readSpc.getSpeed(), "test Speed");
851+
//OpenBSD sets _0_BPS only for the outspeed!
852+
Assertions.assertAll(
853+
() -> {
854+
assertEquals(b, readSpc.getOutSpeed(), "test outSpeed");
855+
},
856+
() -> {
857+
assertEquals(b, readSpc.getInSpeed(), "test inSpeed");
858+
});
837859
} catch (IllegalArgumentException iae) {
838860
switch (b) {
839861
case _0_BPS:
@@ -859,7 +881,7 @@ public void testSpeed() throws Exception {
859881
case _3000000_BPS:
860882
case _3500000_BPS:
861883
case _4000000_BPS:
862-
if (b != readSpc.getSpeed()) {
884+
if (b != readSpc.getOutSpeed() || b != readSpc.getInSpeed()) {
863885
LOG.warning("Can't set speed to " + b);
864886
}
865887
break;
@@ -1442,11 +1464,14 @@ public void testFinalize() throws IOException, InterruptedException {
14421464

14431465
// On Windows the GC needs some time - I don't know why... (FTDI on win64 needs
14441466
// the most...)
1445-
if (System.getProperty("os.name").startsWith("Windows")) {
1446-
Thread.sleep(200);
1447-
} else {
1448-
// termios has a 10ms wait time during close
1449-
Thread.sleep(10);
1467+
switch (MULTIARCHTUPEL_BUILDER.getOS()) {
1468+
case OPEN_BSD:
1469+
case WINDOWS:
1470+
Thread.sleep(200);
1471+
break;
1472+
default:
1473+
// termios has a 10ms wait time during close
1474+
Thread.sleep(10);
14501475
}
14511476

14521477
readSpc = getSerialPortSocketFactory().open(serialPortName);

de.ibapl.spsw.api.tests/src/main/java/de/ibapl/spsw/tests/AbstractPortTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public void run() {
8181
if (data >= 0) {
8282
recBuffer.put((byte) data);
8383
assertEquals(sendBuffer.get(currentRecOffset), recBuffer.get(currentRecOffset), () -> {
84-
return String.format("Arrays differ @%d expected %02x, but was %02x", currentRecOffset, sendBuffer.get(currentRecOffset), recBuffer.get(currentRecOffset));
84+
return String.format("Arrays differ @%d expected 0x%02x, but was 0x%02x", currentRecOffset, sendBuffer.get(currentRecOffset), recBuffer.get(currentRecOffset));
8585
});
8686
currentRecOffset++;
8787
} else {
@@ -101,7 +101,7 @@ public void run() {
101101
for (int i = 0; i < count; i++) {
102102
final int pos = currentRecOffset + i;
103103
assertEquals(sendBuffer.get(currentRecOffset), recBuffer.get(currentRecOffset), () -> {
104-
return String.format("Arrays differ @%d expected %02x, but was %02x", pos,
104+
return String.format("Arrays differ @%d expected 0x%02x, but was 0x%02x", pos,
105105
sendBuffer.get(pos), recBuffer.get(pos));
106106
});
107107
}
@@ -128,7 +128,7 @@ public void run() {
128128
for (int i = 0; i < count; i++) {
129129
final int pos = currentRecOffset + i;
130130
assertEquals(sendBuffer.get(pos), recBuffer.get(pos), () -> {
131-
return String.format("Arrays differ @%d expected %02x, but was %02x", pos,
131+
return String.format("Arrays differ @%d expected 0x%02x, but was 0x%02x", pos,
132132
sendBuffer.get(pos), recBuffer.get(pos));
133133
});
134134
}

de.ibapl.spsw.api.tests/src/main/java/de/ibapl/spsw/tests/PortConfiguration.java

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import de.ibapl.spsw.api.FlowControl;
2828
import de.ibapl.spsw.api.Parity;
2929
import de.ibapl.spsw.api.SerialPortConfiguration;
30-
import de.ibapl.spsw.api.SerialPortSocket;
3130
import de.ibapl.spsw.api.Speed;
3231
import de.ibapl.spsw.api.StopBits;
3332

de.ibapl.spsw.api.tests/src/main/java/de/ibapl/spsw/tests/PortConfigurationFactory.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ static class PortConfigurationImpl implements PortConfiguration {
4747
private DataBits dataBits = DataBits.DB_8;
4848
private Set<FlowControl> flowControl = FlowControl.getFC_NONE(); // getFC_RTS_CTS();
4949
private int interByteReadTimeout = 100;
50-
private int overallReadTimeout = 2000;
51-
private int overallWriteTimeout = 2000;
50+
private int overallReadTimeout = 3000;
51+
private int overallWriteTimeout = 3000;
5252
private Parity parity = Parity.NONE;
5353
private Speed speed = Speed._9600_BPS;
5454
private StopBits stopBits = StopBits.SB_1;

de.ibapl.spsw.api.tests/src/main/java/de/ibapl/spsw/tests/SetupAndTeardownTests.java

-8
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,23 @@
2222
package de.ibapl.spsw.tests;
2323

2424
import de.ibapl.jnhw.libloader.MultiarchTupelBuilder;
25-
import de.ibapl.spsw.api.DataBits;
26-
import de.ibapl.spsw.api.FlowControl;
27-
import de.ibapl.spsw.api.Parity;
2825
import de.ibapl.spsw.api.SerialPortConfiguration;
29-
import de.ibapl.spsw.api.SerialPortSocket;
3026
import de.ibapl.spsw.api.SerialPortSocketFactory;
3127
import de.ibapl.spsw.api.Speed;
32-
import de.ibapl.spsw.api.StopBits;
3328
import java.io.IOException;
3429
import java.io.InputStream;
3530
import java.text.MessageFormat;
3631
import java.util.Iterator;
3732
import java.util.Properties;
3833
import java.util.ServiceLoader;
39-
import java.util.Set;
4034
import java.util.concurrent.ExecutorService;
4135
import java.util.concurrent.Executors;
4236
import java.util.logging.Level;
4337
import java.util.logging.Logger;
4438
import org.junit.jupiter.api.AfterEach;
45-
import static org.junit.jupiter.api.Assertions.assertEquals;
4639
import static org.junit.jupiter.api.Assertions.assertFalse;
4740
import static org.junit.jupiter.api.Assertions.assertTrue;
4841
import static org.junit.jupiter.api.Assumptions.assumeTrue;
49-
import org.junit.jupiter.api.BeforeAll;
5042
import org.junit.jupiter.api.BeforeEach;
5143
import org.junit.jupiter.api.TestInfo;
5244
import org.junit.jupiter.api.TestInstance;

de.ibapl.spsw.api/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>de.ibapl.spsw</groupId>
77
<artifactId>spsw-project</artifactId>
8-
<version>3.0.2-SNAPSHOT</version>
8+
<version>3.1.0-SNAPSHOT</version>
99
<relativePath>../pom.xml</relativePath>
1010
</parent>
1111

de.ibapl.spsw.api/src/main/java/de/ibapl/spsw/api/SerialPortConfiguration.java

+30
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,20 @@ default double calculateSpeedInCharactersPerSecond() throws IOException {
281281
*/
282282
Speed getSpeed() throws IOException;
283283

284+
/**
285+
*
286+
* @return the input speed
287+
* @throws IOException
288+
*/
289+
Speed getInSpeed() throws IOException;
290+
291+
/**
292+
*
293+
* @return the output speed
294+
* @throws IOException
295+
*/
296+
Speed getOutSpeed() throws IOException;
297+
284298
/**
285299
* Read the number of stop bits from the port.
286300
*
@@ -457,6 +471,22 @@ default double calculateSpeedInCharactersPerSecond() throws IOException {
457471
*/
458472
void setSpeed(Speed speed) throws IOException;
459473

474+
/**
475+
*
476+
* @param speed
477+
* @throws IOException
478+
* @throws IllegalArgumentException it the input speed can't be set separately.
479+
*/
480+
void setInSpeed(Speed speed) throws IOException, IllegalArgumentException;
481+
482+
/**
483+
*
484+
* @param speed
485+
* @throws IOException
486+
* @throws IllegalArgumentException it the output speed can't be set separately.
487+
*/
488+
void setOutSpeed(Speed speed) throws IOException, IllegalArgumentException;
489+
460490
/**
461491
* Write the number of stop bits to the port. <br>
462492
* If the number stop bits are not supported by the underlying OS and OEM

0 commit comments

Comments
 (0)