综合平台编程器项目的远程存储
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.
 
 
 
 

98 líneas
2.5 KiB

  1. #include "domain/control_logic_model.h"
  2. #include "domain/register_repository.h"
  3. #include "services/software_logic_executor.h"
  4. #include <QTest>
  5. #include <string>
  6. #include <vector>
  7. namespace
  8. {
  9. LogicNode contact(const std::string &id, int address)
  10. {
  11. return {id,
  12. ContactNodeConfig{
  13. RegisterAddress{RegisterArea::M, address},
  14. ContactMode::NormallyOpen},
  15. true};
  16. }
  17. LogicNode coil(const std::string &id, int address)
  18. {
  19. return {id,
  20. CoilNodeConfig{
  21. RegisterAddress{RegisterArea::M, address},
  22. CoilMode::Normal},
  23. true};
  24. }
  25. ControlLogic makeLogic(int index)
  26. {
  27. LadderRung rung;
  28. rung.id = "rung-" + std::to_string(index);
  29. rung.name = rung.id;
  30. rung.condition = ConditionExpression::fromNode(
  31. contact("contact-" + std::to_string(index), index));
  32. rung.output = coil("coil-" + std::to_string(index), index + 100);
  33. return {"logic-" + std::to_string(index),
  34. "logic-" + std::to_string(index),
  35. {rung},
  36. true};
  37. }
  38. class PerformanceTests final : public QObject
  39. {
  40. Q_OBJECT
  41. private slots:
  42. void softwareExecutor_scansRepresentativeProject()
  43. {
  44. std::vector<ControlLogic> logics;
  45. logics.reserve(100);
  46. for (int index = 0; index < 100; ++index)
  47. {
  48. logics.push_back(makeLogic(index));
  49. }
  50. SoftwareLogicExecutor executor;
  51. VirtualRegisterRepository repository;
  52. QVERIFY(executor.validate(logics).succeeded);
  53. QVERIFY(executor.executeScan(logics, repository).succeeded);
  54. QBENCHMARK
  55. {
  56. executor.executeScan(logics, repository);
  57. }
  58. }
  59. void virtualRepository_handlesBoundaryWorkload()
  60. {
  61. VirtualRegisterRepository repository;
  62. for (int index = 0; index <= RegisterAddress::kMaximumIndex; ++index)
  63. {
  64. QVERIFY(repository.writeBit(
  65. {RegisterArea::M, index}, (index % 2) == 0)
  66. .succeeded);
  67. QVERIFY(repository.readBit({RegisterArea::M, index}).succeeded);
  68. }
  69. QBENCHMARK
  70. {
  71. for (int index = 0; index <= RegisterAddress::kMaximumIndex; ++index)
  72. {
  73. repository.writeBit(
  74. {RegisterArea::M, index}, (index % 2) == 0);
  75. repository.readBit({RegisterArea::M, index});
  76. }
  77. }
  78. }
  79. };
  80. } // namespace
  81. QTEST_APPLESS_MAIN(PerformanceTests)
  82. #include "performance_tests.moc"