Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

7903519 : jtreg/jtharness is missing features for basic crash testing #235

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<StatusTransformer> 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<StatusTransformer> if some implementations are found and empty list if no implementation has been found.
*/
private static synchronized List<StatusTransformer> loadStatusTransformers(){
ServiceLoader<StatusTransformer> loader = ServiceLoader.load(StatusTransformer.class);

Iterator<StatusTransformer> iterator = loader.iterator();
List<StatusTransformer> services = new ArrayList<>();

while (iterator.hasNext()) {
services.add(iterator.next());
}

return services;
}

private void printJDKInfo(PrintWriter pw, String label, JDK jdk, List<String> opts) {
pw.print(label);
pw.print(": ");
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}