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 CFE0C4E2C3C; Sat, 10 Jun 2023 11:10:29 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org CFE0C4E2C3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1686384629; bh=sDB+Mz3zInfMIRQPPmV2dAoCQCgO2vtd36BtT8aPIVA=; 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=Mn6tMDfs+/KaQ5um1Ug1Nxu8e1ePvP5Ipejlor6ZWCa7ZpUMiRWCS6lWwQSLbqIpT 5jMEft+LqvpAQ3syKO8kJvVETlC6s94cjVWXJTicN4ka8xkmkV8WdqrjjMDAhHeEUZ +9bMkMuMQs2Jiz10udVhRRpDtu2o65DfrJ2NDpqE= 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 9AE484E2C3C for ; Sat, 10 Jun 2023 11:07:33 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 9AE484E2C3C Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1q7tdE-0002gO-EQ; Sat, 10 Jun 2023 11:07:32 +0300 To: Igor Munkin , Maxim Kokryashkin , Sergey Bronnikov Date: Sat, 10 Jun 2023 11:03:14 +0300 Message-Id: <8c18475b5e177193b59f087ccc7fe2724a5104b0.1686383897.git.skaplun@tarantool.org> 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: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD965EFE7F2AC62B27A812BF47AEC9B8FAAED21A3AE25A7C519182A05F53808504088FDDD29F9906A6482A0A63C51AD287849E7B2756E90E45AB2BA9606C3AB72AC X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7D6964C9E324ABA58EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637BBCE7257090F96C9EA1F7E6F0F101C6723150C8DA25C47586E58E00D9D99D84E1BDDB23E98D2D38BE5CCB53A13BC8DBAA089671E309666EF4916D37A7D79AA03CC7F00164DA146DAFE8445B8C89999728AA50765F79006377C70927E34808485389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC8D95D32202655EC45F6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA7E827F84554CEF5019E625A9149C048EE9ECD01F8117BC8BEE2021AF6380DFAD18AA50765F790063735872C767BF85DA227C277FBC8AE2E8B9F5955FECEF5819E75ECD9A6C639B01B4E70A05D1297E1BBCB5012B2E24CD356 X-C1DE0DAB: 0D63561A33F958A5429A34B1472D9C2F601F57A5D00D2A379F65A9C052C0F8CAF87CCE6106E1FC07E67D4AC08A07B9B06A1CB4668A9CA5FA9C5DF10A05D560A950611B66E3DA6D700B0A020F03D25A0997E3FB2386030E77 X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CFABD1F0A3C73F9B029FCB20E5E30C88240A9994660478F88D3ABEB6F1F5ABE113CC55679CEC9B022BB5655EA6190D4CDAB5629AECB95B3116D78765DC38236F3C461A413F07889F2102C26D483E81D6BE5EF9655DD6DEA7D65774BB76CC95456EEC5B5AD62611EEC62B5AFB4261A09AF0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojRLo8CqjALXgYIK43BMteqA== X-DA7885C5: DB4EA957482FF6654AAD52CB2238199FF608882B70BF89E5CB98520DBC3D35CC262E2D401490A4A0DB037EFA58388B346E8BC1A9835FDE71 X-Mailru-Sender: 689FA8AB762F73930F533AC2B33E986B7259A60535D8B44CD9C3B5A57CAF79AD0FBE9A32752B8C9C2AA642CC12EC09F1FB559BB5D741EB962F61BD320559CF1EFD657A8799238ED55FEEDEB644C299C0ED14614B50AE0675 X-Mras: Ok Subject: [Tarantool-patches] [PATCH v4 luajit 6/6] test: rewrite lj-49-bad-lightuserdata 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" This patch rewrites the aforementioned test with the usage libtest recently introduced. The approach is similar to the previous patch. Nevertheless, glibc `assert()` is used to check the correctness of the `mmap()` usage. Part of tarantool/tarantool#7900 --- .../lj-49-bad-lightuserdata.test.c} | 47 ++++++++++--------- test/tarantool-tests/CMakeLists.txt | 1 - .../lj-49-bad-lightuserdata.test.lua | 11 ----- .../lj-49-bad-lightuserdata/CMakeLists.txt | 1 - 4 files changed, 25 insertions(+), 35 deletions(-) rename test/{tarantool-tests/lj-49-bad-lightuserdata/testlightuserdata.c => tarantool-c-tests/lj-49-bad-lightuserdata.test.c} (55%) delete mode 100644 test/tarantool-tests/lj-49-bad-lightuserdata.test.lua delete mode 100644 test/tarantool-tests/lj-49-bad-lightuserdata/CMakeLists.txt diff --git a/test/tarantool-tests/lj-49-bad-lightuserdata/testlightuserdata.c b/test/tarantool-c-tests/lj-49-bad-lightuserdata.test.c similarity index 55% rename from test/tarantool-tests/lj-49-bad-lightuserdata/testlightuserdata.c rename to test/tarantool-c-tests/lj-49-bad-lightuserdata.test.c index 1b909fc6..d2f86da2 100644 --- a/test/tarantool-tests/lj-49-bad-lightuserdata/testlightuserdata.c +++ b/test/tarantool-c-tests/lj-49-bad-lightuserdata.test.c @@ -1,16 +1,21 @@ -#include -#include +#include "lua.h" +#include "lauxlib.h" #include #include -#undef NDEBUG -#include +#include "test.h" +#include "utils.h" #define START ((void *)-1) -static int crafted_ptr(lua_State *L) +/* XXX: Still need normal assert to validate mmap correctness. */ +#undef NDEBUG +#include + +static int crafted_ptr(void *test_state) { + lua_State *L = test_state; /* * We know that for arm64 at least 48 bits are available. * So emulate manually push of lightuseradata within @@ -18,15 +23,15 @@ static int crafted_ptr(lua_State *L) */ void *longptr = (void *)(1llu << 48); lua_pushlightuserdata(L, longptr); - assert(longptr == lua_topointer(L, -1)); + assert_ptr_equal(longptr, lua_topointer(L, -1)); /* Clear our stack. */ lua_pop(L, 0); - lua_pushboolean(L, 1); - return 1; + return TEST_EXIT_SUCCESS; } -static int mmaped_ptr(lua_State *L) +static int mmaped_ptr(void *test_state) { + lua_State *L = test_state; /* * If start mapping address is not NULL, then the kernel * takes it as a hint about where to place the mapping, so @@ -38,24 +43,22 @@ static int mmaped_ptr(lua_State *L) -1, 0); if (mmaped != MAP_FAILED) { lua_pushlightuserdata(L, mmaped); - assert(mmaped == lua_topointer(L, -1)); + assert_ptr_equal(mmaped, lua_topointer(L, -1)); assert(munmap(mmaped, pagesize) == 0); } /* Clear our stack. */ lua_pop(L, 0); - lua_pushboolean(L, 1); - return 1; + return TEST_EXIT_SUCCESS; } -static const struct luaL_Reg testlightuserdata[] = { - {"crafted_ptr", crafted_ptr}, - {"mmaped_ptr", mmaped_ptr}, - {NULL, NULL} -}; - -LUA_API int luaopen_testlightuserdata(lua_State *L) +int main(void) { - luaL_register(L, "testlightuserdata", testlightuserdata); - return 1; + lua_State *L = utils_lua_init(); + const struct test_unit tgroup[] = { + test_unit_def(crafted_ptr), + test_unit_def(mmaped_ptr) + }; + const int test_result = test_run_group(tgroup, L); + utils_lua_close(L); + return test_result; } - diff --git a/test/tarantool-tests/CMakeLists.txt b/test/tarantool-tests/CMakeLists.txt index b1c7207f..527905b6 100644 --- a/test/tarantool-tests/CMakeLists.txt +++ b/test/tarantool-tests/CMakeLists.txt @@ -61,7 +61,6 @@ add_subdirectory(gh-5813-resolving-of-c-symbols/gnuhash) add_subdirectory(gh-5813-resolving-of-c-symbols/stripped) add_subdirectory(gh-6098-fix-side-exit-patching-on-arm64) add_subdirectory(gh-6189-cur_L) -add_subdirectory(lj-49-bad-lightuserdata) add_subdirectory(lj-416-xor-before-jcc) add_subdirectory(lj-601-fix-gc-finderrfunc) add_subdirectory(lj-727-lightuserdata-itern) diff --git a/test/tarantool-tests/lj-49-bad-lightuserdata.test.lua b/test/tarantool-tests/lj-49-bad-lightuserdata.test.lua deleted file mode 100644 index 94a743c7..00000000 --- a/test/tarantool-tests/lj-49-bad-lightuserdata.test.lua +++ /dev/null @@ -1,11 +0,0 @@ -local tap = require('tap') - -local test = tap.test('lj-49-bad-lightuserdata') -test:plan(2) - -local testlightuserdata = require('testlightuserdata') - -test:ok(testlightuserdata.crafted_ptr()) -test:ok(testlightuserdata.mmaped_ptr()) - -os.exit(test:check() and 0 or 1) diff --git a/test/tarantool-tests/lj-49-bad-lightuserdata/CMakeLists.txt b/test/tarantool-tests/lj-49-bad-lightuserdata/CMakeLists.txt deleted file mode 100644 index ec6bb62c..00000000 --- a/test/tarantool-tests/lj-49-bad-lightuserdata/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -BuildTestCLib(testlightuserdata testlightuserdata.c) -- 2.34.1