-
Notifications
You must be signed in to change notification settings - Fork 3
tests/lapi: add io tests #140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--[[ | ||
SPDX-License-Identifier: ISC | ||
Copyright (c) 2023-2025, Sergey Bronnikov. | ||
|
||
5.7 – Input and Output Facilities | ||
https://www.lua.org/manual/5.1/manual.html#5.7 | ||
https://www.lua.org/pil/21.1.html | ||
|
||
Does io.lines() stream or slurp the file? | ||
https://stackoverflow.com/questions/43005068/does-io-lines-stream-or-slurp-the-file | ||
|
||
io.lines does not check maximum number of options, | ||
https://www.lua.org/bugs.html#5.3.1-1 | ||
|
||
Synopsis: io.lines([filename, ...]) | ||
]] | ||
|
||
local luzer = require("luzer") | ||
local test_lib = require("lib") | ||
|
||
local function TestOneInput(buf) | ||
local fdp = luzer.FuzzedDataProvider(buf) | ||
local str = fdp:consume_string(test_lib.MAX_STR_LEN) | ||
local lua_chunk = ("io.write([[%s]])"):format(str) | ||
local lua_cmd = ("%s -e '%s'"):format(test_lib.luabin(arg), lua_chunk) | ||
local fh = assert(io.popen(lua_cmd)) | ||
fh:lines("*all") | ||
fh:flush() | ||
fh:close() | ||
end | ||
|
||
local args = { | ||
artifact_prefix = "io_lines_", | ||
} | ||
luzer.Fuzz(TestOneInput, nil, args) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--[[ | ||
SPDX-License-Identifier: ISC | ||
Copyright (c) 2023-2025, Sergey Bronnikov. | ||
5.7 – Input and Output Facilities | ||
https://www.lua.org/manual/5.1/manual.html#5.7 | ||
'popen' can crash if called with an invalid mode, | ||
https://github.com/lua/lua/commit/1ecfbfa1a1debd2258decdf7c1954ac6f9761699 | ||
On some machines, closing a "piped file" (created with io.popen) may crash Lua, | ||
https://www.lua.org/bugs.html#5.0.2-8 | ||
Synopsis: io.popen(prog [, mode]) | ||
]] | ||
|
||
local luzer = require("luzer") | ||
local test_lib = require("lib") | ||
|
||
local function TestOneInput(buf) | ||
local fdp = luzer.FuzzedDataProvider(buf) | ||
local str = fdp:consume_string(test_lib.MAX_STR_LEN) | ||
local lua_chunk = ("io.write([[%s]])"):format(str) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If |
||
local lua_cmd = ("%s -e '%s'"):format(test_lib.luabin(arg), lua_chunk) | ||
local fh = assert(io.popen(lua_cmd, "r")) | ||
fh:lines("*all") | ||
fh:flush() | ||
fh:close() | ||
end | ||
|
||
local args = { | ||
artifact_prefix = "io_popen_", | ||
} | ||
luzer.Fuzz(TestOneInput, nil, args) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--[[ | ||
SPDX-License-Identifier: ISC | ||
Copyright (c) 2023-2025, Sergey Bronnikov. | ||
|
||
5.7 – Input and Output Facilities | ||
https://www.lua.org/manual/5.1/manual.html#5.7 | ||
https://www.lua.org/pil/21.3.html | ||
|
||
Synopsis: io.read(...) | ||
]] | ||
|
||
local luzer = require("luzer") | ||
local test_lib = require("lib") | ||
|
||
local READ_MODE = { "*n", "*a", "*l" } | ||
|
||
local function TestOneInput(buf) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't get the idea of the following test, please add the comment. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea is the following create IO object and make random operations with it (read, write, seek) |
||
local fdp = luzer.FuzzedDataProvider(buf) | ||
local str = fdp:consume_string(test_lib.MAX_STR_LEN) | ||
local lua_cmd = ("%s -e '%s'"):format(test_lib.luabin(arg), str) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the expected behaviour if returned string |
||
local fh = io.popen(lua_cmd, "w") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we use "w" mode if we read data from that program? |
||
local mode = fdp:oneof(READ_MODE) | ||
local cur_pos = fh:seek() | ||
fh:seek("end") | ||
fh:seek("set", cur_pos) | ||
fh:read(mode) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've got the following return values for this read.
|
||
fh:flush() | ||
fh:close() | ||
end | ||
|
||
local args = { | ||
artifact_prefix = "io_read_", | ||
} | ||
luzer.Fuzz(TestOneInput, nil, args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
str
contains]]
this string becomes invalid.