Files
VisualSapfor/src/Visual_DVM_2021/Passes/All/StartSapforTests.java
2023-11-17 00:04:21 +03:00

247 lines
9.8 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package Visual_DVM_2021.Passes.All;
import Common.Constants;
import Common.Current;
import Common.Global;
import Common.UI.UI;
import Common.Utils.Index;
import ProjectData.LanguageName;
import Repository.Server.ServerCode;
import Repository.Server.ServerExchangeUnit_2021;
import TestingSystem.SAPFOR.SapforConfiguration.SapforConfiguration;
import TestingSystem.SAPFOR.SapforConfigurationCommand.SapforConfigurationCommand;
import TestingSystem.SAPFOR.SapforTasksPackage.SapforTasksPackage;
import TestingSystem.Common.Group.Group;
import TestingSystem.DVM.TasksPackage.TasksPackageState;
import TestingSystem.Common.Test.Test;
import Visual_DVM_2021.Passes.PassCode_2021;
import Visual_DVM_2021.Passes.Server.TestingSystemPass;
import java.io.File;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Vector;
public class StartSapforTests extends TestingSystemPass<SapforTasksPackage> {
protected int allTasksCount = 0;
//--
protected LinkedHashMap<Integer, Vector<Integer>> groupsTests = null;
//--
protected LinkedHashMap<String, Test> allTests = null;
protected Vector<String> testsNames_lower = null; //все тесты что участвуют здесь
protected Vector<LanguageName> groupsLanguages = null;
protected File sapfor = null;
//---
//---
@Override
public String getIconPath() {
return "/icons/Start.png";
}
@Override
public String getButtonText() {
return "";
}
@Override
protected boolean needsAnimation() {
return true;
}
//--
protected boolean checkTestName(Test test) {
String name = test.description.toLowerCase();
if (testsNames_lower.contains(name)) {
Log.Writeln_("В пакет не могут входить тесты с одинаковыми именами (без учета регистра):" + test.description.toLowerCase());
return false;
}
testsNames_lower.add(name);
return true;
}
protected boolean getGroupTests(int groupId) {
Vector<Integer> groupTests = new Vector<>();
Vector<Integer> selectedGroupTests = new Vector<>();
//---
for (Test test : Global.testingServer.db.tests.Data.values()) {
if (test.group_id==groupId) {
groupTests.add(test.id);
if (test.isSelected())
selectedGroupTests.add(test.id);
}
}
if (!groupTests.isEmpty() && !selectedGroupTests.isEmpty())
groupTests = selectedGroupTests;
//---
if (groupTests.isEmpty()) {
Log.Writeln_("Пустая группа тестов: " + groupId);
return false;
}
//--
for (int testId : groupTests) {
Test test = Global.testingServer.db.tests.get(testId);
if (!checkTestName(test))
return false;
else
allTests.put(test.description, test);
}
//--
groupsTests.put(groupId, groupTests);
//--
return true;
}
boolean checkTerminalCode(SapforConfiguration sapforConfiguration, PassCode_2021 code, int count, Vector<PassCode_2021> codes) {
if (count > 2) {
Log.Writeln_("Неверная конфигурация:" + sapforConfiguration.id + ": " +
code.getDescription() +
" возможно только один раз.");
return false;
}
//--
if ((count == 1) && codes.size() > 1) {
if (!codes.lastElement().equals(code)) {
Log.Writeln_("Неверная конфигурация:" + sapforConfiguration.id + ": " +
code.getDescription() +
" может быть только завершающей командой!");
return false;
}
}
return true;
}
public boolean getConfigurationCommands(SapforConfiguration sapforConfiguration) {
//1. получить список всех команд.
Vector<PassCode_2021> codes = new Vector<>();
//-- счетчик завершающих команд.
LinkedHashMap<PassCode_2021, Index> terminalCodesCount = new LinkedHashMap<>();
for (PassCode_2021 code : Constants.terminalSapforTestingCodes)
terminalCodesCount.put(code, new Index());
//--
for (SapforConfigurationCommand command : Global.testingServer.db.sapforConfigurationCommands.Data.values()) {
if (command.sapforconfiguration_id.equals(sapforConfiguration.id)) {
codes.add(command.passCode);
//---
for (PassCode_2021 t_code : Constants.terminalSapforTestingCodes) {
if (command.passCode.equals(t_code))
terminalCodesCount.get(t_code).Inc();
}
//---
}
}
//--
if (codes.size() == 0) {
Log.Writeln_("Пустая конфигурация:" + sapforConfiguration.id);
return false;
}
for (PassCode_2021 t_code : Constants.terminalSapforTestingCodes) {
if (!checkTerminalCode(sapforConfiguration, t_code,
terminalCodesCount.get(t_code).getValue(), codes
))
return false;
}
//--
return true;
}
//--
@Override
protected boolean canStart(Object... args) throws Exception {
//--
allTasksCount = 0;
target = null;
//--
groupsTests = new LinkedHashMap<>();
//--->>
testsNames_lower = new Vector<>();
allTests = new LinkedHashMap<>();
groupsLanguages = new Vector<>();
//-->>
if (!Current.getAccount().CheckRegistered(Log)) {
return false;
}
//проверка стартовых условий.
if (!Current.Check(Log, Current.ServerSapfor))
return false;
//--->>
if (Global.testingServer.db.sapforConfigurations.getCheckedCount() == 0) {
Log.Writeln_("Не отмечено ни одной конфигурации SAPFOR.");
return false;
}
//-
for (SapforConfiguration configuration : Global.testingServer.db.sapforConfigurations.getCheckedItems()) {
if (!getConfigurationCommands(configuration))
return false;
}
//--
if (Global.testingServer.db.groups.getCheckedCount() == 0) {
Log.Writeln_("Не отмечено ни одной группы тестов");
return false;
}
//--
for (Group group : Global.testingServer.db.groups.getCheckedItems()) {
//---
if (!groupsLanguages.contains(group.language))
groupsLanguages.add(group.language);
//-
if (groupsLanguages.get(0) != LanguageName.fortran) {
Log.Writeln_("Поддерживается пакетный режим только для языка Fortran!");
return false;
}
if (groupsLanguages.size() > 1) {
Log.Writeln_("Запуск тестов на разных языках в рамках одного пакета запрещен!");
return false;
}
//---
if (!getGroupTests(group.id))
return false;
}
//--
for (int i = 0; i < Global.testingServer.db.sapforConfigurations.getCheckedCount(); ++i) {
for (Vector<Integer> tests : groupsTests.values())
allTasksCount += tests.size();
}
//--
return (UI.Question("Будет запущено:\n"
+ allTasksCount + " задач\n" +
"Продолжить"));
}
//--
@Override
protected void ServerAction() throws Exception {
target = new SapforTasksPackage();
target.genName();
//--
Vector<String> testsIds = new Vector<>();
Vector<String> configurationsIds = new Vector<>();
for (Test test : allTests.values())
testsIds.add(String.valueOf(test.id));
//--
for (SapforConfiguration configuration : Global.testingServer.db.sapforConfigurations.getCheckedItems())
configurationsIds.add(configuration.id);
//--
target.tasksCount = allTasksCount;
target.testsIds = String.join("\n", testsIds);
target.configurationsIds = String.join("\n", configurationsIds);
//--
target.sapforId = Current.getServerSapfor().id;
target.sapfor_drv = Current.getServerSapfor().call_command;
target.sapfor_version = Current.getServerSapfor().version;
target.sapfor_build_date = Current.getServerSapfor().buildDate;
//--
target.testsNames = String.join(";", testsNames_lower);
target.StartDate = new Date().getTime();
target.kernels = Global.properties.TestingKernels;
target.state = TasksPackageState.Queued;
target.needsEmail = Global.properties.EmailOnTestingProgress ? 1 : 0;
//---
Vector<SapforTasksPackage> packages = new Vector<>();
packages.add(target);
Command(new ServerExchangeUnit_2021(ServerCode.PublishAccountObjects, Current.getAccount().email, packages));
}
@Override
protected void performDone() throws Exception {
passes.get(PassCode_2021.SynchronizeTestsTasks).Do();
/*
if (!TestingServer.checkTasks)
TestingServer.TimerOn();
*/
}
@Override
protected void showDone() throws Exception {
server.account_db.sapforTasksPackages.ui_.Select(target.id);
// UI.getMainWindow().getTestingWindow().ShowAutoActualizeTestsState();
}
}