综合平台编程器项目的远程存储
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 

128 líneas
3.5 KiB

  1. #include "domain/control_logic_model.h"
  2. #include "domain/register_repository.h"
  3. #include "domain/virtual_register_repository.h"
  4. #include "services/software_logic_executor.h"
  5. #include <QDebug>
  6. #include <QTest>
  7. #include <string>
  8. #include <utility>
  9. #include <vector>
  10. namespace
  11. {
  12. LogicNode contact(const std::string &id, int address)
  13. {
  14. return {id,
  15. ContactNodeConfig{
  16. RegisterAddress{RegisterArea::M, address},
  17. ContactMode::NormallyOpen},
  18. true};
  19. }
  20. LogicNode coil(const std::string &id, int address)
  21. {
  22. return {id,
  23. CoilNodeConfig{
  24. RegisterAddress{RegisterArea::M, address},
  25. CoilMode::Normal},
  26. true};
  27. }
  28. ControlLogic makeLogic(int index)
  29. {
  30. LadderRung rung;
  31. rung.id = "rung-" + std::to_string(index);
  32. rung.name = rung.id;
  33. for (int column = 0;
  34. column < ProjectLimits::kMaximumConditionColumns;
  35. ++column)
  36. {
  37. rung.cells.push_back({
  38. rung.id + "-cell-" + std::to_string(column),
  39. column == 0 ? LadderCellKind::Node : LadderCellKind::Wire,
  40. column == 0
  41. ? std::optional<LogicNode>{contact(
  42. "contact-" + std::to_string(index), index)}
  43. : std::nullopt});
  44. }
  45. rung.output = coil("coil-" + std::to_string(index), index + 100);
  46. return {"logic-" + std::to_string(index),
  47. "logic-" + std::to_string(index),
  48. {rung},
  49. true,
  50. {}};
  51. }
  52. class PerformanceTests final : public QObject
  53. {
  54. Q_OBJECT
  55. private slots:
  56. void initTestCase()
  57. {
  58. qInfo().noquote()
  59. << QStringLiteral("性能测试开始:下面两项 RESULT 的耗时均为平均每次执行时间");
  60. qInfo().noquote()
  61. << QStringLiteral("测试项目 1:100 个控制逻辑的软件扫描");
  62. qInfo().noquote()
  63. << QStringLiteral("测试项目 2:M0 到 M4000 共 4001 个虚拟 M 地址的完整写入和读取");
  64. }
  65. void softwareExecutor_scansRepresentativeProject()
  66. {
  67. std::vector<ControlLogic> logics;
  68. logics.reserve(100);
  69. for (int index = 0; index < 100; ++index)
  70. {
  71. logics.push_back(makeLogic(index));
  72. }
  73. SoftwareLogicExecutor executor;
  74. VirtualRegisterRepository repository;
  75. QVERIFY(executor.validate(logics).succeeded);
  76. QVERIFY(executor.executeScan(logics, repository).succeeded);
  77. QBENCHMARK
  78. {
  79. executor.executeScan(logics, repository);
  80. }
  81. }
  82. void virtualRepository_handlesBoundaryWorkload()
  83. {
  84. VirtualRegisterRepository repository;
  85. for (int index = 0; index <= RegisterAddress::kMaximumIndex; ++index)
  86. {
  87. QVERIFY(repository.writeBit(
  88. {RegisterArea::M, index}, (index % 2) == 0)
  89. .succeeded);
  90. QVERIFY(repository.readBit({RegisterArea::M, index}).succeeded);
  91. }
  92. QBENCHMARK
  93. {
  94. for (int index = 0; index <= RegisterAddress::kMaximumIndex; ++index)
  95. {
  96. repository.writeBit(
  97. {RegisterArea::M, index}, (index % 2) == 0);
  98. repository.readBit({RegisterArea::M, index});
  99. }
  100. }
  101. }
  102. void cleanupTestCase()
  103. {
  104. qInfo().noquote()
  105. << QStringLiteral("性能测试结束:请结合上方两项 RESULT 和最后的 Totals 判断结果");
  106. }
  107. };
  108. } // namespace
  109. QTEST_APPLESS_MAIN(PerformanceTests)
  110. #include "performance_tests.moc"