Beispiel #1
0
def db_init(host, user, password, port=3306):
    try:
        conn = mdb.connect(host=host, user=user, passwd=password, port=port)
        conn.select_db("rts_db")
        return conn
    except mdb.Error, e:
        log("connect db(User: %s Password: %s Host: %s Port: %d) failed" % (user, password, host, port))
        return None
Beispiel #2
0
def compare_line_index(load_name, diff_list):

    log("compare %s" % load_name)
    #need try ... cache block 
    db_load = offical_load.objects.get(ats_load_name = load_name)

    case_list = rts_case.objects.filter(ats_load_fk = db_load.id)
    
    choiced_case_list = []
    stat_info_list = []
    log("start compare ... ")
    for each_diff in diff_list:
        #each_diff.print_modified_no()
        
        for each_case in case_list:
            case_select_flag = False
            case_buf = case_info(load_name, each_case.ats_case_id)
            stat_info_list.append(case_buf)
            
            #log("caseid = %d, src_name = %s" % (each_case.id, os.path.basename(each_diff.file_name)))
            db_src_list = src_file.objects.filter(ats_case_fk = each_case.id, \
                            ats_src_name = os.path.basename(each_diff.file_name))
            if len(db_src_list) != 1:

                #log("src file list len = %d" % len(db_src_list))
                continue
            #log("caseid = %s, src_name = %s" % (each_case.ats_case_id, os.path.basename(each_diff.file_name)), color='red')
            db_src = db_src_list[0]
            file_buf = file_info(db_src.ats_src_name)
            for each_diff_line in each_diff.old_no_list:
                
                db_line_list = line_executed.objects.filter(ats_src_file_fk = db_src.id, \
                                ats_line_num = each_diff_line)
                if len(db_line_list) == 1:
                    #log("srcid = %d, line number = %d" % (db_src.id, each_diff_line), color='red')
                    db_line = db_line_list[0]
                    choiced_case_list.append(each_case.id)
                    case_select_flag = True
                    file_buf.add_line_no(db_line.ats_line_num)
                    
                    log("matched load %s case %s file %s line %d modified !" % \
                        (db_line.ats_load_name, db_line.ats_case_id, db_src.ats_src_name, db_line.ats_line_num), color='white') 
                    break
                else:
                    pass
            if file_buf.file_line_count() > 0:
                #case_buf.get_file_list().append(file_buf)
                case_buf.add_src_file(file_buf)

            if case_select_flag == True:
                log("This case has been slelected ... ", color='red')
                break

    log("end compare ... ")
    return stat_info_list
Beispiel #3
0
def main():
    db_conn = db_init(rcfg["db_host"], rcfg["db_user"], rcfg["db_password"], rcfg["db_port"])
    if db_conn == None:
        log("connect to db failed, exit ...")
        return
    else:
        pass

    add_action(db_conn, rcfg["prj_root"], rcfg["prj_src_tail"], rcfg["gcov_path"])

    db_conn.commit()
    db_conn.close()
    """        
Beispiel #4
0
def clean_foot(path):
    log("clean foot at %s" % path)

    if os.path.exists(path):
        pass
    else:
        print "%s is not exist" % path
        return

    gcov_num = commands.getoutput("find %s -name '*.gcov' | wc -l" % path)
    gcda_num = commands.getoutput("find %s -name '*.gcda' | wc -l" % path)
    log("gcov files number %s, gcda files number %s" % (gcov_num.strip("\n"), gcda_num.strip("\n")))
    # time.sleep(3)
    os.system("find %s -name '*.gcov' -o -name '*.gcda' | xargs rm " % path)
Beispiel #5
0
    def save(self):
        self.cur.execute(
            "insert into db_src_file \
                    (ats_case_fk_id, ats_load_name, ats_case_id, ats_path_name, ats_src_name, ats_timestamp) \
                    value(%d, '%s', '%s', '%s', '%s', now())"
            % (
                self._case_info.id,
                self._load_info.ats_load_name,
                self._case_info.ats_case_id,
                self._src_file_name,
                self.src_name,
            )
        )

        count = self.cur.execute(
            "select id from db_src_file where ats_case_fk_id = %d and ats_path_name = '%s' LIMIT 1"
            % (self._case_info.id, self._src_file_name)
        )

        if count == 1:
            src_file_id = self.cur.fetchone()
        else:
            log("fetch src file id failed, insert failed")
            return

        for key in self.data:

            self.cur.execute(
                "insert into db_line_executed(ats_src_file_fk_id, ats_load_name, \
                                ats_case_id, ats_path_name, ats_line_num, ats_exec_count, ats_timestamp) \
                                value(%d, '%s', '%s', '%s', %d, %d, now())"
                % (
                    src_file_id[0],
                    self._load_info.ats_load_name,
                    self._case_info.ats_case_id,
                    self._src_file_name,
                    int(key),
                    int(self.data[key]),
                )
            )

        """
