-
Notifications
You must be signed in to change notification settings - Fork 3
tests/lapi: os tests #141
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
Merged
Merged
tests/lapi: os tests #141
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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,45 @@ | ||
--[=[[ | ||
SPDX-License-Identifier: ISC | ||
Copyright (c) 2023-2025, Sergey Bronnikov. | ||
|
||
6.9 – Operating System Facilities | ||
https://www.lua.org/manual/5.3/manual.html#6.9 | ||
|
||
LuaJIT 2.1 VM out of memory for `os.date`, | ||
https://github.com/LuaJIT/LuaJIT/issues/463 | ||
|
||
Checking a format for os.date may read pass the format string, | ||
https://www.lua.org/bugs.html#5.3.3-2 | ||
|
||
os.date throws an error when result is the empty string, | ||
https://www.lua.org/bugs.html#5.1.1-4 | ||
|
||
Synopsis: os.date([format [, time]]) | ||
]]=] | ||
|
||
local luzer = require("luzer") | ||
local test_lib = require("lib") | ||
|
||
local ignored_msgs = { | ||
"invalid conversion specifier", | ||
} | ||
|
||
local function TestOneInput(buf) | ||
local fdp = luzer.FuzzedDataProvider(buf) | ||
os.setlocale(test_lib.random_locale(fdp), "all") | ||
local format = fdp:consume_string(test_lib.MAX_STR_LEN) | ||
local time = fdp:consume_integer(test_lib.MIN_INT, test_lib.MAX_INT) | ||
local err_handler = test_lib.err_handler(ignored_msgs) | ||
local ok, res = xpcall(os.date, err_handler, format, time) | ||
if not ok then return end | ||
assert(type(res) == "string" or | ||
type(res) == "table" or | ||
-- Undocumented. | ||
type(res) == "number" or | ||
res == nil) | ||
end | ||
|
||
local args = { | ||
artifact_prefix = "os_date_", | ||
} | ||
luzer.Fuzz(TestOneInput, nil, args) |
This file contains hidden or 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,33 @@ | ||
--[[ | ||
SPDX-License-Identifier: ISC | ||
Copyright (c) 2023-2025, Sergey Bronnikov. | ||
|
||
6.9 – Operating System Facilities | ||
https://www.lua.org/manual/5.3/manual.html#6.9 | ||
|
||
Synopsis: os.difftime(t2, t1) | ||
]] | ||
|
||
local luzer = require("luzer") | ||
local test_lib = require("lib") | ||
local MIN_INT = test_lib.MIN_INT | ||
local MAX_INT = test_lib.MAX_INT | ||
|
||
local ignored_msgs = { | ||
"number has no integer representation", | ||
} | ||
|
||
local function TestOneInput(buf) | ||
local fdp = luzer.FuzzedDataProvider(buf) | ||
local t1 = fdp:consume_number(MIN_INT, MAX_INT) | ||
local t2 = fdp:consume_number(MIN_INT, MAX_INT) | ||
local err_handler = test_lib.err_handler(ignored_msgs) | ||
local ok, res = xpcall(os.difftime, err_handler, t1, t2) | ||
if not ok then return end | ||
assert(type(res) == "number") | ||
end | ||
|
||
local args = { | ||
artifact_prefix = "os_difftime_", | ||
} | ||
luzer.Fuzz(TestOneInput, nil, args) |
This file contains hidden or 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,21 @@ | ||
--[[ | ||
SPDX-License-Identifier: ISC | ||
Copyright (c) 2023-2025, Sergey Bronnikov. | ||
|
||
6.9 – Operating System Facilities | ||
https://www.lua.org/manual/5.3/manual.html#6.9 | ||
|
||
Synopsis: os.getenv(varname) | ||
]] | ||
|
||
local luzer = require("luzer") | ||
|
||
local function TestOneInput(buf) | ||
local v = os.getenv(buf) | ||
assert(type(v) == "string" or v == nil) | ||
end | ||
|
||
local args = { | ||
artifact_prefix = "os_getenv_", | ||
} | ||
luzer.Fuzz(TestOneInput, nil, args) |
This file contains hidden or 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,28 @@ | ||
--[[ | ||
SPDX-License-Identifier: ISC | ||
Copyright (c) 2023-2025, Sergey Bronnikov. | ||
|
||
6.9 – Operating System Facilities | ||
https://www.lua.org/manual/5.3/manual.html#6.9 | ||
|
||
Synopsis: os.setlocale(locale [, category]) | ||
]] | ||
|
||
local luzer = require("luzer") | ||
local test_lib = require("lib") | ||
|
||
local function TestOneInput(buf) | ||
local fdp = luzer.FuzzedDataProvider(buf) | ||
local locale = fdp:consume_string(test_lib.MAX_STR_LEN) | ||
local category = fdp:oneof({ | ||
"all", "collate", "ctype", "monetary", "numeric", "time", | ||
}) | ||
local locale_string = os.setlocale(locale, category) | ||
assert(type(locale_string) == "string" or | ||
locale_string == nil) | ||
end | ||
|
||
local args = { | ||
artifact_prefix = "os_setlocale_", | ||
} | ||
luzer.Fuzz(TestOneInput, nil, args) |
This file contains hidden or 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,41 @@ | ||
--[[ | ||
SPDX-License-Identifier: ISC | ||
Copyright (c) 2023-2025, Sergey Bronnikov. | ||
|
||
6.9 – Operating System Facilities | ||
https://www.lua.org/manual/5.3/manual.html#6.9 | ||
|
||
Synopsis: os.time([table]) | ||
]] | ||
|
||
local luzer = require("luzer") | ||
local test_lib = require("lib") | ||
local MAX_INT64 = test_lib.MAX_INT64 | ||
local MIN_INT64 = test_lib.MIN_INT64 | ||
|
||
local ignored_msgs = { | ||
"field 'year' is out-of-bound", | ||
} | ||
|
||
local function TestOneInput(buf) | ||
local fdp = luzer.FuzzedDataProvider(buf) | ||
os.setlocale(test_lib.random_locale(fdp), "all") | ||
local time = { | ||
day = fdp:consume_number(MIN_INT64, MAX_INT64), | ||
hour = fdp:consume_number(MIN_INT64, MAX_INT64), | ||
isdst = fdp:consume_boolean(), | ||
min = fdp:consume_number(MIN_INT64, MAX_INT64), | ||
month = fdp:consume_number(MIN_INT64, MAX_INT64), | ||
sec = fdp:consume_number(MIN_INT64, MAX_INT64), | ||
year = fdp:consume_number(MIN_INT64, MAX_INT64), | ||
} | ||
local err_handler = test_lib.err_handler(ignored_msgs) | ||
local ok, res = xpcall(os.time, err_handler, time) | ||
if not ok then return end | ||
assert(type(res) == "number" or type(res) == "table") | ||
end | ||
|
||
local args = { | ||
artifact_prefix = "os_time_", | ||
} | ||
luzer.Fuzz(TestOneInput, nil, args) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.