21
21
*/
22
22
package de .ibapl .spsw .tests ;
23
23
24
- import de .ibapl .jnhw .libloader .MultiarchTupelBuilder ;
25
24
import de .ibapl .spsw .api .DataBits ;
26
25
import de .ibapl .spsw .api .FlowControl ;
27
26
import de .ibapl .spsw .api .Parity ;
48
47
import java .util .List ;
49
48
import java .util .Set ;
50
49
import java .util .concurrent .Future ;
50
+ import java .util .concurrent .TimeUnit ;
51
51
import java .util .logging .Level ;
52
52
import org .junit .jupiter .api .Assertions ;
53
53
import static org .junit .jupiter .api .Assertions .assertEquals ;
59
59
import static org .junit .jupiter .api .Assertions .fail ;
60
60
import static org .junit .jupiter .api .Assumptions .assumeTrue ;
61
61
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 ;
64
63
import org .junit .jupiter .params .ParameterizedTest ;
65
64
import org .junit .jupiter .params .provider .EnumSource ;
66
65
import org .junit .jupiter .params .provider .MethodSource ;
@@ -93,36 +92,22 @@ public void testFlowControl() throws Exception {
93
92
94
93
testFlowControl (EnumSet .of (FlowControl .XON_XOFF_IN ));
95
94
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
+ }
126
111
}
127
112
128
113
@ BaselineTest
@@ -539,14 +524,30 @@ public void testWriteSingleByteTimeout() throws Exception {
539
524
private final static int _16MB = 1024 * 1024 * 16 ;
540
525
private final static int _1MB = 1024 * 1024 ; // Too much for FTDI on Windows there is nothing sent...
541
526
private final static int _256kB = 1024 * 256 ;
527
+ private final static int _8kB = 1024 * 8 ;
542
528
543
529
@ BaselineTest
544
530
@ 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 )
545
546
public void testWrite256kBChunkInfiniteWrite () throws Exception {
546
547
writeChunk (_256kB , Speed ._230400_BPS , 0 );
547
548
}
548
549
549
- @ BaselineTest
550
+ @ NotSupportedByAllDevices
550
551
@ Test
551
552
public void write256kBChunk () throws Exception {
552
553
writeChunk (_256kB , Speed ._230400_BPS , 1000 + 2 * SerialPortConfiguration .calculateMillisForCharacters (_256kB ,
@@ -555,6 +556,7 @@ public void write256kBChunk() throws Exception {
555
556
556
557
@ NotSupportedByAllDevices
557
558
@ Test
559
+ @ Timeout (unit = TimeUnit .MINUTES , value = 2 )
558
560
public void testWrite1MBChunkInfiniteWrite () throws Exception {
559
561
writeChunk (_1MB , Speed ._1000000_BPS , 0 );
560
562
}
@@ -574,6 +576,7 @@ public void write1MBChunk() throws Exception {
574
576
*/
575
577
@ NotSupportedByAllDevices
576
578
@ Test
579
+ @ Timeout (unit = TimeUnit .MINUTES , value = 4 )
577
580
public void testWrite16MBChunkInfiniteWrite () throws Exception {
578
581
writeChunk (_16MB , Speed ._1000000_BPS , 0 );
579
582
}
@@ -593,11 +596,10 @@ public void write16MBChunk() throws Exception {
593
596
594
597
public void writeChunk (int chunksize , Speed speed , int writeTimeout ) throws Exception {
595
598
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 });
599
601
} 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 } );
601
603
}
602
604
603
605
// Set a high speed to speed up things
@@ -607,9 +609,13 @@ public void writeChunk(int chunksize, Speed speed, int writeTimeout) throws Exce
607
609
byte [] data = new byte [chunksize ];
608
610
int dataWritten = 0 ;
609
611
try {
610
- assertTimeoutPreemptively ( Duration . ofMillis ( writeSpc . calculateMillisForCharacters ( data . length * 2 )), () -> {
612
+ if ( writeTimeout == SerialPortSocket . INFINITE_TIMEOUT ) {
611
613
writeSpc .getOutputStream ().write (data );
612
- });
614
+ } else {
615
+ assertTimeoutPreemptively (Duration .ofMillis (writeSpc .calculateMillisForCharacters (data .length * 2 )), () -> {
616
+ writeSpc .getOutputStream ().write (data );
617
+ });
618
+ }
613
619
dataWritten = data .length ;
614
620
} catch (TimeoutIOException e ) {
615
621
dataWritten = e .bytesTransferred ;
@@ -815,11 +821,20 @@ public void testBreak() throws Exception {
815
821
public void testParity (Parity p ) throws Exception {
816
822
LOG .log (Level .INFO , "run testParity({0}) - BaselineTest" , p );
817
823
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 ());
823
838
}
824
839
}
825
840
@@ -833,7 +848,14 @@ public void testSpeed() throws Exception {
833
848
for (Speed b : Speed .values ()) {
834
849
try {
835
850
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
+ });
837
859
} catch (IllegalArgumentException iae ) {
838
860
switch (b ) {
839
861
case _0_BPS :
@@ -859,7 +881,7 @@ public void testSpeed() throws Exception {
859
881
case _3000000_BPS :
860
882
case _3500000_BPS :
861
883
case _4000000_BPS :
862
- if (b != readSpc .getSpeed ()) {
884
+ if (b != readSpc .getOutSpeed () || b != readSpc . getInSpeed ()) {
863
885
LOG .warning ("Can't set speed to " + b );
864
886
}
865
887
break ;
@@ -1442,11 +1464,14 @@ public void testFinalize() throws IOException, InterruptedException {
1442
1464
1443
1465
// On Windows the GC needs some time - I don't know why... (FTDI on win64 needs
1444
1466
// 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 );
1450
1475
}
1451
1476
1452
1477
readSpc = getSerialPortSocketFactory ().open (serialPortName );
0 commit comments