[Toybox] acpi.test, Ifconfig.test fixes

2014-12-01 Thread Cynt Rynt
Hi,

Attached is a patch that adds a first stab at a testsuite for the acpi
utility, and a patch that fixes some of the issues with the ifconfig
testsuite.

1. Changed the context again... I tried running the tests on aboriginal
Linux, but it said there was no ip command, nor modprobe, which are two
alternatives to getting the dummy interface running.  I didn't have much
success with the static-tools.hdc, but it said it couldn't find toybox, but
I tested the testsuite on Kali by invoking sudo make tests... hopefully
will work on platforms other than Kali.

2. Corrected the pretext of the pointotpoint tests
3. Corrections to the pointopoint tests -- spelling, intent, etc.
After playing with ifconfig all weekend, I've come to the grand conclusion
I can't find a way to get ifconfig pointopoint to set the POINTOPOINT
flag... The POINTOPOINT flag appears to be treated as an immutable feature
of the interface by ifconfig.

Other people in the past had the same issue.
http://www.linuxmisc.com/2-linux-networking/ccf70d924f2c289c.htm ,
http://www.linuxmisc.com/2-linux-networking/075ce6d1d544e8fb.htm

ifconfig interface localaddress pointopoint remoteaddress can be used
to configure ip address for tunnels (for Kali at least)...

So if ifconfig is changed to match the documentation, it will not match
Kali, and thus probably not Debian.  Another option could be to clarify the
documentation...

Having gone through all that, and becoming slightly disappointed, I've
rewritten the ifconfig tests to reflect the defacto standard, over the
documentation, but the test can always be rewritten to reflect the
documentation over the defacto standard... if that's desired.

ACPI tests: according to Isaac Dunham, the author of the acpi utility,
there is no standard, so I compared the implemented features to their
counterparts implemented in Kali. The results were very satisfactory -- I
could use no options, reversed options, and got help when using illegal
options.

