diff --git a/src/share/classes/com/sun/javatest/regtest/exec/RegressionScript.java b/src/share/classes/com/sun/javatest/regtest/exec/RegressionScript.java index 1e049c847..18c9d65b3 100644 --- a/src/share/classes/com/sun/javatest/regtest/exec/RegressionScript.java +++ b/src/share/classes/com/sun/javatest/regtest/exec/RegressionScript.java @@ -51,6 +51,8 @@ import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; import java.util.stream.Collectors; +import java.util.Iterator; +import java.util.ServiceLoader; import com.sun.javatest.Script; import com.sun.javatest.Status; @@ -79,6 +81,8 @@ import com.sun.javatest.regtest.tool.Version; import com.sun.javatest.regtest.util.FileUtils; import com.sun.javatest.regtest.util.StringUtils; +import com.sun.javatest.regtest.exec.StatusTransformer; + import static com.sun.javatest.regtest.RStatus.error; import static com.sun.javatest.regtest.RStatus.passed; @@ -328,6 +332,58 @@ public Status run(String[] argv, TestDescription td, TestEnvironment env) { return status; } // run() + /** + * Contains list of {@link StatusTransformer} that transform the test result status, or {@code null} + * if no transformer service was found. + */ + private static final List STATUS_TRANSFORMERS = loadStatusTransformers(); + + /** + * This method runs the statusTransformers stored in the private variable. In case the statusTransformer is null + * it returns the original status. + * @param originalStatus - original status of the testrun + * @param td - description of the test + * @return status after modification (the originalStatus by default) + */ + @Override + protected void setTestResultStatus(TestResult testResultToFill, Status execStatus) { + Status newStatus = execStatus; + try { + TestDescription td = testResultToFill.getDescription(); + } + catch(TestResult.Fault f){ + newStatus = new Status(Status.ERROR, "Invalid state during testing. - test description missin."); + testResultToFill.setStatus(newStatus); + return; + } + for ( StatusTransformer st : STATUS_TRANSFORMERS) { + newStatus = st.transform(newStatus, td); + //in case the status has been modified by this function we want to log it for any user controlling the results. + newStatus = new Status(newStatus.getType(), newStatus.getReason() + + " - The status of this test result has been modified by external code - " + + st.getClass().getName()); + } + testResultToFill.setStatus(newStatus); + } + + /** + * This method tries to search for alternative implementations of StatusTransformer. If no implementation is found + * returns an empty list. + * @return List if some implementations are found and empty list if no implementation has been found. + */ + private static synchronized List loadStatusTransformers(){ + ServiceLoader loader = ServiceLoader.load(StatusTransformer.class); + + Iterator iterator = loader.iterator(); + List services = new ArrayList<>(); + + while (iterator.hasNext()) { + services.add(iterator.next()); + } + + return services; + } + private void printJDKInfo(PrintWriter pw, String label, JDK jdk, List opts) { pw.print(label); pw.print(": "); diff --git a/src/share/classes/com/sun/javatest/regtest/exec/StatusTransformer.java b/src/share/classes/com/sun/javatest/regtest/exec/StatusTransformer.java new file mode 100644 index 000000000..98a7d7496 --- /dev/null +++ b/src/share/classes/com/sun/javatest/regtest/exec/StatusTransformer.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 1997, 2024, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.sun.javatest.regtest.exec; + +import com.sun.javatest.Status; +import com.sun.javatest.TestDescription; + +/** + * Enables users to create their own status modifications for purposes of different testing strategies. + * This allows user to omit certain kinds of failures or pinpoint tests that passed even though the jvm + * crashed in the process without being intended to. + */ +public interface StatusTransformer { + public Status transform(Status originalStatus, TestDescription td); +} +