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 0B8934A0A25; Mon, 5 Jun 2023 13:48:29 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 0B8934A0A25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1685962109; bh=XYCLmc94NJT3D7xH0cs8fSzCZNkdvTQ4O0Ke8udjK6s=; 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=FfbKznol2sa8S0pjuCieG2LWG1HjE8pAG74j9kWxUXQ2waiAtGUF14NbPhiRXg/Er q3vpg7Wd2tes0ImzyBlXLelIJ7wq3EaWwANgoYyp/OmpTHkI4CjDQ1m4cylx5xObS2 JojD1BX9/cJ+atMKYtUh5cuGk0Bz71DDYX1i7YG4= Received: from smtp61.i.mail.ru (smtp61.i.mail.ru [95.163.41.99]) (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 B36F04A0A1F for ; Mon, 5 Jun 2023 13:45:34 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org B36F04A0A1F Received: by smtp61.i.mail.ru with esmtpa (envelope-from ) id 1q67iP-00BFih-K7; Mon, 05 Jun 2023 13:45:34 +0300 To: Igor Munkin , Maxim Kokryashkin , Sergey Bronnikov Date: Mon, 5 Jun 2023 13:41:17 +0300 Message-Id: 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: EEAE043A70213CC8 X-77F55803: 4F1203BC0FB41BD985F8C45B19A33542ED22C940E5ED6AA1E82633E1BA3BD74C182A05F5380850404C228DA9ACA6FE27238ECCE14924868F197EB280A79F72474272DC840D18FA9CF57983629279ECA7 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7AD2F2D6F6013FF7FC2099A533E45F2D0395957E7521B51C2CFCAF695D4D8E9FCEA1F7E6F0F101C6778DA827A17800CE78EA80DE462DCD770EA1F7E6F0F101C6723150C8DA25C47586E58E00D9D99D84E1BDDB23E98D2D38BE5CCB53A13BC8DBAE8E9492E95D29D5724ADFC203733E25CCC7F00164DA146DA9985D098DBDEAEC8A85A14DF5F041C99F6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA73AA81AA40904B5D9A18204E546F3947C61191FCD0E7B64B66E0066C2D8992A164AD6D5ED66289B52698AB9A7B718F8C46E0066C2D8992A16725E5C173C3A84C3A5A5C9631F7CC0DCBA3038C0950A5D36B5C8C57E37DE458B330BD67F2E7D9AF16D1867E19FE14079C09775C1D3CA48CF90D92131081DE7481DD303D21008E298D5E8D9A59859A8B6B372FE9A2E580EFC725E5C173C3A84C3FB9365559B687AC835872C767BF85DA2F004C90652538430E4A6367B16DE6309 X-C1DE0DAB: 0D63561A33F958A53AA4665F3F0995E8290AA7B82D7AB25926586A4E413ECAC1F87CCE6106E1FC07E67D4AC08A07B9B06A1CB4668A9CA5FA9C5DF10A05D560A950611B66E3DA6D700B0A020F03D25A0997E3FB2386030E77 X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CF0BFA37342B4B5291C69B290EEBF40C84719D9831529FD18DA4656D21AE718BFBF31E0254ADC75A06588A46A5EBCE8E371F58F03EF9A44A472C911218820F782D461A413F07889F2102C26D483E81D6BE5EF9655DD6DEA7D65774BB76CC95456EEC5B5AD62611EEC62B5AFB4261A09AF0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojxchphH+YLHw6cXtKx3wY1Q== X-Mailru-Sender: 11C2EC085EDE56FAC07928AF2646A7692FA7C6E2C51E1BE1197EB280A79F724749EBE2174CCC9479DEDBA653FF35249392D99EB8CC7091A70E183A470755BFD208F19895AA18418972D6B4FCE48DF648AE208404248635DF X-Mras: Ok Subject: [Tarantool-patches] [PATCH v3 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..a9cc4763 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_new(crafted_ptr), + test_unit_new(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