рефакторинг определения размерности тестов на сервере.
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;
|
||||
}
|
||||
//--
|
||||
}
|
||||
|
||||
@@ -80,10 +80,6 @@ public class CreateTestFromFile extends Pass<Test> {
|
||||
@Override
|
||||
protected void body() throws Exception {
|
||||
ShowMessage1(projectFile.file.getName());
|
||||
//--
|
||||
File tempProject = packTestCode();
|
||||
ShowMessage2("Синтаксический анализ и определение размерности");
|
||||
if (group.language == LanguageName.fortran)
|
||||
Sapfor.getMinMaxDim(Sapfor.getTempCopy(Global.mainModule.getSapfor().getFile()), tempProject, target);
|
||||
packTestCode();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,12 +36,6 @@ public class TestsForm extends DataSetControlForm<Test> {
|
||||
return RendererLongCell.class;
|
||||
}
|
||||
},
|
||||
new ColumnInfo<Test>("min_dim") {
|
||||
@Override
|
||||
public Object getFieldAt(Test object) {
|
||||
return object.min_dim;
|
||||
}
|
||||
},
|
||||
new ColumnInfo<Test>("max_dim") {
|
||||
@Override
|
||||
public Object getFieldAt(Test object) {
|
||||
|
||||
@@ -107,6 +107,7 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
|
||||
+ "\nТест будет удален"
|
||||
);
|
||||
}
|
||||
db.DetectTestMinMaxDim(db.serverSapfors.getLastDoneVersion(), db.groups.get(test.group_id), test);
|
||||
} else if (object instanceof DVMPackage) {
|
||||
DVMPackage dvmPackage = (DVMPackage) object;
|
||||
//--
|
||||
@@ -287,6 +288,7 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
|
||||
protected void startAdditionalThreads() {
|
||||
testingThread.start();
|
||||
}
|
||||
|
||||
void PerformAutoSapforTesting() throws Exception {
|
||||
TextLog Log = new TextLog();
|
||||
SapforPackage autoPackage = tryAutoSapforTesting(Log);
|
||||
@@ -337,7 +339,7 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
|
||||
return new Pair<>(object, groupFiles);
|
||||
}
|
||||
void RefreshDVMTests() throws Exception {
|
||||
UserAccount account = new UserAccount("server", Constants.MailAddress);
|
||||
UserAccount account = new UserAccount("server", Constants.MailAddress);
|
||||
ServerSapfor serverSapfor = db.serverSapfors.getLastDoneVersion();
|
||||
DownloadRepository downloadRepository = new DownloadRepository();
|
||||
if (!downloadRepository.Do())
|
||||
@@ -379,8 +381,6 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
|
||||
}
|
||||
}
|
||||
groups.sort(Comparator.comparing(o -> o.getKey().description));
|
||||
//-теперь создать тесты.
|
||||
//--
|
||||
for (Pair<Group, Vector<File>> p : groups)
|
||||
db.RefreshGroup(account, serverSapfor, p);
|
||||
}
|
||||
@@ -682,6 +682,7 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
|
||||
}
|
||||
ZipFolderPass zip = new ZipFolderPass();
|
||||
//создание тестов.
|
||||
ServerSapfor serverSapfor = db.serverSapfors.getLastDoneVersion();
|
||||
Vector<Test> tests = new Vector<>();
|
||||
for (String name : versions.keySet()) {
|
||||
File src = versions.get(name);
|
||||
@@ -716,27 +717,9 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
|
||||
throw new RepositoryRefuseException("Не удалось переписать архив проекта");
|
||||
}
|
||||
tests.add(test);
|
||||
db.DetectTestMinMaxDim(serverSapfor, group, test);
|
||||
}
|
||||
}
|
||||
//определение размерности тестов
|
||||
ServerSapfor serverSapfor = db.serverSapfors.getLastDoneVersion();
|
||||
if (serverSapfor != null) {
|
||||
File sapfor_copy = Sapfor.getTempCopy(new File(serverSapfor.call_command));
|
||||
for (Test test : tests) {
|
||||
try {
|
||||
Sapfor.getMinMaxDim(sapfor_copy, test.getServerPath(), test);
|
||||
db.Update(test);
|
||||
Utils.deleteFilesByExtensions(test.getServerPath(),
|
||||
"proj", "dep", "jar"
|
||||
);
|
||||
File visualiser_data = new File(test.getServerPath(), Constants.data);
|
||||
FileUtils.forceDelete(visualiser_data);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
//-"sh"
|
||||
}
|
||||
void ReplaceDVMPackageJson() throws Exception {
|
||||
Pair<DVMPackage, byte[]> p = (Pair<DVMPackage, byte[]>) request.object;
|
||||
@@ -756,27 +739,11 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
|
||||
if (!db.tests.containsKey(key))
|
||||
throw new RepositoryRefuseException("не существует пакета с ключом " + key);
|
||||
}
|
||||
//определение размерности тестов
|
||||
ServerSapfor serverSapfor = db.serverSapfors.getLastDoneVersion();
|
||||
if (serverSapfor != null) {
|
||||
File sapfor_copy = Sapfor.getTempCopy(new File(serverSapfor.call_command));
|
||||
for (Object key : keys) {
|
||||
Test test = db.tests.get(key);
|
||||
Group group = db.groups.get(test.group_id);
|
||||
if (group.language.equals(LanguageName.fortran)) {
|
||||
try {
|
||||
Sapfor.getMinMaxDim(sapfor_copy, test.getServerPath(), test);
|
||||
db.Update(test);
|
||||
Utils.deleteFilesByExtensions(test.getServerPath(),
|
||||
"proj", "dep", "jar"
|
||||
);
|
||||
File visualiser_data = new File(test.getServerPath(), Constants.data);
|
||||
FileUtils.forceDelete(visualiser_data);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Object key : keys) {
|
||||
Test test = db.tests.get(key);
|
||||
Group group = db.groups.get(test.group_id);
|
||||
db.DetectTestMinMaxDim(serverSapfor, group, test);
|
||||
}
|
||||
}
|
||||
void GetDVMPackageCredentials() throws Exception {
|
||||
|
||||
@@ -2,7 +2,6 @@ package _VisualDVM.TestingSystem.Common;
|
||||
import Common.CommonConstants;
|
||||
import Common.Database.RepositoryRefuseException;
|
||||
import Common.Database.SQLITE.SQLiteDatabase;
|
||||
import Common.Utils.TextLog;
|
||||
import Common.Utils.Utils_;
|
||||
import _VisualDVM.ComponentsServer.Component.Sapfor.Sapfor;
|
||||
import _VisualDVM.ComponentsServer.UserAccount.UserAccount;
|
||||
@@ -174,6 +173,20 @@ public class TestsDatabase extends SQLiteDatabase {
|
||||
return res;
|
||||
}
|
||||
//--
|
||||
public void DetectTestMinMaxDim(ServerSapfor serverSapfor, Group group, Test test) throws Exception {
|
||||
switch (group.language) {
|
||||
case fortran:
|
||||
if (serverSapfor != null) {
|
||||
Sapfor.getTestMinMaxDim_F(new File(serverSapfor.call_command), test);
|
||||
Update(test);
|
||||
}
|
||||
break;
|
||||
case c:
|
||||
Sapfor.getTestMinMaxDime_C(test);
|
||||
Update(test);
|
||||
break;
|
||||
}
|
||||
}
|
||||
public void SaveTestFromSingleFile(ServerSapfor sapfor, Group group, Test test, File file) throws Exception {
|
||||
File testDirectory = new File(Global.TestsDirectory, String.valueOf(test.id));
|
||||
Utils_.CheckAndCleanDirectory(testDirectory);
|
||||
@@ -187,29 +200,10 @@ public class TestsDatabase extends SQLiteDatabase {
|
||||
//----------->>
|
||||
ZipFolderPass zip = new ZipFolderPass();
|
||||
zip.Do(testDirectory.getAbsolutePath(), archive.getAbsolutePath());
|
||||
//---
|
||||
//Определение размерности
|
||||
switch (group.language) {
|
||||
case fortran:
|
||||
// временная папка для анализа. чтобы не засорять нормальную.
|
||||
File tempProject = Utils.getTempFileName("test");
|
||||
FileUtils.forceMkdir(tempProject);
|
||||
FileUtils.copyDirectory(testDirectory, tempProject);
|
||||
//--
|
||||
if (sapfor!=null) {
|
||||
if (Sapfor.getMinMaxDim(Sapfor.getTempCopy(new File(sapfor.call_command)), tempProject, test)) {
|
||||
Update(test);
|
||||
} else
|
||||
throw new RepositoryRefuseException("Не удалось определить размерность теста " + Utils_.Brackets(test.description));
|
||||
}
|
||||
break;
|
||||
case c:
|
||||
test.max_dim = Utils.getCTestMaxDim(testFile);
|
||||
Update(test);
|
||||
break;
|
||||
}
|
||||
DetectTestMinMaxDim(sapfor, group, test);
|
||||
}
|
||||
//---
|
||||
//---
|
||||
public void CreateTestFromSingleFile(UserAccount account, ServerSapfor sapfor, Group group, File file, String testDescription) throws Exception {
|
||||
Test test = new Test();
|
||||
test.description = testDescription;
|
||||
|
||||
@@ -7,8 +7,6 @@ import Common.Utils.Utils_;
|
||||
import Common.Visual.UI;
|
||||
import Common.Visual.Windows.Dialog.VFileChooser_;
|
||||
import _VisualDVM.GlobalData.Tasks.TaskState;
|
||||
import _VisualDVM.ProjectData.Files.DBProjectFile;
|
||||
import _VisualDVM.ProjectData.Project.db_project_info;
|
||||
import javafx.util.Pair;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
@@ -19,7 +17,6 @@ import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.*;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.*;
|
||||
@@ -358,56 +355,6 @@ public class Utils {
|
||||
if (matrix.trim().isEmpty()) return 0;
|
||||
return matrix.split(" ").length;
|
||||
}
|
||||
|
||||
public static int getCTestMaxDim(File test) {
|
||||
int fileMax = 0;
|
||||
final String prefix = "#pragma dvm array distribute";
|
||||
int n = 0;
|
||||
try {
|
||||
for (String line : FileUtils.readLines(test, 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 static int getCProjectMaxDim(db_project_info project) {
|
||||
int res = 0;
|
||||
for (DBProjectFile file : project.db.files.Data.values()) {
|
||||
if (file.isActiveProgram())
|
||||
res = Math.max(res, getCTestMaxDim(file.file));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
public static boolean isTimeout(long startDate, long maxtime_sec) {
|
||||
Date now = new Date();
|
||||
long delta = (now.getTime() - startDate) / 1000;
|
||||
|
||||
Reference in New Issue
Block a user