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 DEBA4485705; Thu, 18 May 2023 23:50:31 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org DEBA4485705 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1684443032; bh=Ihd6Zj7dS0Q66RRDmm40iCsFdqZms6SLvwIZNC6VbhQ=; 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=ljsd4v7GFX4Bl8mCOTEnIdCjVvfx/7fgLIBUx/YCyIqFFXxAsAj50dwKMlD7iNqHg aWpxcdzyca3rNFonaKQdPdk9F5lAsnG2+yiJusrUw9qipWp7ikLU8aa2KStdjiDE/x +wnI8RxH51kQh0rOYJCYCob1IsVjICXJAyAfU21Q= Received: from smtpng3.i.mail.ru (smtpng3.i.mail.ru [94.100.177.149]) (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 DB17E485705 for ; Thu, 18 May 2023 23:49:03 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org DB17E485705 Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1pzkYY-0005wh-RE; Thu, 18 May 2023 23:49:03 +0300 To: Igor Munkin , Maxim Kokryashkin , Sergey Bronnikov Date: Thu, 18 May 2023 23:44:50 +0300 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD921E8753A900160F1284B0F69140CBAD1A547053F7D6F1311182A05F538085040175DC1C5E402C107787ED9C43A5108375AB16009D99A71E36EEFB65150F7F85C X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7F9D3BE5B596754B8C2099A533E45F2D0395957E7521B51C2CFCAF695D4D8E9FCEA1F7E6F0F101C6778DA827A17800CE75840EB8CDBC1001FEA1F7E6F0F101C6723150C8DA25C47586E58E00D9D99D84E1BDDB23E98D2D38B6F1F7B995052D5CE92D205286E81FBDE718CB805303A8096CC7F00164DA146DAFE8445B8C89999728AA50765F790063758C4D2C2836A4C79389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC8E6BDB36F057AC83CF6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA7E827F84554CEF5019E625A9149C048EE9ECD01F8117BC8BEE2021AF6380DFAD18AA50765F790063735872C767BF85DA227C277FBC8AE2E8B851EDB9C5A93305EEFF80C71ABB335746BA297DBC24807EABDAD6C7F3747799A X-C1DE0DAB: 0D63561A33F958A59F2A0D646BAA3455DDE4659982D14559180A554079D5EF75F87CCE6106E1FC07E67D4AC08A07B9B01F9513A7CA91E5559C5DF10A05D560A950611B66E3DA6D700B0A020F03D25A0997E3FB2386030E77 X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CFE442EC39D73A150ECF115E670C3E974C153D1F8B720E94AF1BE354E28D837AFB768602CF99B169960DBD3925112B781EF1EDFE43059A5291311EAB0AF3BB339806EEC8038AF5C160 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojXj30btAgf0aq+Eqdg97izg== X-DA7885C5: 24CE6FE1C085E831117DE7BC9A9FF824469DCF1A2EF4463F34F26B6C7CA39BF9262E2D401490A4A0DB037EFA58388B346E8BC1A9835FDE71 X-Mailru-Sender: 689FA8AB762F73933AF1F914F131DBF524BD42BA85809617E684471FA1BA54C30FBE9A32752B8C9C2AA642CC12EC09F1FB559BB5D741EB962F61BD320559CF1EFD657A8799238ED55FEEDEB644C299C0ED14614B50AE0675 X-Mras: Ok Subject: [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 Kaplun via Tarantool-patches Reply-To: Sergey Kaplun Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" This header contains generic init and close for tests and helpers for 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__; \ + 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) -- 2.34.1