Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion common/acs_test_framework_manifests/logs-to-json.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,33 @@ suites:
text: "\"total_warnings\": 1"


# =========================
# BSA LOGS TO JSON
# =========================

- name: bsa_logs_to_json_specific
files:
- common/log_parser/bsa/logs_to_json.py

cases:
- name: limits_all_subtest_descriptions_to_49_nonspace_chars
type: py_function
function: subtest_entry_from_frame
args:
- number: "RULE : 1"
description: "1234567890 1234567890 1234567890 1234567890 1234567890"
level: 1
path:
- "RULE : 1"
- "PASSED"
expect_return:
sub_Test_Number: "RULE : 1"
sub_Test_Description: "1234567890 1234567890 1234567890 1234567890 123456789"
sub_test_result: "PASSED"
sub_Test_Level: 1
sub_Test_Path: "RULE : 1"


# =========================
# EDK2 LOGS TO JSON
# =========================
Expand Down Expand Up @@ -281,4 +308,4 @@ suites:
path: "{dir}/out.json"
- type: file_contains
path: "{dir}/out.json"
text: "AAAA-BBBB"
text: "AAAA-BBBB"
18 changes: 17 additions & 1 deletion common/log_parser/bsa/logs_to_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
)
RULE_LINE_RE = re.compile(r'\b([A-Za-z0-9_]+)\s*:\s*(-|\d+)\s*:\s*(.*)$')
RESULT_RE = re.compile(r'\bResult:\s*(.*)$', re.IGNORECASE)
MAX_SUBTEST_DESCRIPTION_NONSPACE_CHARS = 49

def detect_file_encoding(file_path):
with open(file_path, 'rb') as file:
Expand Down Expand Up @@ -151,6 +152,19 @@ def extract_status_text(status_text):
def make_test_number(rule_id, test_index):
return f"{rule_id} : {test_index or '-'}"

def limit_subtest_description(description):
"""Limit a description to 49 non-whitespace characters."""
description = (description or "").strip()
nonspace_count = 0
for index, char in enumerate(description):
if char.isspace():
continue
nonspace_count += 1
if nonspace_count > MAX_SUBTEST_DESCRIPTION_NONSPACE_CHARS:
return description[:index].rstrip()

return description

# A frame is one rule that has started but has not reached its Result/END line.
# Keeping these frames on a stack lets the parser attach each completed child
# rule to the nearest still-open parent rule.
Expand Down Expand Up @@ -195,7 +209,9 @@ def subtest_entry_from_frame(frame, formatted_result):
# log branch so a partner can compare JSON/HTML directly with the log.
entry = {
"sub_Test_Number": frame.get("number", make_test_number(frame.get("rule_id"), frame.get("index"))),
"sub_Test_Description": frame.get("description", ""),
"sub_Test_Description": limit_subtest_description(
frame.get("description", "")
),
"sub_test_result": formatted_result,
"sub_Test_Level": frame.get("level", 1),
"sub_Test_Path": " / ".join(frame.get("path", []))
Expand Down
Loading