#!/usr/bin/env python

import sys
import os
import subprocess

def main():
    if len(sys.argv) != 3:
        print "Usage: run_gcov_batch.py <bin_path> <dir_to_input>"
        sys.exit(-1)

    bin_path = os.path.abspath(sys.argv[1])
    input_dir = os.path.abspath(sys.argv[2])

    for i in os.listdir(input_dir):
        if i == '.' or i == '..':
            continue

        print "running " + bin_path + " < " + os.path.join(input_dir, i)
        env = os.environ.copy()
        env["GDB_AUTO_EXEC"] = "1"
        env["GDB_BIN_FILE"]  = bin_path
        env["GDB_INPUT_FILE"] = os.path.join(input_dir, i)
        subprocess.call(["gdb"], env=env)

if __name__ == '__main__':
    main()

@@ -56,16 +56,33 @@
 rocess%0A%0A
+import argparse%0A%0A
 def main
@@ -89,121 +89,401 @@
 ():%0A
+%0A
     
-if len(sys.argv) != 3:%0A        print %22Usage: run_gcov_batch.py %3Cbin_path%3E %3Cdir_to_input%3E%22%0A        sys.exit(-1
+parser = argparse.ArgumentParser(usage=%22A tool for running gcov in batch%22)%0A    parser.add_argument(%22--bin_path%22, required=True, help=%22The path to the binary to run%22)%0A    parser.add_argument(%22--input_dir%22, required=True, help=%22The directory containing all the inputs%22)%0A    parser.add_argument(%22--cov_dir%22, help=%22The directory to put the coverage info files%22)%0A%0A    args = parser.parse_args(
 )%0A%0A 
@@ -494,16 +494,17 @@
 in_path 
+ 
 = os.pat
@@ -517,438 +517,1164 @@
 ath(
-sys.argv%5B1%5D)%0A    input_dir = os.path.abspath(sys.argv%5B2%5D)%0A%0A    for i in os.listdir(input_dir):%0A        if i == '.' or i == '..':%0A            continue%0A%0A        print %22running %22 + bin_path + %22 %3C %22 + os.path.join(input_dir, i)%0A        env = os.environ.copy()%0A        env%5B%22GDB_AUTO_EXEC%22%5D = %221%22%0A        env%5B%22GDB_BIN_FILE%22%5D  = bin_path%0A        env%5B%22GDB_INPUT_FILE%22%5D = os.path.join(input_dir, i)%0A        subprocess.call(%5B%22gdb%22%5D, env=env
+args.bin_path)%0A    # here we assume that the executable binary resides%0A    # in the bin directory of the challenge%0A    bin_root_dir = os.path.join(os.path.dirname(bin_path), '..')%0A    bin_filename = os.path.basename(bin_path)%0A    input_dir = os.path.abspath(args.input_dir)%0A    cov_dir   = os.path.abspath(args.cov_dir) if args.cov_dir is not None else %22lcov-%22 + bin_filename%0A%0A    if not os.path.exists(cov_dir):%0A        os.makedirs(cov_dir)%0A%0A    for i in os.listdir(input_dir):%0A        if i == '.' or i == '..':%0A            continue%0A%0A        print %22running %22 + bin_path + %22 %3C %22 + os.path.join(input_dir, i)%0A        env = os.environ.copy()%0A        env%5B%22GDB_AUTO_EXEC%22%5D = %221%22%0A        env%5B%22GDB_BIN_FILE%22%5D  = bin_path%0A        env%5B%22GDB_INPUT_FILE%22%5D = os.path.join(input_dir, i)%0A        null_fd = open(%22/dev/null%22, %22wb%22)%0A        # collect the coverage info%0A        subprocess.call(%5B%22gdb%22%5D, env=env, stdout=null_fd, stderr=null_fd)%0A        # generate lcov info%0A        subprocess.call(%5B'lcov', '-c', '--directory', bin_root_dir,%0A                         '--output-file', os.path.join(cov_dir, i + '.info')%5D,%0A                        stdout=null_fd, stderr=null_fd
 )%0A%0Ai

Update tools/research/run_gcov_batch.py