Browse Source

server-mode: Add project data for unit tests

Do some basic unit tests for "codemodel", "cmakeInputs" and "cache"
commands of the cmake server.

This just calls the commands right now and makes sure the server
thinks it can reply to the request. The data itself is currently not
validated.
Tobias Hunger 9 years ago
parent
commit
71a505870c

+ 2 - 0
Tests/Server/CMakeLists.txt

@@ -10,6 +10,7 @@ macro(do_test bsname file)
     "${CMAKE_SOURCE_DIR}/${file}"
     "${CMAKE_SOURCE_DIR}"
     "${CMAKE_BINARY_DIR}"
+    "${CMAKE_GENERATOR}"
     RESULT_VARIABLE test_result
     )
 
@@ -20,5 +21,6 @@ endmacro()
 
 do_test("test_handshake" "tc_handshake.json")
 do_test("test_globalSettings" "tc_globalSettings.json")
+do_test("test_buildsystem1" "tc_buildsystem1.json")
 
 add_executable(Server empty.cpp)

+ 22 - 0
Tests/Server/buildsystem1/CMakeLists.txt

@@ -0,0 +1,22 @@
+cmake_minimum_required(VERSION 3.4)
+
+project(buildsystem2)
+
+set(var1 123)
+
+set(var2 345)
+
+add_executable(main main.cpp)
+
+add_executable(m_other main.cpp)
+
+add_library(foo foo.cpp)
+
+function(f1)
+endfunction()
+
+set(var3 345)
+
+add_library(someImportedLib UNKNOWN IMPORTED)
+
+add_subdirectory(subdir)

+ 5 - 0
Tests/Server/buildsystem1/foo.cpp

@@ -0,0 +1,5 @@
+
+int foo()
+{
+  return 0;
+}

+ 5 - 0
Tests/Server/buildsystem1/main.cpp

@@ -0,0 +1,5 @@
+
+int main()
+{
+  return 0;
+}

+ 5 - 0
Tests/Server/buildsystem1/subdir/CMakeLists.txt

@@ -0,0 +1,5 @@
+set(bar4 something)
+
+set(bar5 more)
+
+add_executable(ooo empty.cpp)

+ 5 - 0
Tests/Server/buildsystem1/subdir/empty.cpp

@@ -0,0 +1,5 @@
+
+int foo()
+{
+  return 0;
+}

+ 15 - 5
Tests/Server/cmakelib.py

@@ -102,10 +102,20 @@ def waitForMessage(cmakeCommand, expected):
     sys.exit(-1)
   return packet
 
-def waitForReply(cmakeCommand, originalType, cookie):
-  packet = waitForRawMessage(cmakeCommand)
-  if packet['cookie'] != cookie or packet['type'] != 'reply' or packet['inReplyTo'] != originalType:
+def waitForReply(cmakeCommand, originalType, cookie, skipProgress):
+  gotResult = False
+  while True:
+    packet = waitForRawMessage(cmakeCommand)
+    t = packet['type']
+    if packet['cookie'] != cookie or packet['inReplyTo'] != originalType:
+      sys.exit(1)
+    if t == 'message' or t == 'progress':
+      if skipProgress:
+        continue
+    if t == 'reply':
+        break
     sys.exit(1)
+
   return packet
 
 def waitForError(cmakeCommand, originalType, cookie, message):
