Subject: bug#39357: tests/cp/proc-short-read.sh fails in modern build environment

From: Pádraig Brady <[email-masked]>
Date: Tue, 4 Feb 2020 00:45:06 +0000

On 30/01/2020 13:53, Kamil Dudka wrote:
> tests/cp/proc-short-read.sh expects that a pair of subsequent reads from
> /proc/kallsyms will always return the same content.  This does not seem to
> be a safe assumption any more.  The test has started to fail in our build
> environment.  I am not sure how to fix the test.  We could probably make
> it use another file from /proc but most of them are much smaller than
> kallsyms and/or suffer from the same problem.  Output of the failing test
> follows.
> 
> Kamil
> 
> 
> FAIL: tests/cp/proc-short-read
> ==============================

> + compare_ 1 2
> + diff -u 1 2
> --- 1	2020-01-29 12:04:36.923963121 +0000
> +++ 2	2020-01-29 12:04:37.026963484 +0000
> @@ -114819,81 +114819,132 @@
>   0000000000000000 t nfs_file_direct_read.cold	[nfs]
>   0000000000000000 t nfs_file_direct_write.cold	[nfs]
>   0000000000000000 r .LC0	[nfs]
> -0000000000000000 r .LC2	[nfs]
> -0000000000000000 r __ksymtab_nfs_pgio_current_mirror	[nfs]
> -0000000000000000 r __kstrtab_nfs_pgio_current_mirror	[nfs]

> +0000000000000000 r __func__.87038	[nfs]
> +0000000000000000 t __nfs_revalidate_inode.cold	[nfs]
> +0000000000000000 t nfs_revalidate_mapping.cold	[nfs]
> +0000000000000000 d nfs_net_ops	[nfs]
> +0000000000000000 t exit_nfs_fs	[nfs]
> +0000000000000000 r __param_enable_ino64	[nfs]
> +0000000000000000 r __param_str_enable_ino64	[nfs]
> +0000000000000000 r .LC15	[nfs]
> +0000000000000000 r __ksymtab_nfs_fs_type	[nfs]
> +0000000000000000 r __kstrtab_nfs_fs_type	[nfs]

> + fail=1
> + md5sum /proc/kallsyms
> + md5sum 2
> + sed 's/ .*//' 3
> + sed 's/ .*//' 4
> + compare sum.proc sum.2
> + compare_dev_null_ sum.proc sum.2
> + test 2 = 2
> + test xsum.proc = x/dev/null
> + test xsum.2 = x/dev/null
> + return 2
> + case $? in
> + compare_ sum.proc sum.2
> + diff -u sum.proc sum.2
> --- sum.proc	2020-01-29 12:04:37.172963999 +0000
> +++ sum.2	2020-01-29 12:04:37.175964009 +0000
> @@ -1 +1 @@
> -226cd09830f68c56edda0b9272be66e4
> +37d7e78173b2a31d5f27cc66aa52e72a
> + fail=1

Interesting.
The attached changes to /proc/cpuinfo
which is a bit more awkward, but should be a valid test most of the time,
and is also the file for which the original bug report was against.

cheers,
Pádraig
>From 309dcf79f097fc547edbd82cd6601d111277c4f1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <[email-masked]>
Date: Tue, 4 Feb 2020 00:37:23 +0000
Subject: [PATCH] tests: avoid false failure due to varying /proc/kallsyms

* tests/cp/proc-short-read.sh: Switch to using /proc/cpuinfo,
rather than /proc/kallsyms which was seen to vary in some cases.
Fixes https://bugs.gnu.org/39357
---
 tests/cp/proc-short-read.sh | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/tests/cp/proc-short-read.sh b/tests/cp/proc-short-read.sh
index 6c58881de..dcc8b30d5 100755
--- a/tests/cp/proc-short-read.sh
+++ b/tests/cp/proc-short-read.sh
@@ -19,22 +19,18 @@
 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
 print_ver_ cp
 
-kall=/proc/kallsyms
+proc_large=/proc/cpuinfo  # usually > 4KiB
 
-test -r $kall || skip_ "your system lacks $kall"
+test -r $proc_large || skip_ "your system lacks $proc_large"
 
-# Before coreutils-7.3, cp would copy less than 4KiB of this 1MB+ file.
-cp $kall 1    || fail=1
-cat $kall > 2 || fail=1
-compare 1 2   || fail=1
+# Before coreutils-7.3, cp would copy less than 4KiB of this file.
+cp $proc_large 1    || fail=1
+cat $proc_large > 2 || fail=1
 
-# Also check md5sum, just for good measure.
-md5sum $kall > 3 || fail=1
-md5sum 2     > 4 || fail=1
+# adjust varying parts
+sed '/MHz/d; /bogomips/d;' 1 > proc.cp || framework_failure_
+sed '/MHz/d; /bogomips/d;' 2 > proc.cat || framework_failure_
 
-# Remove each file name before comparing checksums.
-sed 's/ .*//' 3 > sum.proc || fail=1
-sed 's/ .*//' 4 > sum.2    || fail=1
-compare sum.proc sum.2 || fail=1
+compare proc.cp proc.cat || fail=1
 
 Exit $fail
-- 
2.24.1