What would make the developing the tests much easier is a prebuilt image
with toybox configured with an allyesconfig (without nfs or nsenter, as
they don't seem to build on Kali).

Hope this helps,
Cindy
diff -r 4faace2c5245 tests/acpi.test
--- /dev/null   Thu Jan 01 00:00:00 1970 +
+++ b/tests/acpi.test   Sun Nov 30 06:46:26 2014 -0800
@@ -0,0 +1,55 @@
+#!/bin/bash
+#
+# Copyright 2014 Cynthia Rempel cynt...@rtems.org
+#
+# Purpose: Tests the acpi command.
+# Requires: grep -i, head -n, wc -l
+
+[ -f testing.sh ]  . testing.sh
+
+#testing name command result infile stdin
+
+# Test Description: Call acpi with no arguments
+# Results Expected: The battery percentage
+testing acpi no arguments acpi | grep -i \Battery\ *[0-9]:\ 
*[0-9][0-9]*%\ | head -n 1 | wc -l \
+   1\n  
+
+# Test Description: Get the power adapters' status
+# Results Expected: Whether the adapters were online or offline
+testing acpi -a acpi -a | grep -i \Adapter\ *[0-9]*:\ *.*\-line\ | head 
-n 1 | wc -l \
+   1\n  
+
+# Test Description: Get the status of the batteries
+# Results Expected: The battery percentage
+testing acpi -b acpi -b | grep -i \Battery\ *[0-9]:\ *[0-9][0-9]*%\ | 
head -n 1 | wc -l \
+   1\n  
+
+# Test Description: Get descriptions of the cooling devices
+# Results Expected: A list of descriptions for cooling devices
+testing acpi -c acpi -c | grep -i \Cooling\ *[0-9]:\ .*\ | head -n 1 | wc 
-l \
+1\n  
+
+# Test Description: Get the temperature
+# Results Expected: A list of readings from temperature sensors
+testing acpi -t acpi -t | grep -i \Thermal\ *[0-9]:\ .*degrees\ | head -n 
1 | wc -l \
+1\n  
+
+# Test Description: Call acpi verbose
+# Results Expected: The battery percentage
+testing acpi -V battery percentage acpi -V | grep -i \Battery\ *[0-9]:\ 
*[0-9][0-9]*%\ | head -n 1 | wc -l \
+1\n  
+
+# Test Description: Get the power adapters' status
+# Results Expected: Whether the adapters were online or offline
+testing acpi -ab acpi -ab | grep -i \Adapter\ *[0-9]*:\ *.*\-line\ | head 
-n 1 | wc -l \
+1\n  
+
+# Test Description: Get the status of the batteries
+# Results Expected: The battery percentage
+testing acpi -ba acpi -ba | grep -i \Battery\ *[0-9]:\ *[0-9][0-9]*%\ | 
head -n 1 | wc -l \
+1\n  
+
+# Test Description: Call an unknown option
+# Results Expected: The usage sent to standard error
+testing acpi -bh acpi -bh | grep -i \usage\ | head -n 1 | wc -l \
+1\n  
diff -r 4faace2c5245 tests/ifconfig.test
--- a/tests/ifconfig.test   Thu Nov 27 00:28:13 2014 -0600
+++ b/tests/ifconfig.test   Sun Nov 30 21:02:57 2014 -0800
@@ -2,8 +2,8 @@
 # Copyright 2014 Cynthia Rempel cynt...@rtems.org
 #
 # Brief: Some cursery coverage tests of ifconfig...
-# Note: requires permissions to run modprobe and all ifconfig options
-# Commands used: grep, grep -i, ip link, ip tuntap, wc -l
+# Note: requires permissions to run all ifconfig options
+# Commands used: grep, grep -i, ip li add dummy, wc -l
 #
 # 

Re: [Toybox] What does the du.c patch do?

2014-12-01 Thread Ashwini Sharma
Hi Rob,

My patch was


+// is recursive tree
+static int is_recursive_loop(struct dirtree *node)
+{
+  struct dirtree *tmp = node;
+
+  while ((tmp = tmp-parent)) {
+if ((tmp-st.st_ino == node-st.st_ino) 
+(tmp-st.st_dev == node-st.st_dev))
+  return 1;
+  }
+  return 0;
+}
+
 // dirtree callback, comput/display size of node
 static int do_du(struct dirtree *node)
 {
@@ -114,6 +127,8 @@
   if (!(toys.optflags  FLAG_l)  !node-again)
 if (seen_inode(TT.inodes, node-st)) return 0;

+  if (is_recursive_loop(node)) goto ADD;
+
   // Collect child info before printing directory size
   if (S_ISDIR(node-st.st_mode)) {
 if (!node-again) {
@@ -121,7 +136,7 @@
   return DIRTREE_COMEAGAIN | (DIRTREE_SYMFOLLOW*!!(toys.optflags 
FLAG_L));
 } else TT.depth--;
   }
-
+ADD:
   node-extra += node-st.st_blocks;
   if (node-parent) node-parent-extra += node-extra;

and not the one you mentioned.

This patch is handling the case, of self point symlinks.

$ mkdir sub
$ cd sub
$ ln -s ../sub lnk
$ cd ../
$ du -L sub

without my patch it will keep looping. This patch stops from this looping.

Thanks,
Ashwini

On Sun, Nov 30, 2014 at 6:03 AM, Rob Landley r...@landley.net wrote:

 Going through Ashwini's patch stack from last month. (Sorry for the delay,
 but I think I applied all the trivial ones in earlier passes.)

 What does the du.c patch do?

   $ mkdir sub
   $ ln -s . sub/here
   $ ln -s loop sub/loop
   $ ./toybox du sub
   4 sub

 There's also a hardlink filter (disabled via -l)...

 I'm tempted to add the following to lib/dirtree.c

 +// Have we already seen this node?
 +int dirtree_seen(struct dirtree *try, struct stat *st)
 +{
 +  while (try) {
 +if (try-st.st_ino==st-st_ino  try-st.st_dev==st-st_dev) return
 1;
 +try = try-parent;
 +  }
 +
 +  return 0;
 +}
 +

 But the existing user I can think of that's already doing this is in cp.c:

 // Detect recursive copies via repeated top node (cp -R .. .) or
 // identical source/target (fun with hardlinks).
 if ((TT.top.st_dev == try-st.st_dev  TT.top.st_ino == try-st.st_ino
   (catch = TT.destname))
 || (!fstatat(cfd, catch, cst, 0)  cst.st_dev == try-st.st_dev
   cst.st_ino == try-st.st_ino))
 {
   error_msg('%s' is '%s', catch, err = dirtree_path(try, 0));
   free(err);

   return 0;
 }

 Which seems to work?

 Anyway, could you give me a testcase where the du.c patch you submitted
 makes a
 difference?

 Rob

___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] What does the du.c patch do?

2014-12-01 Thread Rob Landley
On 12/01/14 05:40, Ashwini Sharma wrote:
 Hi Rob,
...
 $ du -L sub
 
 without my patch it will keep looping. This patch stops from this looping.
 
 Thanks,
 Ashwini

Ah, you're fixing the -L case. (I'd mentally written that off as pilot
error, but I see Ubuntu's du implementation doesn't loop.)

Ok, thanks. I understand now.

Rob
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] expr horizontal lines in extended description?

2014-12-01 Thread Rob Landley
Clarification received from The Austin Group.

(Unfortunately the PDF he mentions costs $2500, and is thus completely
irrelevant in 2014.)

On 12/01/14 09:46, Geoff Clare wrote:
 Rob Landley r...@landley.net wrote, on 29 Nov 2014:

 In http://pubs.opengroup.org/onlinepubs/9699919799/utilities/expr.html
 the extended description says that operators of equal precedence are
 separated by horizontal lines.

 It's an html table, all the entries are separated by horizontal lines. I
 know that * and / are of equal precedence by poking at the gnu/dammit
 implementation of expr, but I dunno how to tell that from the spec?
 
 This is a limitation of the HTML translation.  In the PDF the table
 only has horizontal lines between groups of entries, as follows (just
 showing the operator, for brevity):
 
 
  |
 
  
 
  =
  
  =
  
  =
  !=
 
  +
  -
 
  *
  /
  %
 
  :
 
 (expr)
 
 integer
 string
 
 
 The PDF version always takes precdence over the HTML version.
 
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net