[PATCH] tests: test sort,shuf with rngtest

2013-03-08 Thread Assaf Gordon
Hello,

Regarding comment:

Pádraig Brady wrote, On 03/07/2013 06:26 PM:
 On 03/07/2013 07:32 PM, Assaf Gordon wrote:
 The second attached patch is experimental - it tries to assess the
 randomness of 'shuf' output by running it 1,000 times and checking
 if the output is (very roughly) uniformly distributed. 
 
 Cool, I was considering testing with rngtest or something, so it'll
 be good to have something independent.
(  http://lists.gnu.org/archive/html/coreutils/2013-03/msg00030.html )

Using rngtest is probably much more reliable than the independent test - 
attached are tests for sort and shuf with rngtest.
They are marked 'expensive' as they require an external program and they run 
each test 10 times.

-gordon



From 15392de8f0ffa0746c9fd338ed14d15b614029a3 Mon Sep 17 00:00:00 2001
From: Assaf Gordon assafgor...@gmail.com
Date: Fri, 8 Mar 2013 15:54:24 -0500
Subject: [PATCH] tests: test sort,shuf with rngtest

rngtest check the randomness of data using FIPS 140-2 tests.
http://sourceforge.net/projects/gkernel/

If rngtest is not installed (and available in the PATH),
the tests will be skipped.

These tests are marked 'expensive'. To run directly:

  $ make check TESTS=tests/misc/sort-rand-rngtest.sh \
   SUBDIRS=. RUN_EXPENSIVE_TESTS=yes
  $ make check TESTS=tests/misc/shuf-rand-rngtest.sh \
   SUBDIRS=. RUN_EXPENSIVE_TESTS=yes

* tests/misc/shuf-rand-rngtest.sh - test shuf with rngtest.
* tests/misc/sort-rand-rngtest.sh - test sort with rngtest.
* tests/local.mk - add above tests.
---
 tests/local.mk  |2 +
 tests/misc/shuf-rand-rngtest.sh |   78 +++
 tests/misc/sort-rand-rngtest.sh |   71 +++
 3 files changed, 151 insertions(+), 0 deletions(-)
 create mode 100755 tests/misc/shuf-rand-rngtest.sh
 create mode 100755 tests/misc/sort-rand-rngtest.sh

diff --git a/tests/local.mk b/tests/local.mk
index 607ddc4..21d347a 100644
--- a/tests/local.mk
+++ b/tests/local.mk
@@ -313,6 +313,7 @@ all_tests =	\
   tests/misc/shred-passes.sh			\
   tests/misc/shred-remove.sh			\
   tests/misc/shuf.sh\
+  tests/misc/shuf-rand-rngtest.sh		\
   tests/misc/sort.pl\
   tests/misc/sort-benchmark-random.sh		\
   tests/misc/sort-compress.sh			\
@@ -329,6 +330,7 @@ all_tests =	\
   tests/misc/sort-month.sh			\
   tests/misc/sort-exit-early.sh			\
   tests/misc/sort-rand.sh			\
+  tests/misc/sort-rand-rngtest.sh		\
   tests/misc/sort-spinlock-abuse.sh		\
   tests/misc/sort-stale-thread-mem.sh		\
   tests/misc/sort-unique.sh			\
diff --git a/tests/misc/shuf-rand-rngtest.sh b/tests/misc/shuf-rand-rngtest.sh
new file mode 100755
index 000..9ad2797
--- /dev/null
+++ b/tests/misc/shuf-rand-rngtest.sh
@@ -0,0 +1,78 @@
+#!/bin/sh
+# Test shuf's random output with rngtest
+#
+# NOTE:
+#  rngtest must be installed, or the test will be skipped.
+#  rngtest is available here: http://sourceforge.net/projects/gkernel/
+
+# Copyright (C) 2013 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see http://www.gnu.org/licenses/.
+
+. ${srcdir=.}/tests/init.sh; path_prepend_ ./src
+print_ver_ shuf
+expensive_
+
+if ! which rngtest  /dev/null ; then
+  skip_ rngtest not found - skipping test.
+fi
+
+# Test for randomness several times.
+# On the reare occasion when the randomly sorted data doesn't pass rngtest,
+# it should be just one failure out of 10 rounds.
+# If more rounds fail in a single run - there's likely a real problem.
+ROUNDS=10
+
+( yes 1 | head -n 1 ; yes 0 | head -n 1 )  in || framework_failure_
+
+# rgntest always reads the first 32 bits as bootstrap data
+printf \x00\x00\x00\x00  rngtest_header || framework_failure_
+
+
+# Sanity check:
+#  unsorted data should not be random
+cat in | tr -d '\n' | \
+   perl -npe '$_=pack(b*,$_)'  out_non_random || framework_failure_
+
+echo Testing rngtest on non-random input: 12
+cat rngtest_header out_non_random | rngtest 
+  { fail=1 ; echo rngtest failed to detect non-random data. 12 ; }
+
+#
+# Check randomness of shuf's output
+# (using the 'read-entire-file' code path)
+for i in $(seq $ROUNDS) ; do
+  cat in | shuf | tr -d '\n' | \
+   perl -npe '$_=pack(b*,$_)'  out_random$i || framework_failure_
+
+  echo Testing rngtest on randomly-sorted input (round $i of $ROUNDS): 12
+  cat rngtest_header out_random$i | rngtest ||
+  { fail=1 ; echo shuf random 

bug#13902: BUG : Option -k / --kibibytes no longer works with ls

2013-03-08 Thread Sebastien

Hi,

This is to tell you that option -k (--kibibytes) no longer works with 
the ls command.


Sample output:

$ ls -l
total 81644
drwxrwxr-x. 23 root root 4096 Dec  3 20:22 linux-3.7-rc8
-rw-rw-r--.  1 seb  seb  83581254 Dec  5 21:26 linux-3.7-rc8.tar.bz2
drwx--.  2 root root16384 May  9  2012 lost+found

$ ls -lk
total 81644
drwxrwxr-x. 23 root root 4096 Dec  3 20:22 linux-3.7-rc8
-rw-rw-r--.  1 seb  seb  83581254 Dec  5 21:26 linux-3.7-rc8.tar.bz2
drwx--.  2 root root16384 May  9  2012 lost+found


Tested on: Fedora 18 Spherical Cow with ls (GNU coreutils) 8.17.

Regards,
--
Sebastien GODARD
sebastien.god...@orange.fr





bug#13902: BUG : Option -k / --kibibytes no longer works with ls

2013-03-08 Thread Eric Blake
tag 13902 notabug
thanks

On 03/08/2013 01:09 AM, Sebastien wrote:
 Hi,
 
 This is to tell you that option -k (--kibibytes) no longer works with
 the ls command.

Thanks for the report.  However, according to NEWS, this was a bug fix
of coreutils 8.15:

  ls's -k option no longer affects how ls -l outputs file sizes.
  It now affects only the per-directory block counts written by -l,
  and the sizes written by -s.  This is for compatibility with BSD
  and with POSIX 2008.  Because -k is no longer equivalent to
  --block-size=1KiB, a new long option --kibibyte stands for -k.
  [bug introduced in coreutils-4.5.4]

 
 Sample output:
 
 $ ls -l
 total 81644
 drwxrwxr-x. 23 root root 4096 Dec  3 20:22 linux-3.7-rc8
 -rw-rw-r--.  1 seb  seb  83581254 Dec  5 21:26 linux-3.7-rc8.tar.bz2
 drwx--.  2 root root16384 May  9  2012 lost+found
 
 $ ls -lk
 total 81644
 drwxrwxr-x. 23 root root 4096 Dec  3 20:22 linux-3.7-rc8
 -rw-rw-r--.  1 seb  seb  83581254 Dec  5 21:26 linux-3.7-rc8.tar.bz2
 drwx--.  2 root root16384 May  9  2012 lost+found

This is the correct behavior required by POSIX when using 'ls -k'.  You
were relying on an alternate behavior, where it was a bug that -k
exposed the alternate behavior; but that alternate behavior is still
available to you if you use the proper spelling:

ls -l --block-size=k

Therefore, I'm closing this as not a bug.  Feel free to add further
comments or questions.

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature