Good one.
Kaitlin Rupert wrote:
# HG changeset patch
# User Kaitlin Rupert <karupert(a)us.ibm.com>
# Date 1252022738 25200
# Node ID 2d852ba88fd24102ec988145e464a13f5faae5c0
# Parent db3af9cb2c9affb0a32a8ea3a2c23648c5efe91e
[TEST] Add timestamps to main.py to calculate run time of tests
These changes allow the user to specify the --print-exec-time flag, which will
print the execution time of each test. If this flag isn't specified, the
total run time of the test is still printed.
Signed-off-by: Kaitlin Rupert <karupert(a)us.ibm.com>
diff -r db3af9cb2c9a -r 2d852ba88fd2 suites/libvirt-cim/main.py
--- a/suites/libvirt-cim/main.py Thu Sep 03 13:03:52 2009 -0700
+++ b/suites/libvirt-cim/main.py Thu Sep 03 17:05:38 2009 -0700
@@ -22,6 +22,7 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
+from time import time
from optparse import OptionParser
import os
import sys
@@ -64,6 +65,9 @@
help="Duplicate the output to stderr")
parser.add_option("--report", dest="report",
help="Send report using mail info: --report=<recipient
addr>")
+parser.add_option("--print-exec-time", action="store_true",
+ dest="print_exec_time",
+ help="Print execution time of each test")
TEST_SUITE = 'cimtest'
CIMTEST_RCFILE = '%s/.cimtestrc' % os.environ['HOME']
@@ -146,6 +150,27 @@
return PASS
+def print_exec_time(testsuite, exec_time):
+
+ #Convert run time from seconds to hours
+ tmp = exec_time / (60 * 60)
+ h = int(tmp)
+
+ #Subtract out hours and convert remainder to minutes
+ tmp = (tmp - h) * 60
+ m = int(tmp)
+
+ #Subtract out minutes and convert remainder to seconds
+ tmp = (tmp - m) * 60
+ s = int(tmp)
+
+ #Subtract out seconds and convert remainder to milliseconds
+ tmp = (tmp - s) * 1000
+ msec = int(tmp)
+
+ testsuite.debug(" Execution time: %sh %smin %ssec %smsec" %
+ (h, m, s, msec))
You can remove the blank space from the above log, so that the message
is aligned with the test case log messages.
You can also include some delimiters between the time values to make
more clear, also we can print the hr , min, sec in H, MIN, SEC would be
good.
something like this:
testsuite.debug(" ---------------------------")
testsuite.debug("Execution time: %sh | %smin |%ssec |%smsec|" %
(h, m, s, msec))
This will print the information in the following format.
Starting test suite: libvirt-cim
--------------------------------------------------------------------
ComputerSystem - 04_defineStartVS.py: PASS
---------------------------
Execution time: 0H | 0MIN |1SEC |638MSEC|
--------------------------------------------------------------------
Total test execution:
---------------------------
Execution time: 0H | 0MIN |1SEC |638MSEC|
Testing KVM hypervisor
--------------------------------------------------------------------
ComputerSystem - 04_defineStartVS.py: PASS
---------------------------
Execution time: 0h | 0min |1sec |663msec|
--------------------------------------------------------------------
Total test execution:
---------------------------
Execution time: 0h | 0min |1sec |663msec|
Do we require milliseconds information ?
Can we print the total time as part of the Summary information in the
test run report, otherwise we will have to go to the bottom of the
results to know the total time details.
+
def main():
(options, args) = parser.parse_args()
to_addr = None
@@ -213,6 +238,8 @@
print "\nTesting " + options.virt + " hypervisor"
+ test_run_time_total = 0
+
for test in test_list:
testsuite.debug(div)
t_path = os.path.join(TEST_SUITE, test['group'])
@@ -222,13 +249,25 @@
options.virt, dbg,
options.t_url)
cmd = cdto + ' && ' + ' ' + run
+ start_time = time()
status, output = commands.getstatusoutput(cmd)
+ end_time = time()
os_status = os.WEXITSTATUS(status)
testsuite.print_results(test['group'], test['test'], os_status,
output)
+ exec_time = end_time - start_time
+ test_run_time_total = test_run_time_total + exec_time
+
+ if options.print_exec_time:
+ print_exec_time(testsuite, exec_time)
+
testsuite.debug("%s\n" % div)
+ testsuite.debug("Total test execution: ")
+ print_exec_time(testsuite, test_run_time_total)
+ testsuite.debug("\n")
+
testsuite.finish()
status = cleanup_env(options.ip, options.virt)
_______________________________________________
Libvirt-cim mailing list
Libvirt-cim(a)redhat.com
https://www.redhat.com/mailman/listinfo/libvirt-cim
--
Thanks and Regards,
Deepti B. Kalakeri
IBM Linux Technology Center
deeptik(a)linux.vnet.ibm.com