summaryrefslogtreecommitdiffstats
path: root/test-luawrapper.cc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 09:34:30 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 09:34:30 +0000
commit4fc2f55f761d71aae1f145d5aa94ba929cc39676 (patch)
tree5c1e1db3b46dd4edbe11f612d93cb94b96891ce3 /test-luawrapper.cc
parentInitial commit. (diff)
downloaddnsdist-upstream.tar.xz
dnsdist-upstream.zip
Adding upstream version 1.7.3.upstream/1.7.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test-luawrapper.cc')
-rw-r--r--test-luawrapper.cc33
1 files changed, 33 insertions, 0 deletions
diff --git a/test-luawrapper.cc b/test-luawrapper.cc
new file mode 100644
index 0000000..1004790
--- /dev/null
+++ b/test-luawrapper.cc
@@ -0,0 +1,33 @@
+#define BOOST_TEST_DYN_LINK
+#define BOOST_TEST_NO_MAIN
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#include <boost/test/unit_test.hpp>
+#include "ext/luawrapper/include/LuaContext.hpp"
+
+BOOST_AUTO_TEST_SUITE(test_lua_lightuserdata)
+
+BOOST_AUTO_TEST_CASE(test_registerFunction)
+{
+ // This test comes from luawrapper/tests/custom_types.cc, TEST(CustomTypes, MemberFunctions).
+ // In some versions of luajit, as shipped by Debian Buster and others, Lua lightuserdata
+ // objects can only hold 47 bits of the address of a pointer. If the kernel puts our heap
+ // above that 47 bit limit, this test crashes. Many arm64 Linux kernels are known to put
+ // the heap in that problematic area.
+ struct Object
+ {
+ void increment() { ++value; }
+ int value;
+ };
+
+ LuaContext context;
+ context.registerFunction("increment", &Object::increment);
+
+ context.writeVariable("obj", Object{10});
+ context.executeCode("obj:increment()");
+
+ BOOST_CHECK_EQUAL(11, context.readVariable<Object>("obj").value);
+}
+
+BOOST_AUTO_TEST_SUITE_END()