Skip to content

Commit

Permalink
[thread-cert] print elapsed time of each test when running cert suite (
Browse files Browse the repository at this point in the history
…#10593)

This is helpful to know the exact time that each test take when running
bunch of tests in cert suite.
  • Loading branch information
zesonzhang authored Aug 9, 2024
1 parent 6771761 commit 28b6011
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions tests/scripts/thread-cert/run_cert_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import os
import queue
import subprocess
import time
import traceback
from collections import Counter
from typing import List
Expand Down Expand Up @@ -158,29 +159,36 @@ def run_tests(scripts: List[str], multiply: int = 1, run_directory: str = None):
script_ids = [(script, i) for script in scripts for i in range(multiply)]
port_offset_pool = PortOffsetPool(MAX_JOBS)

def error_callback(port_offset, script, err):
def error_callback(port_offset, script, err, start_time):
port_offset_pool.release(port_offset)

elapsed_time = round(time.time() - start_time)
script_fail_count[script] += 1
if script_succ_count[script] + script_fail_count[script] == multiply:
color = _COLOR_PASS if script_fail_count[script] == 0 else _COLOR_FAIL
print(f'{color}PASS {script_succ_count[script]} FAIL {script_fail_count[script]}{_COLOR_NONE} {script}')
print(
f'{color}PASS {script_succ_count[script]} FAIL {script_fail_count[script]}{_COLOR_NONE} {script} in {elapsed_time}s'
)

def pass_callback(port_offset, script):
def pass_callback(port_offset, script, start_time):
port_offset_pool.release(port_offset)

elapsed_time = round(time.time() - start_time)
script_succ_count[script] += 1
if script_succ_count[script] + script_fail_count[script] == multiply:
color = _COLOR_PASS if script_fail_count[script] == 0 else _COLOR_FAIL
print(f'{color}PASS {script_succ_count[script]} FAIL {script_fail_count[script]}{_COLOR_NONE} {script}')
print(
f'{color}PASS {script_succ_count[script]} FAIL {script_fail_count[script]}{_COLOR_NONE} {script} in {elapsed_time}s'
)

for script, i in script_ids:
port_offset = port_offset_pool.allocate()
pool.apply_async(
run_cert, [i, port_offset, script, run_directory],
callback=lambda ret, port_offset=port_offset, script=script: pass_callback(port_offset, script),
error_callback=lambda err, port_offset=port_offset, script=script: error_callback(
port_offset, script, err))
start_time = time.time()
pool.apply_async(run_cert, [i, port_offset, script, run_directory],
callback=lambda ret, port_offset=port_offset, script=script, start_time=start_time:
pass_callback(port_offset, script, start_time),
error_callback=lambda err, port_offset=port_offset, script=script, start_time=start_time:
error_callback(port_offset, script, err, start_time))

pool.close()
pool.join()
Expand Down

0 comments on commit 28b6011

Please sign in to comment.