[DVSim] Fix how sw_images is treated

This change fixes the way sw_images is treated - it can now be set in
`build_modes`, `run_modes`, test specifications and 'bare' in the HJson
which will get it applied to all tests. Previously, it was not possible
to add it to build_modes. Also a bug prevented it from getting appended
properly across run_modes and test specifications.

Signed-off-by: Srikrishna Iyer <sriyer@google.com>
diff --git a/util/dvsim/Modes.py b/util/dvsim/Modes.py
index 33b5870..5babbf3 100644
--- a/util/dvsim/Modes.py
+++ b/util/dvsim/Modes.py
@@ -263,11 +263,12 @@
         self.is_sim_mode = 0
         self.pre_build_cmds = []
         self.post_build_cmds = []
+        self.en_build_modes = []
+        self.build_opts = []
         self.pre_run_cmds = []
         self.post_run_cmds = []
-        self.build_opts = []
         self.run_opts = []
-        self.en_build_modes = []
+        self.sw_images = []
 
         super().__init__(bdict)
         self.en_build_modes = list(set(self.en_build_modes))
@@ -293,11 +294,11 @@
         self.reseed = None
         self.pre_run_cmds = []
         self.post_run_cmds = []
+        self.en_run_modes = []
         self.run_opts = []
         self.uvm_test = ""
         self.uvm_test_seq = ""
         self.build_mode = ""
-        self.en_run_modes = []
         self.sw_images = []
         self.sw_build_device = ""
 
@@ -416,6 +417,7 @@
             test_obj.pre_run_cmds.extend(test_obj.build_mode.pre_run_cmds)
             test_obj.post_run_cmds.extend(test_obj.build_mode.post_run_cmds)
             test_obj.run_opts.extend(test_obj.build_mode.run_opts)
+            test_obj.sw_images.extend(test_obj.build_mode.sw_images)
 
         # Return the list of tests
         return tests_objs
@@ -423,7 +425,7 @@
     @staticmethod
     def merge_global_opts(tests, global_pre_build_cmds, global_post_build_cmds,
                           global_build_opts, global_pre_run_cmds,
-                          global_post_run_cmds, global_run_opts):
+                          global_post_run_cmds, global_run_opts, global_sw_images):
         processed_build_modes = []
         for test in tests:
             if test.build_mode.name not in processed_build_modes:
@@ -434,6 +436,7 @@
             test.pre_run_cmds.extend(global_pre_run_cmds)
             test.post_run_cmds.extend(global_post_run_cmds)
             test.run_opts.extend(global_run_opts)
+            test.sw_images.extend(global_sw_images)
 
 
 class Regressions(Modes):
diff --git a/util/dvsim/SimCfg.py b/util/dvsim/SimCfg.py
index 238359d..0d0d339 100644
--- a/util/dvsim/SimCfg.py
+++ b/util/dvsim/SimCfg.py
@@ -106,6 +106,7 @@
         self.post_run_cmds = []
         self.run_dir = ""
         self.sw_build_dir = ""
+        self.sw_images = []
         self.pass_patterns = []
         self.fail_patterns = []
         self.name = ""
@@ -281,6 +282,7 @@
                 self.pre_run_cmds.extend(build_mode_obj.pre_run_cmds)
                 self.post_run_cmds.extend(build_mode_obj.post_run_cmds)
                 self.run_opts.extend(build_mode_obj.run_opts)
+                self.sw_images.extend(build_mode_obj.sw_images)
             else:
                 log.error(
                     "Mode \"%s\" enabled on the the command line is not defined",
@@ -294,6 +296,7 @@
                 self.pre_run_cmds.extend(run_mode_obj.pre_run_cmds)
                 self.post_run_cmds.extend(run_mode_obj.post_run_cmds)
                 self.run_opts.extend(run_mode_obj.run_opts)
+                self.sw_images.extend(run_mode_obj.sw_images)
             else:
                 log.error(
                     "Mode \"%s\" enabled on the the command line is not defined",
@@ -391,7 +394,7 @@
         Tests.merge_global_opts(self.run_list, self.pre_build_cmds,
                                 self.post_build_cmds, self.build_opts,
                                 self.pre_run_cmds, self.post_run_cmds,
-                                self.run_opts)
+                                self.run_opts, self.sw_images)
 
         # Check if all items have been processed
         if items_list != []: