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 26D684427C8; Sat, 20 May 2023 11:12:26 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 26D684427C8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1684570346; bh=UZHwsfBmRa7txpV0e7gPqV49D0fF0lNztTP372chawI=; 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=fsMRzJuUi9TNOBG0iuKUGvspkfD7DXI1+lQfE4TfUR7oOmg68mlgZHKnkF1J+UM9w OyOh+2CSPgGf2maVLuMHuDJeE+S0UIZd5QiKy6dPBhijnZBiMzeWiuYrQ15aTFOtCx E8vgEjJAQRQiSRLeDUr6m6i7xeTMHiPpM935NnC0= 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 74D666FCB3 for ; Sat, 20 May 2023 11:12:24 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 74D666FCB3 Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1q0HhP-00080L-F1; Sat, 20 May 2023 11:12:24 +0300 Date: Sat, 20 May 2023 11:08:19 +0300 To: Maxim Kokryashkin Message-ID: References: <0ceed30db5259087a6733c429ed5a2502468ce40.1684442182.git.skaplun@tarantool.org> <1684498677.336586177@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: <1684498677.336586177@f752.i.mail.ru> X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD921E8753A900160F1284B0F69140CBAD176CF7240C0898F5B182A05F538085040C8605960A8E26ABBC3908511A315425262CBA948FEDA668E8A263DE129AF0D71 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7CF4D16325FBE1EEDEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006371C57DA68CF6C21388638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D81711217E1BBD62B2C157D24ACAE93F44117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCAA1C5B227563B4AFA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F4460429728776938767073520CCD848CCB6FE560C6FD1C55BDD38FC3FD2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B6A1DCCEB63E2F10FB089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: 0D63561A33F958A5D9B1536CFB43D766059ACDF609B002AE2215C7ED1EC2B62BF87CCE6106E1FC07E67D4AC08A07B9B0CE135D2742255B35CB5012B2E24CD356 X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CF1FC92C6E7EF1DC58B1224388E605BB4EAADFEEA489E2BD964842BB8B63E5C23A96A3CD8EA40B8F9744C44B1DB2C1FC291F926EF6757612B6597A7CE7316EB889F4E8A8FB6BF8EBF5 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojlaZ30BpkxfKEvggGnykpTw== X-DA7885C5: 2D36C7605F3F53C85ABF246BFD6CDC6570E17FB1CAC6165BF01C288BDC8DC493262E2D401490A4A0DB037EFA58388B346E8BC1A9835FDE71 X-Mailru-Sender: 689FA8AB762F73930F533AC2B33E986B0CD18A8A2E4F24D905230E473618A0330FBE9A32752B8C9C2AA642CC12EC09F1FB559BB5D741EB962F61BD320559CF1EFD657A8799238ED55FEEDEB644C299C0ED14614B50AE0675 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v2 luajit 4/6] test: rewrite misclib-getmetrics-capi test in C 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! See my answers below. On 19.05.23, Maxim Kokryashkin wrote: > > Hi, Sergey > Thanks for the patch. > LGTM, except for a few comments below. >   > >  > >>diff --git a/test/tarantool-c-tests/CMakeLists.txt b/test/tarantool-c-tests/CMakeLists.txt > >>index c6b7cd30..c9d75d6c 100644 > >>--- a/test/tarantool-c-tests/CMakeLists.txt > >>+++ b/test/tarantool-c-tests/CMakeLists.txt > >>@@ -22,13 +22,37 @@ set_target_properties(libtest PROPERTIES > >>   LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" > >> ) > >>  > >>-# XXX: For now, just build libtest. The tests to be depended on > >>-# will be added in the next commit. > >>+# TARGET_C_FLAGS is required here to be sure that headers like > >>+# lj_arch.h in compiled test are consistent with the LuaJIT library > >>+# to link. > >>+AppendFlags(TESTS_C_FLAGS ${TARGET_C_FLAGS}) > >>+ > >>+set(CTEST_SRC_SUFFIX ".test.c") > >>+file(GLOB tests "${CMAKE_CURRENT_SOURCE_DIR}/*${CTEST_SRC_SUFFIX}") > >>+foreach(test_source ${tests}) > >>+ string(REGEX REPLACE ".+/([^/]+)${CTEST_SRC_SUFFIX}" "\\1" exe ${test_source}) > >Please drop a comment explaining the line above. Added the following comment. Branch is force-pushed. =================================================================== diff --git a/test/tarantool-c-tests/CMakeLists.txt b/test/tarantool-c-tests/CMakeLists.txt index c9d75d6c..20495386 100644 --- a/test/tarantool-c-tests/CMakeLists.txt +++ b/test/tarantool-c-tests/CMakeLists.txt @@ -30,6 +30,7 @@ AppendFlags(TESTS_C_FLAGS ${TARGET_C_FLAGS}) set(CTEST_SRC_SUFFIX ".test.c") file(GLOB tests "${CMAKE_CURRENT_SOURCE_DIR}/*${CTEST_SRC_SUFFIX}") foreach(test_source ${tests}) + # Get test name without suffix. Needed to set OUTPUT_NAME. string(REGEX REPLACE ".+/([^/]+)${CTEST_SRC_SUFFIX}" "\\1" exe ${test_source}) add_executable(${exe} EXCLUDE_FROM_ALL ${test_source}) target_include_directories(${exe} PRIVATE =================================================================== > >  > > > >> > >>diff --git a/test/tarantool-tests/misclib-getmetrics-capi.test.lua b/test/tarantool-c-tests/misclib-getmetrics-capi-script.lua > >>similarity index 68% > >>rename from test/tarantool-tests/misclib-getmetrics-capi.test.lua > >>rename to test/tarantool-c-tests/misclib-getmetrics-capi-script.lua > >>index 654e5545..2f0ee5cf 100644 > >>--- a/test/tarantool-tests/misclib-getmetrics-capi.test.lua > >>+++ b/test/tarantool-c-tests/misclib-getmetrics-capi-script.lua > > > >>diff --git a/test/tarantool-c-tests/misclib-getmetrics-capi.test.c b/test/tarantool-c-tests/misclib-getmetrics-capi.test.c > >>new file mode 100644 > >>index 00000000..202cd395 > >>--- /dev/null > >>+++ b/test/tarantool-c-tests/misclib-getmetrics-capi.test.c > >>+ lua_gc(L, LUA_GCCOLLECT, 0); > >>+ luaM_metrics(L, &newm); > >>+ assert_true(newm.gc_steps_pause - oldm.gc_steps_pause == 1); > >>+ assert_true(newm.gc_steps_propagate - oldm.gc_steps_propagate >= 1); > >>+ assert_true(newm.gc_steps_atomic - oldm.gc_steps_atomic == 1); > >>+ assert_true(newm.gc_steps_sweepstring - oldm.gc_steps_sweepstring >= 1); > >>+ assert_true(newm.gc_steps_sweep - oldm.gc_steps_sweep >= 1); > >>+ /* Nothing to finalize, skipped. */ > >>+ assert_true(newm.gc_steps_finalize == 0); > >>+ oldm = newm; > >>+ > >>+ /* > >>+ * Now let's run three GC cycles to ensure that > >>+ * increment was not a lucky coincidence. > >>+ */ > >>+ lua_gc(L, LUA_GCCOLLECT, 0); > >>+ lua_gc(L, LUA_GCCOLLECT, 0); > >>+ lua_gc(L, LUA_GCCOLLECT, 0); > >I think it is better to create a for loop here. I just reuse code from the previous implementation, there is no goal to refactor it. Also, use 3 calls in a raw looks OK to me. > >>+ luaM_metrics(L, &newm); > >>+ assert_true(newm.gc_steps_pause - oldm.gc_steps_pause == 3); > >>+ assert_true(newm.gc_steps_propagate - oldm.gc_steps_propagate >= 3); > >>+ assert_true(newm.gc_steps_atomic - oldm.gc_steps_atomic == 3); > >>+ assert_true(newm.gc_steps_sweepstring - oldm.gc_steps_sweepstring >= 3); > >>+ assert_true(newm.gc_steps_sweep - oldm.gc_steps_sweep >= 3); > >That part is duplicated. It is better to either write a corresponding macro, or > >a function. Ditto. > >>+ /* Nothing to finalize, skipped. */ > >>+/* > >>+ * Get function to call to generate the corresponding snapshot > >>+ * restores on top of the Lua stack. Function returns the amount > >>+ * of snapshot restorations expected. > >>+ * Clear stack after call. > >>+ */ > >>+static void check_snap_restores(lua_State *L) > >>+{ > >>+ struct luam_Metrics oldm, newm; > >>+ luaM_metrics(L, &oldm); > >>+ /* Generate snapshots. */ > >>+ lua_call(L, 0, 1); > >>+ int n = lua_gettop(L); > >>+ /* > >>+ * The first value is the table with functions, > >>+ * the second is number of snapshot restores. > >>+ */ > >>+ if (n != 2 || !lua_isnumber(L, -1)) > >>+ bail_out("incorrect return value: 1 number is required"); > >>+ size_t snap_restores = lua_tonumber(L, -1); > >>+ luaM_metrics(L, &newm); > >>+ /* > >>+ * Remove `snap_restores` from stack. > >>+ * Must be done before potiential assert and exit from > >>+ * the test. > >>+ */ > >>+ lua_pop(L, 1); > >>+ assert_true(newm.jit_snap_restore - oldm.jit_snap_restore > >>+ == snap_restores); > >>+} > >>+ > >>+static int snap_restores_direct_exit(void *test_state) > >>+{ > >>+ lua_State *L = test_state; > >>+ utils_get_aux_lfunc(L); > >>+ check_snap_restores(L); > >>+ return TEST_EXIT_SUCCESS; > >>+} > >>+ > >>+static int snap_restores_direct_exit_scalar(void *test_state) > >>+{ > >>+ lua_State *L = test_state; > >>+ utils_get_aux_lfunc(L); > >>+ check_snap_restores(L); > >>+ return TEST_EXIT_SUCCESS; > >>+} > >>+ > >>+static int snap_restores_side_exit_compiled(void *test_state) > >>+{ > >>+ lua_State *L = test_state; > >>+ utils_get_aux_lfunc(L); > >>+ check_snap_restores(L); > >>+ return TEST_EXIT_SUCCESS; > >>+} > >>+ > >>+static int snap_restores_side_exit_not_compiled(void *test_state) > >>+{ > >>+ lua_State *L = test_state; > >>+ utils_get_aux_lfunc(L); > >>+ check_snap_restores(L); > >>+ return TEST_EXIT_SUCCESS; > >>+} > >>+ > >Same here. Either a dedicated implementation func, or a macro is needed here. `utils_get_aux_lfunc(L)` helper macro looks to the __func__ value, to load the corresponding function from Lua script. We may add the macro to generate functions, but I doubt that it will improve readability of the code. I may add an additional comment to `check_snap_restores()` about `utils_get_aux_lfunc(L)`, but existing one looks self-sufficient for me right now, so please guide me here:). > >>+static int snap_restores_group(void *test_state) > >>diff --git a/test/tarantool-tests/CMakeLists.txt b/test/tarantool-tests/CMakeLists.txt > >>-- > >>2.34.1 > >-- > >Best regards, > >Maxim Kokryashkin > >  -- Best regards, Sergey Kaplun