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).
This commit is contained in:
Arseny Kapoulkine 2019-02-26 22:58:35 -08:00
parent 2c97f100ac
commit 9c03796bde

View File

@ -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, "<node><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/></node>")
TEST_XML(xpath_out_of_memory_evaluate_union, "<node />")
{
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, "<node />")
{
// 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, "<node><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/></node>")
{