-
Notifications
You must be signed in to change notification settings - Fork 0
/
timer_run_test.py
executable file
·134 lines (119 loc) · 6.43 KB
/
timer_run_test.py
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# ////////////////////////////////////////////////////////////////////////////////////////////////////
# Company: MICRO-ELECTRONICS RESEARCH LABORATORY //
# //
# Engineers: Auringzaib Sabir - Verification Engineer //
# //
# Additional contributions by: //
# //
# Create Date: 19-JAN-2022 //
# Design Name: Verification IP of timer //
# Module Name: run_test.py //
# Project Name: Verification of different peripheral devices //
# Language: Python //
# //
# Description: //
# This python script is used to automate the running of constraint random test for the //
# timer(DUT) by timer's verification IP. //
# //
# How to run? //
# //
# Excecute the following command //
# >> python run_test.py 100 //
# Here 100 means 100 contraint random tests will be generated by the timer's VIP //
# NOTE: All test are running on a random seed value //
# //
# Log of each random test that is run with a random seed is stored in a output directory (default //
# output directory is out) //
# NOTE: All test results are dumped in test_results.txt //
# //
# Revision Date: //
# //
# ////////////////////////////////////////////////////////////////////////////////////////////////////
import os
import shutil
import random
import sys
# Setting relative path (__file__)
ROOT_DIR = os.path.realpath(os.path.join(os.path.dirname(__file__), ""))
OUT = "out"
def run_test():
cmd = "python3 script.py"
print("Command to run = ", cmd)
os.system(cmd)
# Function to list number of sub directories in output directory
def list_immediate_sub_directories():
path = ROOT_DIR + "/" + OUT
print("Path to list the sub directories = ", path)
directory_contents = os.listdir(path)
print(directory_contents)
return directory_contents
def process_sub_dir(sub_directorires):
for item in sub_directorires:
print("\nFor seed directory =", item)
# Path to the xrun.log for specific item(seed directory)
path = ROOT_DIR + "/" + OUT + "/" + item + "/" + "xrun.log"
if os.path.isfile(path):
# Print path to log file
print("Path to log file in", item, "directory = ", path)
# file a string in log file to check either test pased or not
test_status = find_string("[TEST PASSED]", path)
# Dump results
dump_results(item, test_status)
# Print Test status
if test_status == 1:
print("TEST PASSED")
else:
print("TEST FAILED")
else:
print("Log file in", item, "directory does not exist")
# Dump the result in test_result file
def dump_results(item, test_status):
if test_status == 1:
f = open("test_results.txt", "a")
write_data = "Timer | Test status: Passed | ", item
f.write(str(write_data))
f.write("\n")
f.close()
else:
f = open("test_results.txt", "a")
write_data = "Timer | Test status: Failed | ", item
f.write(str(write_data))
f.write("\n")
f.close()
def find_string(string_to_find, in_file):
# opening a text file
file = open(in_file, "r")
# read file content
readfile = file.read()
# checking condition for string found or not
if string_to_find in readfile:
print("String", string_to_find, "Found In File")
return 1
else:
print("String", string_to_find, "Not Found")
return 0
# closing a file
file.close()
if __name__ == "__main__":
# Delete the previous output directory before running the latest tests
dir_path = ROOT_DIR + "/" + OUT
print("Printing directory path to remove =", dir_path)
if os.path.exists(dir_path):
shutil.rmtree(dir_path)
# Delete the previous test_results.txt file before dumping the latest tests results
file_path = ROOT_DIR + "/" + "test_results.txt"
print("Printing file path to remove =", file_path)
if os.path.exists(file_path):
os.remove(file_path)
# This is run-time argument, which can be set from command line to instruct how many tests to run
no_of_tests = sys.argv
# Converting this list object to integer
num_of_tests = int(no_of_tests[1])
print("number of test to run = ", num_of_tests)
# "num_of_tests" number of test to run
for x in range(num_of_tests):
run_test()
# Function to list number of sub directories in output directory
sub_directory_list = list_immediate_sub_directories()
# Process sub directories
process_sub_dir(sub_directory_list)