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 33B8248571B; Thu, 18 May 2023 23:52:02 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 33B8248571B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1684443122; 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=d9Eldx5fTUeleVuMMDB4RoAwbEiq20sfHFsaX+igJFbm2qLDe8RNV1JiYp9VOIdw6 SX3L1jaEysLOa7E/fQ3sHjVFCSivk5gwoDTja1Z96K0Ak5XPg0+7zij9970I6/R3yH +Fpf5jayDOd3bms3uv7V+Nc4WMBtoVe7i95BBVKM= 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 4304D485709 for ; Thu, 18 May 2023 23:49:07 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 4304D485709 Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1pzkYc-0005wh-2Z; Thu, 18 May 2023 23:49:06 +0300 To: Igor Munkin , Maxim Kokryashkin , Sergey Bronnikov Date: Thu, 18 May 2023 23:44:53 +0300 Message-Id: <1319c39405834f71893c5cd951b0a525c26354e4.1684442182.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: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD921E8753A900160F1284B0F69140CBAD1A760B8050B399C32182A05F5380850402480D084FAA9C8116250B5ADFA72CE38B0668CB1ABA416CC7AAEA9FAC09780D8 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE721B3E54BB37EA0B4EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F790063768D6DD405B71470F8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D86143F7844628CA5BA5C9076487F82DA1117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCF80095D1E37F4578A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F4460429728776938767073520CCD848CCB6FE560C6FD1C55BDD38FC3FD2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B67393CE827C55B5F775ECD9A6C639B01B4E70A05D1297E1BBCB5012B2E24CD356 X-C1DE0DAB: 0D63561A33F958A50ED8547A885E8952DDE4659982D14559FAAE2A2F63348014F87CCE6106E1FC07E67D4AC08A07B9B06A1CB4668A9CA5FA9C5DF10A05D560A950611B66E3DA6D700B0A020F03D25A0997E3FB2386030E77 X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CFAE30BC81714A72C7182E35D3208DC046B7774EE27BB5E61A15F87A3452346A8535D245DF744597F10DBD3925112B781EDB10048C1D21C96C6DC6FD27C918F6C206EEC8038AF5C160 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojXj30btAgf0byRYpy2KYZ+Q== X-DA7885C5: 114F622B4B35C8D8117DE7BC9A9FF8248A392BBB0A5AA23B65E2065B7FC2CDC8262E2D401490A4A0DB037EFA58388B346E8BC1A9835FDE71 X-Mailru-Sender: 689FA8AB762F73933AF1F914F131DBF52DC6FD753EFB66C0568204579CB38DBA0FBE9A32752B8C9C2AA642CC12EC09F1FB559BB5D741EB962F61BD320559CF1EFD657A8799238ED55FEEDEB644C299C0ED14614B50AE0675 X-Mras: Ok Subject: [Tarantool-patches] [PATCH v2 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