From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 3948570361; Wed, 10 Feb 2021 15:25:55 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 3948570361 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1612959955; bh=NXXy6TzICyl0bOLn9MlEt0Mnyy0o6beXqrs8tO52lL4=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=uU6Vr4lWNEfqsmgVNgVVKhp9t0Ozys9yaikSdx4PLyH/IG8zbXS48nsrAXjiyxXXv 6jeB1Mj2X1GADRgapyIHtvl8bKQnvsEGY/uDqUKP75tGvdXIGGPN8VaHUC0sUw3j0P wMGVAvfLxKwB9WUUtQFd9yQIuECQu5WuXK59nEiE= Received: from mail-lj1-f176.google.com (mail-lj1-f176.google.com [209.85.208.176]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 4F0226AABA for ; Wed, 10 Feb 2021 15:25:20 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 4F0226AABA Received: by mail-lj1-f176.google.com with SMTP id q14so2548672ljp.4 for ; Wed, 10 Feb 2021 04:25:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NEt3DlbM0XxFLXK3o5Udoi8IEli9Uk3e8hkeRkURQtY=; b=fDb0XYPJQ1VDM/qrUUNz5YYKxNOyWMXz+5ZBdslvE8Hy9e9dHssrrg4GHIlN7fRtNb Q7Xynks4IkECVe2vXLkjI6sU/H7Krgvl3P4tssFLOKFODwmiPA4WnTGIZxuHMvneupq/ jPWaJT7gvKeb2/VskG77nRSyD8ay6AcJK5+03usPFRIutF7huh9yWNaAIknAntjc2k+e zNAF6nsFnpjnNkQemtIVxFqabcwegX9t32S95ZOU2B+34YmQncK1V+wsKwFxOrLU1+DE t0xXAE0QZZPz1o87giwUwnk5Yq1/3u5kgrAFmRPV8qznlyjNVbYr2bZOMOJQwl2OHSrp 0sng== X-Gm-Message-State: AOAM533Pz0ikTui05J1xGSiYlOAH9r0TcjieDvSP41f5oiv6yGiaRywQ ev3GJqkOZtGK5pFjdT71vn4YLGVdb4E= X-Google-Smtp-Source: ABdhPJyv4kvEyGyhHH0IAnXropD9SdpJrNxxI8IrG5AiD5IjuXj4wBxW6ksF5RRsnbSIr5UoyD5DrQ== X-Received: by 2002:a2e:8789:: with SMTP id n9mr1765010lji.485.1612959917519; Wed, 10 Feb 2021 04:25:17 -0800 (PST) Received: from grain.localdomain ([5.18.171.94]) by smtp.gmail.com with ESMTPSA id x81sm312739lff.33.2021.02.10.04.25.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Feb 2021 04:25:16 -0800 (PST) Received: by grain.localdomain (Postfix, from userid 1000) id B03EC56017B; Wed, 10 Feb 2021 15:24:49 +0300 (MSK) To: tml Date: Wed, 10 Feb 2021 15:24:48 +0300 Message-Id: <20210210122448.66941-3-gorcunov@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210210122448.66941-1-gorcunov@gmail.com> References: <20210210122448.66941-1-gorcunov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH v17 2/2] test: box/cfunc -- add cmod test X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Cyrill Gorcunov via Tarantool-patches Reply-To: Cyrill Gorcunov Cc: Vladislav Shpilevoy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Note that the test is disabled in suite.ini for a while because we need to update test-run first like | diff --git a/pretest_clean.lua b/pretest_clean.lua | index 9b5ac9d..b0280c4 100644 | --- a/pretest_clean.lua | +++ b/pretest_clean.lua | @@ -272,6 +272,7 @@ local function clean() | package = true, | pickle = true, | popen = true, | + cmod = true, | pwd = true, | socket = true, | strict = true, Part-of #4642 Signed-off-by: Cyrill Gorcunov --- test/box/CMakeLists.txt | 2 + test/box/cfunc1.c | 58 ++++++ test/box/cfunc2.c | 137 +++++++++++++ test/box/cmod.result | 418 ++++++++++++++++++++++++++++++++++++++++ test/box/cmod.test.lua | 155 +++++++++++++++ test/box/suite.ini | 2 +- 6 files changed, 771 insertions(+), 1 deletion(-) create mode 100644 test/box/cfunc1.c create mode 100644 test/box/cfunc2.c create mode 100644 test/box/cmod.result create mode 100644 test/box/cmod.test.lua diff --git a/test/box/CMakeLists.txt b/test/box/CMakeLists.txt index 06bfbbe9d..2afbeadc3 100644 --- a/test/box/CMakeLists.txt +++ b/test/box/CMakeLists.txt @@ -3,3 +3,5 @@ build_module(function1 function1.c) build_module(reload1 reload1.c) build_module(reload2 reload2.c) build_module(tuple_bench tuple_bench.c) +build_module(cfunc1 cfunc1.c) +build_module(cfunc2 cfunc2.c) diff --git a/test/box/cfunc1.c b/test/box/cfunc1.c new file mode 100644 index 000000000..f6829372a --- /dev/null +++ b/test/box/cfunc1.c @@ -0,0 +1,58 @@ +#include +#include +#include + +#include "module.h" + +/* + * Before the reload functions are just declared + * and simply exit with zero. + * + * After the module reload we should provide real + * functionality. + */ + +int +cfunc_nop(box_function_ctx_t *ctx, const char *args, const char *args_end) +{ + (void)ctx; + (void)args; + (void)args_end; + return 0; +} + +int +cfunc_fetch_seq_evens(box_function_ctx_t *ctx, const char *args, const char *args_end) +{ + (void)ctx; + (void)args; + (void)args_end; + return 0; +} + +int +cfunc_multireturn(box_function_ctx_t *ctx, const char *args, const char *args_end) +{ + (void)ctx; + (void)args; + (void)args_end; + return 0; +} + +int +cfunc_args(box_function_ctx_t *ctx, const char *args, const char *args_end) +{ + (void)ctx; + (void)args; + (void)args_end; + return 0; +} + +int +cfunc_sum(box_function_ctx_t *ctx, const char *args, const char *args_end) +{ + (void)ctx; + (void)args; + (void)args_end; + return 0; +} diff --git a/test/box/cfunc2.c b/test/box/cfunc2.c new file mode 100644 index 000000000..8c583e993 --- /dev/null +++ b/test/box/cfunc2.c @@ -0,0 +1,137 @@ +#include +#include +#include + +#include "module.h" + +/* + * Just make sure we've been called. + */ +int +cfunc_nop(box_function_ctx_t *ctx, const char *args, const char *args_end) +{ + (void)ctx; + (void)args; + (void)args_end; + return 0; +} + +/* + * Fetch first N even numbers (just to make sure the order of + * arguments is not screwed). + */ +int +cfunc_fetch_seq_evens(box_function_ctx_t *ctx, const char *args, const char *args_end) +{ + int arg_count = mp_decode_array(&args); + if (arg_count != 1) { + return box_error_set(__FILE__, __LINE__, ER_PROC_C, "%s", + "invalid argument count"); + } + int field_count = mp_decode_array(&args); + if (field_count < 1) { + return box_error_set(__FILE__, __LINE__, ER_PROC_C, "%s", + "invalid array size"); + } + + /* + * We expect even numbers sequence here. The idea is + * to test invalid data an issue an error from inside + * of C function. + */ + for (int i = 1; i <= field_count; i++) { + int val = mp_decode_uint(&args); + int needed = 2 * i; + if (val != needed) { + char res[128]; + snprintf(res, sizeof(res), "%s %d != %d", + "invalid argument", val, needed); + return box_error_set(__FILE__, __LINE__, + ER_PROC_C, "%s", res); + } + } + + return 0; +} + +/* + * Return one element array twice. + */ +int +cfunc_multireturn(box_function_ctx_t *ctx, const char *args, const char *args_end) +{ + char tuple_buf[512]; + char *d = tuple_buf; + d = mp_encode_array(d, 1); + d = mp_encode_uint(d, 1); + assert(d <= tuple_buf + sizeof(tuple_buf)); + + box_tuple_format_t *fmt = box_tuple_format_default(); + box_tuple_t *tuple_a = box_tuple_new(fmt, tuple_buf, d); + if (tuple_a == NULL) + return -1; + int rc = box_return_tuple(ctx, tuple_a); + if (rc == 0) + return box_return_tuple(ctx, tuple_a); + return rc; +} + +/* + * Encode int + string pair back. + */ +int +cfunc_args(box_function_ctx_t *ctx, const char *args, const char *args_end) +{ + uint32_t arg_count = mp_decode_array(&args); + if (arg_count != 2) { + return box_error_set(__FILE__, __LINE__, ER_PROC_C, "%s", + "invalid argument count"); + } + + if (mp_typeof(*args) != MP_UINT) { + return box_error_set(__FILE__, __LINE__, ER_PROC_C, "%s", + "tuple field must be uint"); + } + uint32_t num = mp_decode_uint(&args); + + if (mp_typeof(*args) != MP_STR) { + return box_error_set(__FILE__, __LINE__, ER_PROC_C, "%s", + "tuple field must be string"); + } + const char *str = args; + uint32_t len = mp_decode_strl(&str); + + char tuple_buf[512]; + char *d = tuple_buf; + d = mp_encode_array(d, 2); + d = mp_encode_uint(d, num); + d = mp_encode_str(d, str, len); + assert(d <= tuple_buf + sizeof(tuple_buf)); + + box_tuple_format_t *fmt = box_tuple_format_default(); + box_tuple_t *tuple = box_tuple_new(fmt, tuple_buf, d); + if (tuple == NULL) + return -1; + + return box_return_tuple(ctx, tuple); +} + +/* + * Sum two integers. + */ +int +cfunc_sum(box_function_ctx_t *ctx, const char *args, const char *args_end) +{ + uint32_t arg_count = mp_decode_array(&args); + if (arg_count != 2) { + return box_error_set(__FILE__, __LINE__, ER_PROC_C, "%s", + "invalid argument count"); + } + uint64_t a = mp_decode_uint(&args); + uint64_t b = mp_decode_uint(&args); + + char res[16]; + char *end = mp_encode_uint(res, a + b); + box_return_mp(ctx, res, end); + return 0; +} diff --git a/test/box/cmod.result b/test/box/cmod.result new file mode 100644 index 000000000..69099ddd9 --- /dev/null +++ b/test/box/cmod.result @@ -0,0 +1,418 @@ +-- test-run result file version 2 +-- +-- gh-4642: New cmod module to be able to +-- run C stored functions on read only nodes +-- without requirement to register them with +-- box.schema.func help. +-- +build_path = os.getenv("BUILDDIR") + | --- + | ... +package.cpath = build_path..'/test/box/?.so;'..build_path..'/test/box/?.dylib;'..package.cpath + | --- + | ... + +cmod = require('cmod') + | --- + | ... +fio = require('fio') + | --- + | ... + +ext = (jit.os == "OSX" and "dylib" or "so") + | --- + | ... + +cfunc_path = fio.pathjoin(build_path, "test/box/cfunc.") .. ext + | --- + | ... +cfunc1_path = fio.pathjoin(build_path, "test/box/cfunc1.") .. ext + | --- + | ... +cfunc2_path = fio.pathjoin(build_path, "test/box/cfunc2.") .. ext + | --- + | ... + +_ = pcall(fio.unlink(cfunc_path)) + | --- + | ... +fio.symlink(cfunc1_path, cfunc_path) + | --- + | - true + | ... + +_, err = pcall(cmod.load, 'non-such-module') + | --- + | ... +assert(err ~= nil) + | --- + | - true + | ... + +-- All functions are sitting in cfunc.so. +old_module = cmod.load('cfunc') + | --- + | ... +assert(old_module['tt_dev.refs'] == 1) + | --- + | - true + | ... +old_module_copy = cmod.load('cfunc') + | --- + | ... +assert(old_module['tt_dev.refs'] == 2) + | --- + | - true + | ... +assert(old_module_copy['tt_dev.refs'] == 2) + | --- + | - true + | ... +old_module_copy:unload() + | --- + | - true + | ... +assert(old_module['tt_dev.refs'] == 1) + | --- + | - true + | ... +old_cfunc_nop = old_module:load('cfunc_nop') + | --- + | ... +old_cfunc_fetch_seq_evens = old_module:load('cfunc_fetch_seq_evens') + | --- + | ... +old_cfunc_multireturn = old_module:load('cfunc_multireturn') + | --- + | ... +old_cfunc_args = old_module:load('cfunc_args') + | --- + | ... +old_cfunc_sum = old_module:load('cfunc_sum') + | --- + | ... +assert(old_module['tt_dev.refs'] == 6) + | --- + | - true + | ... + +-- Test for error on nonexisting function. +_, err = pcall(old_module.load, old_module, 'no-such-func') + | --- + | ... +assert(err ~= nil) + | --- + | - true + | ... + +-- Make sure they all are callable. +old_cfunc_nop() + | --- + | ... +old_cfunc_fetch_seq_evens() + | --- + | ... +old_cfunc_multireturn() + | --- + | ... +old_cfunc_args() + | --- + | ... +old_cfunc_sum() + | --- + | ... + +-- Unload the module but keep old functions alive, so +-- they keep reference to NOP module internally +-- and still callable. +old_module:unload() + | --- + | - true + | ... +-- Test refs via function name. +assert(old_cfunc_nop['tt_dev.cmod.refs'] == 5) + | --- + | - true + | ... +old_cfunc_nop() + | --- + | ... +old_cfunc_fetch_seq_evens() + | --- + | ... +old_cfunc_multireturn() + | --- + | ... +old_cfunc_args() + | --- + | ... +old_cfunc_sum() + | --- + | ... + +-- The module is unloaded I should not be able +-- to load new shared library. +old_module:load('cfunc') + | --- + | - error: Expects function = module:load('name') but not module object passed + | ... +-- Neither I should be able to unload module twise. +old_module:unload() + | --- + | - error: The module is unloaded + | ... + +-- Clean old functions. +old_cfunc_nop:unload() + | --- + | - true + | ... +old_cfunc_fetch_seq_evens:unload() + | --- + | - true + | ... +old_cfunc_multireturn:unload() + | --- + | - true + | ... +old_cfunc_args:unload() + | --- + | - true + | ... +assert(old_cfunc_sum['tt_dev.cmod.refs'] == 1) + | --- + | - true + | ... +old_cfunc_sum:unload() + | --- + | - true + | ... + +-- And reload old module again. +old_module = cmod.load('cfunc') + | --- + | ... +old_module_id = old_module['tt_dev.id'] + | --- + | ... +assert(old_module['tt_dev.refs'] == 1) + | --- + | - true + | ... + +-- Overwrite module with new contents. +_ = pcall(fio.unlink(cfunc_path)) + | --- + | ... +fio.symlink(cfunc2_path, cfunc_path) + | --- + | - true + | ... + +-- Load new module, cache should be updated. +new_module = cmod.load('cfunc') + | --- + | ... +new_module_id = new_module['tt_dev.id'] + | --- + | ... + +-- Old and new module keep one reference with +-- different IDs. +assert(old_module['tt_dev.refs'] == 1) + | --- + | - true + | ... +assert(old_module['tt_dev.refs'] == new_module['tt_dev.refs']) + | --- + | - true + | ... +assert(old_module_id ~= new_module_id) + | --- + | - true + | ... + +-- All functions from old module should be loadable. +old_cfunc_nop = old_module:load('cfunc_nop') + | --- + | ... +old_cfunc_fetch_seq_evens = old_module:load('cfunc_fetch_seq_evens') + | --- + | ... +old_cfunc_multireturn = old_module:load('cfunc_multireturn') + | --- + | ... +old_cfunc_args = old_module:load('cfunc_args') + | --- + | ... +old_cfunc_sum = old_module:load('cfunc_sum') + | --- + | ... +assert(old_cfunc_nop['tt_dev.cmod.id'] == old_module_id) + | --- + | - true + | ... +assert(old_cfunc_fetch_seq_evens['tt_dev.cmod.id'] == old_module_id) + | --- + | - true + | ... +assert(old_cfunc_multireturn['tt_dev.cmod.id'] == old_module_id) + | --- + | - true + | ... +assert(old_cfunc_args['tt_dev.cmod.id'] == old_module_id) + | --- + | - true + | ... +assert(old_cfunc_sum['tt_dev.cmod.id'] == old_module_id) + | --- + | - true + | ... +assert(old_module['tt_dev.refs'] == 6) + | --- + | - true + | ... + +-- Lookup for updated symbols. +new_cfunc_nop = new_module:load('cfunc_nop') + | --- + | ... +new_cfunc_fetch_seq_evens = new_module:load('cfunc_fetch_seq_evens') + | --- + | ... +new_cfunc_multireturn = new_module:load('cfunc_multireturn') + | --- + | ... +new_cfunc_args = new_module:load('cfunc_args') + | --- + | ... +new_cfunc_sum = new_module:load('cfunc_sum') + | --- + | ... +assert(new_cfunc_nop['tt_dev.cmod.id'] == new_module_id) + | --- + | - true + | ... +assert(new_cfunc_fetch_seq_evens['tt_dev.cmod.id'] == new_module_id) + | --- + | - true + | ... +assert(new_cfunc_multireturn['tt_dev.cmod.id'] == new_module_id) + | --- + | - true + | ... +assert(new_cfunc_args['tt_dev.cmod.id'] == new_module_id) + | --- + | - true + | ... +assert(new_cfunc_sum['tt_dev.cmod.id'] == new_module_id) + | --- + | - true + | ... +assert(new_module['tt_dev.refs'] == 6) + | --- + | - true + | ... + +-- Call old functions. +old_cfunc_nop() + | --- + | ... +old_cfunc_fetch_seq_evens() + | --- + | ... +old_cfunc_multireturn() + | --- + | ... +old_cfunc_args() + | --- + | ... +old_cfunc_sum() + | --- + | ... + +-- Call new functions. +new_cfunc_nop() + | --- + | ... +new_cfunc_multireturn() + | --- + | - [1] + | - [1] + | ... +new_cfunc_fetch_seq_evens({2,4,6}) + | --- + | ... +new_cfunc_fetch_seq_evens({1,2,3}) -- error, odd numbers sequence + | --- + | - error: invalid argument 1 != 2 + | ... +new_cfunc_args(1, "hello") + | --- + | - [1, 'hello'] + | ... +new_cfunc_sum(1) -- error, one arg passed + | --- + | - error: invalid argument count + | ... +new_cfunc_sum(1,2) + | --- + | - 3 + | ... + +-- Cleanup old module's functions. +old_cfunc_nop:unload() + | --- + | - true + | ... +old_cfunc_fetch_seq_evens:unload() + | --- + | - true + | ... +old_cfunc_multireturn:unload() + | --- + | - true + | ... +old_cfunc_args:unload() + | --- + | - true + | ... +old_cfunc_sum:unload() + | --- + | - true + | ... +old_module:unload() + | --- + | - true + | ... + +-- Cleanup new module data. +new_cfunc_nop:unload() + | --- + | - true + | ... +new_cfunc_multireturn:unload() + | --- + | - true + | ... +new_cfunc_fetch_seq_evens:unload() + | --- + | - true + | ... +new_cfunc_args:unload() + | --- + | - true + | ... +new_cfunc_sum:unload() + | --- + | - true + | ... +new_module:unload() + | --- + | - true + | ... + +-- Cleanup the generated symlink +_ = pcall(fio.unlink(cfunc_path)) + | --- + | ... diff --git a/test/box/cmod.test.lua b/test/box/cmod.test.lua new file mode 100644 index 000000000..ad822df13 --- /dev/null +++ b/test/box/cmod.test.lua @@ -0,0 +1,155 @@ +-- +-- gh-4642: New cmod module to be able to +-- run C stored functions on read only nodes +-- without requirement to register them with +-- box.schema.func help. +-- +build_path = os.getenv("BUILDDIR") +package.cpath = build_path..'/test/box/?.so;'..build_path..'/test/box/?.dylib;'..package.cpath + +cmod = require('cmod') +fio = require('fio') + +ext = (jit.os == "OSX" and "dylib" or "so") + +cfunc_path = fio.pathjoin(build_path, "test/box/cfunc.") .. ext +cfunc1_path = fio.pathjoin(build_path, "test/box/cfunc1.") .. ext +cfunc2_path = fio.pathjoin(build_path, "test/box/cfunc2.") .. ext + +_ = pcall(fio.unlink(cfunc_path)) +fio.symlink(cfunc1_path, cfunc_path) + +_, err = pcall(cmod.load, 'non-such-module') +assert(err ~= nil) + +-- All functions are sitting in cfunc.so. +old_module = cmod.load('cfunc') +assert(old_module['tt_dev.refs'] == 1) +old_module_copy = cmod.load('cfunc') +assert(old_module['tt_dev.refs'] == 2) +assert(old_module_copy['tt_dev.refs'] == 2) +old_module_copy:unload() +assert(old_module['tt_dev.refs'] == 1) +old_cfunc_nop = old_module:load('cfunc_nop') +old_cfunc_fetch_seq_evens = old_module:load('cfunc_fetch_seq_evens') +old_cfunc_multireturn = old_module:load('cfunc_multireturn') +old_cfunc_args = old_module:load('cfunc_args') +old_cfunc_sum = old_module:load('cfunc_sum') +assert(old_module['tt_dev.refs'] == 6) + +-- Test for error on nonexisting function. +_, err = pcall(old_module.load, old_module, 'no-such-func') +assert(err ~= nil) + +-- Make sure they all are callable. +old_cfunc_nop() +old_cfunc_fetch_seq_evens() +old_cfunc_multireturn() +old_cfunc_args() +old_cfunc_sum() + +-- Unload the module but keep old functions alive, so +-- they keep reference to NOP module internally +-- and still callable. +old_module:unload() +-- Test refs via function name. +assert(old_cfunc_nop['tt_dev.cmod.refs'] == 5) +old_cfunc_nop() +old_cfunc_fetch_seq_evens() +old_cfunc_multireturn() +old_cfunc_args() +old_cfunc_sum() + +-- The module is unloaded I should not be able +-- to load new shared library. +old_module:load('cfunc') +-- Neither I should be able to unload module twise. +old_module:unload() + +-- Clean old functions. +old_cfunc_nop:unload() +old_cfunc_fetch_seq_evens:unload() +old_cfunc_multireturn:unload() +old_cfunc_args:unload() +assert(old_cfunc_sum['tt_dev.cmod.refs'] == 1) +old_cfunc_sum:unload() + +-- And reload old module again. +old_module = cmod.load('cfunc') +old_module_id = old_module['tt_dev.id'] +assert(old_module['tt_dev.refs'] == 1) + +-- Overwrite module with new contents. +_ = pcall(fio.unlink(cfunc_path)) +fio.symlink(cfunc2_path, cfunc_path) + +-- Load new module, cache should be updated. +new_module = cmod.load('cfunc') +new_module_id = new_module['tt_dev.id'] + +-- Old and new module keep one reference with +-- different IDs. +assert(old_module['tt_dev.refs'] == 1) +assert(old_module['tt_dev.refs'] == new_module['tt_dev.refs']) +assert(old_module_id ~= new_module_id) + +-- All functions from old module should be loadable. +old_cfunc_nop = old_module:load('cfunc_nop') +old_cfunc_fetch_seq_evens = old_module:load('cfunc_fetch_seq_evens') +old_cfunc_multireturn = old_module:load('cfunc_multireturn') +old_cfunc_args = old_module:load('cfunc_args') +old_cfunc_sum = old_module:load('cfunc_sum') +assert(old_cfunc_nop['tt_dev.cmod.id'] == old_module_id) +assert(old_cfunc_fetch_seq_evens['tt_dev.cmod.id'] == old_module_id) +assert(old_cfunc_multireturn['tt_dev.cmod.id'] == old_module_id) +assert(old_cfunc_args['tt_dev.cmod.id'] == old_module_id) +assert(old_cfunc_sum['tt_dev.cmod.id'] == old_module_id) +assert(old_module['tt_dev.refs'] == 6) + +-- Lookup for updated symbols. +new_cfunc_nop = new_module:load('cfunc_nop') +new_cfunc_fetch_seq_evens = new_module:load('cfunc_fetch_seq_evens') +new_cfunc_multireturn = new_module:load('cfunc_multireturn') +new_cfunc_args = new_module:load('cfunc_args') +new_cfunc_sum = new_module:load('cfunc_sum') +assert(new_cfunc_nop['tt_dev.cmod.id'] == new_module_id) +assert(new_cfunc_fetch_seq_evens['tt_dev.cmod.id'] == new_module_id) +assert(new_cfunc_multireturn['tt_dev.cmod.id'] == new_module_id) +assert(new_cfunc_args['tt_dev.cmod.id'] == new_module_id) +assert(new_cfunc_sum['tt_dev.cmod.id'] == new_module_id) +assert(new_module['tt_dev.refs'] == 6) + +-- Call old functions. +old_cfunc_nop() +old_cfunc_fetch_seq_evens() +old_cfunc_multireturn() +old_cfunc_args() +old_cfunc_sum() + +-- Call new functions. +new_cfunc_nop() +new_cfunc_multireturn() +new_cfunc_fetch_seq_evens({2,4,6}) +new_cfunc_fetch_seq_evens({1,2,3}) -- error, odd numbers sequence +new_cfunc_args(1, "hello") +new_cfunc_sum(1) -- error, one arg passed +new_cfunc_sum(1,2) + +-- Cleanup old module's functions. +old_cfunc_nop:unload() +old_cfunc_fetch_seq_evens:unload() +old_cfunc_multireturn:unload() +old_cfunc_args:unload() +old_cfunc_sum:unload() +old_module:unload() + +-- Cleanup new module data. +new_cfunc_nop:unload() +new_cfunc_multireturn:unload() +new_cfunc_fetch_seq_evens:unload() +new_cfunc_args:unload() +new_cfunc_sum:unload() +new_module:unload() + +-- Cleanup the generated symlink +_ = pcall(fio.unlink(cfunc_path)) diff --git a/test/box/suite.ini b/test/box/suite.ini index e700d0b9e..fc16c5951 100644 --- a/test/box/suite.ini +++ b/test/box/suite.ini @@ -2,7 +2,7 @@ core = tarantool description = Database tests script = box.lua -disabled = rtree_errinj.test.lua tuple_bench.test.lua +disabled = rtree_errinj.test.lua tuple_bench.test.lua cmod.test.lua long_run = huge_field_map_long.test.lua config = engine.cfg release_disabled = errinj.test.lua errinj_index.test.lua rtree_errinj.test.lua upsert_errinj.test.lua iproto_stress.test.lua gh-4648-func-load-unload.test.lua -- 2.29.2