THRIFT-2578 Moving 'make cross' from test.sh to test.py

Signed-off-by: Roger Meier <roger@apache.org>
diff --git a/test/test.py b/test/test.py
old mode 100755
new mode 100644
index 0111a2f..cab942e
--- a/test/test.py
+++ b/test/test.py
@@ -46,18 +46,30 @@
 def relfile(fname):
     return os.path.join(os.path.dirname(__file__), fname)
 
-def runServiceTest(test_name, server_executable, server_extra_args, client_executable, client_extra_args, protocol, transport, port, use_zlib, use_ssl):
+def getSocketArgs(socket_type):
+  if socket_type == 'ip':
+    return ""
+  elif socket_type == 'ip-ssl':
+    return "--ssl"
+  elif socket_type == 'domain':
+    return "--domain-socket=/tmp/ThriftTest.thrift"
+
+def runServiceTest(test_name, server_executable, server_extra_args, client_executable, client_extra_args, server_protocol, client_protocol, transport, port, use_zlib, socket_type):
   # Build command line arguments
   server_args = [relfile(server_executable)]
   cli_args = [relfile(client_executable)]
+  server_args.append('--protocol=%s' % server_protocol)
+  cli_args.append('--protocol=%s' % client_protocol)
+
   for which in (server_args, cli_args):
-    which.append('--protocol=%s' % protocol) # accel, binary or compact
     which.append('--transport=%s' % transport)
     which.append('--port=%d' % port) # default to 9090
     if use_zlib:
       which.append('--zlib')
-    if use_ssl:
+    if socket_type == 'ip-ssl':
       which.append('--ssl')
+    elif socket_type == 'domain':
+      which.append('--domain-socket=/tmp/ThriftTest.thrift')
 #    if options.verbose == 0:
 #      which.append('-q')
 #    if options.verbose == 2:
@@ -73,7 +85,7 @@
     serverproc = subprocess.Popen(server_args, stdout=server_log, stderr=server_log)
   else:
     serverproc = subprocess.Popen(server_args, stdout=server_log, stderr=server_log)
