Fixing error in argument parsing
The change in r3354 caused the --tool argument to not be parsed if it's passed after the test executable. Then it's considered an argument to the test rather than a script flag.
This CL cleans the code a bit and makes it possible to pass all the supported argument in the different ways possible.
NOTICE: To pass arguments to the test executable, you must use the -- argument must be specified before the test arguments start, to signal that everything that comes after it are positional arguments only (which are passed on to the test during execution).
BUG=none
TEST=The following combinations have been tested:
tools/valgrind-webrtc/webrtc_tests.sh -b out/Debug -t test_support_unittests --tool asan
tools/valgrind-webrtc/webrtc_tests.sh -b out/Debug -t test_support_unittests --tool asan -- --foo --bar
tools/valgrind-webrtc/webrtc_tests.sh --tool asan -b out/Debug -t test_support_unittests
tools/valgrind-webrtc/webrtc_tests.sh --tool asan -b out/Debug -t test_support_unittests -- --foo --bar
Review URL: https://webrtc-codereview.appspot.com/1026005
git-svn-id: http://webrtc.googlecode.com/svn/trunk@3355 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/tools/valgrind-webrtc/webrtc_tests.py b/tools/valgrind-webrtc/webrtc_tests.py
index d97dff2..f4ca611 100755
--- a/tools/valgrind-webrtc/webrtc_tests.py
+++ b/tools/valgrind-webrtc/webrtc_tests.py
@@ -105,17 +105,14 @@
parser.error('--test not specified')
# If --build_dir is provided, prepend it to the test executable if needed.
- if options.build_dir and not args[0].startswith(options.build_dir):
- args[0] = os.path.join(options.build_dir, args[0])
+ test_executable = options.test
+ if options.build_dir and not test_executable.startswith(options.build_dir):
+ test_executable = os.path.join(options.build_dir, test_executable)
+ args = [test_executable] + args
- test = WebRTCTest(options, args, options.test)
+ test = WebRTCTest(options, args, 'cmdline')
return test.Run()
if __name__ == '__main__':
- # We do this so the user can write -t <binary> instead of -t cmdline <binary>.
- if '-t' in sys.argv:
- sys.argv.insert(sys.argv.index('-t') + 1, 'cmdline')
- elif '--test' in sys.argv:
- sys.argv.insert(sys.argv.index('--test') + 1, 'cmdline')
return_code = main(sys.argv)
sys.exit(return_code)