From 3ff5afd54131dc611ac08cf4f256a7c081c0cbb3 Mon Sep 17 00:00:00 2001 From: Jeff Morriss Date: Wed, 23 Sep 2015 10:14:31 -0400 Subject: [PATCH] Add a test to verify we pre-allocated enough hf entries. This way we'll know as soon as we drop below the pre-allocated limit. As suggested by Graham on https://code.wireshark.org/review/10601 Change-Id: Ieeb14bdcf991d7a67c30787c97ca24ebb35d1763 Reviewed-on: https://code.wireshark.org/review/10627 Reviewed-by: Alexis La Goutte --- epan/proto.c | 28 +++++++++++++++++++--------- epan/proto.h | 5 +++-- test/suite-unittests.sh | 7 +++++++ tshark.c | 7 ++++--- 4 files changed, 33 insertions(+), 14 deletions(-) diff --git a/epan/proto.c b/epan/proto.c index 203096d3de..e822588af6 100644 --- a/epan/proto.c +++ b/epan/proto.c @@ -7809,8 +7809,11 @@ proto_registrar_dump_values(void) /* Prints the number of registered fields. * Useful for determining an appropriate value for * PROTO_PRE_ALLOC_HF_FIELDS_MEM. + * + * Returns FALSE if PROTO_PRE_ALLOC_HF_FIELDS_MEM is larger than or equal to + * the number of fields, TRUE otherwise. */ -void +gboolean proto_registrar_dump_fieldcount(void) { guint32 i; @@ -7834,17 +7837,24 @@ proto_registrar_dump_fieldcount(void) same_name_count++; } - printf("There are %d header fields registered, of which:\n" - "\t%d are deregistered\n" - "\t%d are protocols\n" - "\t%d have the same name as another field\n\n", + printf ("There are %d header fields registered, of which:\n" + "\t%d are deregistered\n" + "\t%d are protocols\n" + "\t%d have the same name as another field\n\n", gpa_hfinfo.len, deregistered_count, protocol_count, same_name_count); - printf("The header field table consumes %d KiB of memory.\n", - (int)(gpa_hfinfo.allocated_len * sizeof(header_field_info *) / 1024)); - printf("The fields themselves consume %d KiB of memory.\n", - (int)(gpa_hfinfo.len * sizeof(header_field_info) / 1024)); + printf ("%d fields were pre-allocated.\n%s", PROTO_PRE_ALLOC_HF_FIELDS_MEM, + (gpa_hfinfo.allocated_len > PROTO_PRE_ALLOC_HF_FIELDS_MEM) ? + "* * Please increase PROTO_PRE_ALLOC_HF_FIELDS_MEM (in epan/proto.c)! * *\n\n" : + "\n"); + + printf ("The header field table consumes %d KiB of memory.\n", + (int)(gpa_hfinfo.allocated_len * sizeof(header_field_info *) / 1024)); + printf ("The fields themselves consume %d KiB of memory.\n", + (int)(gpa_hfinfo.len * sizeof(header_field_info) / 1024)); + + return (gpa_hfinfo.allocated_len > PROTO_PRE_ALLOC_HF_FIELDS_MEM); } diff --git a/epan/proto.h b/epan/proto.h index 4cf27de497..c30437f9b6 100644 --- a/epan/proto.h +++ b/epan/proto.h @@ -2251,8 +2251,9 @@ WS_DLL_PUBLIC void proto_registrar_dump_protocols(void); /** Dumps a glossary of the field value strings or true/false strings to STDOUT */ WS_DLL_PUBLIC void proto_registrar_dump_values(void); -/** Dumps the number of protocol and field registrations to STDOUT. */ -WS_DLL_PUBLIC void proto_registrar_dump_fieldcount(void); +/** Dumps the number of protocol and field registrations to STDOUT. + @return FALSE if we pre-allocated enough fields, TRUE otherwise. */ +WS_DLL_PUBLIC gboolean proto_registrar_dump_fieldcount(void); /** Dumps a glossary of the protocol and field registrations to STDOUT. */ WS_DLL_PUBLIC void proto_registrar_dump_fields(void); diff --git a/test/suite-unittests.sh b/test/suite-unittests.sh index 380e875f54..e329902b69 100755 --- a/test/suite-unittests.sh +++ b/test/suite-unittests.sh @@ -100,6 +100,12 @@ unittests_step_ftsanity() { unittests_step_test } +unittests_step_fieldcount() { + check_dut tshark + ARGS="-G fieldcount" + unittests_step_test +} + unittests_cleanup_step() { rm -f ./testout.txt } @@ -113,6 +119,7 @@ unittests_suite() { test_step_add "tvbtest" unittests_step_tvbtest test_step_add "wmem_test" unittests_step_wmem_test test_step_add "ftsanity.py" unittests_step_ftsanity + test_step_add "field count" unittests_step_fieldcount } # # Editor modelines - http://www.wireshark.org/tools/modelines.html diff --git a/tshark.c b/tshark.c index ff37f85557..4c4c800fd5 100644 --- a/tshark.c +++ b/tshark.c @@ -1276,9 +1276,10 @@ DIAG_ON(cast-qual) write_prefs(NULL); else if (strcmp(argv[2], "dissector-tables") == 0) dissector_dump_dissector_tables(); - else if (strcmp(argv[2], "fieldcount") == 0) - proto_registrar_dump_fieldcount(); - else if (strcmp(argv[2], "fields") == 0) + else if (strcmp(argv[2], "fieldcount") == 0) { + /* return value for the test suite */ + return proto_registrar_dump_fieldcount(); + } else if (strcmp(argv[2], "fields") == 0) proto_registrar_dump_fields(); else if (strcmp(argv[2], "ftypes") == 0) proto_registrar_dump_ftypes();