[Git][ghc/ghc][wip/romes/12935] Write a test for object determinism
Rodrigo Mesquita (@alt-romes)
gitlab at gitlab.haskell.org
Tue May 21 16:42:26 UTC 2024
Rodrigo Mesquita pushed to branch wip/romes/12935 at Glasgow Haskell Compiler / GHC
Commits:
71e10b23 by Rodrigo Mesquita at 2024-05-21T17:42:17+01:00
Write a test for object determinism
- - - - -
4 changed files:
- + testsuite/tests/determinism/object/Makefile
- + testsuite/tests/determinism/object/all.T
- + testsuite/tests/determinism/object/cabal.project
- + testsuite/tests/determinism/object/check.sh
Changes:
=====================================
testsuite/tests/determinism/object/Makefile
=====================================
@@ -0,0 +1,15 @@
+TOP=../../..
+include $(TOP)/mk/boilerplate.mk
+include $(TOP)/mk/test.mk
+
+.PHONY: T12935
+T12935:
+ $(RM) -rf objs1 objs2
+ cabal get Cabal-3.12.0.0
+ # Ignore that redirecting ofiles elsewhere will cause compilation to fail
+ # because cabal invokes `ar` on the expected object files directly...
+ cabal build -w '$(TEST_HC)' --ghc-options='$(TEST_HC_OPTS)' --ghc-options=-odir=out1 Cabal > /dev/null 2>&1 || true
+ cabal build -w '$(TEST_HC)' --ghc-options='$(TEST_HC_OPTS)' --ghc-options=-odir=out2 Cabal > /dev/null 2>&1 || true
+ ./check.sh $(HostOS)
+
+
=====================================
testsuite/tests/determinism/object/all.T
=====================================
@@ -0,0 +1 @@
+test('T12935', [extra_files(['cabal.project', 'check.sh'])], makefile_test, ['T12935'])
=====================================
testsuite/tests/determinism/object/cabal.project
=====================================
@@ -0,0 +1 @@
+packages: Cabal-3.12.0.0
=====================================
testsuite/tests/determinism/object/check.sh
=====================================
@@ -0,0 +1,62 @@
+#!/bin/sh
+
+set -e
+
+if test -z "$1"
+then
+ echo "Usage: ./check.sh <HostOS> # example ./check.sh darwin"
+ exit 1
+fi
+
+# On darwin we need to pass -m to objdump on Mach-O files
+if test $1 == "darwin"
+then
+ OBJDUMP="objdump -m"
+else
+ OBJDUMP="objdump"
+fi
+
+# Guarantee object files were written
+
+S1=`find out1 -name "*.o" | wc -l`
+S2=`find out2 -name "*.o" | wc -l`
+
+test $S1 > 0
+test $S1 == $S2
+
+# $1 = objects
+# $2 = extra flags
+compareObjs() {
+ for o in $1
+ do
+ echo $OBJDUMP $2 $o
+ echo "--------------------------------------------------------------------------------"
+ # Compare the object dumps except for the first line which prints the file path
+ $OBJDUMP $2 out1/$o | tail -n+2 > dump1
+ $OBJDUMP $2 out2/$o | tail -n+2 > dump2
+ diff dump1 dump2
+ echo "--------------------------------------------------------------------------------"
+ done
+}
+
+# Big fast check
+if diff -r out1 out2
+then
+ echo "OK"
+else
+ echo "--------------------------------------------------------------------------------"
+ echo "Comparing all objects (1. headers, 2. disassembly). Stopping at first failure..."
+ echo "--------------------------------------------------------------------------------"
+
+
+ pushd out1 >/dev/null
+ OBJS=$(find . -type f)
+ popd >/dev/null
+
+ compareObjs "$OBJS" "--all-headers"
+
+ compareObjs "$OBJS" "--disassemble-all"
+
+fi
+
+
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/71e10b23045736f12113272c36dd3178a72043aa
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/71e10b23045736f12113272c36dd3178a72043aa
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20240521/434abcaa/attachment-0001.html>
More information about the ghc-commits
mailing list