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 A1AE345CC35; Sat, 20 May 2023 10:56:41 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org A1AE345CC35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1684569401; bh=vwB4K2cDrvOWy4XUfKVe7zirBEToG5rj4xM3Z8m3LtA=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=kbeqecljpkBZyoClIJ6SyjRLZAkx4riCMnbO3l1i/YwUdLvUDm6Xz5q7nGObHX7H8 oEoDS/ua7/9QB9BvQDYJjnADiJ4O9OU2pCjBRJYUBjkRAWbCRj8OYZXeph/mzrwpJm TANNzFL0qg7L3FI2TDPs/VDG9d/sWRhMpq/nF5mM= 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 3ACE26FCB3 for ; Sat, 20 May 2023 10:56:40 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 3ACE26FCB3 Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1q0HSB-0003VI-4Y; Sat, 20 May 2023 10:56:39 +0300 Date: Sat, 20 May 2023 10:52:34 +0300 To: Maxim Kokryashkin Message-ID: References: <1684497505.831218025@f752.i.mail.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1684497505.831218025@f752.i.mail.ru> X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: EEAE043A70213CC8 X-77F55803: 4F1203BC0FB41BD9688F3C11B78FDEB0DD9D63E22DC2FB44B0414F963B22963C1313CFAB8367EF908E2BE116634AD74DFA257BF609D176A581ACB0ECDA820CBCE2BEBC4B1C2D7A93784ED878CF4C7D9C X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE745C0EDBD94D46193EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F790063707C4856229E8E7E48638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8FD8F4941EC37B18B2F51A8E4948BC340117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC0F49EF363AAD6E82A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F44604297287769387670735200AC5B80A05675ACDE5D25F19253116ADD2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B6A1DCCEB63E2F10FB089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: 0D63561A33F958A504F5B680C6DCA151D59D2FEA2DD9B711F3EE92C30FAB093FF87CCE6106E1FC07E67D4AC08A07B9B01F9513A7CA91E555CB5012B2E24CD356 X-C8649E89: 1C3962B70DF3F0ADBF74143AD284FC7177DD89D51EBB7742424CF958EAFF5D571004E42C50DC4CA955A7F0CF078B5EC49A30900B95165D34D16EA493CC1FD9F8F550887AB07F4B039F8C9624C800C93F1EB70857120C6D979FF444D17B98A6DB1D7E09C32AA3244C27E6202EAE0C6505FE9F2938403558F59CA7333006C390A0927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojlaZ30BpkxfKzcAK2hfW6vg== X-DA7885C5: E58655E0E6838821DA17FC248D4C302DDE149957719EB3D4158EC22B4A4DEFBD262E2D401490A4A0DB037EFA58388B346E8BC1A9835FDE71 X-Mailru-Sender: 689FA8AB762F73930F533AC2B33E986BEB59ACAA6199E26BCCD6E82827830A520FBE9A32752B8C9C2AA642CC12EC09F1FB559BB5D741EB962F61BD320559CF1EFD657A8799238ED55FEEDEB644C299C0ED14614B50AE0675 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 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" Hi, Maxim! Thanks for the review! Please, see my comments below. On 19.05.23, Maxim Kokryashkin wrote: > > Hi, Sergey! > Thanks for the patch! > Please consider a few comments below. > >  > >>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); > >>+} > >Do we __really__ need this function?) We haven't any other work to do __for now__, but with time maybe other checks will come here. So, leave it as is for consistensy, if you don't mind. > >>+ > >>+/* > >>+ * 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"); \ > >The `strstr` function is not safe, use `strnstr` instead. > >Also, maybe it is better to use the `strrstr` variation, > >because it searches from the end. It eleminates issues > >in case of a file with .test.c somewhere else in the name. There's no function named `strnstr()`, in standard C or POSIX. It's not in glibc/Linux either, IINM. I want to avoid additional linking dependencies (as for -lsstrings2). `strstr()` is unsafe when we have non-null terminated strings. It's not our case. > >>+ strcpy(file_suffix, "-script.lua"); \ > >Same applies here. Don't see the reason to write `"script.lua", sizeof("script.lua")` | The strncpy() function is similar, except that at most n bytes of | src are copied. Warning: If there is no null byte among the | first n bytes of src, the string placed in dest will not be | null-terminated. So, I'll just use `strcpy()`. > >>+ \ > >>+ 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 > >  > >-- > >Best regards, > >Maxim Kokryashkin > >  -- Best regards, Sergey Kaplun