On 11/04/2011 07:01 PM, Don Zickus wrote: > I wanted to expand autotest to be able to run tests outside the scope > of the source tree. Not all tests will are appropriate nor are able > to be public. > > I am also lazy, so typing full paths to those tests is annoying. > As a result, I came up with a shortcut 'run' command. This command > takes a test (plus its normal arguments) and tries to locate it in > a list of paths (./tests, /opt/autotest/tests, AUTODIRTEST). If > found, it prepends the path to the test arg and returns it back to > autotest for processing. > > Doing it this way allows autotest to function like it always has > with the 'run' command acting like an alias lookup. > > This allows one to do something like: > > autotest run sleeptest<args> > > and the parser will find the correct path and return this: > > autotest<source tree>/client/tests/sleeptest/control<args> > > NOTE: I extend my laziness by implying a /control to any > test that does not provide a "*control*" in the test name. > > However, you can still do this: > > autotest run sleeptest/control2<args> > > and it will do the right thing: > > autotest<source tree>/client/tests/sleeptest/control2<args>
Ok, this also looks good to me. > Signed-off-by: Don Zickus<[email protected]> > --- > client/bin/cmdparser.py | 34 +++++++++++++++++++++++++++++++--- > 1 files changed, 31 insertions(+), 3 deletions(-) > > diff --git a/client/bin/cmdparser.py b/client/bin/cmdparser.py > index 435e397..bc6be69 100644 > --- a/client/bin/cmdparser.py > +++ b/client/bin/cmdparser.py > @@ -16,7 +16,7 @@ class CommandParser(): > > """ > > - cmdlist = ['help', 'list'] > + cmdlist = ['help', 'list', 'run'] > > def __init__(self): > return > @@ -68,6 +68,7 @@ class CommandParser(): > sys.exit(e) > except: > sys.stderr.write("Failed: command %s\n" % cmd) > + self.help(args) > sys.exit(1) > > # args are cleaned up, return to process the traditional way > @@ -80,8 +81,9 @@ class CommandParser(): > @param args is not used here > """ > > - print "help\t\tOutput a list of supported commands" > - print "list\t\tOutput a list of available tests" > + print "help\t\t\tOutput a list of supported commands" > + print "list\t\t\tOutput a list of available tests" > + print "run<test> [<args>]\tFind given<test> in path and run with > args" > raise SystemExit(0) > > def list(self, args): > @@ -117,3 +119,29 @@ class CommandParser(): > > pipe.close() > raise SystemExit(0) > + > + def run(self, args): > + """ > + Wrap args with a path and send it back to autotest > + """ > + > + if not len(args): > + self.help(args) > + > + test = args.pop(0) > + > + #autotest works on control files > + if not re.search("control", test): > + test = test + "/control" > + > + localdir = os.environ['PWD'] + LOCALDIRTEST > + globaldir = GLOBALDIRTEST > + autodir = os.environ['AUTODIRTEST'] > + > + for dirtest in [localdir, globaldir, autodir]: > + if os.path.isfile(dirtest + "/" + test): > + args.insert(0, dirtest + "/" + test) > + return args > + > + print "Can not find test %s" % test > + raise _______________________________________________ Autotest mailing list [email protected] http://test.kernel.org/cgi-bin/mailman/listinfo/autotest
