уничтожение процесса тестирования.

This commit is contained in:
2023-09-30 18:19:31 +03:00
parent 3373d2e704
commit 2a69143550
8 changed files with 52 additions and 24 deletions

6
.idea/workspace.xml generated
View File

@@ -8,8 +8,12 @@
<component name="ChangeListManager">
<list default="true" id="e42177c3-2328-4b27-8a01-35779b2beb99" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Common/GlobalProperties.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Common/GlobalProperties.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Common/Constants/Constants.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Common/Constants/Constants.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Common/Global.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Common/Global.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Common/Utils/InterruptThread.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Common/Utils/InterruptThread.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/SapforTestingSystem/Json/SapforScenario_json.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/SapforTestingSystem/Json/SapforScenario_json.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/SapforTestingSystem/SapforTestingPlaner/SapforTestingPlanner.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/SapforTestingSystem/SapforTestingPlaner/SapforTestingPlanner.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/SapforTestingSystem/ThreadsPlanner/ThreadsPlanner.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/SapforTestingSystem/ThreadsPlanner/ThreadsPlanner.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Visual_DVM_2021/Passes/All/StartSapforTests.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Visual_DVM_2021/Passes/All/StartSapforTests.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />

View File

@@ -1,22 +1,6 @@
package Common.Constants;
import java.util.regex.Pattern;
public class Constants {
public static final int Nan = -1;
public static char toStrike = (char) 822;
public static final Pattern VALID_EMAIL_ADDRESS_REGEX =
Pattern.compile("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$", Pattern.CASE_INSENSITIVE);
public static char[] forbidden_file_name_characters = new char[]{
'#', '%', '&', '{', '}',
'<', '>', '*', '?', '!',
'$', '\'', '\"', '@', '+',
'`', '|', '=', '#', ':', '/', '\\',
'~', '^'
};
public static char[] regular_metasymbols = new char[]{
'<', '>', '(', ')', '[', ']', '{', '}', '^', '-', '=', '$', '!', '|', '?', '*', '+', '.'
};
//все запретные символы через пробел.
public static String all_forbidden_characters_string = "";
//https://losst.ru/komandy-terminala-linux
public static String[] linux_system_commands = new String[]{
//<editor-fold desc="все линуксовые команды. их МНОГО">
@@ -355,4 +339,21 @@ public class Constants {
"zypper"
//</editor-fold>
};
public static final int Nan = -1;
public static char toStrike = (char) 822;
public static final Pattern VALID_EMAIL_ADDRESS_REGEX =
Pattern.compile("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$", Pattern.CASE_INSENSITIVE);
public static char[] forbidden_file_name_characters = new char[]{
'#', '%', '&', '{', '}',
'<', '>', '*', '?', '!',
'$', '\'', '\"', '@', '+',
'`', '|', '=', '#', ':', '/', '\\',
'~', '^'
};
public static char[] regular_metasymbols = new char[]{
'<', '>', '(', ')', '[', ']', '{', '}', '^', '-', '=', '$', '!', '|', '?', '*', '+', '.'
};
//все запретные символы через пробел.
public static String all_forbidden_characters_string = "";
public static String aborted = "ABORTED";
}

View File

@@ -345,6 +345,7 @@ public class Global {
System.exit(0);
}
public static void ScenarioMode() throws Exception {
isWindows = System.getProperty("os.name").startsWith("Windows");
Log = new Loggable() {
@Override
public String getLogHomePath() {

View File

@@ -6,7 +6,6 @@ import java.io.File;
import java.util.concurrent.Callable;
public class InterruptThread extends Thread{
//------------
public static final String Eliminated = "Eliminated";
public InterruptThread(int sleep_ms, Callable action){
super(() -> {
File interruptFile = new File(db_project_info.interrupt);
@@ -14,7 +13,7 @@ public class InterruptThread extends Thread{
while (true) {
Thread.sleep(sleep_ms);
if (interruptFile.exists()) {
FileUtils.writeStringToFile(new File(Eliminated + " by INTERRUPT file"), "");
FileUtils.writeStringToFile(new File("ABORTED"), "");
FileUtils.forceDelete(interruptFile);
action.call();
}

View File

@@ -4,8 +4,10 @@ import com.google.gson.annotations.Expose;
import java.util.List;
import java.util.Vector;
public class SapforScenario_json {
@Expose
public String sapfor_drv = ""; //файл с сапфором. Имя уникально для сценария.
@Expose
public List<String> tests = new Vector<>();
@Expose
public List<SapforPackage_json> packages= new Vector<>();
public List<SapforPackage_json> packages = new Vector<>();
}

View File

@@ -9,16 +9,17 @@ import SapforTestingSystem.ThreadsPlanner.ThreadsPlanner;
import java.io.File;
import java.nio.file.Paths;
public class SapforTestingPlanner extends ThreadsPlanner {
SapforScenario_json scenario_json = null;
public SapforTestingPlanner() throws Exception {
super(Global.properties.threadsTimeout, Global.properties.threadsNum);
SapforScenario_json scenario_json = (SapforScenario_json) Utils.jsonFromFile(new File(Global.Home, "scenario.txt"), SapforScenario_json.class);
scenario_json = (SapforScenario_json) Utils.jsonFromFile(new File(Global.Home, "scenario.txt"), SapforScenario_json.class);
//формирование списка задач.
for (SapforPackage_json sapforPackage_json : scenario_json.packages) {
for (String testName : scenario_json.tests) {
addThread(() -> {
try {
new SapforTest(
new File(Global.Home, "SAPFOR_F.exe"),
new File(Global.Home, scenario_json.sapfor_drv),
Paths.get(Global.Home, sapforPackage_json.id, testName).toFile(),
sapforPackage_json.flags,
sapforPackage_json.codes).Do();
@@ -28,5 +29,17 @@ public class SapforTestingPlanner extends ThreadsPlanner {
});
}
}
interruptThread.start();
}
@Override
public void Interrupt() throws Exception {
System.out.println("killing "+scenario_json.sapfor_drv+"...");
String kill_command = Global.isWindows? ("taskkill /FI \"IMAGENAME eq " + scenario_json.sapfor_drv+ "\" /F /T"):
("killall -SIGKILL " + scenario_json.sapfor_drv);
Process killer = Runtime.getRuntime().exec(kill_command);
killer.waitFor();
System.out.println("done!");
//todo для надежности сделать еще один kill с внешнего процесса.
// может быть гонка, что нить успеет запустить процесс уже после интеррупта.
}
}

View File

@@ -6,7 +6,12 @@ import java.util.LinkedHashMap;
import java.util.Vector;
public abstract class ThreadsPlanner {
//-->
Thread interruptThread = new InterruptThread(5000, () -> {
protected Thread interruptThread = new InterruptThread(5000, () -> {
try {
Interrupt();
} catch (Exception exception) {
Global.Log.PrintException(exception);
}
System.exit(0);
return null;
});
@@ -42,6 +47,8 @@ public abstract class ThreadsPlanner {
Global.Log.Print("Planner finished");
finalize();
}
public void Interrupt() throws Exception {
}
protected void checkActiveThreads() throws Exception {
Vector<Integer> toExclude = new Vector<>();
//--

View File

@@ -216,7 +216,7 @@ public class StartSapforTests extends Pass_2021<SapforScenario> {
Utils.CheckAndCleanDirectory(scenarioWorkspace);
target.workspace = scenarioWorkspace.getAbsolutePath();
target.testsNames = String.join(";", testsNames_lower);
sapfor = new File(target.workspace, "SAPFOR_F.exe"); //развилка на линукс
sapfor = new File(target.workspace, Utils.getDateName("SAPFOR_F") + (Global.isWindows ? ".exe" : "")); //развилка на линукс
ShowMessage2("Копирование SAPFOR");
FileUtils.copyFile(Current.getSapfor().getFile(), sapfor);
ShowMessage2("Копирование визуализатора");
@@ -232,6 +232,7 @@ public class StartSapforTests extends Pass_2021<SapforScenario> {
//----
File scenarioFile = new File(target.workspace, "scenario.txt");
SapforScenario_json scenario_json = new SapforScenario_json();
scenario_json.sapfor_drv = sapfor.getName();
scenario_json.tests.addAll(allTests.keySet());
//----
Global.db.Update(target);