[libcxx-test] Add test for global constructors

Bug: 110158907
Change-Id: I277f75168d973d7109aed37d9702969394097f81
diff --git a/libcxx-test/libcxx_test.cpp b/libcxx-test/libcxx_test.cpp
index a975713..539b4dc 100644
--- a/libcxx-test/libcxx_test.cpp
+++ b/libcxx-test/libcxx_test.cpp
@@ -52,4 +52,23 @@
 test_abort:;
 }
 
+/*
+ * Inspecting the generated code, it appears this variable can be optimized out
+ * if it is not declared volatile.
+ */
+volatile bool did_init;
+
+class GlobalSetter {
+public:
+    GlobalSetter() { did_init = true; }
+};
+
+GlobalSetter setter;
+
+TEST_F(libcxx, global_constructor) {
+    /* Did a global constructor run? */
+    ASSERT_EQ(true, did_init);
+test_abort:;
+}
+
 PORT_TEST(libcxx, "com.android.libcxxtest");