Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeMirzayanov committed Sep 4, 2023
1 parent 41b1200 commit b3fad97
Show file tree
Hide file tree
Showing 8 changed files with 218 additions and 135 deletions.
124 changes: 0 additions & 124 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,130 +18,6 @@ env:
TEST_REF_FORBID_GEN_REFS: true

jobs:
tests-ubuntu1804-gpp:
strategy:
matrix:
os: [ubuntu-18.04]
compiler: [g++]
version: [7, 9, 10]
name: Use ${{ matrix.compiler }}-${{ matrix.version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Run tests
run: |
cd tests
bash ./run.sh ${{ matrix.compiler }} v${{ matrix.version }}
tests-ubuntu1804-clang:
strategy:
matrix:
os: [ubuntu-18.04]
compiler: [clang++]
version: [9]
name: Use ${{ matrix.compiler }}-${{ matrix.version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Run tests
run: |
cd tests
bash ./run.sh ${{ matrix.compiler }} v${{ matrix.version }}
tests-ubuntu2204-gpp:
strategy:
matrix:
os: [ubuntu-22.04]
compiler: [g++]
version: [9, 10, 11]
name: Use ${{ matrix.compiler }}-${{ matrix.version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Run tests
run: |
cd tests
bash ./run.sh ${{ matrix.compiler }} v${{ matrix.version }}
tests-ubuntu2204-clang:
strategy:
matrix:
os: [ubuntu-22.04]
compiler: [clang++]
version: [12, 13, 14]
name: Use ${{ matrix.compiler }}-${{ matrix.version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Run tests
run: |
cd tests
bash ./run.sh ${{ matrix.compiler }} v${{ matrix.version }}
tests-ubuntu1804-gpp-32:
strategy:
matrix:
os: [ubuntu-18.04]
compiler: [g++]
version: [7, 9, 10]
name: Use ${{ matrix.compiler }}-${{ matrix.version }} -m32 on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Run tests
run: |
sudo apt-get install gcc-${{ matrix.version }}-multilib g++-${{ matrix.version }}-multilib
cd tests
bash ./run.sh ${{ matrix.compiler }} v${{ matrix.version }} 32
tests-ubuntu1804-clang-32:
strategy:
matrix:
os: [ubuntu-18.04]
compiler: [clang++]
version: [9]
name: Use ${{ matrix.compiler }}-${{ matrix.version }} -m32 on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Run tests
run: |
sudo apt-get install gcc-multilib g++-multilib
cd tests
bash ./run.sh ${{ matrix.compiler }} v${{ matrix.version }} 32
tests-ubuntu2204-gpp-32:
strategy:
matrix:
os: [ubuntu-22.04]
compiler: [g++]
version: [9, 10, 11]
name: Use ${{ matrix.compiler }}-${{ matrix.version }} -m32 on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Run tests
run: |
sudo apt-get install gcc-${{ matrix.version }}-multilib g++-${{ matrix.version }}-multilib
cd tests
bash ./run.sh ${{ matrix.compiler }} v${{ matrix.version }} 32
tests-ubuntu2204-clang-32:
strategy:
matrix:
os: [ubuntu-22.04]
compiler: [clang++]
version: [12, 13, 14]
name: Use ${{ matrix.compiler }}-${{ matrix.version }} -m32 on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Run tests
run: |
sudo apt-get install gcc-multilib g++-multilib
cd tests
bash ./run.sh ${{ matrix.compiler }} v${{ matrix.version }} 32
tests-macos11-gpp:
strategy:
matrix:
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ if [[ "$machine" == "Windows" && ("$ARGS_CPP" == "" || "$ARGS_CPP" == "msvc") ]]
echo "Compiler Visual Studio $version ($vs_release-$bits) has been found"
echo call \""$vcvars_bat_file"\" >do-vcvars.bat
echo "bash -c export > vcvars.env" >>do-vcvars.bat
python runner.py do-vcvars.bat
python file-runner.py do-vcvars.bat
grep -v -E "(\(.*=)|(\!.*=)|([A-Z]\-[A-Z].*=)" <vcvars.env >vcvars_filtered.env
source vcvars_filtered.env
rm -f do-vcvars.bat vcvars.env vcvars_filtered.env
Expand Down
Binary file not shown.
162 changes: 162 additions & 0 deletions tests/test-006_interactors/files/crossrun/CrossRun.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class CrossRun {
private static final List<String> messages = Collections.synchronizedList(new ArrayList<String>());

private static volatile boolean failed = false;

private static void error(String message) {
System.out.println("ERROR: " + message);
System.exit(1);
}

public static void main(String[] args) {
int sep = -1;
for (int i = 0; i < args.length; i++) {
if (args[i].equals("--")) {
sep = i;
break;
}
}

if (sep == -1) {
error("Expected exactly one '--' as separator for the two process command lines.");
}

String[] params1 = new String[sep];
System.arraycopy(args, 0, params1, 0, params1.length);

String[] params2 = new String[args.length - sep - 1];
System.arraycopy(args, sep + 1, params2, 0, params2.length);

long startTime = System.currentTimeMillis();

try {
runProcesses(params1, params2);
} catch (IOException e) {
error(e.getMessage());
}

System.out.println("Completed in " + (System.currentTimeMillis() - startTime) + " ms.");
}

private static void runProcesses(String[] params1, String[] params2) throws IOException {
Process process1 = new ProcessBuilder(params1).start();
Process process2 = new ProcessBuilder(params2).start();

Thread readProcess1WriteProcess2Thread =
new Thread(new StreamProxyRunner("process1", "process2", process1.getInputStream(), process2.getOutputStream()));
Thread readProcess2WriteProcess1Thread =
new Thread(new StreamProxyRunner("process2", "process1", process2.getInputStream(), process1.getOutputStream()));

readProcess1WriteProcess2Thread.start();
readProcess2WriteProcess1Thread.start();

int processExitCode1 = -1;
try {
processExitCode1 = process1.waitFor();
} catch (InterruptedException e) {
error(e.getMessage());
}

int processExitCode2 = -1;
try {
processExitCode2 = process2.waitFor();
} catch (InterruptedException e) {
error(e.getMessage());
}

try {
readProcess1WriteProcess2Thread.join();
} catch (InterruptedException e) {
error(e.getMessage());
}

try {
readProcess2WriteProcess1Thread.join();
} catch (InterruptedException e) {
error(e.getMessage());
}

if (processExitCode1 != 0) {
messages.add("The process 1 returned with exit code " + processExitCode1 + ".");
}

if (processExitCode2 != 0) {
messages.add("The process 2 returned with exit code " + processExitCode2 + ".");
}

for (String message : messages) {
System.out.println("* " + message);
}

if (failed) {
System.exit(1);
}
}

@SuppressWarnings("ClassCanBeRecord")
private static final class StreamProxyRunner implements Runnable {
private final String processName1;
private final String processName2;
private final InputStream inputStream;
private final OutputStream outputStream;

private StreamProxyRunner(final String processName1,
final String processName2,
final InputStream inputStream,
final OutputStream outputStream) {
this.processName1 = processName1;
this.processName2 = processName2;
this.inputStream = inputStream;
this.outputStream = outputStream;
}

@Override
public void run() {
byte[] buffer = new byte[65536];

while (true) {
int size;

try {
size = inputStream.read(buffer);
} catch (IOException e) {
messages.add("Unexpected exception " + e.getClass().getSimpleName() + " while reading from the output of the " + processName1 + " process: " + e.getMessage());
failed = true;
break;
}

if (size < 0) {
break;
}

try {
outputStream.write(buffer, 0, size);
outputStream.flush();
} catch (IOException e) {
messages.add("Unexpected exception " + e.getClass().getSimpleName() + " while writing to the input of the " + processName2 + " process: " + e.getMessage());
failed = true;
break;
}
}

try {
inputStream.close();
} catch (IOException e) {
// No operations.
}

try {
outputStream.close();
} catch (IOException e) {
// No operations.
}
}
}
}
53 changes: 53 additions & 0 deletions tests/test-006_interactors/files/crossrun/build-cross-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash

uname_output="$(uname -s)"
case "${uname_output}" in
Linux*) machine=Linux ;;
Darwin*) machine=Mac ;;
CYGWIN*) machine=Windows ;;
MINGW*) machine=Windows ;;
MSYS*) machine=Windows ;;
*) echo "Unknown system '${uname_output}'" && exit 1 ;;
esac

# If JAVA8_32_HOME is set, use its javac
if [[ -n "$JAVA8_32_HOME" ]]; then
if [[ "$machine" == "Windows" ]]; then
JAVA8_32_HOME=$(cygpath "$JAVA8_32_HOME")
fi
export PATH="$JAVA8_32_HOME/bin:$PATH"
fi

# If JAVA7_32_HOME is set, use its javac
if [[ -n "$JAVA7_32_HOME" ]]; then
if [[ "$machine" == "Windows" ]]; then
JAVA7_32_HOME=$(cygpath "$JAVA7_32_HOME")
fi
export PATH="$JAVA7_32_HOME/bin:$PATH"
fi

echo $PATH

# Show javac version
javac -version

# Compile all .java files
javac *.java

# Check if the compilation was successful
if [ $? -ne 0 ]; then
echo "Error during compilation. Exiting."
exit 1
fi

# Create a manifest file for the jar
echo "Main-Class: CrossRun" > manifest.mf

# Package all .class files into a jar
jar cvfm CrossRun.jar manifest.mf *.class

# Cleanup .class files and manifest file (optional)
rm *.class
rm manifest.mf

echo "Done. CrossRun.jar created."
9 changes: 2 additions & 7 deletions tests/test-006_interactors/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,8 @@ bash ../scripts/test-ref r-interactor-a-plus-b-1-2 cat output.01.nix
rm -f output.01 output.01.nix

bash ../scripts/compile src/interactive-a-plus-b.cpp
python src/interactive_runner.py ./interactor-a-plus-b files/"$os"/input.01 output.02 -- ./interactive-a-plus-b 1>interactive_runner.out 2>interactive_runner.err &
echo `/bin/date "+%Y%m%d %T"`
sleep 5
echo `/bin/date "+%Y%m%d %T"`
pkill python
cat interactive_runner.out
cat interactive_runner.err
echo "Running 'java -jar files/crossrun/CrossRun.jar ./interactor-a-plus-b files/"$os"/input.01 output.02 -- ./interactive-a-plus-b'"
java -jar files/crossrun/CrossRun.jar ./interactor-a-plus-b files/"$os"/input.01 output.02 -- ./interactive-a-plus-b
tr -d '\r' < output.02 > output.02.nix
bash ../scripts/test-ref r-interactor-a-plus-b-2-1 cat output.02.nix
rm -f output.02 output.02.nix interactive-a-plus-b interactive-a-plus-b.exe interactor-a-plus-b interactor-a-plus-b.exe interactive_runner.out interactive_runner.err
3 changes: 0 additions & 3 deletions tests/testme.bat

This file was deleted.

0 comments on commit b3fad97

Please sign in to comment.