Add executor and execserver packages

These are more resilient to crashes and OOM than running deqp-vk
directly. executor can be run on the device to do the tests, or it can
be run on the host (and execserver run on the device).

TEST: vim2:go/magma-tps#C0

Change-Id: I58bca936ad7ed4941b1532481b2a361126754c15
diff --git a/external/vulkancts/modules/vulkan/CMakeLists.txt b/external/vulkancts/modules/vulkan/CMakeLists.txt
index 75e59d3..87e6f66 100644
--- a/external/vulkancts/modules/vulkan/CMakeLists.txt
+++ b/external/vulkancts/modules/vulkan/CMakeLists.txt
@@ -108,8 +108,10 @@
 target_link_libraries(deqp-vk-common ${DEQP_VK_COMMON_LIBS})
 add_dependencies(deqp-vk-common deqp-vk-data)
 
-target_link_libraries(deqp-vk-common "libvulkan.so")
-link_directories(${FUCHSIA_LIB_DIR})
+if (DE_OS_IS_FUCHSIA)
+	target_link_libraries(deqp-vk-common "libvulkan.so")
+	link_directories(${FUCHSIA_LIB_DIR})
+endif ()
 
 set(DEQP_VK_SRCS	)
 set(DEQP_VK_LIBS	deqp-vk-common)
diff --git a/fuchsia/BUILD.gn b/fuchsia/BUILD.gn
index ebd1e2b..ab75058 100644
--- a/fuchsia/BUILD.gn
+++ b/fuchsia/BUILD.gn
@@ -17,6 +17,9 @@
   depfile = "$root_out_dir/build-vulkancts/vulkan-cts.d"
   outputs = [
     "$root_out_dir/build-vulkancts/external/vulkancts/modules/vulkan/deqp-vk",
+    "$root_out_dir/build-vulkancts/executor/executor",
+    "$root_out_dir/build-vulkancts/execserver/execserver",
+    "$root_out_dir/build-vulkancts/cases/dEQP-VK-cases.xml",
   ]
 }
 
@@ -47,3 +50,71 @@
   ]
   resources = cts_resources
 }
+
+# To run on device:
+# run vulkan-cts-executor --start-server=/pkg/bin/execserver --testset=dEQP-VK.* --caselistdir=/pkg/data/cases --out=/data/TestLog.qpa --info=/data/infolog.txt --binaryname=/pkg/bin/deqp-vk --workdir=/data
+# Note: the list of cases may include tests that aren't in vk-default.txt "mustpass".
+package("vulkan-cts-executor") {
+  deps = [
+    ":build",
+  ]
+
+  binary = "build-vulkancts/executor/executor"
+  binaries = [
+    {
+      name = "deqp-vk"
+      source = "$root_out_dir/build-vulkancts/external/vulkancts/modules/vulkan/deqp-vk"
+    },
+    {
+      name = "execserver"
+      source = "$root_out_dir/build-vulkancts/execserver/execserver"
+    },
+  ]
+  meta = [
+    {
+      path = rebase_path("meta/vulkan-cts-executor.cmx")
+      dest = "vulkan-cts-executor.cmx"
+    },
+  ]
+  resources = cts_resources
+
+  resources += [
+    {
+      path = rebase_path("$root_out_dir/build-vulkancts/cases/dEQP-VK-cases.xml")
+      dest = "cases/dEQP-VK-cases.xml"
+    },
+  ]
+}
+
+# On device:
+# run vulkan-cts-execserver
+# Run on host:
+# executor/executor --connect=192.168.42.80 --testset=dEQP-VK.* --caselistdir=cases/ --binaryname=/pkg/bin/deqp-vk --workdir=/data --cmdline="--deqp-log-images=disable --deqp-log-shader-sources=disable"
+# Note: the list of cases may include tests that aren't in vk-default.txt "mustpass".
+package("vulkan-cts-execserver") {
+  deps = [
+    ":build",
+  ]
+
+  binary = "build-vulkancts/execserver/execserver"
+  binaries = [
+    {
+      name = "deqp-vk"
+      source = "$root_out_dir/build-vulkancts/external/vulkancts/modules/vulkan/deqp-vk"
+    },
+  ]
+  meta = [
+    {
+      path = rebase_path("meta/vulkan-cts-execserver.cmx")
+      dest = "vulkan-cts-execserver.cmx"
+    },
+  ]
+  resources = cts_resources
+
+  resources += [
+    {
+      path = rebase_path("$root_out_dir/build-vulkancts/cases/dEQP-VK-cases.xml")
+      dest = "cases/dEQP-VK-cases.xml"
+    },
+  ]
+}
diff --git a/fuchsia/build.sh b/fuchsia/build.sh
index ddcd1bf..52db7e4 100755
--- a/fuchsia/build.sh
+++ b/fuchsia/build.sh
@@ -9,6 +9,8 @@
 fuchsia_root=$root_out_dir/../..
 tools_path=$fuchsia_root/buildtools
 build_dir=$root_out_dir/build-vulkancts
