From e9efffe0e14f0b839317983a5ee1b59fa4bf653b Mon Sep 17 00:00:00 2001
From: Ambre Williams <ambre@google.com>
Date: Tue, 23 Apr 2019 17:21:49 +0000
Subject: [PATCH] [cloud_provider_memory_diff] run validation tests

This enables the cloud provider validation tests for the rust cloud
provider.

TEST=cloud_provider_memory_diff_tests runs on CQ

Change-Id: Ia1e0e6f5e79f1a4e18de69412a7848af442fddcd
---
 peridot/packages/tests/BUILD.gn               |  2 +
 .../cloud_provider_memory_diff/BUILD.gn       | 22 ++++++++
 .../validation/BUILD.gn                       | 22 ++++++++
 .../validation/launch.cc                      | 56 +++++++++++++++++++
 .../validation/validation_memory_diff.cmx     |  5 ++
 5 files changed, 107 insertions(+)
 create mode 100644 src/ledger/cloud_provider_memory_diff/validation/BUILD.gn
 create mode 100644 src/ledger/cloud_provider_memory_diff/validation/launch.cc
 create mode 100644 src/ledger/cloud_provider_memory_diff/validation/validation_memory_diff.cmx

diff --git a/peridot/packages/tests/BUILD.gn b/peridot/packages/tests/BUILD.gn
index e7375906efd..b29548865f2 100644
--- a/peridot/packages/tests/BUILD.gn
+++ b/peridot/packages/tests/BUILD.gn
@@ -21,6 +21,8 @@ group("ledger") {
     "//src/ledger/bin:ledger_fuzzers",
     "//src/ledger/bin/testing/ledger_test_instance_provider:ledger_test_instance_provider",
     "//src/ledger/cloud_provider_in_memory/bin",
+    "//src/ledger/cloud_provider_memory_diff",
+    "//src/ledger/cloud_provider_memory_diff:cloud_provider_memory_diff_tests",
   ]
 }
 
diff --git a/src/ledger/cloud_provider_memory_diff/BUILD.gn b/src/ledger/cloud_provider_memory_diff/BUILD.gn
index 1ee8b3fe83a..62ce591fa1d 100644
--- a/src/ledger/cloud_provider_memory_diff/BUILD.gn
+++ b/src/ledger/cloud_provider_memory_diff/BUILD.gn
@@ -34,3 +34,25 @@ package("cloud_provider_memory_diff") {
     },
   ]
 }
+
+package("cloud_provider_memory_diff_tests") {
+  testonly = true
+
+  deps = [
+    "validation",
+  ]
+
+  meta = [
+    {
+      path = rebase_path("validation/validation_memory_diff.cmx")
+      dest = "validation_memory_diff.cmx"
+    },
+  ]
+
+  tests = [
+    {
+      name = "launch_validation_tests_memory_diff"
+      environments = basic_envs
+    },
+  ]
+}
diff --git a/src/ledger/cloud_provider_memory_diff/validation/BUILD.gn b/src/ledger/cloud_provider_memory_diff/validation/BUILD.gn
new file mode 100644
index 00000000000..1e272c49015
--- /dev/null
+++ b/src/ledger/cloud_provider_memory_diff/validation/BUILD.gn
@@ -0,0 +1,22 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+visibility = [ "//src/ledger/cloud_provider_memory_diff/*" ]
+
+executable("validation") {
+  output_name = "launch_validation_tests_memory_diff"
+  testonly = true
+
+  sources = [
+    "launch.cc",
+  ]
+
+  deps = [
+    "//sdk/fidl/fuchsia.ledger.cloud",
+    "//src/ledger/bin/tests/cloud_provider/launcher",
+    "//src/lib/fxl",
+    "//zircon/public/lib/async-cpp",
+    "//zircon/public/lib/async-loop-cpp",
+  ]
+}
diff --git a/src/ledger/cloud_provider_memory_diff/validation/launch.cc b/src/ledger/cloud_provider_memory_diff/validation/launch.cc
new file mode 100644
index 00000000000..deac4209f1f
--- /dev/null
+++ b/src/ledger/cloud_provider_memory_diff/validation/launch.cc
@@ -0,0 +1,56 @@
+// Copyright 2019 The Fuchsia Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <fuchsia/ledger/cloud/cpp/fidl.h>
+#include <lib/async-loop/cpp/loop.h>
+#include <lib/async/cpp/task.h>
+#include <lib/sys/cpp/component_context.h>
+#include <lib/sys/cpp/service_directory.h>
+
+#include <iostream>
+
+#include "src/ledger/bin/tests/cloud_provider/launcher/validation_tests_launcher.h"
+#include "src/lib/fxl/logging.h"
+#include "src/lib/fxl/strings/string_view.h"
+
+namespace {
+
+constexpr fxl::StringView kCloudProviderUrl =
+    "fuchsia-pkg://fuchsia.com/cloud_provider_memory_diff#meta/"
+    "cloud_provider_memory_diff.cmx";
+}  // namespace
+
+int main(int argc, char** argv) {
+  async::Loop loop(&kAsyncLoopConfigAttachToThread);
+  std::unique_ptr<sys::ComponentContext> component_context =
+      sys::ComponentContext::Create();
+  fuchsia::sys::LauncherPtr component_launcher;
+  component_context->svc()->Connect(component_launcher.NewRequest());
+  cloud_provider::ValidationTestsLauncher launcher(
+      component_context.get(),
+      [component_launcher = std::move(component_launcher),
+       &loop](auto request) {
+        fuchsia::sys::LaunchInfo launch_info;
+        launch_info.url = kCloudProviderUrl.ToString();
+        auto cloud_provider_services = sys::ServiceDirectory::CreateWithRequest(
+            &launch_info.directory_request);
+
+        fuchsia::sys::ComponentControllerPtr cloud_instance;
+        component_launcher->CreateComponent(std::move(launch_info),
+                                            cloud_instance.NewRequest());
+        cloud_provider_services->Connect(
+            std::move(request), fuchsia::ledger::cloud::CloudProvider::Name_);
+        return cloud_instance;
+      });
+
+  int32_t return_code = -1;
+  async::PostTask(loop.dispatcher(), [&launcher, &return_code, &loop] {
+    launcher.Run({}, [&return_code, &loop](int32_t result) {
+      return_code = result;
+      loop.Quit();
+    });
+  });
+  loop.Run();
+  return return_code;
+}
diff --git a/src/ledger/cloud_provider_memory_diff/validation/validation_memory_diff.cmx b/src/ledger/cloud_provider_memory_diff/validation/validation_memory_diff.cmx
new file mode 100644
index 00000000000..44d7f240b13
--- /dev/null
+++ b/src/ledger/cloud_provider_memory_diff/validation/validation_memory_diff.cmx
@@ -0,0 +1,5 @@
+{
+    "program": {
+        "binary": "test/launch_validation_tests_memory_diff"
+    }
+}
-- 
GitLab