Add test for starting cpus.

Change-Id: Ia1959e6cf1018722ae140eeed4ffb1fb166ceb0e
diff --git a/test/vm/BUILD.gn b/test/vm/BUILD.gn
index 0ac7cde..7fe6e6a 100644
--- a/test/vm/BUILD.gn
+++ b/test/vm/BUILD.gn
@@ -40,7 +40,7 @@
     "//src:memiter",
     "//src/arch/${plat_arch}:entry",
     "//src/arch/${plat_arch}/vm:hf_call",
-    "//src/arch/${plat_arch}/vm:shutdown",
+    "//src/arch/${plat_arch}/vm:power_mgmt",
     "//src/arch/${plat_arch}/vm:vm_entry",
   ]
 }
@@ -54,7 +54,7 @@
     "//src:dlog",
     "//src/arch/${plat_arch}:entry",
     "//src/arch/${plat_arch}/vm:hf_call",
-    "//src/arch/${plat_arch}/vm:shutdown",
+    "//src/arch/${plat_arch}/vm:power_mgmt",
     "//src/arch/${plat_arch}/vm:vm_entry",
   ]
 }
diff --git a/test/vm/hftest.py b/test/vm/hftest.py
index ac0f247..d80d26b 100755
--- a/test/vm/hftest.py
+++ b/test/vm/hftest.py
@@ -36,7 +36,7 @@
     qemu_args = [
         "timeout", "--foreground", "5s",
         "./prebuilts/linux-x64/qemu/qemu-system-aarch64", "-M", "virt,gic_version=3", "-cpu",
-        "cortex-a57", "-m", "16M", "-machine", "virtualization=true",
+        "cortex-a57", "-smp", "4", "-m", "16M", "-machine", "virtualization=true",
         "-nographic", "-nodefaults", "-serial", "stdio", "-kernel", hafnium,
         "-initrd", initrd
     ]
diff --git a/test/vm/primary_only.c b/test/vm/primary_only.c
index dd7ab48..ba9e6d7 100644
--- a/test/vm/primary_only.c
+++ b/test/vm/primary_only.c
@@ -14,6 +14,12 @@
  * limitations under the License.
  */
 
+#include <stdalign.h>
+
+#include "hf/arch/vm/power_mgmt.h"
+
+#include "hf/spinlock.h"
+
 #include "vmapi/hf/call.h"
 
 #include "hftest.h"
@@ -49,3 +55,29 @@
 	struct hf_vcpu_run_return res = hf_vcpu_run(1, 0);
 	EXPECT_EQ(res.code, HF_VCPU_RUN_WAIT_FOR_INTERRUPT);
 }
+
+/**
+ * Releases the lock passed in.
+ */
+static void vm_cpu_entry(uintptr_t arg)
+{
+	struct spinlock *lock = (struct spinlock *)arg;
+
+	dlog("Second CPU started.\n");
+	sl_unlock(lock);
+}
+
+TEST(cpus, start)
+{
+	struct spinlock lock = SPINLOCK_INIT;
+	alignas(4096) static char other_stack[4096];
+
+	/* Start secondary while holding lock. */
+	sl_lock(&lock);
+	EXPECT_EQ(cpu_start(1, other_stack, sizeof(other_stack), vm_cpu_entry,
+			    (uintptr_t)&lock),
+		  true);
+
+	/* Wait for CPU to release the lock. */
+	sl_lock(&lock);
+}