Skip to contentSkip to conversation

lib/oeqa/selftest/cases/reproducible.py : updated test to faketime in future when buiding the second test build.

PATCH In review Sangeeta Jain 2 participants 3 messages Mar 2, 2021 – Mar 3, 2021

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 lib/oeqa/selftest/cases/reproducible.py : updated test to faketime in future when buiding the second test build.

From: sangeeta jain <[email protected]>

This update will ensure that recipes are not including time stamps by creating an image with modified system time. It uses libfaketime recipe to fake system time to advance by 34308122 seconds

---
 meta/lib/oeqa/selftest/cases/reproducible.py | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
meta/lib/oeqa/selftest/cases/reproducible.py +16 -3
index f2d9f95..c7e1fdf 100644
@@ -163,6 +163,7 @@ class ReproducibleTests(OESelftestTestCase):
     # will test that and also make the test run faster. If your sstate is not
     # reproducible, disable this in your derived test class
     build_from_sstate = True
+    use_faketime = False
 
     def setUpLocal(self):
         super().setUpLocal()
@@ -210,7 +211,7 @@ class ReproducibleTests(OESelftestTestCase):
         bb.utils.mkdirhier(os.path.dirname(dest))
         shutil.copyfile(source, dest)
 
-    def do_test_build(self, name, use_sstate):
+    def do_test_build(self, name, use_sstate, use_faketime):
         capture_vars = ['DEPLOY_DIR_' + c.upper() for c in self.package_classes]
 
         tmpdir = os.path.join(self.topdir, name, 'tmp')
