Multiprocessing keyword support for test execution

Resolves openbmc/openbmc-test-automation#681

Change-Id: I89ba335be351bc055987fb33321bae54c9ad3646
Signed-off-by: George Keishing <gkeishin@in.ibm.com>
diff --git a/lib/jobs_processing.py b/lib/jobs_processing.py
new file mode 100644
index 0000000..c730652
--- /dev/null
+++ b/lib/jobs_processing.py
@@ -0,0 +1,65 @@
+#!/usr/bin/env python
+
+r"""
+This module contains keyword functions to support multiprocessing
+execution of keywords where generic robot keywords don't support.
+
+"""
+
+from robot.libraries.BuiltIn import BuiltIn
+from multiprocessing import Process, Manager
+import os
+import gen_print as gp
+
+
+###############################################################################
+def execute_keyword(keyword_name, return_dict):
+    r"""
+    Execute a robot keyword.
+    In addition to running the caller's keyword, this function will:
+    - Add an entry to the return_dict
+
+    Description of argument(s):
+    keyword_name    Keyword name to be executed.
+    return_dict     A dictionary consisting of pid/process output for the
+                    keys/values. This function will append a new entry to
+                    this dictionary.
+    """
+
+    pid = os.getpid()
+    output = BuiltIn().run_keyword(keyword_name)
+
+    # Build PID:<output> dictionary.
+    return_dict[str(pid)] = str(output)
+
+###############################################################################
+
+
+###############################################################################
+def execute_process(num_process, keyword_name):
+    r"""
+    Execute a robot keyword via multiprocessing process.
+
+    Description of argument(s):
+    num_process         Number of times keyword to be executed.
+    keyword_name     Keyword name to be executed.
+    """
+
+    manager = Manager()
+    return_dict = manager.dict()
+    process_list = []
+
+    # Append user-defined times process needed to execute.
+    for ix in range(int(num_process)):
+        task = Process(target=execute_keyword, args=(keyword_name, return_dict))
+        process_list.append(task)
+        task.start()
+
+    # Wait for process to complete.
+    for task in process_list:
+        task.join()
+
+    # Return function return codes.
+    return return_dict
+
+###############################################################################