综合平台编程器项目的远程存储
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

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