From 5d7ec0a178f15b612a9e303e01bc3c21bdc841ec Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Sun, 5 Oct 2014 23:58:41 -0700 Subject: tests: Temporarily disable tests that are failing in compact mode --- tests/main.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'tests') diff --git a/tests/main.cpp b/tests/main.cpp index 3bcf9be..3231d10 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -159,6 +159,20 @@ int main(int, char** argv) for (test = test_runner::_tests; test; test = test->_next) { + #ifdef PUGIXML_COMPACT + if (false + || strcmp(test->_name, "parse_out_of_memory") == 0 + || strcmp(test->_name, "parse_out_of_memory_halfway") == 0 + || strcmp(test->_name, "dom_node_append_buffer_out_of_memory_extra") == 0 + || strcmp(test->_name, "dom_node_out_of_memory") == 0 + || strcmp(test->_name, "dom_node_copy_out_of_memory") == 0 + || strcmp(test->_name, "dom_node_copy_copyless") == 0 + || strcmp(test->_name, "memory_large_allocations") == 0 + || strcmp(test->_name, "memory_custom_memory_management") == 0 + ) + continue; + #endif + total++; passed += run_test(test); } -- cgit v1.2.3 From 7795f00fbadde2397b5b2631c37f62ef8a21acef Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Fri, 10 Oct 2014 19:32:40 -0700 Subject: tests: Reenable all tests for compact mode --- tests/main.cpp | 14 -------------- 1 file changed, 14 deletions(-) (limited to 'tests') diff --git a/tests/main.cpp b/tests/main.cpp index 3231d10..3bcf9be 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -159,20 +159,6 @@ int main(int, char** argv) for (test = test_runner::_tests; test; test = test->_next) { - #ifdef PUGIXML_COMPACT - if (false - || strcmp(test->_name, "parse_out_of_memory") == 0 - || strcmp(test->_name, "parse_out_of_memory_halfway") == 0 - || strcmp(test->_name, "dom_node_append_buffer_out_of_memory_extra") == 0 - || strcmp(test->_name, "dom_node_out_of_memory") == 0 - || strcmp(test->_name, "dom_node_copy_out_of_memory") == 0 - || strcmp(test->_name, "dom_node_copy_copyless") == 0 - || strcmp(test->_name, "memory_large_allocations") == 0 - || strcmp(test->_name, "memory_custom_memory_management") == 0 - ) - continue; - #endif - total++; passed += run_test(test); } -- cgit v1.2.3 From 50bfdb1856659a89d4db674abe2b69a2c7589a83 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Thu, 6 Nov 2014 09:59:07 +0100 Subject: tests: Fix all tests for compact mode Memory allocation behavior is different in compact mode so tests that rely on current behavior have to be adjusted. --- tests/test_dom_modify.cpp | 5 +++++ tests/test_memory.cpp | 45 ++++++++++++++++++++++++++------------------- 2 files changed, 31 insertions(+), 19 deletions(-) (limited to 'tests') diff --git a/tests/test_dom_modify.cpp b/tests/test_dom_modify.cpp index 45cf3ea..6417033 100644 --- a/tests/test_dom_modify.cpp +++ b/tests/test_dom_modify.cpp @@ -1310,6 +1310,11 @@ TEST(dom_node_copy_copyless) // the document is parsed in-place so there should only be 1 page worth of allocations test_runner::_memory_fail_threshold = 32768 + 128; +#ifdef PUGIXML_COMPACT + // ... and some space for hash table + test_runner::_memory_fail_threshold += 2048; +#endif + xml_document doc; CHECK(doc.load_buffer_inplace(&datacopy[0], datacopy.size() * sizeof(char_t), parse_full)); diff --git a/tests/test_memory.cpp b/tests/test_memory.cpp index 32d395b..ae5eb8c 100644 --- a/tests/test_memory.cpp +++ b/tests/test_memory.cpp @@ -1,30 +1,37 @@ #include "common.hpp" #include "writer_string.hpp" +#include "allocator.hpp" #include namespace { - int allocate_count = 0; - int deallocate_count = 0; + int page_allocs = 0; + int page_deallocs = 0; + + bool is_page(size_t size) + { + return size >= 8192; + } void* allocate(size_t size) { - ++allocate_count; - return new char[size]; + void* ptr = memory_allocate(size); + page_allocs += is_page(memory_size(ptr)); + return ptr; } void deallocate(void* ptr) { - ++deallocate_count; - delete[] reinterpret_cast(ptr); + page_deallocs += is_page(memory_size(ptr)); + memory_deallocate(ptr); } } TEST(memory_custom_memory_management) { - allocate_count = deallocate_count = 0; + page_allocs = page_deallocs = 0; // remember old functions allocation_function old_allocate = get_memory_allocation_function(); @@ -37,30 +44,30 @@ TEST(memory_custom_memory_management) // parse document xml_document doc; - CHECK(allocate_count == 0 && deallocate_count == 0); + CHECK(page_allocs == 0 && page_deallocs == 0); CHECK(doc.load(STR(""))); - CHECK(allocate_count == 2 && deallocate_count == 0); + CHECK(page_allocs == 1 && page_deallocs == 0); // modify document (no new page) CHECK(doc.first_child().set_name(STR("foobars"))); - CHECK(allocate_count == 2 && deallocate_count == 0); + CHECK(page_allocs == 1 && page_deallocs == 0); // modify document (new page) std::basic_string s(65536, 'x'); CHECK(doc.first_child().set_name(s.c_str())); - CHECK(allocate_count == 3 && deallocate_count == 0); + CHECK(page_allocs == 2 && page_deallocs == 0); // modify document (new page, old one should die) s += s; CHECK(doc.first_child().set_name(s.c_str())); - CHECK(allocate_count == 4 && deallocate_count == 1); + CHECK(page_allocs == 3 && page_deallocs == 1); } - CHECK(allocate_count == 4 && deallocate_count == 4); + CHECK(page_allocs == 3 && page_deallocs == 3); // restore old functions set_memory_management_functions(old_allocate, old_deallocate); @@ -68,7 +75,7 @@ TEST(memory_custom_memory_management) TEST(memory_large_allocations) { - allocate_count = deallocate_count = 0; + page_allocs = page_deallocs = 0; // remember old functions allocation_function old_allocate = get_memory_allocation_function(); @@ -80,7 +87,7 @@ TEST(memory_large_allocations) { xml_document doc; - CHECK(allocate_count == 0 && deallocate_count == 0); + CHECK(page_allocs == 0 && page_deallocs == 0); // initial fill for (size_t i = 0; i < 128; ++i) @@ -90,7 +97,7 @@ TEST(memory_large_allocations) CHECK(doc.append_child(node_pcdata).set_value(s.c_str())); } - CHECK(allocate_count > 0 && deallocate_count == 0); + CHECK(page_allocs > 0 && page_deallocs == 0); // grow-prune loop while (doc.first_child()) @@ -116,15 +123,15 @@ TEST(memory_large_allocations) } } - CHECK(allocate_count == deallocate_count + 1); // only one live page left (it waits for new allocations) + CHECK(page_allocs == page_deallocs + 1); // only one live page left (it waits for new allocations) char buffer; CHECK(doc.load_buffer_inplace(&buffer, 0, parse_fragment, get_native_encoding())); - CHECK(allocate_count == deallocate_count); // no live pages left + CHECK(page_allocs == page_deallocs); // no live pages left } - CHECK(allocate_count == deallocate_count); // everything is freed + CHECK(page_allocs == page_deallocs); // everything is freed // restore old functions set_memory_management_functions(old_allocate, old_deallocate); -- cgit v1.2.3 From 6c11a0c693da9ccf38225471d614bde162312427 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Sun, 12 Apr 2015 03:14:08 -0700 Subject: Fix compilation and tests after merge. --- tests/test_dom_modify.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/test_dom_modify.cpp b/tests/test_dom_modify.cpp index 47c4a04..071b798 100644 --- a/tests/test_dom_modify.cpp +++ b/tests/test_dom_modify.cpp @@ -1115,6 +1115,11 @@ TEST(dom_node_append_buffer_out_of_memory_nodes) test_runner::_memory_fail_threshold = 32768 + 128 + data.length() * sizeof(char_t) + 32; +#ifdef PUGIXML_COMPACT + // ... and some space for hash table + test_runner::_memory_fail_threshold += 2048; +#endif + xml_document doc; CHECK_ALLOC_FAIL(CHECK(doc.append_buffer(data.c_str(), data.length() * sizeof(char_t), parse_fragment).status == status_out_of_memory)); @@ -1131,9 +1136,9 @@ TEST(dom_node_append_buffer_out_of_memory_nodes) TEST(dom_node_append_buffer_out_of_memory_name) { - test_runner::_memory_fail_threshold = 32768 + 128; + test_runner::_memory_fail_threshold = 32768 + 4096; - char data[128] = {0}; + char data[4096] = {0}; xml_document doc; CHECK(doc.append_child(STR("root"))); @@ -1459,6 +1464,11 @@ TEST(dom_node_copy_attribute_copyless) // the document is parsed in-place so there should only be 1 page worth of allocations test_runner::_memory_fail_threshold = 32768 + 128; +#ifdef PUGIXML_COMPACT + // ... and some space for hash table + test_runner::_memory_fail_threshold += 2048; +#endif + xml_document doc; CHECK(doc.load_buffer_inplace(&datacopy[0], datacopy.size() * sizeof(char_t), parse_full)); -- cgit v1.2.3 From cb786665d44598cbaff721e50d6a56b7538789e5 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Mon, 13 Apr 2015 20:36:04 -0700 Subject: tests: Add PUGIXML_COMPACT to AppVeyor --- tests/autotest-appveyor.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/autotest-appveyor.ps1 b/tests/autotest-appveyor.ps1 index 8b7a24c..6b88766 100644 --- a/tests/autotest-appveyor.ps1 +++ b/tests/autotest-appveyor.ps1 @@ -21,7 +21,7 @@ foreach ($vs in 9,10,11,12) Invoke-CmdScript "C:\Program Files (x86)\Microsoft Visual Studio $vs.0\VC\vcvarsall.bat" $arch if (! $?) { throw "Error setting up VS$vs $arch" } - foreach ($defines in "standard", "PUGIXML_WCHAR_MODE") + foreach ($defines in "standard", "PUGIXML_WCHAR_MODE", "PUGIXML_COMPACT") { $target = "tests_vs${vs}_${arch}_${defines}" $deflist = if ($defines -eq "standard") { "" } else { "/D$defines" } -- cgit v1.2.3 From 52bcb4ecd6a1f87c7a8f82315faac26f5066117a Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Tue, 21 Apr 2015 21:35:54 -0700 Subject: tests: Adjust allocation thresholds to fix tests --- tests/test_xpath_variables.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/test_xpath_variables.cpp b/tests/test_xpath_variables.cpp index f72d6ff..c4a3b7f 100644 --- a/tests/test_xpath_variables.cpp +++ b/tests/test_xpath_variables.cpp @@ -445,7 +445,7 @@ TEST_XML(xpath_variables_copy, "") CHECK(!set3.get(STR("a"))); } -TEST_XML(xpath_variables_copy_out_of_memory, "") +TEST_XML(xpath_variables_copy_out_of_memory, "") { xpath_variable_set set1; set1.set(STR("a"), true); @@ -471,7 +471,7 @@ TEST_XML(xpath_variables_copy_out_of_memory, "") CHECK(set2.get(STR("a"))->get_boolean() == true); CHECK(set2.get(STR("b"))->get_number() == 2.0); CHECK_STRING(set2.get(STR("c"))->get_string(), STR("string")); - CHECK(set2.get(STR("d"))->get_node_set().size() == 1); + CHECK(set2.get(STR("d"))->get_node_set().size() == 2); } #if __cplusplus >= 201103 -- cgit v1.2.3 From 3643b505a6f95e65037c5d906e7fb81ac16698cf Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Wed, 22 Apr 2015 08:38:52 -0700 Subject: Fix node_pi memory leak --- tests/test_dom_modify.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'tests') diff --git a/tests/test_dom_modify.cpp b/tests/test_dom_modify.cpp index 54bbee4..365561f 100644 --- a/tests/test_dom_modify.cpp +++ b/tests/test_dom_modify.cpp @@ -948,6 +948,25 @@ TEST(dom_node_memory_limit) } } +TEST(dom_node_memory_limit_pi) +{ + const unsigned int length = 65536; + static char_t string[length + 1]; + + for (unsigned int i = 0; i < length; ++i) string[i] = 'a'; + string[length] = 0; + + test_runner::_memory_fail_threshold = 32768 * 2 + sizeof(string); + + xml_document doc; + + for (int j = 0; j < 32; ++j) + { + CHECK(doc.append_child(node_pi).set_value(string)); + CHECK(doc.remove_child(doc.first_child())); + } +} + TEST(dom_node_doctype_top_level) { xml_document doc; -- cgit v1.2.3 From dede617d9fa5e4483ca5ff5e69510f55fdd3eef5 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Wed, 29 Apr 2015 09:21:04 -0700 Subject: tests: Fix spurious failures in compact mode The memory_large_allocations test sometimes classified hash allocations as page allocations since hash table could reach 512 entries. --- tests/test_memory.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test_memory.cpp b/tests/test_memory.cpp index 5edfd65..a571353 100644 --- a/tests/test_memory.cpp +++ b/tests/test_memory.cpp @@ -12,7 +12,7 @@ namespace bool is_page(size_t size) { - return size >= 8192; + return size >= 16384; } void* allocate(size_t size) -- cgit v1.2.3 From 19d43d39fc12ecc6017b5a99098efd0a223662ad Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Sat, 2 May 2015 09:45:26 -0700 Subject: tests: Add one more page reclamation test --- tests/test_memory.cpp | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'tests') diff --git a/tests/test_memory.cpp b/tests/test_memory.cpp index a571353..85d6e86 100644 --- a/tests/test_memory.cpp +++ b/tests/test_memory.cpp @@ -4,6 +4,7 @@ #include "allocator.hpp" #include +#include namespace { @@ -137,6 +138,63 @@ TEST(memory_large_allocations) set_memory_management_functions(old_allocate, old_deallocate); } +TEST(memory_page_management) +{ + page_allocs = page_deallocs = 0; + + // remember old functions + allocation_function old_allocate = get_memory_allocation_function(); + deallocation_function old_deallocate = get_memory_deallocation_function(); + + // replace functions + set_memory_management_functions(allocate, deallocate); + + { + xml_document doc; + + CHECK(page_allocs == 0 && page_deallocs == 0); + + // initial fill + std::vector nodes; + + for (size_t i = 0; i < 4000; ++i) + { + xml_node node = doc.append_child(STR("node")); + CHECK(node); + + nodes.push_back(node); + } + + CHECK(page_allocs > 0 && page_deallocs == 0); + + // grow-prune loop + size_t offset = 0; + size_t prime = 15485863; + + while (nodes.size() > 0) + { + offset = (offset + prime) % nodes.size(); + + doc.remove_child(nodes[offset]); + + nodes[offset] = nodes.back(); + nodes.pop_back(); + } + + CHECK(page_allocs == page_deallocs + 1); // only one live page left (it waits for new allocations) + + char buffer; + CHECK(doc.load_buffer_inplace(&buffer, 0, parse_fragment, get_native_encoding())); + + CHECK(page_allocs == page_deallocs); // no live pages left + } + + CHECK(page_allocs == page_deallocs); // everything is freed + + // restore old functions + set_memory_management_functions(old_allocate, old_deallocate); +} + TEST(memory_string_allocate_increasing) { xml_document doc; -- cgit v1.2.3