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 51E881270B17; Mon, 10 Mar 2025 17:52:10 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 51E881270B17 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1741618330; bh=OBnm4WzakBb3Pz2oxIHZyU2r0pynf49UQMy5Y2O3gN8=; 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=BC1qnKgINehxB2c37MNTBTwRvtbVzcXV7XYaCaZS+fZo7iWY6E+Qe8u1d/FnoamVM dZQ5HFzikxEDS6ClUbSldnKe8FOPWjUvS65bwt1QaMR1hm+e86MpjPW/t6jAL5ysyx zjgkLyDeyKHW7+fl7LHkevxG4KQx1TLNkxvxLL1k= Received: from send277.i.mail.ru (send277.i.mail.ru [95.163.59.116]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id CB1331270B17 for ; Mon, 10 Mar 2025 17:51:39 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org CB1331270B17 Received: by exim-smtp-8cb569c79-b7mkz with esmtpa (envelope-from ) id 1treTi-00000000Jsz-3pFf; Mon, 10 Mar 2025 17:51:39 +0300 To: Sergey Bronnikov Date: Mon, 10 Mar 2025 17:51:35 +0300 Message-ID: X-Mailer: git-send-email 2.48.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: 4F1203BC0FB41BD9C6CD12EFD8DA450FAB883BB70A62B2875CC4261E7F7BD0A300894C459B0CD1B9DD8A3718E98DA1758E7FD94675F33565137CAE08D9B1D4E047602AEF6CF861AE09DF98A5C5F6EC85 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE70C5E0F71D77D667BEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637AC83A81C8FD4AD23D82A6BABE6F325AC2E85FA5F3EDFCBAA7353EFBB553375666DAE1D1A19A1A03E212B395259D8340B163AB99D7AE6C33A9FA12BE59C14436A389733CBF5DBD5E913377AFFFEAFD269176DF2183F8FC7C0FF650BF36608E5878941B15DA834481FCF19DD082D7633A0EF3E4896CB9E6436389733CBF5DBD5E9D5E8D9A59859A8B62B7ABF3321926E07CC7F00164DA146DA6F5DAA56C3B73B237318B6A418E8EAB8D32BA5DBAC0009BE9E8FC8737B5C2249140B36D152ABFE7676E601842F6C81A12EF20D2F80756B5FB606B96278B59C4276E601842F6C81A127C277FBC8AE2E8B3A7E52208E84F7563AA81AA40904B5D99C9F4D5AE37F343AD1F44FA8B9022EA23BBE47FD9DD3FB595F5C1EE8F4F765FC72CEEB2601E22B093A03B725D353964B0B7D0EA88DDEDAC722CA9DD8327EE4930A3850AC1BE2E7356C9A9530EBF72002C4224003CC83647689D4C264860C145E X-C1DE0DAB: 0D63561A33F958A52627F3FCA718699A5002B1117B3ED696EEE38177FE19E1B53D2BBC1EF78EDEBE823CB91A9FED034534781492E4B8EEAD4ADCFBF7921B375DC79554A2A72441328621D336A7BC284946AD531847A6065A535571D14F44ED41 X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CFBCF8DC9824DE2CBF55ECEF986EC1FBFE55FC4C175E90E56AEADE4DABE40994279FED342E2040E994F13513DA892F5B9DD06CEB3B00A4FC19DAD5AB2F78211277E4152B276BD32F6F5F4332CA8FE04980913E6812662D5F2A5EAB5682573093F7837F15F2B5E4A70B33F2C28C22F508233FCF178C6DD14203 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu53w8ahmwBjZKM/YPHZyZHvz5uv+WouB9+ObcCpyrx6l7KImUglyhkEat/+ysWwi0gdhEs0JGjl6ggRWTy1haxBpVdbIX1nthFXMZebaIdHP2ghjoIc/363UZI6Kf1ptIMVQiWK+2I7Y2sYlsF3yItdgI= X-Mailru-Sender: 520A125C2F17F0B1A9638AD358559B590B94169C0E824ED83DE06ABAFEAF6705D5F804AA087D7CCFB7CBEF92542CD7C88B0A2698F12F5C9EC77752E0C033A69E86920BD37369036789A8C6A0E60D2BB63A5DB60FBEB33A8A0DA7A0AF5A3A8387 X-Mras: Ok Subject: [Tarantool-patches] [PATCH luajit 1/3] test: unify helpers for a custom allocator setting 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 patch merges two Lua C libraries that contain custom Lua allocators with the injection of returning `NULL` into 1 library . The new library contains 2 helpers: * `enable_null_alloc()` -- returns `NULL` on every allocation (not reallocation). * `enable_null_doubling_realloc()` -- returns `NULL` on every reallocation that doubles the size of the object. It can be useful for testing corner cases, like OOM during IR/snapshot buffer reallocation during trace recording. The original allocator is returned via the `disable()` library function. The unified library helps to avoid code duplication and can be reused for future tests. Needed for tarantool/tarantool#11055 --- test/tarantool-tests/CMakeLists.txt | 5 +- .../lj-1166-error-stitch-oom-ir-buff.test.lua | 2 +- ...j-1166-error-stitch-oom-snap-buff.test.lua | 2 +- ...j-1247-fin-tab-rehashing-on-trace.test.lua | 4 +- .../CMakeLists.txt | 2 - .../lj_1247_allocinject.c | 49 ------------------- .../CMakeLists.txt | 1 + .../allocinject.c | 34 +++++++++++-- 8 files changed, 37 insertions(+), 62 deletions(-) delete mode 100644 test/tarantool-tests/lj-1247-fin-tab-rehashing-on-trace/CMakeLists.txt delete mode 100644 test/tarantool-tests/lj-1247-fin-tab-rehashing-on-trace/lj_1247_allocinject.c rename test/tarantool-tests/{lj-1166-error-stitch => utils}/CMakeLists.txt (77%) rename test/tarantool-tests/{lj-1166-error-stitch => utils}/allocinject.c (50%) diff --git a/test/tarantool-tests/CMakeLists.txt b/test/tarantool-tests/CMakeLists.txt index a6d09dc7..682a883a 100644 --- a/test/tarantool-tests/CMakeLists.txt +++ b/test/tarantool-tests/CMakeLists.txt @@ -60,13 +60,14 @@ add_subdirectory(lj-802-panic-at-mcode-protfail) add_subdirectory(lj-flush-on-trace) add_subdirectory(lj-1004-oom-error-frame) add_subdirectory(lj-1066-fix-cur_L-after-coroutine-resume) -add_subdirectory(lj-1166-error-stitch) -add_subdirectory(lj-1247-fin-tab-rehashing-on-trace) add_subdirectory(profilers/gh-5813-resolving-of-c-symbols/both) add_subdirectory(profilers/gh-5813-resolving-of-c-symbols/gnuhash) add_subdirectory(profilers/gh-5813-resolving-of-c-symbols/hash) add_subdirectory(profilers/gh-5813-resolving-of-c-symbols/stripped) +# Module for alloc injections to return OOM for allocations. +add_subdirectory(utils) + if(BUILDMODE STREQUAL "dynamic") add_subdirectory(fix-argv-handling) endif() diff --git a/test/tarantool-tests/lj-1166-error-stitch-oom-ir-buff.test.lua b/test/tarantool-tests/lj-1166-error-stitch-oom-ir-buff.test.lua index 354f5975..dc21cfbf 100644 --- a/test/tarantool-tests/lj-1166-error-stitch-oom-ir-buff.test.lua +++ b/test/tarantool-tests/lj-1166-error-stitch-oom-ir-buff.test.lua @@ -57,7 +57,7 @@ jparse.start('t') jit.on() jit.opt.start('hotloop=1', '-loop', '-fold') -allocinject.enable() +allocinject.enable_null_doubling_realloc() tracef() diff --git a/test/tarantool-tests/lj-1166-error-stitch-oom-snap-buff.test.lua b/test/tarantool-tests/lj-1166-error-stitch-oom-snap-buff.test.lua index c8e13760..b2387f23 100644 --- a/test/tarantool-tests/lj-1166-error-stitch-oom-snap-buff.test.lua +++ b/test/tarantool-tests/lj-1166-error-stitch-oom-snap-buff.test.lua @@ -59,7 +59,7 @@ jparse.start('t') jit.opt.start('hotloop=1') jit.on() -allocinject.enable() +allocinject.enable_null_doubling_realloc() tracef() diff --git a/test/tarantool-tests/lj-1247-fin-tab-rehashing-on-trace.test.lua b/test/tarantool-tests/lj-1247-fin-tab-rehashing-on-trace.test.lua index 308043a2..b9a49700 100644 --- a/test/tarantool-tests/lj-1247-fin-tab-rehashing-on-trace.test.lua +++ b/test/tarantool-tests/lj-1247-fin-tab-rehashing-on-trace.test.lua @@ -24,7 +24,7 @@ local test = tap.test('lj-1247-fin-tab-rehashing-on-trace'):skipcond({ -- omitted, we test only the first case. test:plan(2) -local allocinject = require('lj_1247_allocinject') +local allocinject = require('allocinject') local ffi = require('ffi') ffi.cdef[[ @@ -115,7 +115,7 @@ crash_on_trace_unwind_gc_setup() -- OOM on every allocation (i.e., on finalizer table rehashing -- too). -allocinject.enable() +allocinject.enable_null_alloc() local r, err = pcall(f, res_tab) diff --git a/test/tarantool-tests/lj-1247-fin-tab-rehashing-on-trace/CMakeLists.txt b/test/tarantool-tests/lj-1247-fin-tab-rehashing-on-trace/CMakeLists.txt deleted file mode 100644 index 8c6fe7e4..00000000 --- a/test/tarantool-tests/lj-1247-fin-tab-rehashing-on-trace/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -get_filename_component(test_name ${CMAKE_CURRENT_SOURCE_DIR} NAME) -BuildTestCLib(lj_1247_allocinject lj_1247_allocinject.c ${test_name}.test.lua) diff --git a/test/tarantool-tests/lj-1247-fin-tab-rehashing-on-trace/lj_1247_allocinject.c b/test/tarantool-tests/lj-1247-fin-tab-rehashing-on-trace/lj_1247_allocinject.c deleted file mode 100644 index 81aea60b..00000000 --- a/test/tarantool-tests/lj-1247-fin-tab-rehashing-on-trace/lj_1247_allocinject.c +++ /dev/null @@ -1,49 +0,0 @@ -#include "lua.h" -#include "lauxlib.h" - -#undef NDEBUG -#include - -static lua_Alloc old_allocf = NULL; -static void *old_alloc_state = NULL; - -/* Function to be used instead of the default allocator. */ -static void *allocf_with_injection(void *ud, void *ptr, size_t osize, - size_t nsize) -{ - /* Always OOM on allocation (not on realloc). */ - if (ptr == NULL) - return NULL; - else - return old_allocf(ud, ptr, osize, nsize); -} - -static int enable(lua_State *L) -{ - assert(old_allocf == NULL); - old_allocf = lua_getallocf(L, &old_alloc_state); - lua_setallocf(L, allocf_with_injection, old_alloc_state); - return 0; -} - -static int disable(lua_State *L) -{ - assert(old_allocf != NULL); - assert(old_allocf != allocf_with_injection); - lua_setallocf(L, old_allocf, old_alloc_state); - old_allocf = NULL; - old_alloc_state = NULL; - return 0; -} - -static const struct luaL_Reg allocinject[] = { - {"enable", enable}, - {"disable", disable}, - {NULL, NULL} -}; - -LUA_API int luaopen_lj_1247_allocinject(lua_State *L) -{ - luaL_register(L, "lj_1247_allocinject", allocinject); - return 1; -} diff --git a/test/tarantool-tests/lj-1166-error-stitch/CMakeLists.txt b/test/tarantool-tests/utils/CMakeLists.txt similarity index 77% rename from test/tarantool-tests/lj-1166-error-stitch/CMakeLists.txt rename to test/tarantool-tests/utils/CMakeLists.txt index 658b3b8c..624cc933 100644 --- a/test/tarantool-tests/lj-1166-error-stitch/CMakeLists.txt +++ b/test/tarantool-tests/utils/CMakeLists.txt @@ -1,5 +1,6 @@ list(APPEND tests lj-1166-error-stitch-oom-ir-buff.test.lua lj-1166-error-stitch-oom-snap-buff.test.lua + lj-1247-fin-tab-rehashing-on-trace.test.lua ) BuildTestCLib(allocinject allocinject.c "${tests}") diff --git a/test/tarantool-tests/lj-1166-error-stitch/allocinject.c b/test/tarantool-tests/utils/allocinject.c similarity index 50% rename from test/tarantool-tests/lj-1166-error-stitch/allocinject.c rename to test/tarantool-tests/utils/allocinject.c index 88fc9138..21e1d611 100644 --- a/test/tarantool-tests/lj-1166-error-stitch/allocinject.c +++ b/test/tarantool-tests/utils/allocinject.c @@ -7,9 +7,22 @@ static lua_Alloc old_allocf = NULL; static void *old_alloc_state = NULL; -/* Function to be used instead of the default allocator. */ -static void *allocf_with_injection(void *ud, void *ptr, size_t osize, +/* Functions to be used instead of the default allocator. */ + +/* Always OOM on allocation (not on realloc). */ +static void *allocf_inj_null_alloc(void *ud, void *ptr, size_t osize, size_t nsize) +{ + assert(old_allocf != NULL); + if (ptr == NULL) + return NULL; + else + return old_allocf(ud, ptr, osize, nsize); +} + +/* Returns `NULL` on reallocations doubling used memory. */ +static void *allocf_inj_null_doubling_realloc(void *ud, void *ptr, size_t osize, + size_t nsize) { assert(old_allocf != NULL); /* @@ -21,7 +34,7 @@ static void *allocf_with_injection(void *ud, void *ptr, size_t osize, return old_allocf(ud, ptr, osize, nsize); } -static int enable(lua_State *L) +static int enable(lua_State *L, lua_Alloc allocf_with_injection) { assert(old_allocf == NULL); old_allocf = lua_getallocf(L, &old_alloc_state); @@ -29,10 +42,20 @@ static int enable(lua_State *L) return 0; } +static int enable_null_alloc(lua_State *L) +{ + return enable(L, allocf_inj_null_alloc); +} + +static int enable_null_doubling_realloc(lua_State *L) +{ + return enable(L, allocf_inj_null_doubling_realloc); +} + +/* Restore the default allocator function. */ static int disable(lua_State *L) { assert(old_allocf != NULL); - assert(old_allocf != allocf_with_injection); lua_setallocf(L, old_allocf, old_alloc_state); old_allocf = NULL; old_alloc_state = NULL; @@ -40,7 +63,8 @@ static int disable(lua_State *L) } static const struct luaL_Reg allocinject[] = { - {"enable", enable}, + {"enable_null_alloc", enable_null_alloc}, + {"enable_null_doubling_realloc", enable_null_doubling_realloc}, {"disable", disable}, {NULL, NULL} }; -- 2.48.1