server-test.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. from __future__ import print_function
  2. import sys, cmakelib, json, os, shutil
  3. debug = True
  4. cmakeCommand = sys.argv[1]
  5. testFile = sys.argv[2]
  6. sourceDir = sys.argv[3]
  7. buildDir = sys.argv[4] + "/" + os.path.splitext(os.path.basename(testFile))[0]
  8. cmakeGenerator = sys.argv[5]
  9. print("Test:", testFile,
  10. "\n-- SourceDir:", sourceDir,
  11. "\n-- BuildDir:", buildDir,
  12. "\n-- Generator:", cmakeGenerator)
  13. if os.path.exists(buildDir):
  14. shutil.rmtree(buildDir)
  15. proc = cmakelib.initProc(cmakeCommand)
  16. with open(testFile) as f:
  17. testData = json.loads(f.read())
  18. for obj in testData:
  19. if 'sendRaw' in obj:
  20. data = obj['sendRaw']
  21. if debug: print("Sending raw:", data)
  22. cmakelib.writeRawData(proc, data)
  23. elif 'send' in obj:
  24. data = obj['send']
  25. if debug: print("Sending:", json.dumps(data))
  26. cmakelib.writePayload(proc, data)
  27. elif 'recv' in obj:
  28. data = obj['recv']
  29. if debug: print("Waiting for:", json.dumps(data))
  30. cmakelib.waitForMessage(proc, data)
  31. elif 'reply' in obj:
  32. data = obj['reply']
  33. if debug: print("Waiting for reply:", json.dumps(data))
  34. originalType = ""
  35. cookie = ""
  36. skipProgress = False;
  37. if 'cookie' in data: cookie = data['cookie']
  38. if 'type' in data: originalType = data['type']
  39. if 'skipProgress' in data: skipProgress = data['skipProgress']
  40. cmakelib.waitForReply(proc, originalType, cookie, skipProgress)
  41. elif 'error' in obj:
  42. data = obj['error']
  43. if debug: print("Waiting for error:", json.dumps(data))
  44. originalType = ""
  45. cookie = ""
  46. message = ""
  47. if 'cookie' in data: cookie = data['cookie']
  48. if 'type' in data: originalType = data['type']
  49. if 'message' in data: message = data['message']
  50. cmakelib.waitForError(proc, originalType, cookie, message)
  51. elif 'progress' in obj:
  52. data = obj['progress']
  53. if debug: print("Waiting for progress:", json.dumps(data))
  54. originalType = ''
  55. cookie = ""
  56. current = 0
  57. message = ""
  58. if 'cookie' in data: cookie = data['cookie']
  59. if 'type' in data: originalType = data['type']
  60. if 'current' in data: current = data['current']
  61. if 'message' in data: message = data['message']
  62. cmakelib.waitForProgress(proc, originalType, cookie, current, message)
  63. elif 'handshake' in obj:
  64. data = obj['handshake']
  65. if debug: print("Doing handshake:", json.dumps(data))
  66. major = -1
  67. minor = -1
  68. generator = cmakeGenerator
  69. extraGenerator = ''
  70. sourceDirectory = sourceDir
  71. buildDirectory = buildDir
  72. if 'major' in data: major = data['major']
  73. if 'minor' in data: minor = data['minor']
  74. if 'buildDirectory' in data: buildDirectory = data['buildDirectory']
  75. if 'sourceDirectory' in data: sourceDirectory = data['sourceDirectory']
  76. if 'generator' in data: generator = data['generator']
  77. if 'extraGenerator' in data: extraGenerator = data['extraGenerator']
  78. if not os.path.isabs(buildDirectory):
  79. buildDirectory = buildDir + "/" + buildDirectory
  80. if sourceDirectory != '' and not os.path.isabs(sourceDirectory):
  81. sourceDirectory = sourceDir + "/" + sourceDirectory
  82. cmakelib.handshake(proc, major, minor, sourceDirectory, buildDirectory,
  83. generator, extraGenerator)
  84. elif 'validateGlobalSettings' in obj:
  85. data = obj['validateGlobalSettings']
  86. if not 'buildDirectory' in data: data['buildDirectory'] = buildDir
  87. if not 'sourceDirectory' in data: data['sourceDirectory'] = sourceDir
  88. if not 'generator' in data: data['generator'] = cmakeGenerator
  89. if not 'extraGenerator' in data: data['extraGenerator'] = ''
  90. cmakelib.validateGlobalSettings(proc, cmakeCommand, data)
  91. elif 'validateCache' in obj:
  92. data = obj['validateCache']
  93. if not 'isEmpty' in data: data['isEmpty'] = false
  94. cmakelib.validateCache(proc, data)
  95. elif 'message' in obj:
  96. print("MESSAGE:", obj["message"])
  97. elif 'reconnect' in obj:
  98. cmakelib.exitProc(proc)
  99. proc = cmakelib.initProc(cmakeCommand)
  100. else:
  101. print("Unknown command:", json.dumps(obj))
  102. sys.exit(2)
  103. print("Completed")
  104. cmakelib.exitProc(proc)
  105. sys.exit(proc.returncode)