1. 程式人生 > >LTP-DDT測試核心後,整理summary的實現步驟

LTP-DDT測試核心後,整理summary的實現步驟

1、在測試Linux核心後將結果重定向到.txt檔案中,然後提取所用的資訊,如

Module SubModule AllTestSuite TotalCase RunTestSuit PassCase
ddt sata 20 0 0 0
ddt system 33 47 17 0
ddt nand 29 0 0 0
ddt pru 6 0 0 0
ddt eth 12 164 9 23
ddt usbhost 17 0 0 0
ddt powermgr 39 5 3 1
ddt uart 1 22 1 0
system realtime 34 38 16 36

使用python總結出來了,程式碼實現如下

#/usr/bin/python
#ecoding=utf-8
import os
import csv
def get_result(filepath):
    files = os.listdir(filepath)
    #系統級測試用例
system = ['cpuhotplug', 'ipc', 'math', 'mm', 'nptl', 'pipes', 'realtime', 'sched', 'syscalls', 'timers']
    subdict = {}  #字典用於儲存所有的數值
sublist = [] #用於儲存已經訪問的模組
casenum = {} #
用於記錄所有case的字典 skipnum = {} #用於記錄所有skip的字典 failuirenum = {} #用於記錄所有fail case的字典 module = '' #記錄module的名稱 rundict = {} #記錄已經執行的列表 with open('../get_summary.csv','wb') as csvfile: spamwriter = csv.writer(csvfile,dialect='excel') spamwriter.writerow(['Module','SubModule','AllTestSuite','TotalCase'
,'RunTestSuit','PassCase']) for fi in files: filename = os.path.splitext(fi)[0] #print filename submodule = filename.split("_")[0].split("-")[0] if submodule not in sublist: sublist.append(submodule) subdict[submodule] = 1 #總計所有case的初始化 casenum[submodule] = 0 #初始化skip case skipnum[submodule] = 0 #初始化failurecase failuirenum[submodule] = 0 #初始化rundict rundict[submodule] = 0 else: subnum = subdict[submodule] subnum = subnum + 1 subdict[submodule] = subnum file_dir = os.path.join(filepath,fi) #print file_dir fp = open(file_dir) for (num,value) in enumerate(fp): totaltest_index = value.find("Total Tests:") if totaltest_index != -1: test_num = value.split(" ")[2] #統計所有子模組的case casenum[submodule] = int(test_num) + casenum[submodule] rundict[submodule] = rundict[submodule] + 1 #print test_num skippedtest_index = value.find("Total Skipped Tests:") if skippedtest_index != -1: skiptest = value.split(" ")[3] #統計所有skip case skipnum[submodule] = int(skiptest) + skipnum[submodule] #print skiptest totalfail_index = value.find("Total Failures:") if totalfail_index != -1: failure_num = value.split(" ")[2] failuirenum[submodule] = int(failure_num) + failuirenum[submodule] print casenum print skipnum print failuirenum print subdict print rundict for list in sublist: if list in system: module = 'system' else: module = 'ddt' #'Module','SubModule','AllTestSuite','RunTestSuit','TotalCase','PassCase'] runcasenum = casenum[list] - skipnum[list] - failuirenum[list] spamwriter.writerow([ module, list, subdict[list], casenum[list], rundict[list], runcasenum]) get_result("../all_result")