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 9814547EB5B; Mon, 29 May 2023 18:26:17 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 9814547EB5B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1685373977; bh=nIOs0WzI8XsWIRG4ED8VX+JX7XRejwOUcx8qIUmB9pM=; h=Date:To:Cc:References:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=Kuse+sxXQ5+MzS6GY8eODKyKDh/L0dFYEXsH912yGfOz54pcSIeuy/TbwqvCtUgsQ 4pH3AUf0COBYLbdQJZE95YFK3xtTh2RVJ4R4o1f+5LZ439Ge+BRZKVRCN8PzPypQFk MPUBsJ4IAAROM7dh+YaxbBvba9HsKxgNrVp6ISBo= Received: from smtp45.i.mail.ru (smtp45.i.mail.ru [95.163.41.83]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id A22C447DF11 for ; Mon, 29 May 2023 18:26:16 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org A22C447DF11 Received: by smtp45.i.mail.ru with esmtpa (envelope-from ) id 1q3elD-003PFc-Ny; Mon, 29 May 2023 18:26:16 +0300 Message-ID: Date: Mon, 29 May 2023 18:26:15 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Content-Language: en-US To: Sergey Kaplun , Igor Munkin , Maxim Kokryashkin Cc: tarantool-patches@dev.tarantool.org References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9FA9FE7958A526B77D1B2C93AD057A54EFC217733DD93BB3A00894C459B0CD1B9D82B87B50149EDC8E334F801232136F30DCA965BBDF5E25150BEE2EB090F92B7 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7A3DED2DACB82E709C2099A533E45F2D0395957E7521B51C2CFCAF695D4D8E9FCEA1F7E6F0F101C6778DA827A17800CE751BC6685BC61E6BCEA1F7E6F0F101C6723150C8DA25C47586E58E00D9D99D84E1BDDB23E98D2D38BE5CCB53A13BC8DBA4F0A7AD0746592282ACC575435E3498DCC7F00164DA146DAFE8445B8C89999728AA50765F79006376B023E84F73EF47C389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC864A52DF3AE21010FF6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA73AA81AA40904B5D9A18204E546F3947C8D6D1DB188AF51016136E347CC761E074AD6D5ED66289B52698AB9A7B718F8C46E0066C2D8992A16725E5C173C3A84C31DEDF2E2F39E2AF1BA3038C0950A5D36B5C8C57E37DE458B330BD67F2E7D9AF16D1867E19FE14079C09775C1D3CA48CF3D321E7403792E342EB15956EA79C166A417C69337E82CC275ECD9A6C639B01B78DA827A17800CE74ABCC139FF3F849B731C566533BA786AA5CC5B56E945C8DA X-B7AD71C0: 4965CFDFE0519134C1FE400A9E48C5401DD40DE57556AFB266D16FC5F53507A1816E0A2A8F779BBED8D40077074E805C66D16FC5F53507A117535B0CF9F6D0C3EE9D5CB6078CC77CE26E269E7006C8F2146EF582D857B11F X-C1DE0DAB: 0D63561A33F958A5519C16ED2E44D3FA5C4D9F0947717D3208D696FB7E8696D6F87CCE6106E1FC07E67D4AC08A07B9B0CE135D2742255B35CB5012B2E24CD356 X-C8649E89: 1C3962B70DF3F0AD75DCE07D45A749953FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CF5DA9996272314040C8A69F0249254CC906C32D5B689A99D6910696F2E82C7AD280C7DAD1783D929BA0A56A47F2C7DF64F85C145D87D08AA766A0631BEF7B81BBF4E8A8FB6BF8EBF5 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojjwJ7vqadnRvBJmLd+ZNv6Q== X-Mailru-Sender: 11C2EC085EDE56FAC07928AF2646A7699581CA4C0B2A321AC8CF3602B6505BB10D95629463F16A6AEBA65886582A37BD66FEC6BF5C9C28D98A98C1125256619760D574B6FC815AB872D6B4FCE48DF648AE208404248635DF X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v2 luajit 3/6] test: introduce utils.h helper for C tests 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: Sergey Bronnikov via Tarantool-patches Reply-To: Sergey Bronnikov Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi, Sergey! Thanks for the patch! See my comments below. On 5/18/23 23:44, Sergey Kaplun wrote: > This header contains generic init and close for tests and helpers for probably "generic init and close *functions*"? > loading auxiliary Lua script with functions to run inside a C test. > > It will be properly used in the next commit. > > Part of tarantool/tarantool#7900 > --- > test/tarantool-c-tests/utils.h | 63 ++++++++++++++++++++++++++++++++++ > 1 file changed, 63 insertions(+) > create mode 100644 test/tarantool-c-tests/utils.h > > diff --git a/test/tarantool-c-tests/utils.h b/test/tarantool-c-tests/utils.h > new file mode 100644 > index 00000000..cf668006 > --- /dev/null > +++ b/test/tarantool-c-tests/utils.h > @@ -0,0 +1,63 @@ > +#include > +#include > + > +#include "lauxlib.h" > +#include "lua.h" > +#include "luajit.h" > +#include "lualib.h" > + > +#include "test.h" > + > +/* Generic init for our tests. */ > +static lua_State *utils_lua_init(void) > +{ > + lua_State *L = luaL_newstate(); > + if (!L) > + bail_out("Can't init Lua state"); > + /* Stop collector during library initialization. */ > + lua_gc(L, LUA_GCSTOP, 0); > + luaL_openlibs(L); > + lua_gc(L, LUA_GCRESTART, -1); > + return L; > +} > + > +/* Generic close for our tests. */ > +static void utils_lua_close(lua_State *L) > +{ > + lua_close(L); > +} > + > +/* > + * Load the pair to the test file . > + * Each file should return the table with functions (named the > + * same as the corresponding unit tests) to call in unit tests. > + * Push the table with those functions on the Lua stack. > + */ > +#define utils_load_aux_script(L) do { \ > + /* \ > + * Format script name. \ > + * `__ABS_FILENAME__` is set via CMake. \ > + */ \ > + char script[PATH_MAX] = __ABS_FILENAME__; \ Why do you need to pass user script to a test library from a build system? Can we pass it in a user function? my_test.c: char script_path[PATH_MAX] = __TEST_LUA_SCRIPT_ABS_PATH__; utils_load_aux_script(L, script_path) BTW filename cannot be absolute, path could be. > + char *file_suffix = strstr(script, ".test.c"); \ > + strcpy(file_suffix, "-script.lua"); \ > + \ > + if (luaL_dofile((L), script) != LUA_OK) { \ > + test_comment("Can't load %s: '%s'", script, \ > + lua_tostring((L), -1)); \ > + bail_out("Can't load auxiliary script"); \ > + } \ > + \ > + if (!lua_istable((L), -1)) \ > + bail_out("Returned value from script is not a table"); \ > +} while (0) > + > +/* > + * Accept a table on top of the Lua stack which containing the > + * function named as the unit test we currently executing. > + */ > +#define utils_get_aux_lfunc(L) do { \ > + lua_getfield((L), -1, __func__); \ > + if (!lua_isfunction((L), -1)) \ > + bail_out("Can't get auxiliary test function"); \ > +} while (0)