blob: ca53361ea0a2e71b1f8773f39ff1bb52452d145a [file] [log] [blame]
Mate Toth-Pal83a45bd2023-09-01 11:17:19 +02001#
2# SPDX-License-Identifier: BSD-3-Clause
3# SPDX-FileCopyrightText: Copyright TF-RMM Contributors.
4#
5
6#
7# Helper functions for formatting the summary file
8#
9
10function(rmm_cbmc_align_to_middle field_width padding_character text)
11 set (pad_pool "")
12 foreach(i RANGE ${field_width})
13 string(APPEND pad_pool ${padding_character})
14 endforeach()
15 string(LENGTH ${text} text_len)
16 math(EXPR leading_space "(${field_width} - ${text_len}) / 2")
17 math(EXPR trailing_space "${field_width} - ${text_len} - ${leading_space}")
18 string (SUBSTRING ${pad_pool} 0 ${leading_space} leading_spaces)
19 string (SUBSTRING ${pad_pool} 0 ${trailing_space} trailing_spaces)
20
21 set(aligned_text "")
22 string (APPEND aligned_text "${leading_spaces}" "${text}" "${trailing_spaces}")
23 set(aligned_text "${aligned_text}" PARENT_SCOPE)
24endfunction()
25
26function(rmm_cbmc_append_separator summary_width result_dir file)
27 rmm_cbmc_align_to_middle(${summary_width} "-" "-")
28 set(separator_line "")
29 string(APPEND separator_line "+" "${aligned_text}" "+" "${aligned_text}" "+\n")
30 file(APPEND ${result_dir}/${file} ${separator_line})
31endfunction()
32
33function(rmm_cbmc_write_summary_header summary_width result_dir file summary_header)
34 file(MAKE_DIRECTORY ${result_dir})
35 file(WRITE ${result_dir}/${file} "")
36 rmm_cbmc_append_separator(${summary_width} ${result_dir} ${file})
37 rmm_cbmc_align_to_middle(${summary_width} " " "FILENAME")
38 set(field1 "${aligned_text}")
39 rmm_cbmc_align_to_middle(${summary_width} " " "${summary_header}")
40 set(field2 "${aligned_text}")
41 set(header "")
42 string(APPEND header "|" "${field1}" "|" "${field2}" "|\n")
43 file(APPEND ${result_dir}/${file} ${header})
44 rmm_cbmc_append_separator(${summary_width} ${result_dir} ${file})
45endfunction()
46
47function(rmm_cbmc_append_summary testbench_filename output_file summary_width result_dir file summary_pattern)
48 rmm_cbmc_align_to_middle(${summary_width} " " ${testbench_filename})
49 set(testbench_filename "${aligned_text}")
50
51 execute_process(COMMAND grep -E "${summary_pattern}" ${output_file} OUTPUT_VARIABLE testbench_result)
52
53 if("${testbench_result}" STREQUAL "")
54 rmm_cbmc_align_to_middle(${summary_width} " " "N/A")
55 set(testbench_result "${aligned_text}")
56 endif()
57
58 string(REPLACE "\n" "" testbench_result "${testbench_result}")
59 string(REGEX REPLACE "[^\\*]*\\*\\*[\\s]*" "" testbench_result "${testbench_result}")
60
61 rmm_cbmc_align_to_middle(${summary_width} " " ${testbench_result})
62 set(testbench_result "${aligned_text}")
63
64 string(APPEND summary_data "|${testbench_filename}|${testbench_result}|\n")
65 file(APPEND ${result_dir}/${file} ${summary_data})
66 rmm_cbmc_append_separator(${summary_width} ${result_dir} ${file})
67endfunction()