8218197: [failurehandler] parent processes shouldn't be killed till their children are handle
authoriignatyev
Mon, 04 Feb 2019 17:53:26 -0800
changeset 53650 5ed765426c72
parent 53620 ffac5eabbf28
child 53651 0331b08811ad
8218197: [failurehandler] parent processes shouldn't be killed till their children are handle Reviewed-by: dholmes, kbarrett
test/failure_handler/src/share/classes/jdk/test/failurehandler/HtmlSection.java
test/failure_handler/src/share/classes/jdk/test/failurehandler/ToolKit.java
test/failure_handler/src/share/classes/jdk/test/failurehandler/action/ActionHelper.java
test/failure_handler/src/share/classes/jdk/test/failurehandler/action/PatternAction.java
--- a/test/failure_handler/src/share/classes/jdk/test/failurehandler/HtmlSection.java	Fri Feb 01 13:33:02 2019 -0800
+++ b/test/failure_handler/src/share/classes/jdk/test/failurehandler/HtmlSection.java	Mon Feb 04 17:53:26 2019 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -153,13 +153,11 @@
     public HtmlSection createChildren(String[] sections) {
         int i = 0;
         int n = sections.length;
-        HtmlSection current = rootSection;
-        if (current != null) {
-            for (; i < n && current.child != null;
-                    ++i, current = current.child) {
-                if (!sections[i].equals(current.child.name)) {
-                    break;
-                }
+        HtmlSection current = this;
+        for (; i < n && current.child != null;
+                ++i, current = current.child) {
+            if (!sections[i].equals(current.child.name)) {
+                break;
             }
         }
         for (; i < n; ++i) {
--- a/test/failure_handler/src/share/classes/jdk/test/failurehandler/ToolKit.java	Fri Feb 01 13:33:02 2019 -0800
+++ b/test/failure_handler/src/share/classes/jdk/test/failurehandler/ToolKit.java	Mon Feb 04 17:53:26 2019 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -31,6 +31,7 @@
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Queue;
+import java.util.Deque;
 
 public class ToolKit implements EnvironmentInfoGatherer, ProcessInfoGatherer {
     private final List<ActionSet> actions = new ArrayList<>();
@@ -52,20 +53,27 @@
 
     @Override
     public void gatherProcessInfo(HtmlSection section, long pid) {
-        Queue<Long> pids = new LinkedList<>();
-        pids.add(pid);
-        for (Long p = pids.poll(); p != null; p = pids.poll()) {
-            HtmlSection pidSection = section.createChildren("" + p);
-            List<Long> children = helper.getChildren(pidSection, p);
+        // as some of actions can kill a process, we need to get children of all
+        // test process first, and run the actions starting from the leaves
+        // and going up by the process tree
+        Deque<Long> orderedPids = new LinkedList<>();
+        Queue<Long> testPids = new LinkedList<>();
+        testPids.add(pid);
+        HtmlSection ptreeSection = section.createChildren("test_processes");
+        for (Long p = testPids.poll(); p != null; p = testPids.poll()) {
+            orderedPids.addFirst(p);
+            List<Long> children = helper.getChildren(ptreeSection, p);
             if (!children.isEmpty()) {
-                HtmlSection s = pidSection.createChildren("children");
+                HtmlSection s = ptreeSection.createChildren("" + p);
                 for (Long c : children) {
                     s.link(section, c.toString(), c.toString());
                 }
-                pids.addAll(children);
+                testPids.addAll(children);
             }
+        }
+        for (Long p : orderedPids) {
             for (ActionSet set : actions) {
-                set.gatherProcessInfo(pidSection, p);
+                set.gatherProcessInfo(section, p);
             }
         }
     }
--- a/test/failure_handler/src/share/classes/jdk/test/failurehandler/action/ActionHelper.java	Fri Feb 01 13:33:02 2019 -0800
+++ b/test/failure_handler/src/share/classes/jdk/test/failurehandler/action/ActionHelper.java	Mon Feb 04 17:53:26 2019 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -64,7 +64,7 @@
     public ActionHelper(Path workDir, String prefix, Properties properties,
                         Path... jdks) throws InvalidValueException {
         this.workDir = workDir.toAbsolutePath();
-        getChildren = new PatternAction("children",
+        getChildren = new PatternAction(null,
                 Utils.prependPrefix(prefix, "getChildren"), properties);
         ValueHandler.apply(this, properties, prefix);
         String[] pathStrings = System.getenv("PATH").split(File.pathSeparator);
--- a/test/failure_handler/src/share/classes/jdk/test/failurehandler/action/PatternAction.java	Fri Feb 01 13:33:02 2019 -0800
+++ b/test/failure_handler/src/share/classes/jdk/test/failurehandler/action/PatternAction.java	Mon Feb 04 17:53:26 2019 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -44,7 +44,7 @@
 
     public PatternAction(String name, String id, Properties properties)
             throws InvalidValueException {
-        action = new SimpleAction(("pattern." + name), id, properties);
+        action = new SimpleAction(name != null ? ("pattern." + name) : "pattern", id, properties);
         ValueHandler.apply(this, properties, id);
         originalArgs = action.args.clone();
     }