From 82cb98270dfa933e5b3e1f95371c69ce00982101 Mon Sep 17 00:00:00 2001 From: Mateusz Pietryga Date: Sun, 15 Aug 2021 18:41:18 +0200 Subject: [PATCH] Github actions pipeline for integration testing --- .github/workflows/integration-test.yml | 79 +++++++++++++++++++ .../library-compatibility/pom.xml | 49 ++++++++++++ .../src/main/java/com/example/Main.java | 41 ++++++++++ pom.xml | 2 +- 4 files changed, 170 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/integration-test.yml create mode 100644 integration-test/library-compatibility/pom.xml create mode 100644 integration-test/library-compatibility/src/main/java/com/example/Main.java diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml new file mode 100644 index 000000000..dc1b33814 --- /dev/null +++ b/.github/workflows/integration-test.yml @@ -0,0 +1,79 @@ +name: Integration test +on: workflow_dispatch + +env: + MAVEN_OPTS: -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn + JAVA_32: https://cdn.azul.com/zulu/bin/zulu11.50.19-ca-jre11.0.12-win_i686.zip + JAVA_64: https://cdn.azul.com/zulu/bin/zulu11.50.19-ca-jre11.0.12-win_x64.zip + +jobs: + test-on-wine: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 11 + uses: actions/setup-java@v2 + with: + java-version: 11 + distribution: temurin + + - name: Build main package + run: mvn -B install -Ppackage -DskipTests + + - name: Build test project runnable jar + run: mvn -B -f integration-test/library-compatibility/pom.xml compile assembly:single + + - name: Install dependencies + run: | + sudo dpkg --add-architecture i386 + sudo apt-get -qq update + sudo apt-get -qq install -y socat wine > /dev/null + + - name: Get Java 32 for Windows + run: | + wget -qO jre32.zip ${JAVA_32} + unzip -qq jre32.zip -d $HOME/win32 + mv $(ls -d $HOME/win32/*/) $HOME/win32/jre + + - name: Get Java 64 for Windows + run: | + wget -qO jre64.zip ${JAVA_64} + unzip -qq jre64.zip -d $HOME/win64 + mv $(ls -d $HOME/win64/*/) $HOME/win64/jre + + - name: Setup wine + run: | + WINEPREFIX=~/win32/.wine WINEARCH=win32 wine wineboot + WINEPREFIX=~/win64/.wine WINEARCH=win64 wine wineboot + + - name: Set up serial port pair + run: | + ( socat -d -d PTY,link=$HOME/com1,raw,echo=0 PTY,link=$HOME/com2,raw,echo=0) & + sleep 1 + export COM1=$( readlink $HOME/com1 ) + export COM2=$( readlink $HOME/com2 ) + + export WINEPREFIX=~/win32/.wine + wine reg add "HKLM\\Software\\Wine\\Ports" /v "COM1" /t REG_SZ /d "${COM1}" + wine reg add "HKLM\\Software\\Wine\\Ports" /v "COM2" /t REG_SZ /d "${COM2}" + ln -fs ${COM1} ${WINEPREFIX}/dosdevices/com1 + ln -fs ${COM2} ${WINEPREFIX}/dosdevices/com2 + + export WINEPREFIX=~/win64/.wine + wine reg add "HKLM\\Software\\Wine\\Ports" /v "COM1" /t REG_SZ /d "${COM1}" + wine reg add "HKLM\\Software\\Wine\\Ports" /v "COM2" /t REG_SZ /d "${COM2}" + ln -fs ${COM1} ${WINEPREFIX}/dosdevices/com1 + ln -fs ${COM2} ${WINEPREFIX}/dosdevices/com2 + + - name: Run test project under wine32 + run: | + export WINEPREFIX=~/win32/.wine + wine ~/win32/jre/bin/java.exe -jar $( winepath -w integration-test/library-compatibility/target/runme.jar ) + + - name: Run test project under wine64 + run: | + export WINEPREFIX=~/win64/.wine + wine ~/win64/jre/bin/java.exe -jar $( winepath -w integration-test/library-compatibility/target/runme.jar ) + + - name: Cleanup + run: pkill socat || true diff --git a/integration-test/library-compatibility/pom.xml b/integration-test/library-compatibility/pom.xml new file mode 100644 index 000000000..90ddf5f4c --- /dev/null +++ b/integration-test/library-compatibility/pom.xml @@ -0,0 +1,49 @@ + + + 4.0.0 + + com.IntegrationTest + jssc-test + 2.9.4-SNAPSHOT + + + 6 + 6 + + + + + net.jockx + test-jssc + 2.9.4-SNAPSHOT + + + org.slf4j + slf4j-simple + 1.7.30 + + + + + + + maven-assembly-plugin + + + + com.example.Main + + + + jar-with-dependencies + + runme + false + + + + + + \ No newline at end of file diff --git a/integration-test/library-compatibility/src/main/java/com/example/Main.java b/integration-test/library-compatibility/src/main/java/com/example/Main.java new file mode 100644 index 000000000..0029a633d --- /dev/null +++ b/integration-test/library-compatibility/src/main/java/com/example/Main.java @@ -0,0 +1,41 @@ +package com.example; + +import jssc.*; + +import java.util.Arrays; + +public class Main { + + static SerialPortEventListener listener = new SerialPortEventListener() { + @Override + public void serialEvent(SerialPortEvent serialPortEvent) { + System.err.println("Event type " + serialPortEvent.getEventType()); + try { + System.out.println(serialPortEvent.getPort().readString()); + } catch (SerialPortException e) { + e.printStackTrace(); + } + } + }; + + public static void main(String... args) throws SerialPortException, InterruptedException { + String[] serialPorts = SerialPortList.getPortNames(); + String portAName = serialPorts[0]; + String portBName = serialPorts[1]; + System.out.println("Serial ports: " + Arrays.asList(SerialPortList.getPortNames())); + final SerialPort portA = new SerialPort(portAName); + final SerialPort portB = new SerialPort(portBName); + portA.openPort(); + portB.openPort(); + + portA.addEventListener(listener); + portB.addEventListener(listener); + + portA.writeBytes("Hello, it's A".getBytes()); + portB.writeBytes("Hello, it's B".getBytes()); + + Thread.sleep(1000); + portA.closePort(); + portB.closePort(); + } +} diff --git a/pom.xml b/pom.xml index bc05be5d4..37d56eaf6 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ net.jockx test-jssc - 2.9.3-SNAPSHOT + 2.9.4-SNAPSHOT Java Simple Serial Connector