Beispiel #6
0
def flush_gcda_files_from_specific_dir(path, *specific_dirs):
    spec_dir_array = []

    gcov_num = commands.getoutput("find %s -name '*.gcov' | wc -l" % path)
    gcda_num = commands.getoutput("find %s -name '*.gcda' | wc -l" % path)
    log("flush gcda files\n\tgcov files number %s, gcda files number %s" % (gcov_num.strip("\n"), gcda_num.strip("\n")))

    for each_xarg in specific_dirs:
        spec_dir_array.append(each_xarg)

    if len(spec_dir_array) != 0:
        for each_spec_dir in spec_dir_array:
            flush_gcda_to_gcov(path + "/" + each_spec_dir)

    else:
        print "No specific directory. visit all directory"
        for root, dirs, files in os.walk(path):
            if ".svn" in dirs:
                dirs.remove(".svn")
            for each_dir in dirs:
                flush_gcda_to_gcov("%s/%s" % (root, each_dir))
Beispiel #7
0
def add_action(db_conn, prj_path, prj_src_path_tail, log_path):
    # load_info = offical_load(ats_load_name = load_name)
    # load_info.save()
    # os.system('rm -rf %s/%s' % (log_path, prj_name))
    for gcda_log_dir in os.listdir(log_path):
        result = re.search(r"finished", gcda_log_dir)
        if result:
            print " %s has been processed. skip it" % gcda_log_dir
            continue

        name_backup = gcda_log_dir
        load_id, case_id, time_stamp = gcda_log_dir.split("__")

        load_list = offical_load.objects.filter(ats_load_name=load_id)
        if len(load_list) == 1:
            load_info = load_list[0]
        else:
            load_info = offical_load(ats_load_name=load_id)
            load_info.save()

        case_info = rts_case(ats_case_id=case_id, ats_load_name=load_info.ats_load_name, ats_load_fk=load_info)
        case_info.save()

        log("mv %s/%s %s/%s" % (log_path, gcda_log_dir, log_path, load_id))
        os.rename("%s/%s" % (log_path, gcda_log_dir), "%s/%s" % (log_path, load_id))
        log("cp -rfp %s/%s %s" % (log_path, load_id, prj_path))
        os.system("cp -rfp %s/%s %s" % (log_path, load_id, prj_path))

        prj_src_dir = "%s/%s/%s" % (prj_path, load_id, prj_src_path_tail)
        print "project src path %s" % prj_src_dir

        # flush_gcda_files_from_specific_dir(prj_src_dir, 'application', 'XuanWu')
        flush_gcda_files_from_specific_dir(prj_src_dir)
        # gcov process
        parse_gcov_file(load_info, case_info, prj_src_dir, db_conn)
        clean_foot(prj_src_dir)
        os.rename("%s/%s" % (log_path, load_id), "%s/%s.finished" % (log_path, name_backup))
    def parse_section(self):
        try:
            for line in self.section.split("\n"):
                # get the source file name
                if line[0:7] == "Index: ":
                    m = re.match(r"Index: (?P<name>.*)$", line)
                    if m:
                        self.file_name = m.group("name")
                    else:
                        log("get source file failed")

                elif line[0:5] == "=====":
                    pass

                # get version
                elif line[0:3] == "---":
                    m = re.match(r"[^(]*([^)]*)", line)
                    if m:
                        self.version = m.group(1)[1:]
                    else:
                        log("get version failed")

                elif line[0:3] == "+++":
                    pass

                elif line[0:2] == "@@":
                    m = re.match(r"@@ (?P<f>.*) @@", line)
                    if m:
                        # print m.group('f')
                        src_line = m.group("f")
                        old_tmp, new_tmp = m.group("f").split()
                        try:
                            old_no, old_line = old_tmp[1:].split(",")
                            new_no, new_line = new_tmp[1:].split(",")
                            # self.old_line = int(old_line)
                            # self.new_line = int(new_line)
                        except ValueError, e:
                            # log("This is a special ")
                            old_no = old_tmp[1:]
                            new_no = new_tmp[1:]
                            # self.old_line = 0
                            # self.new_line = 0

                        self.cur_old_no = int(old_no) - 1
                        self.cur_new_no = int(new_no) - 1

                elif line[0] in (" ", "-", "+"):
                    if line[0] == " ":
                        self.cur_old_no += 1
                        self.cur_new_no += 1
                        self.pn_flag = False

                    elif line[0] == "-":
                        self.cur_old_no += 1
                        self.old_no_list.append(self.cur_old_no)

                    elif line[0] == "+":
                        self.cur_new_no += 1
                        self.new_no_list.append(self.cur_new_no)
                        if self.pn_flag:
                            pass
                        else:
                            self.pn_flag = True
                            self.old_no_list.append(self.cur_old_no)

                    else:
                        print "May be some error occurent (inner) ... "
                else:
                        self.cur_old_no += 1
                        self.old_no_list.append(self.cur_old_no)

                    elif line[0] == "+":
                        self.cur_new_no += 1
                        self.new_no_list.append(self.cur_new_no)
                        if self.pn_flag:
                            pass
                        else:
                            self.pn_flag = True
                            self.old_no_list.append(self.cur_old_no)

                    else:
                        print "May be some error occurent (inner) ... "
                else:
                    log(line)
                    print "May be some error occurent (outer) ... "

        except IndexError, result:
            # log("This section is finished. return ")
            pass