@@ -126,10 +136,10 @@ def handshake(cmakeCommand, major, minor, source, build, generator, extraGenerat
   writePayload(cmakeCommand, { 'type': 'handshake', 'protocolVersion': version,
     'cookie': 'TEST_HANDSHAKE', 'sourceDirectory': source, 'buildDirectory': build,
     'generator': generator, 'extraGenerator': extraGenerator })
-  waitForReply(cmakeCommand, 'handshake', 'TEST_HANDSHAKE')
+  waitForReply(cmakeCommand, 'handshake', 'TEST_HANDSHAKE', False)
 
 def validateGlobalSettings(cmakeCommand, cmakeCommandPath, data):
-  packet = waitForReply(cmakeCommand, 'globalSettings', '')
+  packet = waitForReply(cmakeCommand, 'globalSettings', '', False)
 
   capabilities = packet['capabilities']
 

+ 22 - 15
Tests/Server/server-test.py

@@ -1,24 +1,25 @@
-import sys, cmakelib, json
+import sys, cmakelib, json, os, shutil
 
 debug = True
 
 cmakeCommand = sys.argv[1]
 testFile = sys.argv[2]
 sourceDir = sys.argv[3]
-buildDir = sys.argv[4]
+buildDir = sys.argv[4] + "/" + os.path.splitext(os.path.basename(testFile))[0]
+cmakeGenerator = sys.argv[5]
 
-print("SourceDir: ", sourceDir, " -- BuildDir: ", buildDir)
+print("Test:", testFile,
+      "\n-- SourceDir:", sourceDir,
+      "\n-- BuildDir:", buildDir,
+      "\n-- Generator:", cmakeGenerator)
+
+if os.path.exists(buildDir):
+    shutil.rmtree(buildDir)
 
 proc = cmakelib.initProc(cmakeCommand)
 
 with open(testFile) as f:
-    testText = f.read()
-    testText = testText.replace('%BUILDDIR%', buildDir)
-    testText = testText.replace('%SOURCEDIR%', sourceDir)
-    testData = json.loads(testText)
-
-buildDir = sys.argv[3]
-sourceDir = sys.argv[4]
+    testData = json.loads(f.read())
 
 for obj in testData:
     if 'sendRaw' in obj:
@@ -38,9 +39,11 @@ for obj in testData:
         if debug: print("Waiting for reply:", json.dumps(data))
         originalType = ""
         cookie = ""
+        skipProgress = False;
         if 'cookie' in data: cookie = data['cookie']
         if 'type' in data: originalType = data['type']
-        cmakelib.waitForReply(proc, originalType, cookie)
+        if 'skipProgress' in data: skipProgress = data['skipProgress']
+        cmakelib.waitForReply(proc, originalType, cookie, skipProgress)
     elif 'error' in obj:
         data = obj['error']
         if debug: print("Waiting for error:", json.dumps(data))
@@ -68,8 +71,8 @@ for obj in testData:
         if debug: print("Doing handshake:", json.dumps(data))
         major = -1
         minor = -1
-        generator = 'Ninja'
-        extraGenerator = 'CodeBlocks'
+        generator = cmakeGenerator
+        extraGenerator = ''
         sourceDirectory = sourceDir
         buildDirectory = buildDir
         if 'major' in data: major = data['major']
@@ -78,14 +81,18 @@ for obj in testData:
         if 'sourceDirectory' in data: sourceDirectory = data['sourceDirectory']
         if 'generator' in data: generator = data['generator']
         if 'extraGenerator' in data: extraGenerator = data['extraGenerator']
+        if not os.path.isabs(buildDirectory):
+            buildDirectory = buildDir + "/" + buildDirectory
+        if not os.path.isabs(sourceDirectory):
+            sourceDirectory = sourceDir + "/" + sourceDirectory
         cmakelib.handshake(proc, major, minor, sourceDirectory, buildDirectory,
           generator, extraGenerator)
     elif 'validateGlobalSettings' in obj:
         data = obj['validateGlobalSettings']
         if not 'buildDirectory' in data: data['buildDirectory'] = buildDir
         if not 'sourceDirectory' in data: data['sourceDirectory'] = sourceDir
-        if not 'generator' in data: data['generator'] = 'Ninja'
-        if not 'extraGenerator' in data: data['extraGenerator'] = 'CodeBlocks'
+        if not 'generator' in data: data['generator'] = cmakeGenerator
+        if not 'extraGenerator' in data: data['extraGenerator'] = ''
         cmakelib.validateGlobalSettings(proc, cmakeCommand, data)
     elif 'message' in obj:
         print("MESSAGE:", obj["message"])

+ 27 - 0
Tests/Server/tc_buildsystem1.json

@@ -0,0 +1,27 @@
+[
+{ "message": "Testing globalSettings" },
+
+{ "handshake": {"major": 1, "sourceDirectory":"buildsystem1","buildDirectory":"buildsystem1"} },
+
+{ "message": "Configure:" },
+{ "send": { "type": "configure", "cookie":"CONFIG" } },
+{ "reply": { "type": "configure", "cookie":"CONFIG", "skipProgress":true } },
+
+{ "message": "Compute:" },
+{ "send": { "type": "compute", "cookie":"COMPUTE" } },
+{ "reply": { "type": "compute", "cookie":"COMPUTE", "skipProgress":true } },
+
+{ "message": "Codemodel:" },
+{ "send": { "type": "codemodel", "cookie":"CODEMODEL" } },
+{ "reply": { "type": "codemodel", "cookie":"CODEMODEL" } },
+
+{ "message": "CMake Inputs:"},
+{ "send": { "type": "cmakeInputs", "cookie":"INPUTS" } },
+{ "reply": { "type": "cmakeInputs", "cookie":"INPUTS" } },
+
+{ "message": "Cache:"},
+{ "send": { "type": "cache", "cookie":"CACHE" } },
+{ "reply": { "type": "cache", "cookie":"CACHE" } },
+
+{ "message": "Everything ok." }
+]