Tests for host -> guest interrupts

Change-Id: I505f698accd852bf021aa473eb0db60ba1b07faf
diff --git a/guest/vsoc/lib/guest_region_e2e_test.cpp b/guest/vsoc/lib/guest_region_e2e_test.cpp
index be02ff8..6fee190 100644
--- a/guest/vsoc/lib/guest_region_e2e_test.cpp
+++ b/guest/vsoc/lib/guest_region_e2e_test.cpp
@@ -59,6 +59,17 @@
     }
   }
 
+  void CheckHostStrings() {
+    ASSERT_TRUE(region.Open());
+    size_t num_data = Layout::NumFillRecords(region.region_data_size());
+    EXPECT_LE(2, num_data);
+    Layout* r = region.data();
+    for (size_t i = 0; i < num_data; ++i) {
+      EXPECT_STREQ(Layout::host_pattern,
+                   make_nonvolatile(r->data[i].host_writable));
+    }
+  }
+
   void DeathTestGuestRegion()  {
     // We don't want a tombstone, and we're already in the child.
     // region, so we modify the behavior of LOG(ABORT) to print the
@@ -71,6 +82,11 @@
     // region.Open should never return.
     EXPECT_FALSE(region.Open());
   }
+
+  void WaitForHostInterrupt() {
+    ASSERT_TRUE(region.Open());
+    region.WaitForInterrupt();
+  }
 };
 
 TEST(RegionTest, PrimaryRegionWritable) {
@@ -101,6 +117,26 @@
               ".*" DEATH_TEST_MESSAGE ".*");
 }
 
+TEST(RegionTest, TestPrimaryHostInterrupt) {
+  RegionTest<E2EPrimaryTestRegion> test;
+  test.WaitForHostInterrupt();
+}
+
+TEST(RegionTest, PrimaryRegionHostWritesVisisble) {
+  RegionTest<E2EPrimaryTestRegion> test;
+  test.CheckHostStrings();
+}
+
+TEST(RegionTest, TestSecondaryHostInterrupt) {
+  RegionTest<E2ESecondaryTestRegion> test;
+  test.WaitForHostInterrupt();
+}
+
+TEST(RegionTest, SecondaryRegionHostWritesVisible) {
+  RegionTest<E2ESecondaryTestRegion> test;
+  test.CheckHostStrings();
+}
+
 int main(int argc, char** argv) {
   android::base::InitLogging(argv);
   testing::InitGoogleTest(&argc, argv);
diff --git a/host/vsoc/lib/host_region_e2e_test.cpp b/host/vsoc/lib/host_region_e2e_test.cpp
index 8acd88a..a214679 100644
--- a/host/vsoc/lib/host_region_e2e_test.cpp
+++ b/host/vsoc/lib/host_region_e2e_test.cpp
@@ -55,6 +55,11 @@
                    make_nonvolatile(r->data[i].host_writable));
     }
   }
+
+  void SendInterruptToGuest() {
+    EXPECT_TRUE(region.Open());
+    region.InterruptPeer();
+  }
 };
 
 TEST(RegionTest, PrimaryRegionWritable) {
@@ -62,11 +67,21 @@
   test.TestHostRegion();
 }
 
+TEST(RegionTest, PrimaryRegionInterrupt) {
+  RegionTest<E2EPrimaryTestRegion> test;
+  test.SendInterruptToGuest();
+}
+
 TEST(RegionTest, SecondaryRegionWritable) {
   RegionTest<E2ESecondaryTestRegion> test;
   test.TestHostRegion();
 }
 
+TEST(RegionTest, SecondarRegionInterrupt) {
+  RegionTest<E2ESecondaryTestRegion> test;
+  test.SendInterruptToGuest();
+}
+
 /**
  * Defines an end-to-end region with a name that should never be configured.
  */