From: Rhodri James Date: Wed, 26 Jul 2017 16:33:10 +0000 (+0100) Subject: Make test_nsalloc_xmlns() robust vs changes in allocation patterns. X-Git-Tag: R_2_2_3~16^2~70 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1aa5529cf48c257f42c1c4dc38a99a9b3fba612a;p=libexpat Make test_nsalloc_xmlns() robust vs changes in allocation patterns. Most of the allocation tests use some complicated logic to ensure that cached memory allocations do not cause the test to miss out some possible allocation failure paths. A more robust way to do that is to free and recreate the parser, avoiding caching altogether. This should be done with the test case section teardown and setup routines, so that the right sort of parser is created. This is the first in a series of commits to switch over to this test structure --- diff --git a/expat/tests/runtests.c b/expat/tests/runtests.c index 6a72c401..38cb6565 100644 --- a/expat/tests/runtests.c +++ b/expat/tests/runtests.c @@ -10434,37 +10434,29 @@ START_TEST(test_nsalloc_xmlns) " \n" ""; unsigned int i; - int repeated = 0; +#define MAX_ALLOC_COUNT 30 - for (i = 0; i < 10; i++) { - /* Repeat some tests with the same allocation count to - * catch cached allocations not freed by XML_ParserReset() - */ - if ((i == 4 && repeated == 3) || - (i == 7 && repeated == 8)) { - i -= 2; - repeated++; - } - else if ((i == 2 && repeated < 2) || - (i == 3 && repeated < 3) || - (i == 3 && repeated > 3 && repeated < 7) || - (i == 5 && repeated < 8)) { - i--; - repeated++; - } + for (i = 0; i < MAX_ALLOC_COUNT; i++) { allocation_count = i; /* Exercise more code paths with a default handler */ XML_SetDefaultHandler(parser, dummy_default_handler); if (_XML_Parse_SINGLE_BYTES(parser, text, strlen(text), XML_TRUE) != XML_STATUS_ERROR) break; - XML_ParserReset(parser, NULL); + /* Resetting the parser is insufficient, because some memory + * allocations are cached within the parser. Instead we use + * the teardown and setup routines to ensure that we have the + * right sort of parser back in our hands. + */ + nsalloc_teardown(); + nsalloc_setup(); } if (i == 0) fail("Parsing worked despite failing allocations"); - else if (i == 10) - fail("Parsing failed even at allocation count 10"); + else if (i == MAX_ALLOC_COUNT) + fail("Parsing failed even at maximum allocation count"); } +#undef MAX_ALLOC_COUNT END_TEST /* Test XML_ParseBuffer interface with namespace and a dicky allocator */