From: Cyrill Gorcunov <gorcunov@gmail.com> To: tml <tarantool-patches@dev.tarantool.org> Cc: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>, Alexander Turenko <alexander.turenko@tarantool.org> Subject: [Tarantool-patches] [PATCH v4 6/6] test: box/cfunc -- add simple module test Date: Thu, 1 Oct 2020 16:51:13 +0300 [thread overview] Message-ID: <20201001135113.329664-7-gorcunov@gmail.com> (raw) In-Reply-To: <20201001135113.329664-1-gorcunov@gmail.com> Note that the test is disabled for a while since 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, | + cfunc = true, | pwd = true, | socket = true, | strict = true, ie need to enable cfunc module. Part-of #4642 Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com> --- test/box/CMakeLists.txt | 2 + test/box/cfunc.result | 116 ++++++++++++++++++++++++++++++++++++++++ test/box/cfunc.test.lua | 56 +++++++++++++++++++ test/box/cfunc1.c | 46 ++++++++++++++++ test/box/cfunc2.c | 46 ++++++++++++++++ test/box/suite.ini | 2 +- 6 files changed, 267 insertions(+), 1 deletion(-) create mode 100644 test/box/cfunc.result create mode 100644 test/box/cfunc.test.lua create mode 100644 test/box/cfunc1.c create mode 100644 test/box/cfunc2.c 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/cfunc.result b/test/box/cfunc.result new file mode 100644 index 000000000..beb07d775 --- /dev/null +++ b/test/box/cfunc.result @@ -0,0 +1,116 @@ +-- test-run result file version 2 +build_path = os.getenv("BUILDDIR") + | --- + | ... +package.cpath = build_path..'/test/box/?.so;'..build_path..'/test/box/?.dylib;'..package.cpath + | --- + | ... + +cfunc = require('cfunc') + | --- + | ... +fio = require('fio') + | --- + | ... + +cfunc_path = fio.pathjoin(build_path, "test/box/cfunc.so") + | --- + | ... +cfunc1_path = fio.pathjoin(build_path, "test/box/cfunc1.so") + | --- + | ... +cfunc2_path = fio.pathjoin(build_path, "test/box/cfunc2.so") + | --- + | ... + +_ = pcall(fio.unlink(cfunc_path)) + | --- + | ... +fio.symlink(cfunc1_path, cfunc_path) + | --- + | - true + | ... + +-- +-- Both of them are sitting in cfunc.so +cfunc.create('cfunc.cfunc_sole_call') + | --- + | ... +cfunc.create('cfunc.cfunc_fetch_array') + | --- + | ... + +-- +-- Make sure they are registered fine +cfunc.exists('cfunc.cfunc_sole_call') + | --- + | - true + | ... +cfunc.exists('cfunc.cfunc_fetch_array') + | --- + | - true + | ... + +-- +-- And they are listed +cfunc.list() + | --- + | - - cfunc.cfunc_sole_call + | - cfunc.cfunc_fetch_array + | ... + +-- +-- Make sure they all collable +cfunc.call('cfunc.cfunc_sole_call') + | --- + | ... +cfunc.call('cfunc.cfunc_fetch_array', {1,2,3,4}) + | --- + | ... +-- This one should issue an error +cfunc.call('cfunc.cfunc_fetch_array', {1,2,4}) + | --- + | - error: invalid argument 4 != 3 + | ... + +-- +-- Clean old function references and reload new one. +_ = pcall(fio.unlink(cfunc_path)) + | --- + | ... +fio.symlink(cfunc2_path, cfunc_path) + | --- + | - true + | ... + +cfunc.reload('cfunc.cfunc_fetch_array') + | --- + | ... + +cfunc.call('cfunc.cfunc_sole_call') + | --- + | ... +cfunc.call('cfunc.cfunc_fetch_array', {2,4,6}) + | --- + | ... + +-- +-- Clean it up +cfunc.drop('cfunc.cfunc_sole_call') + | --- + | ... +cfunc.drop('cfunc.cfunc_fetch_array') + | --- + | ... + +-- +-- List should be empty +cfunc.list() + | --- + | ... + +-- +-- Cleanup the generated symlink +_ = pcall(fio.unlink(cfunc_path)) + | --- + | ... diff --git a/test/box/cfunc.test.lua b/test/box/cfunc.test.lua new file mode 100644 index 000000000..01e5fbebb --- /dev/null +++ b/test/box/cfunc.test.lua @@ -0,0 +1,56 @@ +build_path = os.getenv("BUILDDIR") +package.cpath = build_path..'/test/box/?.so;'..build_path..'/test/box/?.dylib;'..package.cpath + +cfunc = require('cfunc') +fio = require('fio') + +cfunc_path = fio.pathjoin(build_path, "test/box/cfunc.so") +cfunc1_path = fio.pathjoin(build_path, "test/box/cfunc1.so") +cfunc2_path = fio.pathjoin(build_path, "test/box/cfunc2.so") + +_ = pcall(fio.unlink(cfunc_path)) +fio.symlink(cfunc1_path, cfunc_path) + +-- +-- Both of them are sitting in cfunc.so +cfunc.create('cfunc.cfunc_sole_call') +cfunc.create('cfunc.cfunc_fetch_array') + +-- +-- Make sure they are registered fine +cfunc.exists('cfunc.cfunc_sole_call') +cfunc.exists('cfunc.cfunc_fetch_array') + +-- +-- And they are listed +cfunc.list() + +-- +-- Make sure they all collable +cfunc.call('cfunc.cfunc_sole_call') +cfunc.call('cfunc.cfunc_fetch_array', {1,2,3,4}) +-- This one should issue an error +cfunc.call('cfunc.cfunc_fetch_array', {1,2,4}) + +-- +-- Clean old function references and reload new one. +_ = pcall(fio.unlink(cfunc_path)) +fio.symlink(cfunc2_path, cfunc_path) + +cfunc.reload('cfunc.cfunc_fetch_array') + +cfunc.call('cfunc.cfunc_sole_call') +cfunc.call('cfunc.cfunc_fetch_array', {2,4,6}) + +-- +-- Clean it up +cfunc.drop('cfunc.cfunc_sole_call') +cfunc.drop('cfunc.cfunc_fetch_array') + +-- +-- List should be empty +cfunc.list() + +-- +-- Cleanup the generated symlink +_ = pcall(fio.unlink(cfunc_path)) diff --git a/test/box/cfunc1.c b/test/box/cfunc1.c new file mode 100644 index 000000000..4334f28da --- /dev/null +++ b/test/box/cfunc1.c @@ -0,0 +1,46 @@ +#include <stdio.h> +#include <stdbool.h> +#include <msgpuck.h> + +#include "module.h" + +/* + * Just make sure we've been called. + */ +int +cfunc_sole_call(box_function_ctx_t *ctx, const char *args, const char *args_end) +{ + say_info("-- cfunc_sole_call - called --"); + printf("ok - cfunc_sole_call\n"); + return 0; +} + +/* + * Fetch N-array + */ +int +cfunc_fetch_array(box_function_ctx_t *ctx, const char *args, const char *args_end) +{ + int arg_count = mp_decode_array(&args); + int field_count = mp_decode_array(&args); + + (void)arg_count; + (void)field_count; + + say_info("-- cfunc_fetch_array - called --"); + + for (int i = 0; i < field_count; i++) { + int val = mp_decode_uint(&args); + int needed = (i+1); + 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); + } + } + + printf("ok - cfunc_fetch_array\n"); + return 0; +} diff --git a/test/box/cfunc2.c b/test/box/cfunc2.c new file mode 100644 index 000000000..30ac48010 --- /dev/null +++ b/test/box/cfunc2.c @@ -0,0 +1,46 @@ +#include <stdio.h> +#include <stdbool.h> +#include <msgpuck.h> + +#include "module.h" + +/* + * Just make sure we've been called. + */ +int +cfunc_sole_call(box_function_ctx_t *ctx, const char *args, const char *args_end) +{ + say_info("-- cfunc_sole_call - called --"); + printf("ok - cfunc_sole_call\n"); + return 0; +} + +/* + * Fetch N-array + */ +int +cfunc_fetch_array(box_function_ctx_t *ctx, const char *args, const char *args_end) +{ + int arg_count = mp_decode_array(&args); + int field_count = mp_decode_array(&args); + + (void)arg_count; + (void)field_count; + + say_info("-- cfunc_fetch_array - called --"); + + for (int i = 0; i < field_count; i++) { + int val = mp_decode_uint(&args); + int needed = 2 * (i+1); + 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); + } + } + + printf("ok - cfunc_fetch_array\n"); + return 0; +} diff --git a/test/box/suite.ini b/test/box/suite.ini index 793b8bf76..54130f43f 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 cfunc.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.26.2
next prev parent reply other threads:[~2020-10-01 13:52 UTC|newest] Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-10-01 13:51 [Tarantool-patches] [PATCH v4 0/6] box/func: implement cfunc Lua module Cyrill Gorcunov 2020-10-01 13:51 ` [Tarantool-patches] [PATCH v4 1/6] box/func: factor out c function entry structure Cyrill Gorcunov 2020-10-01 13:51 ` [Tarantool-patches] [PATCH v4 2/6] box/func: provide module_sym_call Cyrill Gorcunov 2020-10-01 13:51 ` [Tarantool-patches] [PATCH v4 3/6] box/func: more detailed error in module reloading Cyrill Gorcunov 2020-10-01 13:51 ` [Tarantool-patches] [PATCH v4 4/6] box/func: export func_split_name helper Cyrill Gorcunov 2020-10-01 13:51 ` [Tarantool-patches] [PATCH v4 5/6] box/func: implement cfunc Lua module Cyrill Gorcunov 2020-10-03 13:55 ` Vladislav Shpilevoy 2020-10-05 10:31 ` Cyrill Gorcunov 2020-10-05 21:59 ` Vladislav Shpilevoy 2020-10-06 12:55 ` Cyrill Gorcunov 2020-10-01 13:51 ` Cyrill Gorcunov [this message] 2020-10-03 13:55 ` [Tarantool-patches] [PATCH v4 6/6] test: box/cfunc -- add simple module test Vladislav Shpilevoy 2020-10-03 13:55 ` [Tarantool-patches] [PATCH v4 0/6] box/func: implement cfunc Lua module Vladislav Shpilevoy 2020-10-05 11:51 ` Cyrill Gorcunov 2020-10-05 21:59 ` Vladislav Shpilevoy
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20201001135113.329664-7-gorcunov@gmail.com \ --to=gorcunov@gmail.com \ --cc=alexander.turenko@tarantool.org \ --cc=tarantool-patches@dev.tarantool.org \ --cc=v.shpilevoy@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH v4 6/6] test: box/cfunc -- add simple module test' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox