Skip to content

Commit

Permalink
Do not fail sudo tests if running under root
Browse files Browse the repository at this point in the history
  • Loading branch information
apangin committed Oct 10, 2024
1 parent 3992d6a commit 445bafb
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion test/one/profiler/test/TestProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,14 @@ private void moveLogs() {
}
}

private boolean isRoot() {
try (Stream<String> lines = Files.lines(Paths.get("/proc/self/status"))) {
return lines.anyMatch(s -> s.startsWith("Uid:") && s.matches("Uid:\\s+0\\s+0.*"));
} catch (IOException e) {
return false;
}
}

@Override
public void close() {
p.destroy();
Expand Down Expand Up @@ -262,7 +270,7 @@ public Output profile(String args) throws IOException, TimeoutException, Interru

public Output profile(String args, boolean sudo) throws IOException, TimeoutException, InterruptedException {
List<String> cmd = new ArrayList<>();
if (sudo) {
if (sudo && (new File("/usr/bin/sudo").exists() || !isRoot())) {
cmd.add("/usr/bin/sudo");
}
cmd.add("build/bin/asprof");
Expand Down

0 comments on commit 445bafb

Please sign in to comment.