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 C440B451814; Tue, 11 Mar 2025 14:32:27 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org C440B451814 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1741692747; bh=/iDYszb0Bewq+Vv04tPgkY/QqAUDtxl9/EAvMCivdVM=; 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=G7BslhKKkipMkHmYmaZ9iEuNB6R4yCdih1gOs1z8nGsAWWY4Xa14JBuJF1f2offhg gMW/s2J28fvebRydm82h97toAqWFj+D+SCwHelnHtox+5P8Pz8ZyGtnDWUGhUOivzL 3urpZfF8YK05kLoqHFX3FmEeF83LC8R6XJcZvLMA= Received: from send266.i.mail.ru (send266.i.mail.ru [95.163.59.105]) (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 8F1E3451814 for ; Tue, 11 Mar 2025 14:32:26 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 8F1E3451814 Received: by exim-smtp-69cc44787d-w6trl with esmtpa (envelope-from ) id 1trxqT-00000000PMD-1VhH; Tue, 11 Mar 2025 14:32:25 +0300 Content-Type: multipart/alternative; boundary="------------lOeWuMzlME8v1nWrIiu9nSoa" Message-ID: <8ee07c5f-6326-4618-bc3f-247efa79c46a@tarantool.org> Date: Tue, 11 Mar 2025 14:32:24 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: Sergey Kaplun Cc: tarantool-patches@dev.tarantool.org References: In-Reply-To: X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD96E8ECD36702C4DEF79AF4384E6313C2896545A11BCDAD002182A05F538085040533FCDE7A438BBF23DE06ABAFEAF6705EBDD896CE0A9D9BFF23922FCC1A5D848BE26E60622977F24 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE78BAADB77C21FF6F2EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637AC83A81C8FD4AD23D82A6BABE6F325AC2E85FA5F3EDFCBAA7353EFBB553375666DAE1D1A19A1A03EAA48245C2DC9B435A1E70C2545B39ACAB58477E27D259842389733CBF5DBD5E913377AFFFEAFD269176DF2183F8FC7C05A64D9A1E9CA65708941B15DA834481FCF19DD082D7633A0EF3E4896CB9E6436389733CBF5DBD5E9D5E8D9A59859A8B66EA1BA7CA28B4A74CC7F00164DA146DA6F5DAA56C3B73B237318B6A418E8EAB8D32BA5DBAC0009BE9E8FC8737B5C2249D01E056A5B680B9576E601842F6C81A12EF20D2F80756B5FB606B96278B59C4276E601842F6C81A127C277FBC8AE2E8B406472BB8DA3E0C63AA81AA40904B5D99C9F4D5AE37F343AD1F44FA8B9022EA23BBE47FD9DD3FB595F5C1EE8F4F765FC72CEEB2601E22B093A03B725D353964B0B7D0EA88DDEDAC722CA9DD8327EE4930A3850AC1BE2E735BCC85A7874001769C4224003CC83647689D4C264860C145E X-C1DE0DAB: 0D63561A33F958A5478D0EAFB40CA8175002B1117B3ED696DA75516C83E8D05AC638DF663A625AFA823CB91A9FED034534781492E4B8EEAD21D4E6D365FE45D1BDAD6C7F3747799A X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CF1E4C73808798E330A066A2D6B6B98884A1905997DC4C0B3A3E3273BCF2B7C8CDFB7A4CF61EC7A84FF13513DA892F5B9DF643D1763EF9DECEF7555F62569F2FB7228DC79DDAC88625111DC66A97D0BFE2913E6812662D5F2AB9AF64DB4688768036DF5FE9C0001AF333F2C28C22F508233FCF178C6DD14203 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu53w8ahmwBjZKM/YPHZyZHvz5uv+WouB9+ObcCpyrx6l7KImUglyhkEat/+ysWwi0gdhEs0JGjl6ggRWTy1haxBpVdbIX1nthFXMZebaIdHP2ghjoIc/363UZI6Kf1ptIMVQiWK+2I7Y2sEhuZwSYxq80= X-Mailru-Sender: C4F68CFF4024C8867DFDF7C7F2588458712785EA1056BE284756507F36A35F4B494D99524B53394727BE5B7301A3B380645D15D82EE4B272BD6E4642A116CA93524AA66B5ACBE6721EF430B9A63E2A504198E0F3ECE9B5443453F38A29522196 X-Mras: Ok Subject: Re: [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 Bronnikov via Tarantool-patches Reply-To: Sergey Bronnikov Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" This is a multi-part message in MIME format. --------------lOeWuMzlME8v1nWrIiu9nSoa Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi, Sergey! Thanks for the patch! LGTM with two comments below. Feel free to ignore. Sergey On 10.03.2025 17:51, Sergey Kaplun wrote: > This patch merges two Lua C libraries that contain custom Lua allocators > with the injection of returning `NULL` into 1 library Minor: s/1/a single/ > . The new library contains 2 helpers: Minor: s/2/two/ > * `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} > }; --------------lOeWuMzlME8v1nWrIiu9nSoa Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit

Hi, Sergey!

Thanks for the patch! LGTM with two comments below.

Feel free to ignore.

Sergey

On 10.03.2025 17:51, Sergey Kaplun wrote:
This patch merges two Lua C libraries that contain custom Lua allocators
with the injection of returning `NULL` into 1 library
Minor: s/1/a single/
<utils/allocinject.c>. The new library contains 2 helpers:
Minor: s/2/two/
* `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 <assert.h>
-
-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}
 };
--------------lOeWuMzlME8v1nWrIiu9nSoa--