From: Maxim Kokryashkin via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: "Sergey Kaplun" <skaplun@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH v2 luajit 6/6] test: rewrite lj-49-bad-lightuserdata test in C
Date: Fri, 19 May 2023 15:40:33 +0300 [thread overview]
Message-ID: <1684500033.287216159@f752.i.mail.ru> (raw)
In-Reply-To: <1319c39405834f71893c5cd951b0a525c26354e4.1684442182.git.skaplun@tarantool.org>
[-- Attachment #1: Type: text/plain, Size: 4944 bytes --]
Hi, Sergey!
Thanks for the patch!
LGTM
--
Best regards,
Maxim Kokryashkin
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 <lua.h>
-#include <lauxlib.h>
+#include "lua.h"
+#include "lauxlib.h"
#include <sys/mman.h>
#include <unistd.h>
-#undef NDEBUG
-#include <assert.h>
+#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 <assert.h>
+
+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
[-- Attachment #2: Type: text/html, Size: 6077 bytes --]
next prev parent reply other threads:[~2023-05-19 12:40 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-18 20:44 [Tarantool-patches] [PATCH v2 luajit 0/6] Revorking C tests Sergey Kaplun via Tarantool-patches
2023-05-18 20:44 ` [Tarantool-patches] [PATCH v2 luajit 1/6] test: fix setting of {DY}LD_LIBRARY_PATH variables Sergey Kaplun via Tarantool-patches
2023-05-19 11:23 ` Maxim Kokryashkin via Tarantool-patches
2023-05-22 11:03 ` Sergey Bronnikov via Tarantool-patches
2023-05-23 6:47 ` Sergey Kaplun via Tarantool-patches
2023-05-29 14:37 ` Sergey Bronnikov via Tarantool-patches
2023-05-18 20:44 ` [Tarantool-patches] [PATCH v2 luajit 2/6] test: introduce module for C tests Sergey Kaplun via Tarantool-patches
2023-05-19 11:46 ` Maxim Kokryashkin via Tarantool-patches
2023-05-22 12:33 ` Sergey Bronnikov via Tarantool-patches
2023-05-24 6:41 ` Sergey Kaplun via Tarantool-patches
2023-05-25 17:33 ` Sergey Bronnikov via Tarantool-patches
2023-05-29 10:03 ` Sergey Kaplun via Tarantool-patches
2023-05-29 14:38 ` Sergey Bronnikov via Tarantool-patches
2023-05-31 13:32 ` Sergey Kaplun via Tarantool-patches
2023-05-18 20:44 ` [Tarantool-patches] [PATCH v2 luajit 3/6] test: introduce utils.h helper " Sergey Kaplun via Tarantool-patches
2023-05-19 11:58 ` Maxim Kokryashkin via Tarantool-patches
2023-05-20 7:52 ` Sergey Kaplun via Tarantool-patches
2023-05-29 15:26 ` Sergey Bronnikov via Tarantool-patches
2023-05-18 20:44 ` [Tarantool-patches] [PATCH v2 luajit 4/6] test: rewrite misclib-getmetrics-capi test in C Sergey Kaplun via Tarantool-patches
2023-05-19 12:17 ` Maxim Kokryashkin via Tarantool-patches
2023-05-20 8:08 ` Sergey Kaplun via Tarantool-patches
2023-05-29 16:15 ` Sergey Bronnikov via Tarantool-patches
2023-05-18 20:44 ` [Tarantool-patches] [PATCH v2 luajit 5/6] test: rewrite misclib-sysprof-capi " Sergey Kaplun via Tarantool-patches
2023-05-19 13:00 ` Maxim Kokryashkin via Tarantool-patches
2023-05-20 7:28 ` Sergey Kaplun via Tarantool-patches
2023-05-18 20:44 ` [Tarantool-patches] [PATCH v2 luajit 6/6] test: rewrite lj-49-bad-lightuserdata " Sergey Kaplun via Tarantool-patches
2023-05-19 12:40 ` Maxim Kokryashkin via Tarantool-patches [this message]
2023-05-19 14:29 ` [Tarantool-patches] [PATCH v2 luajit 0/6] Revorking C tests Maxim Kokryashkin via Tarantool-patches
2023-05-20 8:38 ` Sergey Kaplun via Tarantool-patches
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1684500033.287216159@f752.i.mail.ru \
--to=tarantool-patches@dev.tarantool.org \
--cc=m.kokryashkin@tarantool.org \
--cc=skaplun@tarantool.org \
--subject='Re: [Tarantool-patches] [PATCH v2 luajit 6/6] test: rewrite lj-49-bad-lightuserdata test in C' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox