2024-10-09 22:21:57 +03:00
|
|
|
|
package _VisualDVM.TestingSystem.DVM;
|
2024-10-07 14:22:52 +03:00
|
|
|
|
import Common.Utils.CommonUtils;
|
2024-10-09 22:01:19 +03:00
|
|
|
|
import _VisualDVM.Constants;
|
2024-10-07 00:58:29 +03:00
|
|
|
|
import _VisualDVM.Global;
|
2024-10-09 22:01:19 +03:00
|
|
|
|
import _VisualDVM.Utils;
|
2024-10-09 22:21:57 +03:00
|
|
|
|
import _VisualDVM.GlobalData.RemoteFile.RemoteFile;
|
|
|
|
|
|
import _VisualDVM.GlobalData.Tasks.TaskState;
|
|
|
|
|
|
import _VisualDVM.TestingSystem.Common.TasksPackageState;
|
|
|
|
|
|
import _VisualDVM.TestingSystem.DVM.DVMTasks.DVMCompilationTask;
|
|
|
|
|
|
import _VisualDVM.TestingSystem.DVM.DVMTasks.DVMRunTask;
|
2024-04-15 22:09:10 +03:00
|
|
|
|
import Visual_DVM_2021.Passes.All.UnzipFolderPass;
|
|
|
|
|
|
import javafx.util.Pair;
|
|
|
|
|
|
import org.apache.commons.io.FileUtils;
|
2024-04-13 20:09:26 +03:00
|
|
|
|
|
2024-04-15 22:09:10 +03:00
|
|
|
|
import java.io.File;
|
|
|
|
|
|
import java.nio.file.Paths;
|
|
|
|
|
|
import java.util.*;
|
2024-04-27 18:44:36 +03:00
|
|
|
|
public class RemoteDVMTestingPlanner extends DVMTestingPlanner {
|
2024-04-15 22:09:10 +03:00
|
|
|
|
RemoteFile packageRemoteWorkspace = null;
|
2024-04-27 18:44:36 +03:00
|
|
|
|
public RemoteDVMTestingPlanner(String... args) {
|
|
|
|
|
|
super(args);
|
2024-04-15 22:09:10 +03:00
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected boolean Connect() {
|
|
|
|
|
|
if (user.connection == null) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
user.connection = new UserConnection(machine, user);
|
|
|
|
|
|
Print("Соединение c " + machine.getURL() + " " + user.login + " успешно установлено.");
|
2024-05-21 23:07:42 +03:00
|
|
|
|
Print("Проверка инициализации..");
|
2024-05-21 23:20:50 +03:00
|
|
|
|
user.connection.CheckUserInitialization(testingPackage.sender_address);
|
2024-04-15 22:09:10 +03:00
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
Print(ex.toString());
|
|
|
|
|
|
user.connection = null;
|
|
|
|
|
|
Print("Не удалось установить соединение.");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return user.connection != null;
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected void Disconnect() {
|
|
|
|
|
|
if (user.connection != null) {
|
|
|
|
|
|
user.connection.Disconnect();
|
|
|
|
|
|
user.connection = null;
|
|
|
|
|
|
Print("Соединение c " + machine.getURL() + " " + user.login + " сброшено.");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//----
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected void TestsSynchronize() throws Exception {
|
2024-09-14 00:18:27 +03:00
|
|
|
|
System.out.println("--");
|
2024-04-15 22:09:10 +03:00
|
|
|
|
testingPackage.readJson();
|
2024-09-14 00:18:27 +03:00
|
|
|
|
System.out.println("+");
|
2024-04-15 22:09:10 +03:00
|
|
|
|
LinkedHashMap<Integer, File> tests = getTestsFromJson();
|
|
|
|
|
|
//синхронизировать их.
|
|
|
|
|
|
for (int test_id : tests.keySet()) {
|
2024-09-25 01:42:30 +03:00
|
|
|
|
System.out.println("test=" + test_id);
|
2024-04-15 22:09:10 +03:00
|
|
|
|
File test = tests.get(test_id);
|
|
|
|
|
|
RemoteFile test_dst = new RemoteFile(testingPackage.user_workspace + "/projects/" + test_id, true);
|
|
|
|
|
|
user.connection.MKDIR(test_dst);
|
|
|
|
|
|
user.connection.SynchronizeSubDirsR(test, test_dst);
|
|
|
|
|
|
}
|
2024-09-14 00:18:27 +03:00
|
|
|
|
System.out.println("++");
|
2024-04-15 22:09:10 +03:00
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected void PackageWorkspaceCreation() throws Exception {
|
2024-09-14 00:18:27 +03:00
|
|
|
|
System.out.println("package workspace creation");
|
2024-04-15 22:09:10 +03:00
|
|
|
|
if (!CheckModules()) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2024-09-14 00:18:27 +03:00
|
|
|
|
System.out.println("modules checked");
|
2024-04-15 22:09:10 +03:00
|
|
|
|
//--
|
|
|
|
|
|
testingPackage.readJson();
|
|
|
|
|
|
//--
|
|
|
|
|
|
LinkedHashMap<Integer, File> tests = getTestsFromJson();
|
|
|
|
|
|
//создать папку для пакета.
|
2024-09-14 01:16:08 +03:00
|
|
|
|
user.connection.RMDIR(packageRemoteWorkspace.full_name);
|
2024-04-15 22:09:10 +03:00
|
|
|
|
user.connection.sftpChannel.mkdir(packageRemoteWorkspace.full_name);
|
|
|
|
|
|
//положить туда запакованные тексты задач.
|
|
|
|
|
|
Vector<String> compilationLines = new Vector<>();
|
|
|
|
|
|
Vector<String> runLines = new Vector<>();
|
|
|
|
|
|
for (DVMCompilationTask compilationTask : testingPackage.package_json.compilationTasks) {
|
|
|
|
|
|
String makefileText = generateMakefile(tests.get(compilationTask.test_id), compilationTask.language, testingPackage.drv, compilationTask.flags);
|
|
|
|
|
|
compilationLines.addAll(compilationTask.pack(makefileText));
|
|
|
|
|
|
for (DVMRunTask runTask : compilationTask.runTasks)
|
|
|
|
|
|
runLines.addAll(runTask.pack(null));
|
|
|
|
|
|
}
|
|
|
|
|
|
RemoteFile compilationPackage = new RemoteFile(packageRemoteWorkspace, "compilationTasks");
|
|
|
|
|
|
RemoteFile runPackage = new RemoteFile(packageRemoteWorkspace, "runTasks");
|
|
|
|
|
|
user.connection.writeToFile(String.join("\n", compilationLines) + "\n", compilationPackage);
|
|
|
|
|
|
user.connection.writeToFile(String.join("\n", runLines) + "\n", runPackage);
|
|
|
|
|
|
// --
|
|
|
|
|
|
user.connection.MKDIR(new RemoteFile(packageRemoteWorkspace, "state"));
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected void AnalyseResults() throws Exception {
|
2024-09-25 01:42:30 +03:00
|
|
|
|
boolean hasErrors = false;
|
2024-04-15 22:09:10 +03:00
|
|
|
|
testingPackage.readJson();
|
|
|
|
|
|
Print("analysing results");
|
|
|
|
|
|
Vector<DVMRunTask> runTasks = new Vector<>();
|
|
|
|
|
|
for (DVMCompilationTask compilationTask : testingPackage.package_json.compilationTasks)
|
|
|
|
|
|
runTasks.addAll(compilationTask.runTasks);
|
|
|
|
|
|
//----
|
|
|
|
|
|
getTasksInfo(testingPackage.package_json.compilationTasks, "CompilationInfo.txt");
|
|
|
|
|
|
getTasksInfo(runTasks, "RunningInfo.txt");
|
|
|
|
|
|
//--
|
|
|
|
|
|
int ct_count = 0;
|
|
|
|
|
|
int rt_count = 0;
|
2024-10-03 16:21:11 +03:00
|
|
|
|
int good=0;
|
2024-04-15 22:09:10 +03:00
|
|
|
|
//--
|
|
|
|
|
|
for (DVMCompilationTask compilationTask : testingPackage.package_json.compilationTasks) {
|
|
|
|
|
|
compilationTask.dvm_package_id = testingPackage.id;
|
2024-09-25 01:42:30 +03:00
|
|
|
|
if (!compilationTask.state.equals(TaskState.Done))
|
|
|
|
|
|
hasErrors = true;
|
2024-04-15 22:09:10 +03:00
|
|
|
|
ct_count++;
|
|
|
|
|
|
File ct_workspace = Paths.get(packageLocalWorkspace.getAbsolutePath(), "results", String.valueOf(compilationTask.id)).toFile();
|
|
|
|
|
|
if (ct_workspace.exists()) {
|
|
|
|
|
|
for (DVMRunTask runTask : compilationTask.runTasks) {
|
|
|
|
|
|
runTask.dvm_package_id = testingPackage.id;
|
|
|
|
|
|
rt_count++;
|
|
|
|
|
|
runTask.compilation_state = compilationTask.state;
|
|
|
|
|
|
runTask.compilation_time = compilationTask.Time;
|
|
|
|
|
|
if (compilationTask.state == TaskState.DoneWithErrors) {
|
|
|
|
|
|
runTask.state = TaskState.Canceled;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
File rt_workspace = Paths.get(packageLocalWorkspace.getAbsolutePath(), "results", String.valueOf(runTask.id)).toFile();
|
|
|
|
|
|
if (rt_workspace.exists() && runTask.state.equals(TaskState.Finished)) {
|
|
|
|
|
|
//анализ задачи на запуск.
|
|
|
|
|
|
File outFile = new File(rt_workspace, Constants.out_file);
|
|
|
|
|
|
File errFile = new File(rt_workspace.getAbsolutePath(), Constants.err_file);
|
|
|
|
|
|
//--
|
|
|
|
|
|
String output = FileUtils.readFileToString(outFile);
|
|
|
|
|
|
String errors = FileUtils.readFileToString(errFile);
|
|
|
|
|
|
//--
|
|
|
|
|
|
List<String> output_lines = Arrays.asList(output.split("\n"));
|
|
|
|
|
|
List<String> errors_lines = Arrays.asList(errors.split("\n"));
|
|
|
|
|
|
//---
|
|
|
|
|
|
if (Utils.isCrushed(output_lines, errors_lines)) {
|
|
|
|
|
|
runTask.state = TaskState.Crushed;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
Pair<TaskState, Integer> results = new Pair<>(TaskState.Done, 100);
|
|
|
|
|
|
switch (runTask.test_type) {
|
|
|
|
|
|
case Correctness:
|
|
|
|
|
|
results = Utils.analyzeCorrectness(output_lines);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case Performance:
|
|
|
|
|
|
results = Utils.analyzePerformance(output_lines);
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
runTask.state = results.getKey();
|
|
|
|
|
|
runTask.progress = results.getValue();
|
|
|
|
|
|
runTask.CleanTime = Utils.parseCleanTime(output);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-09-25 01:42:30 +03:00
|
|
|
|
if (!runTask.state.equals(TaskState.Done))
|
|
|
|
|
|
hasErrors = true;
|
2024-10-03 16:21:11 +03:00
|
|
|
|
else good++;
|
2024-04-15 22:09:10 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
testingPackage.progress = 100;
|
|
|
|
|
|
testingPackage.saveJson(); //запись обновленных результатов пакета в json!
|
|
|
|
|
|
Print("analysis done, ct_count=" + ct_count + " rt count=" + rt_count);
|
2024-10-03 16:21:11 +03:00
|
|
|
|
testingPackage.state = hasErrors ? TasksPackageState.DoneWithErrors : TasksPackageState.Done;
|
|
|
|
|
|
double percent = ( ((double)(good))/testingPackage.tasksCount)*100.0;
|
|
|
|
|
|
testingPackage.description = "Выполнено на "+((int)percent)+"%\n"+
|
|
|
|
|
|
"Всего задач: "+testingPackage.tasksCount+", из них с ошибками "+(testingPackage.tasksCount-good);
|
|
|
|
|
|
UpdatePackageState();
|
2024-04-15 22:09:10 +03:00
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected void PackageStart() throws Exception {
|
|
|
|
|
|
String plannerStartCommand = String.join(" ",
|
2024-10-07 14:22:52 +03:00
|
|
|
|
CommonUtils.DQuotes(getPlanner()),
|
|
|
|
|
|
CommonUtils.DQuotes(user.workspace),
|
|
|
|
|
|
CommonUtils.DQuotes(packageRemoteWorkspace.full_name),
|
|
|
|
|
|
CommonUtils.DQuotes(testingPackage.kernels),
|
|
|
|
|
|
CommonUtils.DQuotes(testingPackage.drv));
|
2024-04-15 22:41:13 +03:00
|
|
|
|
user.connection.startShellProcess(packageRemoteWorkspace, "planner_output",
|
2024-04-15 22:09:10 +03:00
|
|
|
|
"ulimit -s unlimited", plannerStartCommand);
|
2024-04-15 22:41:13 +03:00
|
|
|
|
//---
|
|
|
|
|
|
RemoteFile PID = new RemoteFile(packageRemoteWorkspace, "PID");
|
|
|
|
|
|
while (!user.connection.Exists(PID)) {
|
|
|
|
|
|
Print("PID not found");
|
2024-10-07 22:22:51 +03:00
|
|
|
|
CommonUtils.sleep(1000);
|
2024-04-15 22:41:13 +03:00
|
|
|
|
}
|
2024-04-21 00:01:17 +03:00
|
|
|
|
testingPackage.PID = user.connection.readFromFile(PID).replace("\n", "").replace("\r", "");
|
2024-04-15 22:41:13 +03:00
|
|
|
|
//---
|
2024-10-07 14:22:52 +03:00
|
|
|
|
System.out.println("PID=" + CommonUtils.Brackets(testingPackage.PID));
|
2024-04-15 22:09:10 +03:00
|
|
|
|
RemoteFile STARTED = new RemoteFile(packageRemoteWorkspace, "STARTED");
|
|
|
|
|
|
while (!user.connection.Exists(STARTED)) {
|
|
|
|
|
|
Print("waiting for package start...");
|
2024-10-07 22:22:51 +03:00
|
|
|
|
CommonUtils.sleep(1000);
|
2024-04-15 22:09:10 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected boolean CheckNextState() throws Exception {
|
|
|
|
|
|
boolean progress_changed = false;
|
|
|
|
|
|
boolean state_changed = false;
|
|
|
|
|
|
RemoteFile progress = new RemoteFile(packageRemoteWorkspace, "progress");
|
|
|
|
|
|
if (user.connection.Exists(progress)) {
|
|
|
|
|
|
String s = user.connection.readFromFile(progress);
|
|
|
|
|
|
int current_progress = Integer.parseInt(s);
|
|
|
|
|
|
if (current_progress != testingPackage.progress) {
|
|
|
|
|
|
Print("progress changed: " + current_progress);
|
|
|
|
|
|
testingPackage.progress = current_progress;
|
|
|
|
|
|
progress_changed = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
RemoteFile stateDir = new RemoteFile(packageRemoteWorkspace, "state");
|
|
|
|
|
|
//состояния пакета могут меняться только по возрастанию. ищем, появилось ли такое.
|
|
|
|
|
|
Vector<TasksPackageState> higherStates = testingPackage.state.getHigherStates();
|
|
|
|
|
|
Collections.reverse(higherStates); //берем в обратном порядке, чтобы быстрее найти высшее.
|
|
|
|
|
|
for (TasksPackageState state : higherStates) {
|
|
|
|
|
|
RemoteFile file = new RemoteFile(stateDir, state.toString());
|
|
|
|
|
|
if (user.connection.Exists(file)) {
|
|
|
|
|
|
Print("found new state: " + file.name);
|
|
|
|
|
|
testingPackage.state = state;
|
|
|
|
|
|
state_changed = true;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//--
|
|
|
|
|
|
user.connection.iterations++;
|
|
|
|
|
|
if (user.connection.iterations == 100) {
|
|
|
|
|
|
Disconnect();
|
|
|
|
|
|
}
|
|
|
|
|
|
//--
|
|
|
|
|
|
return progress_changed || state_changed;
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected void DownloadResults() throws Exception {
|
|
|
|
|
|
Utils.CheckDirectory(packageLocalWorkspace);
|
|
|
|
|
|
RemoteFile remote_results_archive = new RemoteFile(packageRemoteWorkspace, "results.zip");
|
|
|
|
|
|
File results_archive = new File(packageLocalWorkspace, "results.zip");
|
2024-10-07 14:22:52 +03:00
|
|
|
|
user.connection.performScript(packageRemoteWorkspace, "zip -r " + CommonUtils.DQuotes("results.zip") + " " + CommonUtils.DQuotes("results"));
|
2024-04-15 22:09:10 +03:00
|
|
|
|
//---
|
|
|
|
|
|
if (user.connection.Exists(remote_results_archive)) {
|
|
|
|
|
|
user.connection.getSingleFile(remote_results_archive.full_name, results_archive.getAbsolutePath());
|
|
|
|
|
|
UnzipFolderPass unzipFolderPass = new UnzipFolderPass();
|
|
|
|
|
|
unzipFolderPass.Do(results_archive.getAbsolutePath(), packageLocalWorkspace.getAbsolutePath(), false);
|
|
|
|
|
|
}
|
|
|
|
|
|
//---
|
2024-04-26 18:23:08 +03:00
|
|
|
|
if (Global.properties.eraseTestingWorkspaces && user.connection.Exists(packageRemoteWorkspace))
|
|
|
|
|
|
user.connection.RMDIR(packageRemoteWorkspace.full_name);
|
2024-04-21 00:01:17 +03:00
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected void MachineConnectionError() {
|
2024-04-24 22:23:50 +03:00
|
|
|
|
Finalize("Количество безуспешных попыток соединения с машиной " + machine.getURL() + " превысило 10");
|
2024-04-21 00:01:17 +03:00
|
|
|
|
}
|
2024-04-15 22:09:10 +03:00
|
|
|
|
@Override
|
|
|
|
|
|
protected void Kill() throws Exception {
|
|
|
|
|
|
if (!testingPackage.PID.isEmpty()) {
|
|
|
|
|
|
user.connection.Command("kill -9 " + testingPackage.PID);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
2024-04-24 22:23:50 +03:00
|
|
|
|
protected void InitSessionCredentials() {
|
|
|
|
|
|
packageRemoteWorkspace = new RemoteFile(user.workspace + "/tests", String.valueOf(testingPackage.id), true);
|
|
|
|
|
|
packageLocalWorkspace = new File(Global.DVMPackagesDirectory, String.valueOf(testingPackage.id));
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
2024-04-27 18:44:36 +03:00
|
|
|
|
protected boolean CheckModules() throws Exception {
|
2024-05-22 00:09:01 +03:00
|
|
|
|
String log = user.connection.CheckModulesVersion();
|
|
|
|
|
|
if (!log.isEmpty()) {
|
|
|
|
|
|
testingPackage.description = log;
|
|
|
|
|
|
testingPackage.state = TasksPackageState.Aborted;
|
|
|
|
|
|
return false;
|
2024-04-27 18:44:36 +03:00
|
|
|
|
}
|
|
|
|
|
|
return true;
|
2024-04-15 22:09:10 +03:00
|
|
|
|
}
|
2024-10-03 16:21:11 +03:00
|
|
|
|
@Override
|
|
|
|
|
|
public String packageDescription() {
|
|
|
|
|
|
return "DVM";
|
|
|
|
|
|
}
|
2024-04-13 20:09:26 +03:00
|
|
|
|
}
|