7
7
import sys
8
8
import argparse
9
9
import json
10
+ import os
11
+ import glob
12
+ import xml .etree .ElementTree as ET
10
13
11
14
from datetime import datetime , timedelta
12
15
@@ -50,34 +53,33 @@ def test_100_get_crash_count(self):
50
53
- Expected : crash count shall not be more than 5.
51
54
"""
52
55
# Arrange ------------------------------------------------------------------------
53
- from_ts = round (int (datetime .timestamp (datetime .now () - timedelta (seconds = 5 ))))
56
+ from_ts = round (int (datetime .timestamp (datetime .now () - timedelta (minutes = 1 ))))
54
57
header = {"Authorization" : self .access_token }
55
- node_id = 'BiPVyKJVAenRJaBMTZ7HzE '
58
+ node_id = 'eZzk4U2Xn4Aqwmitw4x6gc '
56
59
57
60
curr_ts = round (int (datetime .timestamp (datetime .now ())))
58
- max_time = 10 * 60 # duration in seconds
61
+ max_time = 10 * 60 # duration in seconds (10 minutes)
59
62
crash_count = 0
60
63
filt = '[{"f":"Node.ID","o":"keyword","v":["%s"]},{"f":"Type","o":"keyword","v":["crash"]}]' % node_id
61
64
encoded_filter = urllib .parse .quote (filt , safe = '~@#$&()*!+=:;,?/\' ' )
65
+
62
66
while (curr_ts - from_ts ) < max_time :
63
- print ("\n completed {} seconds out of {} crash count is {} " .format (curr_ts - from_ts , max_time , crash_count ))
64
67
url = self .diag_uri + "/query/filters/suggest?from_ts={}&to_ts={}&filters={}&fieldname=Type" .\
65
68
format (from_ts , curr_ts , encoded_filter )
66
69
# Act ----------------------------------------------------------------------------
67
70
resp_crash_filter = requests .get (url = url , verify = False , headers = header , cookies = None )
68
71
json_resp_crash_filter = json .loads (resp_crash_filter .text )["list" ]
69
-
70
72
# Assert -------------------------------------------------------------------------
71
73
self .assertEqual (resp_crash_filter .status_code , 200 , "S100.1 Unexpected status code for {} \n " .format (node_id ))
72
74
# Check if any crash is present
73
75
if len (json .loads (resp_crash_filter .text )["list" ]):
74
- self .assertEqual (json_resp_crash_filter ["key" ], "crash" , "S100.2 key is not present for {}" .format (node_id ))
75
- self .assertLessEqual (json_resp_crash_filter ["count" ], 5 , "S100.3 Crash count is not same as expected for {}" . format (node_id ))
76
- crash_count = json_resp_crash_filter ["count" ]
77
-
76
+ self .assertEqual (json_resp_crash_filter [0 ]["key" ], "crash" , "S100.2 key is not present for {}" .format (node_id ))
77
+ self .assertLessEqual (json_resp_crash_filter [0 ]["count" ], 5 , "S100.3 Crash count is not same as expected for {}" . format (node_id ))
78
+ crash_count = json_resp_crash_filter [0 ]["count" ]
78
79
# update variable curr_ts after every one minute
79
80
time .sleep (60 )
80
81
curr_ts = round (int (datetime .timestamp (datetime .now ())))
82
+ print ("\n Final crash count after 10 minutes is {} " .format (crash_count ))
81
83
82
84
83
85
if __name__ == '__main__' :
@@ -103,4 +105,35 @@ def test_100_get_crash_count(self):
103
105
suite = unittest .TestSuite ()
104
106
suite .addTest (TestCaseInsights ('test_100_get_crash_count' , ** kwargs ))
105
107
xmlrunner .XMLTestRunner (verbosity = 2 ).run (unittest .TestSuite (suite ))
108
+
109
+ # Test report generation
110
+ for ele in (os .listdir ()):
111
+ if ele .endswith ("xml" ):
112
+ os .system ("junit2html {} {}.html" .format (ele , os .path .splitext (ele )[0 ]))
113
+ # Parse the XML report
114
+ xml_report = ET .parse (ele )
115
+ failures = xml_report .findall ('.//failure' )
116
+ errors = xml_report .findall ('.//error' )
117
+ if len (failures ) > 0 or len (errors ) > 0 :
118
+ print ("Tests failed. see console log for details" )
119
+ sys .exit (1 )
120
+
121
+ # PATH of test reports generated by IDF unit tests
122
+ IDF_DIR = '../../../../esp-idf/TEST_LOGS'
123
+ xml_reports = glob .glob (os .path .join (IDF_DIR , '**/*.xml' ), recursive = True )
124
+ xml_file_path = os .path .abspath (xml_reports [0 ])
125
+
126
+ if not xml_file_path :
127
+ print ("XML reports of IDF unit tests not generated" )
128
+ sys .exit (1 )
129
+ else :
130
+ os .system ("junit2html {} {}.html" .format (xml_file_path , "unit_test_report" ))
131
+ # Parse the XML report
132
+ xml_report = ET .parse (xml_file_path )
133
+ failures = xml_report .findall ('.//failure' )
134
+ errors = xml_report .findall ('.//error' )
135
+ if len (failures ) > 0 or len (errors ) > 0 :
136
+ print ("Tests failed. see console log for details" )
137
+ sys .exit (1 )
138
+
106
139
sys .exit (0 )
0 commit comments