-  
+
   def ensureServerAlive():
     if serverproc.poll() is not None:
       print ('FAIL: Server process (%s) failed with retcode %d'
@@ -87,13 +99,15 @@
   max_attempts = 100
   try:
     attempt = 0
-    while sock.connect_ex(('127.0.0.1', port)) != 0:
-      attempt += 1
-      if attempt >= max_attempts:
-        raise Exception("TestServer not ready on port %d after %.2f seconds"
-                        % (port, sleep_time * attempt))
-      ensureServerAlive()
-      time.sleep(sleep_time)
+
+    if socket_type != 'domain':
+      while sock.connect_ex(('127.0.0.1', port)) != 0:
+        attempt += 1
+        if attempt >= max_attempts:
+          raise Exception("TestServer not ready on port %d after %.2f seconds"
+                          % (port, sleep_time * attempt))
+        ensureServerAlive()
+        time.sleep(sleep_time)
   finally:
     sock.close()
 
@@ -142,12 +156,15 @@
 
 if os.path.exists('log'): shutil.rmtree('log')
 os.makedirs('log')
+if os.path.exists('results.json'): os.remove('results.json')
+results_json = open("results.json","a")
+results_json.write("[\n")
 
-with open('tests.json') as data_file:    
+with open('tests.json') as data_file:
     data = json.load(data_file)
 
 #subprocess.call("export NODE_PATH=../lib/nodejs/test:../lib/nodejs/lib:${NODE_PATH}")
-
+count = 0
 for server in data["server"]:
   server_executable = server["executable"]
   server_extra_args = ""
@@ -166,22 +183,73 @@
           if protocol in client["protocols"]:
             if transport in client["transports"]:
               if sock in client["sockets"]:
+                if count != 0:
+                  results_json.write(",\n")
+                count = 1
+                results_json.write("\t[\n\t\t\"" + server_lib + "\",\n\t\t\"" + client_lib + "\",\n\t\t\"" + protocol + "\",\n\t\t\"" + transport + "-" + sock + "\",\n" )
                 test_name = server_lib + "_" + client_lib + "_" + protocol + "_" + transport + "_" + sock
-                ssl = 0
-                if sock == 'ip-ssl':
-                  ssl = 1
-                ret = runServiceTest(test_name, server_executable, server_extra_args, client_executable, client_extra_args, protocol, transport, 9090, 0, ssl)
+                ret = runServiceTest(test_name, server_executable, server_extra_args, client_executable, client_extra_args, protocol, protocol, transport, 9090, 0, sock)
                 if ret != None:
                   failed += 1
                   print "Error: %s" % ret
                   print "Using"
-                  print (' Server: %s --protocol=%s --transport=%s %s'
-                    % (server_executable, protocol, transport, ' '.join(server_extra_args)))
-                  print (' Client: %s --protocol=%s --transport=%s %s'
-                    % (client_executable, protocol, transport, ''.join(client_extra_args)))
-
-
+                  print (' Server: %s --protocol=%s --transport=%s %s %s'
+                    % (server_executable, protocol, transport, getSocketArgs(sock), ' '.join(server_extra_args)))
+                  print (' Client: %s --protocol=%s --transport=%s %s %s'
+                    % (client_executable, protocol, transport, getSocketArgs(sock), ''.join(client_extra_args)))
+                  results_json.write("\t\t\"failure (<a href=\\\"log/" + test_name + "_client.log\\\">client</a>, <a href=\\\"log/" + test_name + "_server.log\\\">server</a>)\"\n")
+                else:
+                  results_json.write("\t\t\"success (<a href=\\\"log/" + test_name + "_client.log\\\">client</a>, <a href=\\\"log/" + test_name + "_server.log\\\">server</a>)\"\n")
+                results_json.write("\t]")
                 test_count += 1
-
-print '%s failed of %s tests in total' % (failed, test_count)
-
+          if protocol == 'binary' and 'accel' in client["protocols"]:
+            if transport in client["transports"]:
+              if sock in client["sockets"]:
+                if count != 0:
+                  results_json.write(",\n")
+                count = 1
+                results_json.write("\t[\n\t\t\"" + server_lib + "\",\n\t\t\"" + client_lib + "\",\n\t\t\"accel-binary\",\n\t\t\"" + transport + "-" + sock + "\",\n" )
+                test_name = server_lib + "_" + client_lib + "_accel-binary_" + transport + "_" + sock
+                ret = runServiceTest(test_name, server_executable, server_extra_args, client_executable, client_extra_args, protocol, 'accel', transport, 9090, 0, sock)
+                if ret != None:
+                  failed += 1
+                  print "Error: %s" % ret
+                  print "Using"
+                  print (' Server: %s --protocol=%s --transport=%s %s %s'
+                    % (server_executable, protocol, transport, getSocketArgs(sock), ' '.join(server_extra_args)))
+                  print (' Client: %s --protocol=%s --transport=%s %s %s'
+                    % (client_executable, protocol, transport , getSocketArgs(sock), ''.join(client_extra_args)))
+                  results_json.write("\t\t\"failure (<a href=\\\"log/" + test_name + "_client.log\\\">client</a>, <a href=\\\"log/" + test_name + "_server.log\\\">server</a>)\"\n")
+                else:
+                  results_json.write("\t\t\"success (<a href=\\\"log/" + test_name + "_client.log\\\">client</a>, <a href=\\\"log/" + test_name + "_server.log\\\">server</a>)\"\n")
+                results_json.write("\t]")
+                test_count += 1
+          if protocol == 'accel' and 'binary' in client["protocols"]:
+            if transport in client["transports"]:
+              if sock in client["sockets"]:
+                if count != 0:
+                  results_json.write(",\n")
+                count = 1
+                results_json.write("\t[\n\t\t\"" + server_lib + "\",\n\t\t\"" + client_lib + "\",\n\t\t\"binary-accel\",\n\t\t\"" + transport + "-" + sock + "\",\n" )
+                test_name = server_lib + "_" + client_lib + "_accel-binary_" + transport + "_" + sock
+                ssl = 0
+                if sock == 'ip-ssl':
+                  ssl = 1
+                ret = runServiceTest(test_name, server_executable, server_extra_args, client_executable, client_extra_args, protocol, 'binary', transport, 9090, 0, sock)
+                if ret != None:
+                  failed += 1
+                  print "Error: %s" % ret
+                  print "Using"
+                  print (' Server: %s --protocol=%s --transport=%s %s %s'
+                    % (server_executable, protocol, transport + sock, getSocketArgs(sock), ' '.join(server_extra_args)))
+                  print (' Client: %s --protocol=%s --transport=%s %s %s'
+                    % (client_executable, protocol, transport + sock, getSocketArgs(sock), ''.join(client_extra_args)))
+                  results_json.write("\t\t\"failure (<a href=\\\"log/" + test_name + "_client.log\\\">client</a>, <a href=\\\"log/" + test_name + "_server.log\\\">server</a>)\"\n")
+                else:
+                  results_json.write("\t\t\"success (<a href=\\\"log/" + test_name + "_client.log\\\">client</a>, <a href=\\\"log/" + test_name + "_server.log\\\">server</a>)\"\n")
+                results_json.write("\t]")
+                test_count += 1
+results_json.write("\n]")
+results_json.flush()
+results_json.close()
+print '%s failed of %s tests in total' % (failed, test_count)
\ No newline at end of file