Allow specifying Gfxstream transport type in End2End tests

... and run tests with virtio gpu pipe specified as well. This
replicates seeing "failed to find process owned resources" errors.

Bug: b/293897204
Test: GfxstreamEnd2EndTests
Change-Id: Ic8904974c41b0c345253a3ff3dd8e12cb2423756
diff --git a/common/GfxstreamEnd2EndTests.cpp b/common/GfxstreamEnd2EndTests.cpp
index 1d82c71..0d1da31 100644
--- a/common/GfxstreamEnd2EndTests.cpp
+++ b/common/GfxstreamEnd2EndTests.cpp
@@ -349,6 +349,28 @@
     return ahb->getResourceId();
 }
 
+std::string GfxstreamTransportToEnvVar(GfxstreamTransport transport) {
+    switch (transport) {
+        case GfxstreamTransport::kVirtioGpuAsg: {
+            return "virtio-gpu-asg";
+        }
+        case GfxstreamTransport::kVirtioGpuPipe: {
+            return "virtio-gpu-pipe";
+        }
+    }
+}
+
+std::string GfxstreamTransportToString(GfxstreamTransport transport) {
+    switch (transport) {
+        case GfxstreamTransport::kVirtioGpuAsg: {
+            return "VirtioGpuAsg";
+        }
+        case GfxstreamTransport::kVirtioGpuPipe: {
+            return "VirtioGpuPipe";
+        }
+    }
+}
+
 std::string TestParams::ToString() const {
     std::string ret;
     ret += (with_gl ? "With" : "Without");
@@ -357,6 +379,8 @@
     ret += "Vk";
     ret += (with_vk_snapshot ? "With" : "Without");
     ret += "Snapshot";
+    ret += "Over";
+    ret += GfxstreamTransportToString(with_transport);
     return ret;
 }
 
@@ -437,6 +461,9 @@
 void GfxstreamEnd2EndTest::SetUp() {
     const TestParams params = GetParam();
 
+    const std::string transportValue = GfxstreamTransportToEnvVar(params.with_transport);
+    ASSERT_THAT(setenv("GFXSTREAM_TRANSPORT", transportValue.c_str(), /*overwrite=*/1), Eq(0));
+
     ASSERT_THAT(setenv("GFXSTREAM_EMULATED_VIRTIO_GPU_WITH_GL",
                        params.with_gl ? "Y" : "N", /*overwrite=*/1), Eq(0));
     ASSERT_THAT(setenv("GFXSTREAM_EMULATED_VIRTIO_GPU_WITH_VK",
diff --git a/common/GfxstreamEnd2EndTests.h b/common/GfxstreamEnd2EndTests.h
index 6bd64df..05be997 100644
--- a/common/GfxstreamEnd2EndTests.h
+++ b/common/GfxstreamEnd2EndTests.h
@@ -272,10 +272,16 @@
     int getHostHandle(EGLClientBuffer buffer, Gralloc*) override;
 };
 
+enum class GfxstreamTransport {
+  kVirtioGpuAsg,
+  kVirtioGpuPipe,
+};
+
 struct TestParams {
     bool with_gl;
     bool with_vk;
     bool with_vk_snapshot = false;
+    GfxstreamTransport with_transport = GfxstreamTransport::kVirtioGpuAsg;
 
     std::string ToString() const;
     friend std::ostream& operator<<(std::ostream& os, const TestParams& params);
diff --git a/common/GfxstreamEnd2EndVkTests.cpp b/common/GfxstreamEnd2EndVkTests.cpp
index 7af6f44..0ca742e 100644
--- a/common/GfxstreamEnd2EndVkTests.cpp
+++ b/common/GfxstreamEnd2EndVkTests.cpp
@@ -460,10 +460,22 @@
                             TestParams{
                                 .with_gl = false,
                                 .with_vk = true,
+                                .with_transport = GfxstreamTransport::kVirtioGpuAsg,
                             },
                             TestParams{
                                 .with_gl = true,
                                 .with_vk = true,
+                                .with_transport = GfxstreamTransport::kVirtioGpuAsg,
+                            },
+                            TestParams{
+                                .with_gl = false,
+                                .with_vk = true,
+                                .with_transport = GfxstreamTransport::kVirtioGpuPipe,
+                            },
+                            TestParams{
+                                .with_gl = true,
+                                .with_vk = true,
+                                .with_transport = GfxstreamTransport::kVirtioGpuPipe,
                             },
                         }),
                         &GetTestName);
diff --git a/gl-host-common/opengl/GLProcessPipe.cpp b/gl-host-common/opengl/GLProcessPipe.cpp
index f26bb78..d22e74f 100644
--- a/gl-host-common/opengl/GLProcessPipe.cpp
+++ b/gl-host-common/opengl/GLProcessPipe.cpp
@@ -154,7 +154,7 @@
     // identifiers, since the IDs are assigned sequentially from a 64-bit ID
     // space.
     // Please change it if you ever have a use case that exhausts them
-    uint64_t m_uniqueId;
+    uint64_t m_uniqueId = -1;
     bool m_hasData = false;
     static std::atomic<uint64_t> s_headId;
 
diff --git a/guest/OpenglSystemCommon/HostConnection.cpp b/guest/OpenglSystemCommon/HostConnection.cpp
index 5394aa4..b261479 100644
--- a/guest/OpenglSystemCommon/HostConnection.cpp
+++ b/guest/OpenglSystemCommon/HostConnection.cpp
@@ -159,6 +159,11 @@
 
 #if defined(__ANDROID__)
     transport = android::base::GetProperty("ro.boot.hardware.gltransport", "");
+#else
+    const char* transport_envvar = getenv("GFXSTREAM_TRANSPORT");
+    if (transport_envvar != nullptr) {
+        transport = std::string(transport_envvar);
+    }
 #endif
 
     if (transport.empty()) {