+caselist_build_dir=$root_out_dir/build-vulkancts/cases-build
+caselist_out_dir=$root_out_dir/build-vulkancts/cases
 sysroot=$root_out_dir/sdks/zircon_sysroot/sysroot
 
 if [ ! -d "$sysroot" ]; then
@@ -29,10 +31,11 @@
 popd
 
 # builds the test executable for the host in order to write out test cases
-#pushd $fuchsia_root/third_party/vulkan-cts
-#mkdir -p cases
-#python scripts/build_caselists.py cases
-#popd
+pushd $fuchsia_root/third_party/vulkan-cts
+mkdir -p $caselist_out_dir
+mkdir -p $caselist_build_dir
+python scripts/build_caselists.py -b $caselist_build_dir -m dEQP-VK $caselist_out_dir
+popd
 
 mkdir -p $build_dir
 $fuchsia_root/third_party/vulkan-cts/fuchsia/gendepsfile.py $build_dir/vulkan-cts.d $fuchsia_root/third_party/vulkan-cts
diff --git a/fuchsia/meta/vulkan-cts-execserver.cmx b/fuchsia/meta/vulkan-cts-execserver.cmx
new file mode 100644
index 0000000..9bc8486
--- /dev/null
+++ b/fuchsia/meta/vulkan-cts-execserver.cmx
@@ -0,0 +1,9 @@
+{
+    "program": {
+        "binary": "bin/app"
+    },
+    "sandbox": {
+        "dev": [ "class/framebuffer" ],
+        "features": [ "vulkan", "persistent-storage" ]
+    }
+}
diff --git a/fuchsia/meta/vulkan-cts-executor.cmx b/fuchsia/meta/vulkan-cts-executor.cmx
new file mode 100644
index 0000000..9bc8486
--- /dev/null
+++ b/fuchsia/meta/vulkan-cts-executor.cmx
@@ -0,0 +1,9 @@
+{
+    "program": {
+        "binary": "bin/app"
+    },
+    "sandbox": {
+        "dev": [ "class/framebuffer" ],
+        "features": [ "vulkan", "persistent-storage" ]
+    }
+}
diff --git a/fuchsia/vulkan-cts b/fuchsia/vulkan-cts
index bce3fde..ede91af 100644
--- a/fuchsia/vulkan-cts
+++ b/fuchsia/vulkan-cts
@@ -3,6 +3,8 @@
         "cpp"
     ],
     "packages": [
-        "//third_party/vulkan-cts/fuchsia:vulkan-cts"
+        "//third_party/vulkan-cts/fuchsia:vulkan-cts",
+        "//third_party/vulkan-cts/fuchsia:vulkan-cts-execserver",
+        "//third_party/vulkan-cts/fuchsia:vulkan-cts-executor"
     ]
 }