testCTestHardwareSpec.cxx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include "cmCTestHardwareSpec.h"
  5. struct ExpectedSpec
  6. {
  7. std::string Path;
  8. bool ParseResult;
  9. cmCTestHardwareSpec Expected;
  10. };
  11. static const std::vector<ExpectedSpec> expectedHardwareSpecs = {
  12. /* clang-format off */
  13. {"spec1.json", true, {{{
  14. {"gpus", {
  15. {"2", 4},
  16. {"e", 1},
  17. }},
  18. {"threads", {
  19. }},
  20. }}}},
  21. {"spec2.json", true, {{{
  22. }}}},
  23. {"spec3.json", false, {{{}}}},
  24. {"spec4.json", false, {{{}}}},
  25. {"spec5.json", false, {{{}}}},
  26. {"spec6.json", false, {{{}}}},
  27. {"spec7.json", false, {{{}}}},
  28. {"spec8.json", false, {{{}}}},
  29. {"spec9.json", false, {{{}}}},
  30. {"spec10.json", false, {{{}}}},
  31. {"spec11.json", false, {{{}}}},
  32. {"spec12.json", false, {{{}}}},
  33. {"spec13.json", false, {{{}}}},
  34. {"spec14.json", true, {{{}}}},
  35. {"spec15.json", true, {{{}}}},
  36. {"spec16.json", true, {{{}}}},
  37. {"spec17.json", false, {{{}}}},
  38. {"spec18.json", false, {{{}}}},
  39. {"noexist.json", false, {{{}}}},
  40. /* clang-format on */
  41. };
  42. static bool testSpec(const std::string& path, bool expectedResult,
  43. const cmCTestHardwareSpec& expected)
  44. {
  45. cmCTestHardwareSpec actual;
  46. bool result = actual.ReadFromJSONFile(path);
  47. if (result != expectedResult) {
  48. std::cout << "ReadFromJSONFile(\"" << path << "\") returned " << result
  49. << ", should be " << expectedResult << std::endl;
  50. return false;
  51. }
  52. if (result && actual != expected) {
  53. std::cout << "ReadFromJSONFile(\"" << path
  54. << "\") did not give expected spec" << std::endl;
  55. return false;
  56. }
  57. return true;
  58. }
  59. int testCTestHardwareSpec(int argc, char** const argv)
  60. {
  61. if (argc < 2) {
  62. std::cout << "Invalid arguments.\n";
  63. return -1;
  64. }
  65. int retval = 0;
  66. for (auto const& spec : expectedHardwareSpecs) {
  67. std::string path = argv[1];
  68. path += "/testCTestHardwareSpec_data/";
  69. path += spec.Path;
  70. if (!testSpec(path, spec.ParseResult, spec.Expected)) {
  71. retval = -1;
  72. }
  73. }
  74. return retval;
  75. }