Skip to content

Commit

Permalink
fix(unittests): coredump when running unit tests #18663
Browse files Browse the repository at this point in the history
fs_init() must be called before early_init() in init/helpers.lua

If I run 'make unittest' on my Mac (macOS 10.14/Mojave or 12/Big Sur, intel
CPU), every test produce a core dump.

Call sequence in the core is:
    early_init()            main.c:197
    set_init_1()            option.c:508
    runtimepath_default()   runtime.c:1205
    get_lib_dir()           runtime.c:1175
    os_isdir()              fs.c:137
    os_getperm()            fs.c:777
    os_stat()               fs.c:761
    fs_loop_lock()          fs.c:72
    uv_mutex_lock(&fs_loop_mutex)   thread.c:352
    abort()

.deps/build/src/libuv/src/unix/thread.c:

    void uv_mutex_lock(uv_mutex_t* mutex) {
      if (pthread_mutex_lock(mutex))
        abort();	// line 352
    }

So pthread_mutex_lock(&fs_loop_mutex) failed. The reason seems to be simple.
fs_init() was not called and fs_loop_mutex has not been initialized. fs_init()
was moved out from early_init() in main.c by
b87867e, but unit/helpers.lua was not updated
accordingly.
  • Loading branch information
Jun-T committed May 21, 2022
1 parent b3453ea commit afa99f4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/nvim/os/fs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef NVIM_OS_FS_H
#define NVIM_OS_FS_H

#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "os/fs.h.generated.h"
#endif
#endif // NVIM_OS_FS_H
4 changes: 3 additions & 1 deletion test/unit/helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ local init = only_separate(function()
c.func(unpack(c.args))
end
libnvim.time_init()
libnvim.fs_init()
libnvim.event_init()
libnvim.early_init(nil)
if child_calls_mod then
Expand Down Expand Up @@ -778,7 +779,8 @@ local function cppimport(path)
return cimport(Paths.test_source_path .. '/test/includes/pre/' .. path)
end

cimport('./src/nvim/types.h', './src/nvim/main.h', './src/nvim/os/time.h')
cimport('./src/nvim/types.h', './src/nvim/main.h', './src/nvim/os/time.h',
'./src/nvim/os/fs.h')

local function conv_enum(etab, eval)
local n = tonumber(eval)
Expand Down

0 comments on commit afa99f4

Please sign in to comment.