[gnome-settings-daemon/benzea/timetravel: 2/2] meson: Add option to run using UML time-travel mode




commit 1299b99cea1a76bdcd07698664657a85f76604a7
Author: Benjamin Berg <bberg redhat com>
Date:   Wed Nov 25 18:10:08 2020 +0100

    meson: Add option to run using UML time-travel mode
    
    Not that this actually helps much. Loading all the python stuff inside
    UML is extremely slow (due to ptrace). As such, it is actually slower to
    use, but still academically interesting.

 meson.build       | 10 ++++++++++
 meson_options.txt |  2 ++
 tests/time-travel | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 65 insertions(+)
---
diff --git a/meson.build b/meson.build
index 7dbee64b..16f715c4 100644
--- a/meson.build
+++ b/meson.build
@@ -253,6 +253,16 @@ meson.add_install_script(
   gsd_datadir
 )
 
+
+# Add a time-travel test setup which optimizes away all the sleeps
+if get_option('uml') != ''
+    time_travel = find_program('tests/time-travel')
+    add_test_setup(
+      'timetravel',
+      exe_wrapper : [ time_travel, get_option('uml')],
+    )
+endif
+
 output = '\n        ' + meson.project_name() + ' ' + meson.project_version() +'\n'
 output += '        =============================\n\n'
 output += '        prefix:                   ' + gsd_prefix + '\n'
diff --git a/meson_options.txt b/meson_options.txt
index 3e04cf64..e30846d7 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -12,3 +12,5 @@ option('usb-protection', type: 'boolean', value: true, description: 'build with
 option('wayland', type: 'boolean', value: true, description: 'build with Wayland support')
 option('wwan', type: 'boolean', value: true, description: 'build with WWAN support')
 option('colord', type: 'boolean', value: true, description: 'build with colord support')
+
+option('uml', type: 'string', value: '', description: 'Absolute path to UML binary that supports 
time-travel, speeds up testing')
diff --git a/tests/time-travel b/tests/time-travel
new file mode 100644
index 00000000..48842da1
--- /dev/null
+++ b/tests/time-travel
@@ -0,0 +1,53 @@
+#!/bin/sh
+
+UML_BIN="$1"
+shift
+
+wrapper=$( mktemp time-travel-setup-XXXXXX.sh )
+wrapper_full_path="$( pwd )/$wrapper"
+
+result="$wrapper_full_path.res"
+cat >"$wrapper" <<%EOF
+#! /bin/sh
+
+# Serialized environment
+$( export )
+
+mount -o remount,rw /
+mount tmp -t tmpfs /tmp
+mount tmp -t tmpfs /root
+mount tmp -t tmpfs /var
+mount proc -t proc /proc
+mount sys -t sysfs /sys
+
+if which haveged >/dev/null 2>&1 ; then
+    haveged
+elif which rngd >/dev/null 2>&1 ; then
+    # for some strange reason, this doesn't work so well
+    # when we don't start it into foreground with -f ...
+    rngd -f -r /dev/hw_random &
+else
+    echo "No entropy gathering daemon available - aborting!"
+    exit 1
+fi
+
+# Execute the test
+$@
+res=\$?
+echo \$res >"$result"
+
+poweroff -f
+%EOF
+chmod +x "$wrapper"
+
+$UML_BIN mem=512M root=none hostfs=/ rootfstype=hostfs rootflags=/ init="$wrapper_full_path" 
no_console_suspend con=null con0=null,fd:1 time-travel=inf-cpu
+reset -I
+rm -f $wrapper
+
+if [ -f $result ]; then
+  res=$( cat "$result" )
+  rm -f "$result"
+  exit $res
+else
+  exit -1
+fi


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]