рефакторинг определения размерности тестов на сервере.
This commit is contained in:
@@ -2,7 +2,6 @@ package _VisualDVM.ComponentsServer.Component.Sapfor;
|
||||
import Common.CommonConstants;
|
||||
import Common.Passes.PassException;
|
||||
import Common.Utils.Utils_;
|
||||
import Common.Utils.Vector_;
|
||||
import Common.Visual.UI;
|
||||
import _VisualDVM.ComponentsServer.Component.OSDComponent;
|
||||
import _VisualDVM.ComponentsServer.Component.Visualizer_2;
|
||||
@@ -12,15 +11,18 @@ import _VisualDVM.Passes.PassCode;
|
||||
import _VisualDVM.Passes.Sapfor.SapforAnalysis;
|
||||
import _VisualDVM.ProjectData.Files.DBProjectFile;
|
||||
import _VisualDVM.ProjectData.Files.UI.Editor.SPFEditor;
|
||||
import _VisualDVM.ProjectData.Project.db_project_info;
|
||||
import _VisualDVM.TestingSystem.Common.Test.Test;
|
||||
import _VisualDVM.Utils;
|
||||
import javafx.util.Pair;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.attribute.PosixFilePermission;
|
||||
import java.util.*;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
public abstract class Sapfor extends OSDComponent {
|
||||
public static final int empty_code = -100;
|
||||
public static final int canceled_code = -99;
|
||||
@@ -271,37 +273,7 @@ public abstract class Sapfor extends OSDComponent {
|
||||
result_lines
|
||||
);
|
||||
}
|
||||
public static File getTempCopy(File src) throws Exception {
|
||||
if (temp_copy == null || !temp_copy.exists()) {
|
||||
temp_copy = Utils.getTempFileName("SAPFOR" + (Utils_.isWindows() ? ".exe" : ""));
|
||||
FileUtils.copyFile(src, temp_copy);
|
||||
temp_copy.setExecutable(true);
|
||||
}
|
||||
return temp_copy;
|
||||
}
|
||||
//--
|
||||
public static boolean getMinMaxDim(File sapfor_drv, File workspace, Test test) throws Exception {
|
||||
File sapfor = Sapfor.getTempCopy(sapfor_drv);
|
||||
String flags = "-noLogo";
|
||||
if (Sapfor.parse(sapfor, workspace, flags)
|
||||
) {
|
||||
Vector<String> outputLines = new Vector<>();
|
||||
if (Sapfor.analysis(sapfor, workspace, PassCode.SPF_GetMaxMinBlockDistribution, flags, outputLines)) {
|
||||
//---
|
||||
for (String line : outputLines) {
|
||||
String prefix = "GET_MIN_MAX_BLOCK_DIST: ";
|
||||
if (line.startsWith(prefix)) {
|
||||
String s = line.substring(prefix.length());
|
||||
String[] data = s.split(" ");
|
||||
test.min_dim = Math.max(Integer.parseInt(data[0]), 0);
|
||||
test.max_dim = Math.max(Integer.parseInt(data[1]), 0);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public static int readVersionFromCode(File versionFile) {
|
||||
int res = CommonConstants.Nan;
|
||||
if (versionFile.exists()) {
|
||||
@@ -366,7 +338,7 @@ public abstract class Sapfor extends OSDComponent {
|
||||
"SPF_OpenDvmStatistic",
|
||||
-Global.messagesServer.getPort(),
|
||||
"",
|
||||
// Global.packSapforSettings(),
|
||||
// Global.packSapforSettings(),
|
||||
src);
|
||||
return result;
|
||||
}
|
||||
@@ -567,26 +539,113 @@ public abstract class Sapfor extends OSDComponent {
|
||||
if ((UI.isActive()) && (Global.mainModule.getUI().hasMainWindow()) && (Global.mainModule.getUI().getVersionsWindow() != null))
|
||||
Global.mainModule.getUI().getVersionsWindow().BlockVariants();
|
||||
}
|
||||
//--------------------------------------------------------------------------->>
|
||||
//временный (?) проход, по тихому получить размерность теста, предварительно выполнив тихий парс.
|
||||
//тут все одноразовое. считаем что таблицы бд уже заполнены как надо.
|
||||
/*
|
||||
public LanguageStyle getStyle() throws Exception {
|
||||
return (Global.mainModule.getDb()).settings.get(SettingName.FREE_FORM).toBoolean() ? LanguageStyle.free : LanguageStyle.fixed;
|
||||
//--
|
||||
public static int getFileMaxDim_C(File file) {
|
||||
int fileMax = 0;
|
||||
final String prefix = "#pragma dvm array distribute";
|
||||
int n = 0;
|
||||
try {
|
||||
for (String line : FileUtils.readLines(file, Charset.defaultCharset())) {
|
||||
// #pragma dvm array distribute[block][block], не важно
|
||||
String packedLine = Utils_.removeCharacters(Utils_.removeRedundantSpaces(line).toLowerCase(), "\n", "\r", "\t");
|
||||
if (packedLine.startsWith(prefix)) {
|
||||
packedLine = packedLine.substring(prefix.length());
|
||||
boolean bracketOpen = false;
|
||||
int pragmaMax = 0;
|
||||
String distr = "";
|
||||
for (int i = packedLine.indexOf('['); i < packedLine.length(); ++i) {
|
||||
char c = packedLine.charAt(i);
|
||||
if (bracketOpen) {
|
||||
if (c == ']') {
|
||||
bracketOpen = false;
|
||||
if (distr.equals("block"))
|
||||
pragmaMax++;
|
||||
distr = "";
|
||||
} else {
|
||||
distr += c;
|
||||
}
|
||||
} else {
|
||||
if (c == '[') {
|
||||
bracketOpen = true;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
fileMax = Math.max(fileMax, pragmaMax);
|
||||
}
|
||||
++n;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return fileMax;
|
||||
}
|
||||
*/
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
/*
|
||||
public String getConsoleFlags() throws Exception {
|
||||
Vector<String> res = new Vector<>();
|
||||
if ((Global.mainModule.getDb()).settings.get(SettingName.FREE_FORM).toBoolean())
|
||||
res.add("-f90");
|
||||
if ((Global.mainModule.getDb()).settings.get(SettingName.STATIC_SHADOW_ANALYSIS).toBoolean())
|
||||
res.add("-sh");
|
||||
res.add("-shwidth " + (Global.mainModule.getDb()).settings.get(SettingName.MAX_SHADOW_WIDTH));
|
||||
if ((Global.mainModule.getDb()).settings.get(SettingName.KEEP_SPF_DIRECTIVES).toBoolean())
|
||||
res.add("-keepSPF");
|
||||
return String.join(" ", res);
|
||||
public static int getProjectMinMaxDim_C(db_project_info project) {
|
||||
int res = 0;
|
||||
for (DBProjectFile file : project.db.files.Data.values()) {
|
||||
if (file.isActiveProgram())
|
||||
res = Math.max(res, Sapfor.getFileMaxDim_C(file.file));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
*/
|
||||
public static Pair<Integer, Integer> getProjectFolderMinMaxDim_F(File sapfor_drv, File projectPath) {
|
||||
String flags = "-noLogo";
|
||||
Pair<Integer, Integer> res = new Pair<>(0, 0);
|
||||
try {
|
||||
if (Sapfor.parse(sapfor_drv, projectPath, flags)
|
||||
) {
|
||||
Vector<String> outputLines = new Vector<>();
|
||||
if (Sapfor.analysis(sapfor_drv, projectPath, PassCode.SPF_GetMaxMinBlockDistribution, flags, outputLines)) {
|
||||
//---
|
||||
for (String line : outputLines) {
|
||||
String prefix = "GET_MIN_MAX_BLOCK_DIST: ";
|
||||
if (line.startsWith(prefix)) {
|
||||
String s = line.substring(prefix.length());
|
||||
String[] data = s.split(" ");
|
||||
res = new Pair<>(Math.max(Integer.parseInt(data[0]), 0), Math.max(Integer.parseInt(data[1]), 0));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
Utils.deleteFilesByExtensions(projectPath,
|
||||
"proj", "dep", "jar"
|
||||
);
|
||||
File visualiser_data = new File(projectPath, Constants.data);
|
||||
if (visualiser_data.exists())
|
||||
FileUtils.forceDelete(visualiser_data);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
public static void getTestMinMaxDim_F(File sapfor_drv, Test test) {
|
||||
Pair<Integer, Integer> res = getProjectFolderMinMaxDim_F(sapfor_drv, test.getServerPath());
|
||||
test.min_dim = res.getKey();
|
||||
test.max_dim = res.getValue();
|
||||
}
|
||||
public static void getTestMinMaxDime_C(Test test) {
|
||||
File workspace = test.getServerPath();
|
||||
Vector<File> files = new Vector<>();
|
||||
String[] names = test.files.split("\n");
|
||||
for (String name : names) {
|
||||
if (!name.isEmpty()) {
|
||||
files.add(new File(workspace, name));
|
||||
}
|
||||
}
|
||||
int min_dim = 0;
|
||||
int max_dim = 0;
|
||||
for (File file: files){
|
||||
max_dim = Math.max(max_dim,getFileMaxDim_C(file));
|
||||
}
|
||||
test.min_dim = min_dim;
|
||||
test.max_dim = max_dim;
|
||||
}
|
||||
//--
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user