[Reproducible-builds] [misc] 01/01: Add a test-reproducibility script
Jérémy Bobbio
lunar at moszumanska.debian.org
Sun Aug 31 08:09:40 UTC 2014
This is an automated email from the git hooks/post-receive script.
lunar pushed a commit to branch master
in repository misc.
commit d0530819b8c57a4eede03e6e334cef4eee6b672b
Author: Jérémy Bobbio <lunar at debian.org>
Date: Sun Aug 31 08:07:15 2014 +0000
Add a test-reproducibility script
The script will take a command and run it several time, varying only one factor
each time amongst time, current directory, current user and group, hostname and
kernel version.
This is untested, but the idea is to give `dpkg-buildpackage` as the command in
order to see which factors introduce unreproducibility in a given package.
---
test-reproducibility/t/all | 7 +++
test-reproducibility/t/test-script | 48 ++++++++++++++++++
test-reproducibility/test-reproducibility | 84 +++++++++++++++++++++++++++++++
3 files changed, 139 insertions(+)
diff --git a/test-reproducibility/t/all b/test-reproducibility/t/all
new file mode 100755
index 0000000..0fdf000
--- /dev/null
+++ b/test-reproducibility/t/all
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+date -u
+pwd
+id
+hostname
+uname -r
diff --git a/test-reproducibility/t/test-script b/test-reproducibility/t/test-script
new file mode 100755
index 0000000..1ce73e2
--- /dev/null
+++ b/test-reproducibility/t/test-script
@@ -0,0 +1,48 @@
+#!/bin/sh
+
+assert() {
+ "$@" || { echo "'$@' failed." && exit 1; }
+}
+
+echo "Testing happy path."
+OUTPUT="$(../test-reproducibility echo)"
+assert test $? -eq 0
+assert test "$OUTPUT" = "OK"
+
+echo "Testing timestamps."
+OUTPUT="$(../test-reproducibility date -u)"
+assert test $? -eq 1
+assert test "$OUTPUT" = "ERRORS: timestamps"
+
+echo "Testing build path."
+OUTPUT="$(../test-reproducibility pwd)"
+assert test $? -eq 1
+assert test "$OUTPUT" = "ERRORS: build-path"
+
+echo "Testing usernames."
+OUTPUT="$(../test-reproducibility id)"
+assert test $? -eq 1
+assert test "$OUTPUT" = "ERRORS: usernames"
+
+echo "Testing hostname."
+OUTPUT="$(../test-reproducibility hostname)"
+assert test $? -eq 1
+assert test "$OUTPUT" = "ERRORS: hostname"
+
+echo "Testing kernel version."
+OUTPUT="$(../test-reproducibility uname -r)"
+assert test $? -eq 1
+assert test "$OUTPUT" = "ERRORS: kernel-version"
+
+echo "Testing all of the above"
+OUTPUT="$(../test-reproducibility ./all)"
+assert test $? -eq 1
+echo "$OUTPUT" | assert grep -q "^ERRORS:"
+echo "$OUTPUT" | assert grep -q -w "timestamps"
+echo "$OUTPUT" | assert grep -q -w "build-path"
+echo "$OUTPUT" | assert grep -q -w "usernames"
+echo "$OUTPUT" | assert grep -q -w "hostname"
+echo "$OUTPUT" | assert grep -q -w "kernel-version"
+
+echo "All good."
+exit 0
diff --git a/test-reproducibility/test-reproducibility b/test-reproducibility/test-reproducibility
new file mode 100755
index 0000000..7ae345e
--- /dev/null
+++ b/test-reproducibility/test-reproducibility
@@ -0,0 +1,84 @@
+#!/bin/sh
+
+set -e
+
+COMMAND="$@"
+NOW="$(date +%s)"
+
+TEST_REPRODUCIBILITY_TMPDIR="$(mktemp -d)"
+if ! [ -d "$TEST_REPRODUCIBILITY_TMPDIR" ]; then
+ echo "Unable to create temporary directory." >&2
+ exit 254
+fi
+trap "rm -rf '$TEST_REPRODUCIBILITY_TMPDIR'" EXIT
+FAKETIME_RECORD_FILE="$TEST_REPRODUCIBILITY_TMPDIR/faketime-record"
+
+
+run_baseline() {
+ FAKETIME_SAVE_FILE="$FAKETIME_RECORD_FILE" faketime "@+$NOW" $COMMAND
+}
+
+run_different_time() {
+ faketime "tomorrow" $COMMAND
+}
+
+run_different_path() {
+ faketime @+$NOW proot -b "$PWD":/something sh -c "cd /something && $COMMAND"
+}
+
+run_different_user() {
+ local new_uid new_gid
+
+ new_uid=$(($(id -u) + 1))
+ new_gid=$(($(id -g) + 1))
+ faketime @+$NOW proot -i "$new_uid:$new_gid" $COMMAND
+}
+
+run_different_hostname() {
+ local current_user
+
+ current_user="$(whoami)"
+ sudo unshare --uts -- sh -c "hostname different-hostname && su $current_user -c 'faketime @+$NOW $COMMAND'"
+}
+
+run_different_kernel() {
+ local current_kernel
+
+ current_kernel="$(uname -r)"
+ faketime @+$NOW proot -k "${current_kernel}+different" $COMMAND
+}
+
+(run_baseline > "$TEST_REPRODUCIBILITY_TMPDIR/output-baseline")
+if [ -s "$FAKETIME_RECORD_FILE" ]; then
+ FAKETIME_LOAD_FILE="$FAKETIME_RECORD_FILE"
+fi
+(run_different_time > "$TEST_REPRODUCIBILITY_TMPDIR/output-different-time")
+(run_different_path > "$TEST_REPRODUCIBILITY_TMPDIR/output-different-path")
+(run_different_user > "$TEST_REPRODUCIBILITY_TMPDIR/output-different-user")
+(run_different_hostname > "$TEST_REPRODUCIBILITY_TMPDIR/output-different-hostname")
+(run_different_kernel > "$TEST_REPRODUCIBILITY_TMPDIR/output-different-kernel")
+
+ERRORS=""
+if ! diff -q "$TEST_REPRODUCIBILITY_TMPDIR/output-baseline" "$TEST_REPRODUCIBILITY_TMPDIR/output-different-time" >/dev/null; then
+ ERRORS="${ERRORS:+$ERRORS }timestamps"
+fi
+if ! diff -q "$TEST_REPRODUCIBILITY_TMPDIR/output-baseline" "$TEST_REPRODUCIBILITY_TMPDIR/output-different-path" >/dev/null; then
+ ERRORS="${ERRORS:+$ERRORS }build-path"
+fi
+if ! diff -q "$TEST_REPRODUCIBILITY_TMPDIR/output-baseline" "$TEST_REPRODUCIBILITY_TMPDIR/output-different-user" >/dev/null; then
+ ERRORS="${ERRORS:+$ERRORS }usernames"
+fi
+if ! diff -q "$TEST_REPRODUCIBILITY_TMPDIR/output-baseline" "$TEST_REPRODUCIBILITY_TMPDIR/output-different-hostname" >/dev/null; then
+ ERRORS="${ERRORS:+$ERRORS }hostname"
+fi
+if ! diff -q "$TEST_REPRODUCIBILITY_TMPDIR/output-baseline" "$TEST_REPRODUCIBILITY_TMPDIR/output-different-kernel" >/dev/null; then
+ ERRORS="${ERRORS:+$ERRORS }kernel-version"
+fi
+
+if [ "$ERRORS" ]; then
+ echo "ERRORS: $ERRORS"
+ exit 1
+fi
+
+echo "OK"
+exit 0
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/misc.git
More information about the Reproducible-builds
mailing list