Tests: factored out code to execute test commands

Factored out code to execute test commands from standalone_main.c, in
order to reuse function in a standalone secure partition.

Change-Id: I671aa64e48f209eb718e6e12c78b4fa4995c2b4a
Signed-off-by: J-Alves <joao.alves@arm.com>
diff --git a/test/hftest/common.c b/test/hftest/common.c
index 15700e4..344ff24 100644
--- a/test/hftest/common.c
+++ b/test/hftest/common.c
@@ -227,6 +227,51 @@
 	HFTEST_LOG("    Run the named test from the named test suite.");
 }
 
+void hftest_command(struct fdt *fdt)
+{
+	struct memiter command_line;
+	struct memiter command;
+
+	if (!hftest_ctrl_start(fdt, &command_line)) {
+		HFTEST_LOG("Unable to read the command line.");
+		return;
+	}
+
+	if (!memiter_parse_str(&command_line, &command)) {
+		HFTEST_LOG("Unable to parse command.");
+		return;
+	}
+
+	if (memiter_iseq(&command, "exit")) {
+		hftest_device_exit_test_environment();
+		return;
+	}
+
+	if (memiter_iseq(&command, "json")) {
+		hftest_json();
+		return;
+	}
+
+	if (memiter_iseq(&command, "run")) {
+		struct memiter suite_name;
+		struct memiter test_name;
+
+		if (!memiter_parse_str(&command_line, &suite_name)) {
+			HFTEST_LOG("Unable to parse test suite.");
+			return;
+		}
+
+		if (!memiter_parse_str(&command_line, &test_name)) {
+			HFTEST_LOG("Unable to parse test.");
+			return;
+		}
+		hftest_run(suite_name, test_name, fdt);
+		return;
+	}
+
+	hftest_help();
+}
+
 static uintptr_t vcpu_index_to_id(size_t index)
 {
 	/* For now we use indices as IDs for vCPUs. */
diff --git a/test/hftest/standalone_main.c b/test/hftest/standalone_main.c
index d73bfb5..10e9ef0 100644
--- a/test/hftest/standalone_main.c
+++ b/test/hftest/standalone_main.c
@@ -25,8 +25,6 @@
 {
 	struct fdt fdt;
 	size_t fdt_len;
-	struct memiter command_line;
-	struct memiter command;
 
 	/*
 	 * Initialize the stage-1 MMU and identity-map the entire address space.
@@ -50,44 +48,7 @@
 		goto out;
 	}
 
-	if (!hftest_ctrl_start(&fdt, &command_line)) {
-		HFTEST_LOG("Unable to read the command line.");
-		goto out;
-	}
-
-	if (!memiter_parse_str(&command_line, &command)) {
-		HFTEST_LOG("Unable to parse command.");
-		goto out;
-	}
-
-	if (memiter_iseq(&command, "exit")) {
-		hftest_device_exit_test_environment();
-		goto out;
-	}
-
-	if (memiter_iseq(&command, "json")) {
-		hftest_json();
-		goto out;
-	}
-
-	if (memiter_iseq(&command, "run")) {
-		struct memiter suite_name;
-		struct memiter test_name;
-
-		if (!memiter_parse_str(&command_line, &suite_name)) {
-			HFTEST_LOG("Unable to parse test suite.");
-			goto out;
-		}
-
-		if (!memiter_parse_str(&command_line, &test_name)) {
-			HFTEST_LOG("Unable to parse test.");
-			goto out;
-		}
-		hftest_run(suite_name, test_name, &fdt);
-		goto out;
-	}
-
-	hftest_help();
+	hftest_command(&fdt);
 
 out:
 	hftest_ctrl_finish();