Lists the available tests based on either a local ./tests
directory, a global /opt/autotest/tests directory or the
packages AUTODIRTEST directory.

The output will list the test name and a description based on the
NAME field in the control file (or None if not found).

The way this works is we walk each of the above directories looking
for a "*control*" file.  The idea is each test has to have at least
a /control file.  Some times tests will have different variants. Hence
the wildcard approach.

Because printing out <test>/control seemed redundant and defeats the
point of the next command (run), any test directory that has a
/control file in it, we only print the <test> name instead of
<test>/control.  For the control file variants we print the whole thing.

Sample output:

List of found tests on the system
Unless otherwise specified, any output implies a /control file

globally imported tests (/opt/autotest/tests)
 None                                               [None]

autotest's prepackaged tests (/ssd/dzickus/git/autotest/client/tests)
 cpu_hotplug                                        ['cpu_hotplug']
 crashtest                                          ["Sleeptest"]
 crashtest/control2                                 ["Sleeptest"]
 disktest                                           ['Disktest']
 disktest/control.export                            ["Disktest using export"]
 error_test_fail                                    ["error test for FAIL"]
 error_test_na                                      ["error test for TEST_NA"]
 error_test_na/control2                             ["error test for top level 
TestNAError == TEST

Signed-off-by: Don Zickus <[email protected]>
---
 client/bin/autotest     |    2 +
 client/bin/cmdparser.py |   67 ++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 68 insertions(+), 1 deletions(-)

diff --git a/client/bin/autotest b/client/bin/autotest
index 1d19cba..a82b512 100755
--- a/client/bin/autotest
+++ b/client/bin/autotest
@@ -14,11 +14,13 @@ from autotest_lib.client.bin import cmdparser
 # directory and ensure we have $AUTODIR in our environment.
 autodirbin = os.path.dirname(os.path.realpath(sys.argv[0]))
 autodir = os.path.dirname(autodirbin)
+autodirtest = autodir + "/tests"
 
 sys.path.insert(0, autodirbin)
 
 os.environ['AUTODIR'] = autodir
 os.environ['AUTODIRBIN'] = autodirbin
+os.environ['AUTODIRTEST'] = autodirtest
 os.environ['PYTHONPATH'] = autodirbin
 
 parser = OptionParser(usage='Usage: %prog [options] <control-file>')
diff --git a/client/bin/cmdparser.py b/client/bin/cmdparser.py
index f2683f0..435e397 100644
--- a/client/bin/cmdparser.py
+++ b/client/bin/cmdparser.py
@@ -8,16 +8,47 @@
 import copy, os, platform, re, shutil, sys, time, traceback, types, glob
 import logging, getpass, errno, weakref
 
+LOCALDIRTEST = "/tests"
+GLOBALDIRTEST = "/opt/autotest/tests"
+
 class CommandParser():
     """A client-side command wrapper for newbies
 
     """
 
-    cmdlist = ['help']
+    cmdlist = ['help', 'list']
 
     def __init__(self):
         return
 
+    def __print_control_list(self, pipe, path):
+
+        if not os.path.isdir(path):
+            pipe.write(" %-50s [%s]\n" % ("None", "None"))
+            return
+
+        #The strategy here is to walk the root directory
+        #looking for "*control*" files in some directory
+        #and printing them out
+        for root, dirs, files in sorted(os.walk(path)):
+            for name in files:
+                if re.search("control", name):
+                    #strip full path
+                    r = re.sub(path + "/", "", root)
+                    text = "%s/%s" % (r, name)
+                    desc = "None"
+
+                    if name == "control":
+                        #imply /control by listing only directory name
+                        text = "%s" % r
+
+                    for line in open(root + "/" + name).readlines():
+                        if re.match("NAME", line):
+                            #we have a description line
+                            desc = re.split("=\s*", line, 
maxsplit=1)[1].rstrip()
+                            break
+                    pipe.write(" %-50s [%s]\n" % (text, desc))
+ 
     def parse_args(self, args):
         """
         Process a client side command
@@ -50,5 +81,39 @@ class CommandParser():
         """
 
         print "help\t\tOutput a list of supported commands"
+        print "list\t\tOutput a list of available tests"
         raise SystemExit(0)
 
+    def list(self, args):
+        """
+        List the available tests for users to choose from
+        """
+
+        #a favorite feature from git :-)
+        pipe = os.popen('less -FRSX', 'w')
+
+        pipe.write("List of found tests on the system\n")
+        pipe.write("Unless otherwise specified, any output implies a /control 
file\n")
+        pipe.write("\n")
+
+        #walk local ./tests directory
+        dirtest = os.environ['PWD'] + LOCALDIRTEST
+        #don't repeat autodirtest results
+        if not dirtest == os.environ['AUTODIRTEST']:
+            pipe.write("locally found tests (%s)\n" % dirtest)
+            self.__print_control_list(pipe, dirtest)
+            pipe.write("\n")
+
+        #walk globaldirtests directory
+        dirtest = GLOBALDIRTEST
+        pipe.write("globally imported tests (%s)\n" % dirtest)
+        self.__print_control_list(pipe, dirtest)
+        pipe.write("\n")
+
+        #walk autodirtest directory
+        dirtest = os.environ['AUTODIRTEST']
+        pipe.write("autotest's prepackaged tests (%s)\n" % dirtest)
+        self.__print_control_list(pipe, dirtest)
+
+        pipe.close()
+        raise SystemExit(0)
-- 
1.7.6.4

_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to