[libcxx-test] Add simple test for C++ stdlib

Bug: 110158907
Change-Id: I7236ddca21685d769db1fa32d9d77217e0e3979e
diff --git a/build-config-usertests b/build-config-usertests
index 7337dd7..cf0892a 100644
--- a/build-config-usertests
+++ b/build-config-usertests
@@ -17,6 +17,7 @@
 [
     # userspace tests that don't use storage
     porttest("com.android.libctest"),
+    porttest("com.android.libcxxtest"),
     porttest("com.android.timer-unittest"),
     porttest("com.android.ipc-unittest.ctrl"),
     porttest("com.android.appmgmt-unittest.appmngr"),
diff --git a/libcxx-test/libcxx_test.cpp b/libcxx-test/libcxx_test.cpp
new file mode 100644
index 0000000..a975713
--- /dev/null
+++ b/libcxx-test/libcxx_test.cpp
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <errno.h>
+
+#include <trusty_unittest.h>
+
+#define CHECK_ERRNO(e)       \
+    do {                     \
+        ASSERT_EQ(e, errno); \
+        errno = 0;           \
+    } while (0)
+#define CLEAR_ERRNO() \
+    do {              \
+        errno = 0;    \
+    } while (0)
+
+typedef struct libcxx {
+} libcxx_t;
+
+TEST_F_SETUP(libcxx) {
+    /* Isolate the tests. */
+    CLEAR_ERRNO();
+}
+
+TEST_F_TEARDOWN(libcxx) {
+    /* errno should have been checked and cleared if the test sets errno. */
+    CHECK_ERRNO(0);
+
+test_abort:;
+}
+
+class Dummy {};
+
+TEST_F(libcxx, new_and_delete) {
+    Dummy* tmp = new Dummy();
+    ASSERT_NE(nullptr, tmp);
+    delete tmp;
+test_abort:;
+}
+
+PORT_TEST(libcxx, "com.android.libcxxtest");
diff --git a/libcxx-test/manifest.c b/libcxx-test/manifest.c
new file mode 100644
index 0000000..7bc36fd
--- /dev/null
+++ b/libcxx-test/manifest.c
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stddef.h>
+#include <stdio.h>
+#include <trusty_app_manifest.h>
+
+trusty_app_manifest_t TRUSTY_APP_MANIFEST_ATTRS trusty_app_manifest = {
+        /* UUID : {31c9af88-c894-4c49-b726-bd4622a92b9c} */
+        {0x31c9af88,
+         0xc894,
+         0xb726,
+         {0xb7, 0x26, 0xbd, 0x46, 0x22, 0xa9, 0x2b, 0x9c}},
+
+        /* optional configuration options here */
+        {
+                TRUSTY_APP_CONFIG_MIN_STACK_SIZE(1 * 4096),
+                /* four pages for heap */
+                TRUSTY_APP_CONFIG_MIN_HEAP_SIZE(4 * 4096),
+        },
+};
diff --git a/libcxx-test/rules.mk b/libcxx-test/rules.mk
new file mode 100644
index 0000000..43da6ea
--- /dev/null
+++ b/libcxx-test/rules.mk
@@ -0,0 +1,32 @@
+# Copyright (C) 2019 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+LOCAL_DIR := $(GET_LOCAL_DIR)
+
+MODULE := $(LOCAL_DIR)
+
+MODULE_SRCS += \
+	$(LOCAL_DIR)/libcxx_test.cpp \
+	$(LOCAL_DIR)/manifest.c
+
+MODULE_DEPS += \
+	trusty/user/base/lib/libc-trusty \
+	trusty/user/base/lib/libstdc++-trusty \
+	trusty/user/base/lib/unittest \
+
+# Don't let the compiler optimize out the code we're testing. new, delete, etc.
+MODULE_COMPILEFLAGS := -ffreestanding
+
+include make/module.mk
diff --git a/usertests-inc.mk b/usertests-inc.mk
index 66e713e..52e1450 100644
--- a/usertests-inc.mk
+++ b/usertests-inc.mk
@@ -25,6 +25,7 @@
 	trusty/user/app/sample/ipc-unittest/main \
 	trusty/user/app/sample/ipc-unittest/srv \
 	trusty/user/app/sample/libc-test \
+	trusty/user/app/sample/libcxx-test \
 	trusty/user/app/sample/storage-unittest \
 	trusty/user/app/sample/timer \