diff options
author | Hanoh Haim <hhaim@cisco.com> | 2015-12-28 11:35:04 +0200 |
---|---|---|
committer | Hanoh Haim <hhaim@cisco.com> | 2015-12-28 11:35:04 +0200 |
commit | 9d41785b3109b9ee6ee948c6d1040d1577567597 (patch) | |
tree | 1def083d510a770af68d9a124d7500080183473c /linux_dpdk | |
parent | 9d1cd91825d48a97ca0ea21fa7bd34900f6c7450 (diff) |
add coverity script
Diffstat (limited to 'linux_dpdk')
-rw-r--r-- | linux_dpdk/cov.py | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/linux_dpdk/cov.py b/linux_dpdk/cov.py new file mode 100644 index 00000000..6d23842c --- /dev/null +++ b/linux_dpdk/cov.py @@ -0,0 +1,134 @@ +# hhaim 2015 +import sys +import os +import argparse; +import uuid +import urllib2 + + + +H_COV_VER = "0.0.1" + +class cov_driver(object): + args=None; + + +BUILD_NUM_FILE = "../VERSION" + +COV_FILE_OUT = 'trex-64.bz2' + +#'http://www.python.org/' +def check_url_is_valid (url): + try: + f = urllib2.urlopen(url) + f.read() + return 0 + except : + return -1 + + +def get_build_num (): + s=''; + if os.path.isfile(BUILD_NUM_FILE): + f=open(BUILD_NUM_FILE,'r'); + s+=f.readline().rstrip(); + f.close(); + return s; + +def get_build_num_dis (): + return get_build_num ()+ "-"+str(uuid.uuid1()) + + +def process_options (): + parser = argparse.ArgumentParser(usage=""" + cov -b # build sa + cov -u #upload sa + """, + description="sa utility ", + epilog=" written by hhaim"); + + + parser.add_argument('-b', action='store_true', + help='build ') + parser.add_argument('-u', action='store_true', + help='upload ') + parser.add_argument('-nc', action='store_true', + help='build without clean ') + + parser.add_argument('--version', action='version', + version=H_COV_VER ) + + cov_driver.args = parser.parse_args(); + + + + +def run_cmd (cmd,is_exception=True): + print "run cmd '%s'" % (cmd) + res=os.system(cmd); + if is_exception and (res !=0): + s= "ERORR cmd return error !"; + raise Exception(s); + else: + print "OK" + + +def run_build (is_clean): + clean_str = "" + if is_clean : + clean_str = "clean" + cov_build_cmd = cov_driver.tool_path+"cov-analysis-linux64-7.7.0.4/bin/cov-build --dir cov-int ./b %s build --target=_t-rex-64" % (clean_str); + run_cmd(cov_build_cmd); + if os.path.isfile(COV_FILE_OUT) : + run_cmd(('rm %s' % COV_FILE_OUT)); + run_cmd("tar caf %s cov-int" % COV_FILE_OUT); + +def upload (): + if not os.path.isfile(COV_FILE_OUT) : + s="ERROR file %s does not exit try to build it " % (COV_FILE_OUT); + raise Exception (s) + if check_url_is_valid ('http://www.google.com/')<0: + s="ERROR, You are under firewall, try from another build server"; + raise Exception (s) + + ver=get_build_num_dis () + cmd='curl --form token=fRIZZCAGD9TnkSiuxXiEAQ --form email='+cov_driver.user_name+'@cisco.com --form file=@./'+COV_FILE_OUT+' --form version="'+ver+'" --form description="'+ver+'" https://scan.coverity.com/builds?project=cisco-system-traffic-generator%2Ftrex-core' + run_cmd(cmd); + +def check_env (env,err): + if os.environ.has_key(env) == False : + s= "ERROR you should define %s, %" % (env,err) + raise Exception(s); + + +def main_cov (): + args=cov_driver.args + + if args.b : + is_clean = not args.nc + run_build (is_clean) + + if args.u: + upload () + + +def main (): + try: + check_env ('NBAR_ENV',"should defined to the tools path") + check_env ('USER',"should be defined as your user name") + + cov_driver.tool_path=os.environ['NBAR_ENV'] + cov_driver.user_name=os.environ['USER'] + process_options () + main_cov () + exit(0); + except Exception, e: + print str(e); + exit(-1); + + + +if __name__ == "__main__": + main(); + + |