@@ -239,6 +240,18 @@ class ReproducibleTests(OESelftestTestCase):
                 SSTATE_MIRRORS = ""
                 ''')
 
+        if use_faketime:
+            # This config fragment will enable to fake system time
+            # advance by 34308122 sec
+            bitbake("libfaketime")
+            find_binary = "find . -path '*/image/*/libfaketime.so.1"
+            full_path_to_binary = runCmd(find_binary)
+            binary_path = full_path_to_binary.split("./")
+            ld_preload_path = os.path.join(os.environ.get('BUILDDIR'), binary_path[1])
+            seconds_add_to_system_time = "+34308122"
+            cmd = 'LD_PRELOAD=%s FAKETIME=%s' %(ld_preload_path, seconds_add_to_system_time)
+            runCmd(cmd)
+
         self.logger.info("Building %s (sstate%s allowed)..." % (name, '' if use_sstate else ' NOT'))
         self.write_config(config)
         d = get_bb_vars(capture_vars)
@@ -265,9 +278,9 @@ class ReproducibleTests(OESelftestTestCase):
             os.chmod(save_dir, stat.S_IRWXU | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH)
             self.logger.info('Non-reproducible packages will be copied to %s', save_dir)
 
-        vars_A = self.do_test_build('reproducibleA', self.build_from_sstate)
+        vars_A = self.do_test_build('reproducibleA', self.build_from_sstate, self.use_faketime)
 
-        vars_B = self.do_test_build('reproducibleB', False)
+        vars_B = self.do_test_build('reproducibleB', False, True)
 
         # NOTE: The temp directories from the reproducible build are purposely
         # kept after the build so it can be diffed for debugging.
Signature · 1 line
2.7.4
#1 lore raw

PATCH v2 2/2 meta/recipes-support/libfaketime: added recipe libfaketime

From: sangeeta jain <[email protected]>

libfaketime intercepts various system calls that programs use to retrieve the current date and time. It then reports modified (faked) dates and times (as specified the user) to these programs. It can modify the system time a program sees without having to change the time system-wide. It is useful for QA to fake the time in the future when building the test build to check for better reproducibility.

---
 meta/recipes-support/libfaketime/libfaketime_0.9.8.bb | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
 create mode 100644 meta/recipes-support/libfaketime/libfaketime_0.9.8.bb
meta/recipes-support/libfaketime/libfaketime_0.9.8.bb new file +19 -0
new file mode 100644
index 0000000..e7e203b
@@ -0,0 +1,19 @@
+SUMMARY = "It can modify the system time a program sees without changing time system-wide"
+HOMEPAGE = "https://github.com/wolfcw/libfaketime"
+LICENSE = "GPLv2"
+LIC_FILES_CHKSUM = "file://COPYING;md5=b234ee4d69f5fce4486a80fdaf4a4263"
+
+SRC_URI = "git://github.com/wolfcw/libfaketime.git;protocol=https"
+
+SRCREV = "dc2ae5eef31c7a64ce3a976487d8e57d50b8d594"
+
+S = "${WORKDIR}/git"
+
+do_compile() {
+        oe_runmake -C src
+}
+
+do_install() {
+
+         oe_runmake install DESTDIR=${D} PREFIX=${prefix}/ LIBDIRNAME=${baselib}
+}
\ No newline at end of file
Signature · 1 line
2.7.4
#2 lore raw
In reply to Sangeeta Jain
Quoted 42 lines · Sangeeta Jain

From: sangeeta jain <[email protected]>

This update will ensure that recipes are not including time stamps by creating an image with modified system time. It uses libfaketime recipe to fake system time to advance by 34308122 seconds

---
 meta/lib/oeqa/selftest/cases/reproducible.py | 19 ++++++++++++++++---

 1 file changed, 16 insertions(+), 3 deletions(-)
meta/lib/oeqa/selftest/cases/reproducible.py +0 -0
index f2d9f95..c7e1fdf 100644
@@ -163,6 +163,7 @@ class ReproducibleTests(OESelftestTestCase):
      # will test that and also make the test run faster. If your sstate is not
      # reproducible, disable this in your derived test class

     build_from_sstate = True
+ use_faketime = False

     def setUpLocal(self):
         super().setUpLocal()

meta/lib/oeqa/selftest/cases/reproducible.py +0 -0
@@ -210,7 +211,7 @@ class ReproducibleTests(OESelftestTestCase):
          bb.utils.mkdirhier(os.path.dirname(dest))
          shutil.copyfile(source, dest)

meta/lib/oeqa/selftest/cases/reproducible.py +1 -1
-    def do_test_build(self, name, use_sstate):
+    def do_test_build(self, name, use_sstate, use_faketime):

         capture_vars = ['DEPLOY_DIR_' + c.upper() for c in self.package_classes]

         tmpdir = os.path.join(self.topdir, name, 'tmp')

meta/lib/oeqa/selftest/cases/reproducible.py +0 -0
@@ -239,6 +240,18 @@ class ReproducibleTests(OESelftestTestCase):

                 SSTATE_MIRRORS = ""
                 ''')

meta/lib/oeqa/selftest/cases/reproducible.py +2 -0
+        if use_faketime:
+            # This config fragment will enable to fake system time

meta/lib/oeqa/selftest/cases/reproducible.py class ReproducibleTests(OESelftestTestCase): · line 254

Quoted 10 lines
meta/lib/oeqa/selftest/cases/reproducible.py +10 -0
+            # advance by 34308122 sec
+            bitbake("libfaketime")
+            find_binary = "find . -path '*/image/*/libfaketime.so.1"
+            full_path_to_binary = runCmd(find_binary)
+            binary_path = full_path_to_binary.split("./")
+            ld_preload_path = os.path.join(os.environ.get('BUILDDIR'), binary_path[1])
+            seconds_add_to_system_time = "+34308122"
+            cmd = 'LD_PRELOAD=%s FAKETIME=%s' %(ld_preload_path, seconds_add_to_system_time)
+            runCmd(cmd)
+

This doesn't make sense to me. Surely the build has to run under the LD_PRELOAD to fake the time? How did you test this?

This method of finding the binary looks error prone too, which "image" directory are you trying to use here?

Also, the recipe addition doesn't add a maintainers entry.

Cheers,

Richard