diff mbox series

rteval: enhancement to --kcompile-source option for kernel tarball

Message ID 20220805003219.1248947-1-magodse@redhat.com
State New
Headers show
Series rteval: enhancement to --kcompile-source option for kernel tarball | expand

Commit Message

Manasi Godse Aug. 5, 2022, 12:32 a.m. UTC
The --kcompile-source option is enhanced such that it can find the
kernel source tarballs using the values as 'linux-5.18.1' , '5.18.1',
'linux-5.18.1.tar.xz' This eliminates the need to type the entire
source filename as a value to the option. The enhancement will look for
the tarballs in the loadsource directory.

Signed-off-by: Manasi Godse <magodse@redhat.com>
---
 rteval/modules/loads/kcompile.py | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/rteval/modules/loads/kcompile.py b/rteval/modules/loads/kcompile.py
index 6dd8d940f8b3..7d78d0ff9cae 100644
--- a/rteval/modules/loads/kcompile.py
+++ b/rteval/modules/loads/kcompile.py
@@ -166,16 +166,33 @@  class Kcompile(CommandLineLoad):
             raise rtevalRuntimeError(self, \
                 f"error removing builddir ({self.buildir}) (ret={ret})")
 
+    def _find_tarball(self):
+       # If the user specifies the full kernel name, check if available
+        tarfile = os.path.join(self.srcdir, self._cfg.source)
+        if os.path.exists(tarfile):
+            return tarfile
+
+        if 'rc' in self._cfg.source:
+            tarfile_prefix = re.search(r"\d{1,2}\.\d{1,3}\-[a-z]*\d{1,2}", self._cfg.source).group(0)
+        else:
+            tarfile_prefix = re.search(r"\d{1,2}\.\d{1,3}\.*\d{1,2}", self._cfg.source).group(0)
+
+        # either a tar.xz or tar.gz might exist. Check for both.
+        xz_file = os.path.join(self.srcdir,"linux-" + tarfile_prefix + ".tar.xz" )
+        gz_file = os.path.join(self.srcdir,"linux-" + tarfile_prefix + ".tar.gz" )
+        if os.path.exists(xz_file):
+            return xz_file
+        elif os.path.exists(gz_file):
+            return gz_file
+        raise rtevalRuntimeError(self, f"tarfile {tarfile} does not exist!")
+
     def _WorkloadSetup(self):
         if self._donotrun:
             return
 
         # find our source tarball
         if self._cfg.source:
-            tarfile = os.path.join(self.srcdir, self._cfg.source)
-            if not os.path.exists(tarfile):
-                raise rtevalRuntimeError(self, f" tarfile {tarfile} does not exist!")
-            self.source = tarfile
+            self.source = self._find_tarball()
             kernel_prefix = re.search(r"linux-\d{1,2}\.\d{1,3}\.*\d{1,2}", self.source).group(0)
         else:
             tarfiles = glob.glob(os.path.join(self.srcdir, f"{DEFAULT_KERNEL_PREFIX}*"))