server-test.py 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import sys, cmakelib, json
  2. debug = True
  3. cmakeCommand = sys.argv[1]
  4. testFile = sys.argv[2]
  5. sourceDir = sys.argv[3]
  6. buildDir = sys.argv[4]
  7. print("SourceDir: ", sourceDir, " -- BuildDir: ", buildDir)
  8. proc = cmakelib.initProc(cmakeCommand)
  9. with open(testFile) as f:
  10. testText = f.read()
  11. testText = testText.replace('%BUILDDIR%', buildDir)
  12. testText = testText.replace('%SOURCEDIR%', sourceDir)
  13. testData = json.loads(testText)
  14. buildDir = sys.argv[3]
  15. sourceDir = sys.argv[4]
  16. for obj in testData:
  17. if 'sendRaw' in obj:
  18. data = obj['sendRaw']
  19. if debug: print("Sending raw:", data)
  20. cmakelib.writeRawData(proc, data)
  21. elif 'send' in obj:
  22. data = obj['send']
  23. if debug: print("Sending:", json.dumps(data))
  24. cmakelib.writePayload(proc, data)
  25. elif 'recv' in obj:
  26. data = obj['recv']
  27. if debug: print("Waiting for:", json.dumps(data))
  28. cmakelib.waitForMessage(proc, data)
  29. elif 'reply' in obj:
  30. data = obj['reply']
  31. if debug: print("Waiting for reply:", json.dumps(data))
  32. originalType = ""
  33. cookie = ""
  34. if 'cookie' in data: cookie = data['cookie']
  35. if 'type' in data: originalType = data['type']
  36. cmakelib.waitForReply(proc, originalType, cookie)
  37. elif 'error' in obj:
  38. data = obj['error']
  39. if debug: print("Waiting for error:", json.dumps(data))
  40. originalType = ""
  41. cookie = ""
  42. message = ""
  43. if 'cookie' in data: cookie = data['cookie']
  44. if 'type' in data: originalType = data['type']
  45. if 'message' in data: message = data['message']
  46. cmakelib.waitForError(proc, originalType, cookie, message)
  47. elif 'progress' in obj:
  48. data = obj['progress']
  49. if debug: print("Waiting for progress:", json.dumps(data))
  50. originalType = ''
  51. cookie = ""
  52. current = 0
  53. message = ""
  54. if 'cookie' in data: cookie = data['cookie']
  55. if 'type' in data: originalType = data['type']
  56. if 'current' in data: current = data['current']
  57. if 'message' in data: message = data['message']
  58. cmakelib.waitForProgress(proc, originalType, cookie, current, message)
  59. elif 'handshake' in obj:
  60. data = obj['handshake']
  61. if debug: print("Doing handshake:", json.dumps(data))
  62. major = -1
  63. minor = -1
  64. generator = 'Ninja'
  65. extraGenerator = 'CodeBlocks'
  66. sourceDirectory = sourceDir
  67. buildDirectory = buildDir
  68. if 'major' in data: major = data['major']
  69. if 'minor' in data: minor = data['minor']
  70. if 'buildDirectory' in data: buildDirectory = data['buildDirectory']
  71. if 'sourceDirectory' in data: sourceDirectory = data['sourceDirectory']
  72. if 'generator' in data: generator = data['generator']
  73. if 'extraGenerator' in data: extraGenerator = data['extraGenerator']
  74. cmakelib.handshake(proc, major, minor, sourceDirectory, buildDirectory,
  75. generator, extraGenerator)
  76. elif 'validateGlobalSettings' in obj:
  77. data = obj['validateGlobalSettings']
  78. if not 'buildDirectory' in data: data['buildDirectory'] = buildDir
  79. if not 'sourceDirectory' in data: data['sourceDirectory'] = sourceDir
  80. if not 'generator' in data: data['generator'] = 'Ninja'
  81. if not 'extraGenerator' in data: data['extraGenerator'] = 'CodeBlocks'
  82. cmakelib.validateGlobalSettings(proc, cmakeCommand, data)
  83. elif 'message' in obj:
  84. print("MESSAGE:", obj["message"])
  85. else:
  86. print("Unknown command:", json.dumps(obj))
  87. sys.exit(2)
  88. print("Completed")
  89. sys.exit(0)