This is an automated email from the ASF dual-hosted git repository.

alexey pushed a commit to branch branch-1.15.x
in repository https://gitbox.apache.org/repos/asf/kudu.git

commit 1bc0a57e6446153e422ca05a7744fbffe52a31f2
Author: Alexey Serbin <[email protected]>
AuthorDate: Sat May 22 13:39:53 2021 -0700

    [java] utility to detect sanitizer type used for kudu CLI
    
    This patch adds a new test utility to determine the type of the C++
    sanitizer type used by the kudu CLI binary, if any.  The new utility is
    added into the kudu-test-utils package.  I found it's useful to find
    whether the mini-cluster binaries are built with TSAN/ASAN sanitizers,
    so it's possible to skip heavy test scenarios which are not stable when
    running against binaries built with ASAN/TSAN support.
    
    I didn't add any tests, but this functionality is going to be used
    in a follow-up patch.
    
    Change-Id: I08c978ecda7321038b97c5c885914c02122606c1
    Reviewed-on: http://gerrit.cloudera.org:8080/17487
    Tested-by: Alexey Serbin <[email protected]>
    Reviewed-by: Grant Henke <[email protected]>
    (cherry picked from commit 6a0752420fdf46b821038d2f789cc9742a2ac864)
    Reviewed-on: http://gerrit.cloudera.org:8080/17492
---
 .../apache/kudu/test/cluster/KuduBinaryInfo.java   | 80 ++++++++++++++++++++++
 1 file changed, 80 insertions(+)

diff --git 
a/java/kudu-test-utils/src/main/java/org/apache/kudu/test/cluster/KuduBinaryInfo.java
 
b/java/kudu-test-utils/src/main/java/org/apache/kudu/test/cluster/KuduBinaryInfo.java
index 8294e33..f65cd31 100644
--- 
a/java/kudu-test-utils/src/main/java/org/apache/kudu/test/cluster/KuduBinaryInfo.java
+++ 
b/java/kudu-test-utils/src/main/java/org/apache/kudu/test/cluster/KuduBinaryInfo.java
@@ -17,6 +17,16 @@
 
 package org.apache.kudu.test.cluster;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.List;
+
+import com.google.common.base.Joiner;
+import com.google.common.collect.Lists;
 import org.apache.yetus.audience.InterfaceAudience;
 import org.apache.yetus.audience.InterfaceStability;
 
@@ -52,4 +62,74 @@ public class KuduBinaryInfo {
   public String getSaslDir() {
     return saslDir;
   }
+
+  /**
+   * The C++ sanitizer type enabled for the kudu CLI binary.
+   */
+  public enum SanitizerType {
+    NONE,
+    ASAN,
+    TSAN,
+  }
+
+  /**
+   * @return sanitizer type for the kudu CLI binary.
+   */
+  public static SanitizerType getSanitizerType() {
+    List<String> vs = getBinaryVersionStrings();
+    if (vs.size() < 1 || !vs.get(0).startsWith("kudu ")) {
+      throw new RuntimeException(String.format(
+          "unexpected version output from kudu binary: %s",
+          Joiner.on("\n").join(vs)));
+    }
+    for (String s : vs) {
+      if (s.equals("ASAN enabled")) {
+        return SanitizerType.ASAN;
+      } else if (s.equals("TSAN enabled")) {
+        return SanitizerType.TSAN;
+      }
+    }
+    return SanitizerType.NONE;
+  }
+
+  /**
+   * @return sequence of strings output by 'kudu --version'
+   */
+  private static List<String> getBinaryVersionStrings() {
+    try {
+      KuduBinaryLocator.ExecutableInfo exeInfo =
+          KuduBinaryLocator.findBinary("kudu");
+      ProcessBuilder pb = new ProcessBuilder(
+          Lists.newArrayList(exeInfo.exePath(), "--version"));
+      pb.environment().putAll(exeInfo.environment());
+      pb.redirectError(ProcessBuilder.Redirect.INHERIT);
+      final Process p = pb.start();
+      List<String> result = new ArrayList<>();
+      try (InputStreamReader isr = new InputStreamReader(p.getInputStream(), 
UTF_8);
+           BufferedReader br = new BufferedReader(isr)) {
+        while (true) {
+          String line = br.readLine();
+          if (line == null) {
+            break;
+          }
+          result.add(line);
+        }
+      }
+      final int exitCode = p.waitFor();
+      if (exitCode != 0) {
+        // Don't bother reporting the contents of stderr: it should be in the
+        // log of the parent process due to the stderr redirection.
+        throw new RuntimeException(String.format(
+            "unexpected exit code from kudu binary: %d", exitCode));
+      }
+      return result;
+    } catch (IOException e) {
+      throw new RuntimeException(
+          "unexpected exception while trying to run kudu binary", e);
+    } catch (InterruptedException e) {
+      Thread.currentThread().interrupt();
+      throw new RuntimeException(
+          "unexpected exception while trying to run kudu binary", e);
+    }
+  }
 }

Reply via email to