diff --git a/test/unit/vy_cache.c b/test/unit/vy_cache.c index dcda5d32df1851097b48879321a37abd2630a377..ce339b8101828a471041643c56d3d537f76e9558 100644 --- a/test/unit/vy_cache.c +++ b/test/unit/vy_cache.c @@ -1,12 +1,11 @@ #include "trivia/util.h" #include "vy_iterators_helper.h" -#include "vy_history.h" #include "fiber.h" const struct vy_stmt_template key_template = STMT_TEMPLATE(0, SELECT, vyend); static void -test_basic() +test_basic(void) { header(); plan(6); @@ -20,10 +19,6 @@ test_basic() struct vy_entry select_all = vy_new_simple_stmt(format, key_def, &key_template); - struct mempool history_node_pool; - mempool_create(&history_node_pool, cord_slab_cache(), - sizeof(struct vy_history_node)); - /* * Fill the cache with 3 chains. */ @@ -127,8 +122,6 @@ test_basic() vy_history_cleanup(&history); vy_cache_iterator_close(&itr); - - mempool_destroy(&history_node_pool); tuple_unref(select_all.stmt); destroy_test_cache(&cache, key_def, format); check_plan(); @@ -136,12 +129,14 @@ test_basic() } int -main() +main(void) { vy_iterator_C_test_init(1LLU * 1024LLU * 1024LLU * 1024LLU); + plan(1); + test_basic(); vy_iterator_C_test_finish(); - return 0; + return check_plan(); } diff --git a/test/unit/vy_iterators_helper.c b/test/unit/vy_iterators_helper.c index fc06dbea932bb2a77fe83b0f9363a8bd76770f27..ae2213e9cb46bd9cb826ab10d28432297c5e64bc 100644 --- a/test/unit/vy_iterators_helper.c +++ b/test/unit/vy_iterators_helper.c @@ -2,6 +2,7 @@ #include "memory.h" #include "fiber.h" #include "say.h" +#include "small/mempool.h" #include "tt_uuid.h" struct tt_uuid INSTANCE_UUID; @@ -9,6 +10,7 @@ struct tt_uuid INSTANCE_UUID; struct vy_stmt_env stmt_env; struct vy_mem_env mem_env; struct vy_cache_env cache_env; +struct mempool history_node_pool; void vy_iterator_C_test_init(size_t cache_size) @@ -24,11 +26,14 @@ vy_iterator_C_test_init(size_t cache_size) vy_cache_env_set_quota(&cache_env, cache_size); size_t mem_size = 64 * 1024 * 1024; vy_mem_env_create(&mem_env, mem_size); + mempool_create(&history_node_pool, cord_slab_cache(), + sizeof(struct vy_history_node)); } void vy_iterator_C_test_finish() { + mempool_destroy(&history_node_pool); vy_mem_env_destroy(&mem_env); vy_cache_env_destroy(&cache_env); vy_stmt_env_destroy(&stmt_env); diff --git a/test/unit/vy_iterators_helper.h b/test/unit/vy_iterators_helper.h index 60b5a15d86ba311dbdd0f89ab803b4834fa57cd7..c6a7f506da64d499c58b08f2c6e8a736abbb67af 100644 --- a/test/unit/vy_iterators_helper.h +++ b/test/unit/vy_iterators_helper.h @@ -37,6 +37,7 @@ #include "small/lsregion.h" #include "vy_mem.h" #include "vy_cache.h" +#include "vy_history.h" #include "vy_read_view.h" #define UNIT_TAP_COMPATIBLE 1 @@ -56,6 +57,7 @@ STMT_TEMPLATE_FLAGS(lsn, type, VY_STMT_DEFERRED_DELETE, __VA_ARGS__) extern struct vy_stmt_env stmt_env; extern struct vy_mem_env mem_env; extern struct vy_cache_env cache_env; +extern struct mempool history_node_pool; #if defined(__cplusplus) extern "C" { diff --git a/test/unit/vy_mem.c b/test/unit/vy_mem.c index 328d3bd7ec0ffcbc06143903774e2d8b99174290..439e3684b4c7343895a4c3b02aa80e1fc5b1af87 100644 --- a/test/unit/vy_mem.c +++ b/test/unit/vy_mem.c @@ -1,9 +1,11 @@ #include <trivia/config.h> #include "memory.h" #include "fiber.h" -#include "vy_history.h" #include "vy_iterators_helper.h" +static struct key_def *key_def; +static struct tuple_format *format; + static void test_basic(void) { @@ -11,13 +13,7 @@ test_basic(void) plan(9); - /* Create key_def */ - uint32_t fields[] = { 0 }; - uint32_t types[] = { FIELD_TYPE_UNSIGNED }; - struct key_def *key_def = box_key_def_new(fields, types, 1); - assert(key_def != NULL); struct vy_mem *mem = create_test_mem(key_def); - is(mem->dump_lsn, -1, "mem->dump_lsn on empty mem"); const struct vy_stmt_template stmts[] = { STMT_TEMPLATE(100, REPLACE, 1), STMT_TEMPLATE(101, REPLACE, 1), @@ -58,7 +54,6 @@ test_basic(void) /* Clean up */ vy_mem_delete(mem); - key_def_delete(key_def); fiber_gc(); footer(); @@ -67,36 +62,14 @@ test_basic(void) } static void -test_iterator_restore_after_insertion() +test_iterator_restore_after_insertion(void) { header(); plan(1); - /* Create key_def */ - uint32_t fields[] = { 0 }; - uint32_t types[] = { FIELD_TYPE_UNSIGNED }; - struct key_def *key_def = box_key_def_new(fields, types, 1); - assert(key_def != NULL); - - /* Create format */ - struct tuple_format * - format = vy_simple_stmt_format_new(&stmt_env, &key_def, 1); - assert(format != NULL); - tuple_format_ref(format); - - /* Create lsregion */ - struct lsregion lsregion; - struct slab_cache *slab_cache = cord_slab_cache(); - lsregion_create(&lsregion, slab_cache->arena); - struct vy_entry select_key = vy_entry_key_new(stmt_env.key_format, key_def, NULL, 0); - - struct mempool history_node_pool; - mempool_create(&history_node_pool, cord_slab_cache(), - sizeof(struct vy_history_node)); - uint64_t restore_on_value = 20; uint64_t restore_on_value_reverse = 60; char data[16]; @@ -204,7 +177,7 @@ test_iterator_restore_after_insertion() vy_history_create(&history, &history_node_pool); int rc = vy_mem_iterator_next(&itr, &history); e = vy_history_last_stmt(&history); - assert(rc == 0); + fail_unless(rc == 0); size_t j = 0; while (e.stmt != NULL) { if (j >= expected_count) { @@ -225,7 +198,7 @@ test_iterator_restore_after_insertion() break; int rc = vy_mem_iterator_next(&itr, &history); e = vy_history_last_stmt(&history); - assert(rc == 0); + fail_unless(rc == 0); } if (e.stmt == NULL && j != expected_count) wrong_output = true; @@ -297,7 +270,7 @@ test_iterator_restore_after_insertion() j++; int rc = vy_mem_iterator_next(&itr, &history); e = vy_history_last_stmt(&history); - assert(rc == 0); + fail_unless(rc == 0); } if (j != expected_count) wrong_output = true; @@ -308,22 +281,15 @@ test_iterator_restore_after_insertion() vy_history_cleanup(&history); vy_mem_delete(mem); - lsregion_gc(&lsregion, 2); } ok(!wrong_output, "check wrong_output %d", i_fail); /* Clean up */ - mempool_destroy(&history_node_pool); - tuple_unref(select_key.stmt); tuple_unref(restore_on_key.stmt); tuple_unref(restore_on_key_reverse.stmt); - tuple_format_unref(format); - lsregion_destroy(&lsregion); - key_def_delete(key_def); - fiber_gc(); check_plan(); @@ -332,14 +298,26 @@ test_iterator_restore_after_insertion() } int -main(int argc, char *argv[]) +main(void) { vy_iterator_C_test_init(0); plan(2); + + uint32_t fields[] = { 0 }; + uint32_t types[] = { FIELD_TYPE_UNSIGNED }; + key_def = box_key_def_new(fields, types, 1); + fail_if(key_def == NULL); + format = vy_simple_stmt_format_new(&stmt_env, &key_def, 1); + fail_if(format == NULL); + tuple_format_ref(format); + test_basic(); test_iterator_restore_after_insertion(); + tuple_format_unref(format); + key_def_delete(key_def); vy_iterator_C_test_finish(); + return check_plan(); }