From 7a908a2876902d8f56892f50fce98f9bb92b9f04 Mon Sep 17 00:00:00 2001 From: Vern Paxson Date: Thu, 2 Jan 2025 15:32:30 -0800 Subject: [PATCH] Extended ZAM validation to include macros --- auxil/gen-zam | 2 +- src/script_opt/ZAM/Validate.cc | 16 +++++++++++++--- src/script_opt/ZAM/ZOp.h | 4 ++++ testing/btest/Baseline/opt.validate-ZAM/output | 2 -- testing/btest/opt/validate-ZAM.zeek | 5 +++-- 5 files changed, 21 insertions(+), 8 deletions(-) delete mode 100644 testing/btest/Baseline/opt.validate-ZAM/output diff --git a/auxil/gen-zam b/auxil/gen-zam index 517bf6a5c8..e780bb6c17 160000 --- a/auxil/gen-zam +++ b/auxil/gen-zam @@ -1 +1 @@ -Subproject commit 517bf6a5c8dc6afdee2b854d575dbdd15736afc5 +Subproject commit e780bb6c17f55ef5a4a739c14f49b3f454991dea diff --git a/src/script_opt/ZAM/Validate.cc b/src/script_opt/ZAM/Validate.cc index 4bd5a4494b..6f2cd042eb 100644 --- a/src/script_opt/ZAM/Validate.cc +++ b/src/script_opt/ZAM/Validate.cc @@ -13,9 +13,11 @@ using std::string; namespace zeek::detail { std::unordered_map zam_inst_desc = { +#include "ZAM-OpDesc.h" +}; -#include "ZAM-Desc.h" - +std::vector> zam_macro_desc = { +#include "ZAM-MacroDesc.h" }; // While the following has commonalities that could be factored out, @@ -107,7 +109,15 @@ void validate_ZAM_insts() { for ( auto& zid : zam_inst_desc ) analyze_ZAM_inst(ZOP_name(zid.first), zid.second); - printf("%d valid, %d tested, %d skipped\n", num_valid, num_tested, num_skipped); + int num_valid_macros = 0; + for ( auto& md : zam_macro_desc ) { + if ( std::regex_search(md.second, std::regex("\\$[0-9$]")) ) + reporter->InternalError("macro %s contains dollar parameter: %s", md.first.c_str(), md.second.c_str()); + ++num_valid_macros; + } + + printf("%d valid ops, %d tested, %d skipped, %d valid macros\n", num_valid, num_tested, num_skipped, + num_valid_macros); } } // namespace zeek::detail diff --git a/src/script_opt/ZAM/ZOp.h b/src/script_opt/ZAM/ZOp.h index 09e44f145d..783facff36 100644 --- a/src/script_opt/ZAM/ZOp.h +++ b/src/script_opt/ZAM/ZOp.h @@ -72,6 +72,10 @@ struct ZAMInstDesc { // Provides access to the validation description of each operation. extern std::unordered_map zam_inst_desc; +// Same, for the associated macros. First field is macro name, second is +// definition (including "#define" etc.). +extern std::vector> zam_macro_desc; + // Maps an operand to its flavor. extern ZAMOp1Flavor op1_flavor[]; diff --git a/testing/btest/Baseline/opt.validate-ZAM/output b/testing/btest/Baseline/opt.validate-ZAM/output deleted file mode 100644 index e99ede3a6b..0000000000 --- a/testing/btest/Baseline/opt.validate-ZAM/output +++ /dev/null @@ -1,2 +0,0 @@ -### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. -1255 valid, 1908 tested, 440 skipped diff --git a/testing/btest/opt/validate-ZAM.zeek b/testing/btest/opt/validate-ZAM.zeek index 0206d5a7a0..bbe14f7097 100644 --- a/testing/btest/opt/validate-ZAM.zeek +++ b/testing/btest/opt/validate-ZAM.zeek @@ -1,4 +1,5 @@ # @TEST-DOC: ZAM maintenance script for validating synthesized operations. # -# @TEST-EXEC: zeek -b -O validate-ZAM %INPUT >output -# @TEST-EXEC: btest-diff output +# We don't check the output, since it varies for benign reasons as ZAM +# operations are modified. What matters is the exit status of success. +# @TEST-EXEC: zeek -b -O validate-ZAM %INPUT