Skip to content

Commit 739d393

Browse files
committed
cmake: run tests with Valgrind
This patch enables running tests with Valgrind. There is a `VALGRIND_OPTS` variable [1] that we can set -- it makes the usage of valgrind more flexible -- we can define any necessary flags in the command line (not at the building stage). By default, the suppression file is set to `src/lj.supp`. Also, this patch disables the following tests when running with Valgrind due to failures: Disabled due tarantool/tarantool#10803: - tarantool-tests/gh-7264-add-proto-trace-sysprof-default.test.lua - tarantool-tests/lj-512-profiler-hook-finalizers.test.lua - tarantool-tests/lj-726-profile-flush-close.test.lua - tarantool-tests/misclib-sysprof-lapi.test.lua - tarantool-tests/profilers/gh-5688-tool-cli-flag.test.lua Timed out due to running under Valgrind: - tarantool-tests/gh-7745-oom-on-trace.test.lua - tarantool-tests/lj-1034-tabov-error-frame.test.lua - tarantool-c-tests/gh-8594-sysprof-ffunc-crash.c_test [1]: https://valgrind.org/docs/manual/manual-core.html#manual-core.defopts Part of tarantool/tarantool#3705
1 parent b52fe97 commit 739d393

11 files changed

+55
-3
lines changed

CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,11 @@ endif()
289289
# ASan enabled.
290290
option(LUAJIT_USE_ASAN "Build LuaJIT with AddressSanitizer" OFF)
291291
if(LUAJIT_USE_ASAN)
292+
if(LUAJIT_USE_VALGRIND)
293+
message(FATAL_ERROR
294+
"AddressSanitizer and Valgrind cannot be used simultaneously."
295+
)
296+
endif()
292297
if(NOT LUAJIT_USE_SYSMALLOC)
293298
message(WARNING
294299
"Unfortunately, internal LuaJIT memory allocator is not instrumented yet,"

test/CMakeLists.txt

+17
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,23 @@ add_custom_target(${PROJECT_NAME}-lint DEPENDS
6969
)
7070

7171
set(LUAJIT_TEST_COMMAND "${LUAJIT_TEST_BINARY} -e dofile[[${LUAJIT_TEST_INIT}]]")
72+
73+
if(LUAJIT_USE_VALGRIND)
74+
if (NOT LUAJIT_USE_SYSMALLOC)
75+
message(WARNING
76+
"LUAJIT_USE_SYSMALLOC option is mandatory for Valgrind's memcheck tool"
77+
" on x64 and the only way to get useful results from it for all other"
78+
" architectures.")
79+
endif()
80+
81+
find_program(VALGRIND valgrind)
82+
set(LUAJIT_TEST_VALGRIND_SUPP "--suppressions=${LUAJIT_SOURCE_DIR}/lj.supp")
83+
set(LUAJIT_TEST_COMMAND
84+
"${VALGRIND} --verbose --error-exitcode=1 \
85+
${LUAJIT_TEST_VALGRIND_SUPP} ${LUAJIT_TEST_COMMAND}")
86+
list(APPEND LUA_TEST_ENV_MORE LUAJIT_TEST_USE_VALGRIND=1)
87+
endif()
88+
7289
separate_arguments(LUAJIT_TEST_COMMAND)
7390

7491
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

test/tarantool-c-tests/CMakeLists.txt

+10-1
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,19 @@ foreach(test_source ${tests})
5656

5757
# Generate CMake tests.
5858
set(test_title "test/${TEST_SUITE_NAME}/${exe}${C_TEST_SUFFIX}")
59+
set(test_command ${CMAKE_CURRENT_BINARY_DIR}/${exe}${C_TEST_SUFFIX})
60+
61+
if(LUAJIT_USE_VALGRIND)
62+
set(test_command
63+
"${VALGRIND} --verbose --error-exitcode=1 \
64+
${LUAJIT_TEST_VALGRIND_SUPP} ${test_command}")
65+
endif()
66+
5967
add_test(NAME ${test_title}
60-
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${exe}${C_TEST_SUFFIX}
68+
COMMAND ${test_command}
6169
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
6270
)
71+
6372
set_tests_properties(${test_title} PROPERTIES
6473
LABELS ${TEST_SUITE_NAME}
6574
DEPENDS tarantool-c-tests-deps

test/tarantool-c-tests/gh-8594-sysprof-ffunc-crash.test.c

+7
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
* * https://github.com/tarantool/tarantool/issues/9387
4747
*/
4848

49+
#define UNUSED(x) ((void)(x))
50+
4951
#define MESSAGE "Canary is alive"
5052
#define LUACALL "local a = tostring('" MESSAGE "') return a"
5153

@@ -248,6 +250,10 @@ static int tracer(pid_t chpid)
248250

249251
static int test_tostring_call(void *ctx)
250252
{
253+
#if LUAJIT_USE_VALGRIND
254+
UNUSED(ctx);
255+
return skip("Disabled with Valgrind (Timeout)");
256+
#else
251257
pid_t chpid = fork();
252258
switch(chpid) {
253259
case -1:
@@ -264,6 +270,7 @@ static int test_tostring_call(void *ctx)
264270
default:
265271
return tracer(chpid);
266272
}
273+
#endif
267274
}
268275

269276
#else /* LUAJIT_OS == LUAJIT_OS_LINUX && LUAJIT_TARGET == LUAJIT_ARCH_X64 */

test/tarantool-tests/gh-7745-oom-on-trace.test.lua

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ local test = tap.test('OOM on trace'):skipcond({
66
(jit.os == 'OSX'),
77
['Disabled on MacOS due to #8652'] = jit.os == 'OSX',
88
['Test requires JIT enabled'] = not jit.status(),
9+
['Disabled with Valgrind (Timeout)'] = os.getenv("LUAJIT_TEST_USE_VALGRIND"),
910
})
1011

1112
test:plan(1)

test/tarantool-tests/lj-1034-tabov-error-frame.test.lua

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ local test = tap.test('lj-1034-tabov-error-frame'):skipcond({
44
['Test requires JIT enabled'] = not jit.status(),
55
['Test requires GC64 mode enabled'] = not ffi.abi('gc64'),
66
['Disabled on MacOS due to #8652'] = jit.os == 'OSX',
7+
['Disabled with Valgrind (Timeout)'] = os.getenv("LUAJIT_TEST_USE_VALGRIND"),
78
})
89

910
-- XXX: The test for the problem uses the table of GC

test/tarantool-tests/lj-512-profiler-hook-finalizers.test.lua

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
local tap = require('tap')
22
local profile = require('jit.profile')
33

4-
local test = tap.test('lj-512-profiler-hook-finalizers')
4+
local test = tap.test('lj-512-profiler-hook-finalizers'):skipcond({
5+
-- See also https://github.com/tarantool/tarantool/issues/10803.
6+
['Disabled due to #10803'] = os.getenv("LUAJIT_TEST_USE_VALGRIND"),
7+
})
58
test:plan(1)
69

710
-- Sampling interval in ms.

test/tarantool-tests/lj-726-profile-flush-close.test.lua

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
local tap = require('tap')
22

3-
local test = tap.test('lj-726-profile-flush-close')
3+
local test = tap.test('lj-726-profile-flush-close'):skipcond({
4+
-- See also https://github.com/tarantool/tarantool/issues/10803.
5+
['Disabled due to #10803'] = os.getenv("LUAJIT_TEST_USE_VALGRIND"),
6+
})
47
test:plan(1)
58

69
local TEST_FILE = 'lj-726-profile-flush-close.profile'

test/tarantool-tests/profilers/gh-5688-tool-cli-flag.test.lua

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ local test = tap.test('gh-5688-tool-cli-flag'):skipcond({
77
['No profile tools CLI option integration'] = _TARANTOOL,
88
-- See also https://github.com/LuaJIT/LuaJIT/issues/606.
99
['Disabled due to LuaJIT/LuaJIT#606'] = os.getenv('LUAJIT_TABLE_BUMP'),
10+
-- See also https://github.com/tarantool/tarantool/issues/10803.
11+
['Disabled due to #10803'] = os.getenv("LUAJIT_TEST_USE_VALGRIND"),
1012
})
1113

1214
test:plan(3)

test/tarantool-tests/profilers/gh-7264-add-proto-trace-sysprof-default.test.lua

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ local test = tap.test('gh-7264-add-proto-trace-sysprof-default'):skipcond({
66
['Sysprof is implemented for Linux only'] = jit.os ~= 'Linux',
77
-- See also https://github.com/LuaJIT/LuaJIT/issues/606.
88
['Disabled due to LuaJIT/LuaJIT#606'] = os.getenv('LUAJIT_TABLE_BUMP'),
9+
-- See also https://github.com/tarantool/tarantool/issues/10803.
10+
['Disabled due to #10803'] = os.getenv("LUAJIT_TEST_USE_VALGRIND"),
911
})
1012

1113
test:plan(2)

test/tarantool-tests/profilers/misclib-sysprof-lapi.test.lua

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ local test = tap.test("misc-sysprof-lapi"):skipcond({
55
["Sysprof is implemented for Linux only"] = jit.os ~= "Linux",
66
-- See also https://github.com/LuaJIT/LuaJIT/issues/606.
77
["Disabled due to LuaJIT/LuaJIT#606"] = os.getenv("LUAJIT_TABLE_BUMP"),
8+
-- See also https://github.com/tarantool/tarantool/issues/10803.
9+
['Disabled due to #10803'] = os.getenv("LUAJIT_TEST_USE_VALGRIND"),
810
})
911

1012
test:plan(19)

0 commit comments

Comments
 (0)