def svn_diff(branch1, branch2):
    """svn diff, got the diff file """
    diff1 = os.path.basename(branch1)
    diff2 = os.path.basename(branch2)
    diff1 = diff1.replace("-", ".")
    diff2 = diff2.replace("-", ".")

    # print '%s  %s' % (diff1, diff2)
Beispiel #10
0
    def parse_section(self):
        try:
            for line in self.section.split('\n'):
                #get the source file name
                if line[0:7] == 'Index: ':
                    m = re.match(r'Index: (?P<name>.*)$', line)
                    if m:
                        self.file_name = m.group('name')
                    else:
                        log("get source file failed")

                elif line[0:5] == '=====':
                    pass

                #get version
                elif line[0:3] == '---':
                    m = re.match(r'[^(]*([^)]*)', line)
                    if m:
                        self.version = m.group(1)[1:]
                    else:
                        log("get version failed")
                        
                elif line[0:3] == '+++':
                    pass
                    
                elif line[0:2] == '@@':
                    m = re.match(r'@@ (?P<f>.*) @@', line)
                    if m:
                        #print m.group('f')
                        src_line = m.group('f')
                        old_tmp, new_tmp = m.group('f').split()
                        try:
                            old_no, old_line = old_tmp[1:].split(',')
                            new_no, new_line = new_tmp[1:].split(',')
                            #self.old_line = int(old_line)
                            #self.new_line = int(new_line)
                        except ValueError, e:
                            #log("This is a special ")
                            old_no = old_tmp[1:]
                            new_no = new_tmp[1:]
                            #self.old_line = 0
                            #self.new_line = 0

                        self.cur_old_no = int(old_no) - 1
                        self.cur_new_no = int(new_no) - 1
                    
                elif line[0] in (' ', '-', '+'):
                    if line[0] == ' ':
                        self.cur_old_no += 1
                        self.cur_new_no += 1

                    elif line[0] == '-':
                        self.cur_old_no += 1
                        self.old_no_list.append(self.cur_old_no)

                    elif line[0] == '+':
                        self.cur_new_no += 1
                        self.new_no_list.append(self.cur_new_no)

                    else:
                        print 'May be some error occurent (inner) ... '
                else: