Subject: [PATCH 1/2] gnu: Add memtest86+.

From: Tobias Geerinckx-Rice <[email-masked]>
Date: Mon, 1 Oct 2018 12:19:24 +0200

* gnu/packages/hardware.scm (memtest86+): New public variable.
---
 gnu/packages/hardware.scm | 66 +++++++++++++++++++++++++++++++++++++--
 1 file changed, 64 insertions(+), 2 deletions(-)

diff --git a/gnu/packages/hardware.scm b/gnu/packages/hardware.scm
index f77336e50..558ba4ef8 100644
--- a/gnu/packages/hardware.scm
+++ b/gnu/packages/hardware.scm
@@ -18,6 +18,7 @@
 
 (define-module (gnu packages hardware)
   #:use-module (gnu packages compression)
+  #:use-module (gnu packages gcc)
   #:use-module (gnu packages glib)
   #:use-module (gnu packages libusb)
   #:use-module (gnu packages linux)
@@ -74,6 +75,67 @@ calibrated, and restored when the calibration is applied.")
     (license (list license:bsd-3        ; FindDDCUtil.cmake
                    license:gpl2+))))    ; everything else
 
+;; Distinct from memtest86, which is obsolete.
+(define-public memtest86+
+  (package
+    (name "memtest86+")
+    ;; Update the description when/if UEFI support is released.
+    (version "5.01")
+    (source
+     (origin
+       (method url-fetch)
+       (uri (string-append "https://www.memtest.org/download/5.01/memtest86+-"
+                           version ".tar.gz"))
+       (sha256
+        (base32 "0fch1l55753y6jkk0hj8f6vw4h1kinkn9ysp22dq5g9zjnvjf88l"))))
+    (build-system gnu-build-system)
+    (arguments
+     `(#:phases
+       (modify-phases %standard-phases
+         (delete 'configure)            ; no configure script
+         (replace 'build
+           ;; The default 'make all' does wonderful things, like scp(1) a file to
+           ;; 192.168.0.12. Build the bootable images and nothing more.
+           (lambda _
+             (invoke "make"
+                     "memtest"          ; ELF executable
+                     "memtest.bin")))   ; DOS/MBR boot sector
+         (replace 'install
+           (lambda* (#:key outputs #:allow-other-keys)
+             (let* ((out (assoc-ref outputs "out"))
+                    (lib (string-append out "/lib/memtest86+"))
+                    (doc (string-append out "/share/doc/memtest86+-" ,version)))
+               (for-each
+                (lambda (file)
+                  (install-file file lib))
+                (list "memtest"
+                      "memtest.bin"))
+               (for-each
+                (lambda (file)
+                  (install-file file doc))
+                (list "FAQ"
+                      "README"))))))
+       #:tests? #f))                    ; no way to test this
+    (native-inputs
+     ;; Newer GCCs fail with a deluge of "multiple definition of `__foo'" errors.
+     `(("gcc" ,gcc-4.9)))
+    ;; XXX How can I ask to simply 'build the same thing on x86_64 as on i686'?
+    (supported-systems (list "i686-linux"))
+    (home-page "https://www.memtest.org/")
+    (synopsis "Thorough real-mode memory tester")
+    (description
+     "Memtest86+ is a thorough, stand-alone memory test for x86-architecture
+systems.  It runs independently of any operating system, at computer boot-up, so
+that it can scan all of your RAM for hardware defects.
+
+Most errors reported by Memtest86+ can be solved by replacing (parts of) your
+RAM, but the test implicitly tests the CPU, caches, and motherboard as well.
+It is impossible for the test to determine which component caused the failure to
+occur: the only option is to replace more parts until the failure is corrected.
+
+Memtest86+ cannot currently be used on computers booted with UEFI.")
+    (license license:gpl2)))
+
 (define-public msr-tools
   (package
     (name "msr-tools")
@@ -89,6 +151,7 @@ calibrated, and restored when the calibration is applied.")
     (arguments
      `(#:make-flags
        (list (string-append "sbindir=" (assoc-ref %outputs "out") "/sbin"))
+       #:tests? #f                      ; no test suite
        #:phases
        (modify-phases %standard-phases
          (delete 'configure)            ; no configure script
@@ -98,8 +161,7 @@ calibrated, and restored when the calibration is applied.")
              (let* ((out  (assoc-ref outputs "out"))
                     (sbin (string-append out "/sbin")))
                (mkdir-p sbin)
-               #t))))
-       #:tests? #f))                    ; no test suite
+               #t))))))
     (native-inputs
      `(("unzip" ,unzip)))
     ;; These registers and the CPUID instruction only exist on (most) x86 chips.
-- 
2.18.0