2023-09-30 22:02:58 +03:00
|
|
|
|
package SapforTestingSystem;
|
2023-10-04 22:01:09 +03:00
|
|
|
|
import Common.Constants;
|
2023-09-30 18:22:14 +03:00
|
|
|
|
import Common.Global;
|
2023-09-30 00:18:44 +03:00
|
|
|
|
import Common.Utils.Utils;
|
2023-09-30 20:56:59 +03:00
|
|
|
|
import GlobalData.Tasks.TaskState;
|
2023-10-06 22:51:09 +03:00
|
|
|
|
import ProjectData.Messages.Errors.MessageError;
|
2023-10-04 00:25:36 +03:00
|
|
|
|
import SapforTestingSystem.Json.SapforConfiguration_json;
|
2023-09-30 20:56:59 +03:00
|
|
|
|
import SapforTestingSystem.Json.SapforVersion_json;
|
|
|
|
|
|
import SapforTestingSystem.SapforTask.SapforTask;
|
2023-09-30 00:18:44 +03:00
|
|
|
|
import Visual_DVM_2021.Passes.PassCode_2021;
|
2023-09-30 22:02:58 +03:00
|
|
|
|
import Visual_DVM_2021.Passes.Pass_2021;
|
2023-09-30 00:18:44 +03:00
|
|
|
|
import org.apache.commons.io.FileUtils;
|
2023-09-22 00:16:46 +03:00
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
2023-09-30 00:18:44 +03:00
|
|
|
|
import java.nio.charset.Charset;
|
2023-09-30 22:02:58 +03:00
|
|
|
|
import java.nio.file.Paths;
|
2023-09-30 00:18:44 +03:00
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
|
import java.util.Comparator;
|
|
|
|
|
|
import java.util.Vector;
|
2023-10-06 22:51:09 +03:00
|
|
|
|
|
|
|
|
|
|
import static java.lang.Character.isDigit;
|
2023-09-30 22:02:58 +03:00
|
|
|
|
public class PerformSapforTask extends Pass_2021<SapforTask> {
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public String getDescription() {
|
2023-11-14 16:19:31 +03:00
|
|
|
|
return "";
|
|
|
|
|
|
// "Запуск задачи SAPFOR"; Оставляем пустое описание чтобы не засорять журнал.
|
2023-09-30 22:02:58 +03:00
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected boolean needsAnimation() {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
//--
|
2023-09-30 00:18:44 +03:00
|
|
|
|
File sapfor_drv;
|
2023-10-04 00:25:36 +03:00
|
|
|
|
SapforConfiguration_json sapforConfiguration_json;
|
2023-09-30 00:18:44 +03:00
|
|
|
|
//-----
|
2023-10-29 01:03:37 +03:00
|
|
|
|
File root;
|
2023-09-30 00:18:44 +03:00
|
|
|
|
File parentTask;
|
|
|
|
|
|
File task;
|
|
|
|
|
|
//-----
|
|
|
|
|
|
Process process = null;
|
|
|
|
|
|
int exit_code = Constants.Nan;
|
|
|
|
|
|
//----
|
|
|
|
|
|
File outputFile = null;
|
|
|
|
|
|
File errorsFile = null;
|
2023-09-22 00:16:46 +03:00
|
|
|
|
//--
|
2023-09-30 00:18:44 +03:00
|
|
|
|
Vector<String> outputLines;
|
|
|
|
|
|
Vector<String> errorsLines;
|
|
|
|
|
|
//---
|
2023-09-30 22:02:58 +03:00
|
|
|
|
@Override
|
|
|
|
|
|
protected boolean canStart(Object... args) throws Exception {
|
|
|
|
|
|
sapfor_drv = (File) args[0];
|
2023-10-04 00:25:36 +03:00
|
|
|
|
sapforConfiguration_json = (SapforConfiguration_json) args[1];
|
2023-10-18 22:16:22 +03:00
|
|
|
|
target = (SapforTask) args[2];
|
2023-09-30 22:02:58 +03:00
|
|
|
|
//--->>
|
2023-10-18 22:16:22 +03:00
|
|
|
|
parentTask = Paths.get(Global.Home, sapforConfiguration_json.id, target.test_description).toFile();
|
2023-10-29 01:03:37 +03:00
|
|
|
|
root = new File(Global.Home, sapforConfiguration_json.id);
|
2023-09-30 22:02:58 +03:00
|
|
|
|
task = null;
|
|
|
|
|
|
//--->>
|
|
|
|
|
|
return true;
|
2023-09-30 00:18:44 +03:00
|
|
|
|
}
|
|
|
|
|
|
protected static boolean checkLines(Vector<String> lines) {
|
|
|
|
|
|
for (String line : lines) {
|
|
|
|
|
|
if (line.toLowerCase().contains("internal error")) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (line.toLowerCase().contains("exception")) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (line.contains("[ERROR]")) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2023-10-06 22:51:09 +03:00
|
|
|
|
if (line.toLowerCase().contains("segmentation fault")) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2023-09-30 00:18:44 +03:00
|
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
protected boolean performSapforScript(String name, File workspace, String command, String outName, String errName) throws Exception {
|
|
|
|
|
|
process = null;
|
|
|
|
|
|
exit_code = Constants.Nan;
|
|
|
|
|
|
//---
|
2023-10-06 22:51:09 +03:00
|
|
|
|
File data_workspace = new File(workspace, Constants.data);
|
2023-09-30 00:18:44 +03:00
|
|
|
|
Utils.CheckDirectory(data_workspace);
|
|
|
|
|
|
outputFile = new File(data_workspace, outName);
|
|
|
|
|
|
errorsFile = new File(data_workspace, errName);
|
|
|
|
|
|
Utils.delete_with_check(outputFile);
|
|
|
|
|
|
Utils.delete_with_check(errorsFile);
|
|
|
|
|
|
//---
|
2023-09-30 20:56:59 +03:00
|
|
|
|
File file = new File(data_workspace, name + (Global.isWindows ? ".bat" : ".sh"));
|
2023-09-30 00:18:44 +03:00
|
|
|
|
FileUtils.write(file,
|
|
|
|
|
|
Utils.DQuotes(sapfor_drv.getAbsolutePath())
|
2023-10-18 22:16:22 +03:00
|
|
|
|
+ (target.flags.isEmpty() ? "" : (" " + target.flags))
|
2023-09-30 00:18:44 +03:00
|
|
|
|
+ " -noLogo"
|
|
|
|
|
|
+ " " + command +
|
|
|
|
|
|
" 1>" +
|
|
|
|
|
|
Utils.DQuotes(outputFile.getAbsolutePath()) +
|
|
|
|
|
|
" 2>" +
|
|
|
|
|
|
Utils.DQuotes(errorsFile.getAbsolutePath()),
|
|
|
|
|
|
Charset.defaultCharset());
|
|
|
|
|
|
if (!file.setExecutable(true))
|
2023-09-30 18:22:14 +03:00
|
|
|
|
throw new Exception("Не удалось сделать файл скрипта " + name + " исполняемым!");
|
2023-09-30 00:18:44 +03:00
|
|
|
|
//--
|
2023-10-23 01:32:28 +03:00
|
|
|
|
boolean flag = false;
|
|
|
|
|
|
do {
|
|
|
|
|
|
try {
|
|
|
|
|
|
ProcessBuilder procBuilder = new ProcessBuilder(file.getAbsolutePath());
|
|
|
|
|
|
procBuilder.directory(workspace);
|
|
|
|
|
|
process = procBuilder.start();
|
|
|
|
|
|
exit_code = process.waitFor();
|
|
|
|
|
|
flag = true;
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
Global.Log.PrintException(ex);
|
|
|
|
|
|
Utils.sleep(1000);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
while (!flag);
|
2023-09-30 00:18:44 +03:00
|
|
|
|
process = null;
|
|
|
|
|
|
//---
|
|
|
|
|
|
outputLines = new Vector<>(FileUtils.readLines(outputFile));
|
|
|
|
|
|
errorsLines = new Vector<>(FileUtils.readLines(errorsFile));
|
2023-10-23 01:32:28 +03:00
|
|
|
|
return (exit_code == 0) &&
|
|
|
|
|
|
checkLines(outputLines) &&
|
|
|
|
|
|
checkLines(errorsLines);
|
2023-09-30 00:18:44 +03:00
|
|
|
|
}
|
|
|
|
|
|
protected boolean parse() throws Exception {
|
|
|
|
|
|
if (performSapforScript("parse", parentTask,
|
|
|
|
|
|
"-parse *.f *.for *.fdv *.f90 *.f77",
|
2023-10-07 00:45:09 +03:00
|
|
|
|
Constants.parse_out_file,
|
|
|
|
|
|
Constants.parse_err_file)
|
2023-09-30 00:18:44 +03:00
|
|
|
|
&& (new File(parentTask, "dvm.proj")).exists()) {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
} else {
|
2023-09-30 22:02:58 +03:00
|
|
|
|
target.state = TaskState.DoneWithErrors;
|
2023-09-30 00:18:44 +03:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-10-07 00:45:09 +03:00
|
|
|
|
//слегка изменить подход.
|
2023-09-30 00:18:44 +03:00
|
|
|
|
protected boolean transformation(PassCode_2021 code) throws Exception {
|
|
|
|
|
|
task = new File(parentTask, "v1");
|
|
|
|
|
|
Utils.CheckAndCleanDirectory(task); //папка для преобразования.
|
2023-10-07 00:45:09 +03:00
|
|
|
|
//если версия пустая, это тоже результат тестирования. Поэтому должна учитываться в древе.
|
2023-10-29 01:03:37 +03:00
|
|
|
|
target.versions.add(new SapforVersion_json(
|
|
|
|
|
|
root.getAbsolutePath(),
|
|
|
|
|
|
task.getAbsolutePath(), code.getDescription()));
|
2023-10-07 00:45:09 +03:00
|
|
|
|
//---
|
2023-09-30 00:18:44 +03:00
|
|
|
|
if (performSapforScript("transformation", parentTask,
|
|
|
|
|
|
code.getTestingCommand() + " -F " + Utils.DQuotes(task.getAbsolutePath()),
|
2023-10-07 00:45:09 +03:00
|
|
|
|
Constants.out_file,
|
|
|
|
|
|
Constants.err_file
|
2023-09-30 00:18:44 +03:00
|
|
|
|
)) {
|
2023-09-30 22:02:58 +03:00
|
|
|
|
target.state = TaskState.Done;
|
2023-09-30 00:18:44 +03:00
|
|
|
|
parentTask = task;
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2023-09-30 22:02:58 +03:00
|
|
|
|
target.state = TaskState.DoneWithErrors;
|
2023-09-30 00:18:44 +03:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2023-10-07 00:45:09 +03:00
|
|
|
|
protected void variants() throws Exception {
|
|
|
|
|
|
//папки вариантов создается самим сапфором.
|
2023-10-07 21:02:01 +03:00
|
|
|
|
target.state = performSapforScript("create_variants", parentTask, " -t 13 -allVars"
|
2023-10-10 16:53:29 +03:00
|
|
|
|
+ " -tinfo"
|
2023-10-07 21:02:01 +03:00
|
|
|
|
,
|
2023-10-07 00:45:09 +03:00
|
|
|
|
Constants.out_file,
|
|
|
|
|
|
Constants.err_file
|
|
|
|
|
|
) ? TaskState.Done : TaskState.DoneWithErrors;
|
|
|
|
|
|
//найти папки с вариантами.
|
|
|
|
|
|
File[] files_ = parentTask.listFiles((dir, name) -> dir.isDirectory() && Utils.isParallelVersionName(name));
|
|
|
|
|
|
if ((files_ != null) && (files_.length > 0)) {
|
|
|
|
|
|
Vector<File> files = new Vector<>(Arrays.asList(files_));
|
|
|
|
|
|
files.sort(Comparator.comparingInt(o -> Integer.parseInt(o.getName().substring(1))));
|
|
|
|
|
|
for (File file : files)
|
2023-10-29 01:03:37 +03:00
|
|
|
|
target.variants.add(
|
|
|
|
|
|
|
|
|
|
|
|
new SapforVersion_json(
|
|
|
|
|
|
root.getAbsolutePath(),
|
|
|
|
|
|
file.getAbsolutePath(), PassCode_2021.SPF_CreateParallelVariant.getDescription()));
|
2023-09-30 00:18:44 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-10-06 22:51:09 +03:00
|
|
|
|
//-------------------------------------------------->>
|
|
|
|
|
|
public MessageError unpackMessage(String line_in) throws Exception {
|
|
|
|
|
|
MessageError res = new MessageError();
|
|
|
|
|
|
res.file = "";
|
|
|
|
|
|
res.line = Constants.Nan;
|
|
|
|
|
|
res.value = "";
|
|
|
|
|
|
String line = line_in.substring(9);
|
2023-10-07 01:17:06 +03:00
|
|
|
|
//System.out.println(line);
|
2023-10-06 22:51:09 +03:00
|
|
|
|
int i = 0;
|
|
|
|
|
|
int s = 0;
|
|
|
|
|
|
String lexeme = "";
|
|
|
|
|
|
//#1020: red43.fdv: line 988]: Active DVM directives are not supported (turn on DVM-directive support option)
|
|
|
|
|
|
for (char c : line.toCharArray()) {
|
|
|
|
|
|
// System.out.print("<s=" + s + ">");
|
|
|
|
|
|
// System.out.println(c);
|
|
|
|
|
|
switch (s) {
|
|
|
|
|
|
case 0:
|
|
|
|
|
|
//поиск groups_s
|
|
|
|
|
|
if (c == '#') {
|
|
|
|
|
|
s = 1;
|
|
|
|
|
|
lexeme = "";
|
|
|
|
|
|
} else return null;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
//group_s
|
|
|
|
|
|
if (isDigit(c)) {
|
|
|
|
|
|
res.group_s += c;
|
|
|
|
|
|
lexeme += c;
|
|
|
|
|
|
} else if (c == ':') {
|
|
|
|
|
|
s = 2;
|
|
|
|
|
|
res.group = Integer.parseInt(lexeme);
|
|
|
|
|
|
} else return null;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
//поиск filename
|
|
|
|
|
|
if (c == ' ') {
|
|
|
|
|
|
s = 3;
|
|
|
|
|
|
} else return null;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 3:
|
|
|
|
|
|
//filename
|
|
|
|
|
|
if (c == ':') {
|
|
|
|
|
|
s = 4;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
res.file += c;
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 4:
|
|
|
|
|
|
//поиск line
|
|
|
|
|
|
if (c == ' ') {
|
|
|
|
|
|
s = 5;
|
|
|
|
|
|
lexeme = "";
|
|
|
|
|
|
} else return null;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 5:
|
|
|
|
|
|
//line
|
|
|
|
|
|
if (c == ' ') {
|
|
|
|
|
|
if (!lexeme.equals("line"))
|
|
|
|
|
|
return null;
|
|
|
|
|
|
else {
|
|
|
|
|
|
s = 6;
|
|
|
|
|
|
lexeme = "";
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
lexeme += c;
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 6:
|
|
|
|
|
|
//line number
|
|
|
|
|
|
if (isDigit(c)) {
|
|
|
|
|
|
lexeme += c;
|
|
|
|
|
|
} else if (c == ']') {
|
|
|
|
|
|
res.line = Integer.parseInt(lexeme);
|
|
|
|
|
|
s = 7;
|
|
|
|
|
|
} else return null;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 7:
|
|
|
|
|
|
//Поиск value
|
|
|
|
|
|
if (c == ':') {
|
|
|
|
|
|
s = 8;
|
|
|
|
|
|
} else return null;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 8:
|
|
|
|
|
|
if (c == ' ') {
|
|
|
|
|
|
s = 9;
|
|
|
|
|
|
} else return null;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 9:
|
|
|
|
|
|
//value
|
|
|
|
|
|
res.value += c;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
;
|
|
|
|
|
|
++i;
|
|
|
|
|
|
}
|
|
|
|
|
|
//--
|
|
|
|
|
|
if (s != 9)
|
|
|
|
|
|
return null;
|
|
|
|
|
|
//--
|
|
|
|
|
|
return res;
|
|
|
|
|
|
}
|
|
|
|
|
|
public void readMessagesFromFileDump(File file, Vector<MessageError> messages) throws Exception {
|
|
|
|
|
|
//Образец запакованного сообщения
|
|
|
|
|
|
//ERROR - [#1020: red43.fdv: line 988]: Active DVM directives are not supported (turn on DVM-directive support option)
|
|
|
|
|
|
Vector<String> lines = new Vector<>(FileUtils.readLines(file));
|
|
|
|
|
|
if (!lines.isEmpty()) {
|
|
|
|
|
|
for (int i = lines.size() - 1; i >= 0; --i) {
|
|
|
|
|
|
String line = lines.get(i);
|
|
|
|
|
|
if (line.startsWith("ERROR - ")) {
|
|
|
|
|
|
MessageError message = unpackMessage(line);
|
|
|
|
|
|
if (message != null)
|
|
|
|
|
|
messages.add(message);
|
|
|
|
|
|
//--
|
|
|
|
|
|
} else break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-10-07 00:45:09 +03:00
|
|
|
|
//--
|
2023-10-29 01:03:37 +03:00
|
|
|
|
/*
|
2023-10-07 00:45:09 +03:00
|
|
|
|
protected void createVersionProjectData(SapforVersion_json version, boolean isTransformation) throws Exception {
|
2023-10-06 22:51:09 +03:00
|
|
|
|
db_project_info project = new db_project_info();
|
|
|
|
|
|
project.Home = new File(version.version);
|
|
|
|
|
|
project.name = project.Home.getName();
|
|
|
|
|
|
project.description = version.description;
|
|
|
|
|
|
project.languageName = LanguageName.fortran;
|
|
|
|
|
|
project.creationDate = Utils.getDateNumber();
|
|
|
|
|
|
//--
|
|
|
|
|
|
Vector<MessageError> messages = new Vector<>();
|
|
|
|
|
|
//--
|
|
|
|
|
|
if (isTransformation) {
|
2023-10-07 00:45:09 +03:00
|
|
|
|
File p_out = Paths.get(project.Home.getAbsolutePath(), Constants.data, Constants.parse_out_file).toFile();
|
2023-10-10 16:53:29 +03:00
|
|
|
|
File p_err = Paths.get(project.Home.getAbsolutePath(), Constants.data, Constants.parse_err_file).toFile();
|
2023-10-07 00:45:09 +03:00
|
|
|
|
File out = Paths.get(project.Home.getAbsolutePath(), Constants.data, Constants.out_file).toFile();
|
|
|
|
|
|
File err = Paths.get(project.Home.getAbsolutePath(), Constants.data, Constants.err_file).toFile();
|
2023-10-06 22:51:09 +03:00
|
|
|
|
//--
|
|
|
|
|
|
if (p_out.exists()) {
|
|
|
|
|
|
project.Log += (FileUtils.readFileToString(p_out));
|
|
|
|
|
|
readMessagesFromFileDump(p_out, messages);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (out.exists()) {
|
|
|
|
|
|
project.Log += "\n" + FileUtils.readFileToString(out);
|
|
|
|
|
|
readMessagesFromFileDump(out, messages);
|
|
|
|
|
|
}
|
2023-10-07 00:45:09 +03:00
|
|
|
|
//в потоки ошибок идет информация от операционной системы. сообщений там быть не должно.
|
|
|
|
|
|
if (p_err.exists())
|
|
|
|
|
|
project.Log += (FileUtils.readFileToString(p_err));
|
|
|
|
|
|
if (err.exists())
|
|
|
|
|
|
project.Log += "\n" + FileUtils.readFileToString(err);
|
2023-10-06 22:51:09 +03:00
|
|
|
|
//--
|
|
|
|
|
|
}
|
|
|
|
|
|
project.CreateVisualiserData();
|
|
|
|
|
|
//---
|
2023-10-29 01:03:37 +03:00
|
|
|
|
|
2023-10-06 22:51:09 +03:00
|
|
|
|
if (isTransformation && !messages.isEmpty()) {
|
2023-10-16 01:51:36 +03:00
|
|
|
|
project.Open(); //нельзя!!! сначала надо определиться с версиями. И только потом, получать файлы.
|
|
|
|
|
|
//а так же, убрать dep и txt
|
2023-10-06 22:51:09 +03:00
|
|
|
|
project.db.BeginTransaction();
|
|
|
|
|
|
for (MessageError m : messages) {
|
|
|
|
|
|
if (project.db.files.containsKey(m.file)) {
|
|
|
|
|
|
DBProjectFile file = project.db.files.Data.get(m.file);
|
|
|
|
|
|
file.CreateAndAddNewMessage(1, m.value, m.line, m.group);
|
|
|
|
|
|
//update file
|
|
|
|
|
|
project.db.Update(file);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
project.db.Commit();
|
2023-10-16 01:43:59 +03:00
|
|
|
|
project.db.Disconnect();
|
2023-10-06 22:51:09 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-10-29 01:03:37 +03:00
|
|
|
|
*/
|
2023-10-06 22:51:09 +03:00
|
|
|
|
//-------------------------------------------------->>
|
2023-09-30 22:02:58 +03:00
|
|
|
|
@Override
|
|
|
|
|
|
protected void body() throws Exception {
|
2023-10-29 01:03:37 +03:00
|
|
|
|
target.versions.add(new SapforVersion_json(target.test_description, "исходная"));
|
2023-10-04 00:25:36 +03:00
|
|
|
|
for (PassCode_2021 code : sapforConfiguration_json.codes) {
|
2023-09-30 00:18:44 +03:00
|
|
|
|
if (parse()) {
|
|
|
|
|
|
if (code.equals(PassCode_2021.CreateParallelVariants))
|
|
|
|
|
|
variants();
|
|
|
|
|
|
else if (!transformation(code))
|
|
|
|
|
|
break;
|
|
|
|
|
|
} else
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2023-10-07 00:45:09 +03:00
|
|
|
|
}
|
2023-09-21 21:17:02 +03:00
|
|
|
|
}
|