forked from LuaJIT/LuaJIT
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reported by Guilherme Batalheiro. (cherry picked from commit fca6633) Before the patch, a function `prof_finish` wrote a string `No samples collected` to a profiler output file and then exited. Due to early exit, the output file handle stay open. This patch fixes the condition and the file handle is closed even if the number of samples is equal to 0. Sergey Bronnikov: * added the description and the test for the problem Part of tarantool/tarantool#11055
- Loading branch information
Showing
2 changed files
with
67 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
test/tarantool-tests/lj-1304-close-profile-dump-with-0-samples.test.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
local tap = require('tap') | ||
-- Test file to demonstrate LuaJIT incorrect behaviour with missed | ||
-- closing a file handle for the profile output file. | ||
-- See also: https://github.com/LuaJIT/LuaJIT/issues/1304. | ||
local test = tap.test('lj-1304-close-profile-dump-with-0-samples') | ||
local profilename = require('utils').tools.profilename | ||
|
||
test:plan(2) | ||
|
||
local filename = profilename('sysprof') | ||
-- An interval of the profiling is set to a huge enough value to | ||
-- be sure that there are no samples collected. | ||
local jit_p_options = 'i9999999' | ||
|
||
local function close_profile_dump_with_0_samples(subtest) | ||
local jit_p = require('jit.p') | ||
|
||
subtest:plan(1) | ||
|
||
collectgarbage('stop') | ||
|
||
jit_p.start(jit_p_options, filename) | ||
jit_p.stop() | ||
|
||
local f = io.open(filename, 'r') | ||
local p_content = f:read('a*') | ||
subtest:is(p_content, '[No samples collected]\n', | ||
'profile dump has no samples') | ||
f:close() | ||
|
||
-- Teardown. | ||
collectgarbage('restart') | ||
os.remove(filename) | ||
end | ||
|
||
local function close_profile_dump_with_0_samples_with_unload(subtest) | ||
local jit_p = require('jit.p') | ||
|
||
subtest:plan(1) | ||
|
||
collectgarbage('stop') | ||
jit_p.start(jit_p_options, filename) | ||
jit_p.stop() | ||
|
||
-- Unload the module and clean the local. | ||
package.loaded['jit.p'] = nil | ||
jit_p = nil -- luacheck: no unused | ||
collectgarbage('collect') | ||
|
||
local f = io.open(filename, 'r') | ||
local p_content = f:read('a*') | ||
subtest:is(p_content, '[No samples collected]\n', | ||
'profile dump has no samples') | ||
f.close() | ||
|
||
-- Teardown. | ||
collectgarbage('restart') | ||
os.remove(filename) | ||
end | ||
|
||
test:test('close profile dump with 0 samples', | ||
close_profile_dump_with_0_samples) | ||
test:test('close profile dump with 0 samples and profile module unload', | ||
close_profile_dump_with_0_samples_with_unload) | ||
|
||
test:done(true) |