Skip to content

Commit

Permalink
jtreg-wrappers: Add runtime check for native clients
Browse files Browse the repository at this point in the history
  • Loading branch information
zzambers committed Nov 6, 2023
1 parent 861e1aa commit 9592b42
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 15 deletions.
89 changes: 89 additions & 0 deletions jtreg-wrappers/SysDepsProps.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import java.io.InputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.FileSystems;
import java.util.Map;
import java.util.HashMap;
import java.util.concurrent.Callable;

public class SysDepsProps implements Callable<Map<String, String>> {

Thread streamDiscarder(final InputStream is) {
return new Thread() {
@Override
public void run() {
try {
try {
while (is.read() >= 0) { /* discard */ };
} finally {
is.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
};
}

boolean checkOnPath(String cmd) {
ProcessBuilder pb = new ProcessBuilder(cmd, "--help");
Process p = null;
Thread outDiscarder = null;
Thread errDiscarder = null;
int retVal = 0;
try {
p = pb.start(); // throws exception if program does not exist
outDiscarder = streamDiscarder(p.getInputStream());
outDiscarder.start();
errDiscarder = streamDiscarder(p.getErrorStream());
errDiscarder.start();
p.getOutputStream().close();
p.waitFor();
return true;
} catch (Exception ex) {
if (p != null) {
p.destroy();
}
} finally {
try {
if (outDiscarder != null) {
outDiscarder.join();
}
if (errDiscarder != null) {
errDiscarder.join();
}
} catch (InterruptedException ex) {}
}
return false;
}

boolean fileExists(String path) {
return Files.exists(FileSystems.getDefault().getPath(path));
}

boolean checkGnutlsCli() {
return checkOnPath("gnutls-cli");
}

boolean checkTstclnt() {
if (fileExists("/usr/lib64/nss/unsupported-tools/tstclnt")
|| fileExists("/usr/lib/nss/unsupported-tools/tstclnt")) {
return true;
}
return checkOnPath("tstclnt");
}

@Override
public Map<String, String> call() {
Map<String, String> map = new HashMap<String, String>();
map.put("bin.gnutlscli", checkGnutlsCli() ? "true": "false");
map.put("bin.tstclnt", checkTstclnt() ? "true": "false");
return map;
}

public static void main(String[] args) {
for (Map.Entry<String,String> entry: new SysDepsProps().call().entrySet()) {
System.out.println(entry.getKey() + ": " + entry.getValue());
}
}
}
4 changes: 4 additions & 0 deletions jtreg-wrappers/TEST.ROOT
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
requires.extraPropDefns = SysDepsProps.java
requires.properties = \
bin.gnutlscli \
bin.tstclnt
2 changes: 1 addition & 1 deletion jtreg-wrappers/ssl-tests-gnutls-client.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
# @test
# @requires os.family == "linux"
# @requires os.family == "linux" & bin.gnutlscli != "false"
# @bug 6666666
# @summary ssl-tests with gnutls client
# @run shell/timeout=1000 ssl-tests-gnutls-client.sh
Expand Down
15 changes: 1 addition & 14 deletions jtreg-wrappers/ssl-tests-nss-client.sh
Original file line number Diff line number Diff line change
@@ -1,26 +1,13 @@
#!/bin/sh
# @test
# @requires os.family == "linux"
# @requires os.family == "linux" & bin.tstclnt != "false"
# @bug 6666666
# @summary ssl-test with nss client
# @run shell/timeout=1000 ssl-tests-nss-client.sh

set -eu
rm -rf build

if ! type tstclnt > /dev/null 2>&1 \
&& ! [ -e "/usr/lib64/nss/unsupported-tools/tstclnt" ] \
&& ! [ -e "/usr/lib/nss/unsupported-tools/tstclnt" ] ; then
if grep -Eiq 'Fedora|Red Hat|Ubuntu' /etc/os-release > /dev/null 2>&1 ; then
# Error on system, where it should be available
echo "Error: Missing tstclnt tool, please install NSS tools"
exit 1
else
echo "Skipping, required tstclnt tool not found"
exit 0
fi
fi

if ! type listsuites > /dev/null 2>&1 \
&& ! [ -e "/usr/lib64/nss/unsupported-tools/listsuites" ] \
&& ! [ -e "/usr/lib/nss/unsupported-tools/listsuites" ] ; then
Expand Down

0 comments on commit 9592b42

Please sign in to comment.