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

Patch: cdwijayarathna
diff --git a/test/test.py b/test/test.py
index 0eb22c3..00d2d0d 100644
--- a/test/test.py
+++ b/test/test.py
@@ -55,10 +55,23 @@
   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):
+def runServiceTest(test_name, server_lib, server_executable, server_extra_args, client_lib,  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 = []
+  cli_args = []
+  if server_lib == 'java':
+    server_executable[2] = relfile(server_executable[2])
+    server_args.extend(server_executable)
+    server_args.extend(['-Dtestargs','\"'])
+  else:
+    server_args = [relfile(server_executable)]
+  if client_lib == 'java':
+    client_executable[2] = relfile(client_executable[2])
+    cli_args.extend(client_executable)
+    cli_args.extend(['-Dtestargs','\"'])
+  else:
+    cli_args = [relfile(client_executable)]
+
   server_args.append('--protocol=%s' % server_protocol)
   cli_args.append('--protocol=%s' % client_protocol)
 
@@ -75,9 +88,14 @@
 #      which.append('-q')
 #    if options.verbose == 2:
 #      which.append('-v')
+  if server_lib == 'java':
+    server_args.append('\"')
+  if client_lib == 'java':
+    cli_args.append('\"')
 
   server_args.extend(server_extra_args)
   cli_args.extend(client_extra_args)
+
   server_log=open("log/" + test_name + "_server.log","a")
   client_log=open("log/" + test_name + "_client.log","a")
 
@@ -196,7 +214,7 @@
                   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
-                  ret = runServiceTest(test_name, server_executable, server_extra_args, client_executable, client_extra_args, protocol, protocol, transport, 9090, 0, sock)
+                  ret = runServiceTest(test_name, server_lib, server_executable, server_extra_args, client_lib, client_executable, client_extra_args, protocol, protocol, transport, 9090, 0, sock)
                   if ret != None:
                     failed += 1
                     print "Error: %s" % ret
@@ -205,10 +223,10 @@
                       % (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")
+                    results_json.write("\t\t\"failure\",\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]")
+                    results_json.write("\t\t\"success\",\n")
+                  results_json.write("\t\t{\n\t\t\t\"Client\":\"log/" + test_name + "_client.log\",\n\t\t\t\"Server\":\"log/" + test_name + "_server.log\"\n\t\t}\n\t]")
                   test_count += 1
             if protocol == 'binary' and 'accel' in client["protocols"]:
               if transport in client["transports"]:
@@ -218,7 +236,8 @@
                   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)
+                  ret = runServiceTest(test_name, server_lib,server_executable, server_extra_args, client_lib, client_executable, client_extra_args, protocol, 'accel', transport, 9090, 0, sock)
+
                   if ret != None:
                     failed += 1
                     print "Error: %s" % ret
@@ -227,10 +246,10 @@
                       % (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")
+                    results_json.write("\t\t\"failure\",\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]")
+                    results_json.write("\t\t\"success\",\n")
+                  results_json.write("\t\t{\n\t\t\t\"Client\":\"log/" + test_name + "_client.log\",\n\t\t\t\"Server\":\"log/" + test_name + "_server.log\"\n\t\t}\n\t]")
                   test_count += 1
             if protocol == 'accel' and 'binary' in client["protocols"]:
               if transport in client["transports"]:
@@ -239,8 +258,8 @@
                     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
-                  ret = runServiceTest(test_name, server_executable, server_extra_args, client_executable, client_extra_args, protocol, 'binary', transport, 9090, 0, sock)
+                  test_name = server_lib + "_" + client_lib + "_binary-accel_" + transport + "_" + sock
+                  ret = runServiceTest(test_name, server_lib,server_executable, server_extra_args, client_lib, client_executable, client_extra_args, protocol, 'binary', transport, 9090, 0, sock)
                   if ret != None:
                     failed += 1
                     print "Error: %s" % ret
@@ -249,10 +268,10 @@
                       % (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")
+                    results_json.write("\t\t\"failure\",\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]")
+                    results_json.write("\t\t\"success\",\n")
+                  results_json.write("\t\t{\n\t\t\t\"Client\":\"log/" + test_name + "_client.log\",\n\t\t\t\"Server\":\"log/" + test_name + "_server.log\"\n\t\t}\n\t]")
                   test_count += 1
 results_json.write("\n]")
 results_json.flush()