aboutsummaryrefslogtreecommitdiffstats
path: root/Ptest_Result_Comparison.py
blob: f36774153103b8fe6c79c2d1393e54e528e7efb0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
################## pTest result comparison script#################

# This script lists the degradation of the ptest results of the required 'package(s)' of the current release when compared with that of the previous release  
# This script takes the ptest results of the previous and current releases for comparison as input and creates a comparision.txt log file 
# Script prints test cases which PASS in the previous release but FAIL in the current release 
# An output text file, containing the final result is generated after the successfull execution of script.
# package_list needs to be updated if there is a modification in the package  
# Script is tested on Ubuntu version 16.04

import os,sys
previous_release_file = raw_input("Enter complete path for previous release file: ")
current_release_file = raw_input("Enter complete path for current release file: ")

# Command to generate the .txt comparison log file from previous and current release's ptest logs. 
cmd = ("git diff " + previous_release_file + " " + current_release_file + ">" + " ptest_comparision_log.txt")
os.system(cmd)

test_num1 = 0
test_num2 = 0
count = 0
package_name = raw_input('Enter the package name to be compared:')

comparision_file = open("ptest_comparision_log.txt","r+")

package_list = []
for line in comparision_file:
	if ("BEGIN: " in line):
		x=line.split("/")[3].strip()
		package_list.append(x)

# checking if package name is correctly entered or not
while (package_name not in package_list):
	print "package name is not found. Please enter the correct package name."
	package_name = raw_input("Enter the package name to be compared:")

beginning = ("BEGIN: /usr/lib/" + package_name + "/ptest")
ending=("END: /usr/lib/" + package_name + "/ptest")
# if package name is entered correctly 
comparision_file = open("ptest_comparision_log.txt","r+")
# directing the result for previous release passed test cases into a output_pass.txt
output_pass=open("output_pass.txt","w+")
for line in comparision_file:
	if beginning in line :
		print >> output_pass, "----------------------------------------------------------"
		print >> output_pass, "Package Name: ",package_name
		print >> output_pass, "----------------------------------------------------------"
		print >> output_pass, "checking for test cases passed in previous release: "
		print >> output_pass, " "
		for  line in comparision_file:
			if ending in line:
				print >> output_pass, "----------------------------------------------------------"
				print >> output_pass, "TOTAL PASSED IN PREVIOUS RELEASE: ",test_num1
				print >> output_pass, "----------------------------------------------------------"
				break
			elif ("-PASS:" in line):
				print  >> output_pass, line
				test_num1 = test_num1+1
			else:
				pass
comparision_file.close()

comparision_file = open("ptest_comparision_log.txt","r+")
# directing the result for current release failed test cases into a output_fail.txt
output_fail = open("output_fail.txt","w+")
for line in comparision_file:
	if beginning in line :
		print >> output_fail, "----------------------------------------------------------"
		print >> output_fail, "Package Name: ",package_name
		print >> output_fail, "----------------------------------------------------------"
		print >> output_fail, "checking for test cases failed in current release: "
		print >> output_fail, " "
		for line in comparision_file:
			if ending in line:
				print >> output_fail, "----------------------------------------------------------"
				print >> output_fail, "TOTAL FAILED IN CURRENT RELEASE: ",test_num2
				print >> output_fail, "----------------------------------------------------------"
				break
			elif ("+FAIL:" in line):
				print >> output_fail, line
				test_num2 = test_num2+1
			else:
				pass

# directing the result of output_pass.txt and output_fail.txt for the same test cases into a output_file.txt
output_file = open("output.txt","w+")
print >> output_file, "--------------------------------------------------------------------------------------"
print >> output_file, "Package Name: ",package_name
print >> output_file, "--------------------------------------------------------------------------------------"

with open("output_pass.txt", "r") as output_pass:
	for line1 in output_pass:
		if "PASS:" in line1:
			match = line1.split(":")[-1].strip()
			with open("output_fail.txt","r") as output_fail:
				for line2 in output_fail:
					if match in line2:
						count = count+1
						print >> output_file, line1
						print >> output_file, line2
						break
					else:
						pass

output_file=open("output.txt","a+")
print  >> output_file, "---------------------------------------------------------------------------------------"
print >> output_file,"Total number of test cases passing in Previous release but failing in Current release: ",count
print  >> output_file, "---------------------------------------------------------------------------------------"
output_file.close()

# printing the result of output.txt on the terminal	
output_file=open("output.txt","r+")
output_file_contents = output_file.read()
print (output_file_contents)
output_file.close()