From 12e8b699ce10bcfd77391a2660da29420f97f04d Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Tue, 26 Feb 2019 22:58:35 -0800 Subject: [PATCH] tests: Expand out-of-memory union tests We now have two tests: one tests behavior when we run out of space when appending the node set (in which case the append fails), another one tests behavior when we run out of space when filtering the node set (in which case the set still contains redundant data). --- tests/test_xpath.cpp | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/tests/test_xpath.cpp b/tests/test_xpath.cpp index 5cafb47..fe1e312 100644 --- a/tests/test_xpath.cpp +++ b/tests/test_xpath.cpp @@ -449,16 +449,41 @@ TEST(xpath_out_of_memory_evaluate_substring) CHECK_ALLOC_FAIL(CHECK(q.evaluate_string(0, 0, xml_node()) == 1)); } -/* -TEST_XML(xpath_out_of_memory_evaluate_union, "") +TEST_XML(xpath_out_of_memory_evaluate_union, "") { - test_runner::_memory_fail_threshold = 32768 + 4096 * 2; + // left hand side: size * sizeof(xpath_node) (8 on 32-bit, 16 on 64-bit) + // right hand side: same + // to make sure that when we append right hand side to left hand side, we run out of an XPath stack page (4K), we need slightly more than 2K/8 = 256 nodes on 32-bit, 128 nodes on 64-bit + size_t count = sizeof(void*) == 4 ? 300 : 150; - xpath_query q(STR("a|(a|(a|(a|(a|(a|(a|(a|(a|(a|(a|(a|(a|(a|(a|(a|(a|(a|(a|(a|a)))))))))))))))))))")); + for (size_t i = 0; i < count; ++i) + doc.first_child().append_child(STR("a")); + + xpath_query q(STR("a|a")); + + test_runner::_memory_fail_threshold = 1; CHECK_ALLOC_FAIL(CHECK(q.evaluate_node_set(doc.child(STR("node"))).empty())); } -*/ + +TEST_XML(xpath_out_of_memory_evaluate_union_hash, "") +{ + // left hand side: size * sizeof(xpath_node) (8 on 32-bit, 16 on 64-bit) + // right hand side: same + // hash table: size * 1.5 * sizeof(void*) + // to make sure that when we append right hand side to left hand side, we do *not* run out of an XPath stack page (4K), we need slightly less than 2K/8 = 256 nodes on 32-bit, 128 nodes on 64-bit + size_t count = sizeof(void*) == 4 ? 200 : 100; + + for (size_t i = 0; i < count; ++i) + doc.first_child().append_child(STR("a")); + + xpath_query q(STR("a|a")); + + test_runner::_memory_fail_threshold = 1; + + CHECK_ALLOC_FAIL(CHECK(q.evaluate_node_set(doc.child(STR("node"))).empty())); +} + TEST_XML(xpath_out_of_memory_evaluate_predicate, "") {