Skip to content

Commit 205ba33

Browse files
committed
tests/lapi: os tests
1 parent 0508724 commit 205ba33

File tree

6 files changed

+152
-0
lines changed

6 files changed

+152
-0
lines changed

tests/lapi/os_clock_test.lua

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--[[
2+
SPDX-License-Identifier: ISC
3+
Copyright (c) 2023-2025, Sergey Bronnikov.
4+
5+
6.9 – Operating System Facilities
6+
https://www.lua.org/manual/5.3/manual.html#6.9
7+
8+
Synopsis: os.clock()
9+
]]
10+
11+
local luzer = require("luzer")
12+
13+
local function TestOneInput(buf)
14+
os.clock(buf)
15+
end
16+
17+
local args = {
18+
artifact_prefix = "os_clock_",
19+
}
20+
luzer.Fuzz(TestOneInput, nil, args)

tests/lapi/os_date_test.lua

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--[=[[
2+
SPDX-License-Identifier: ISC
3+
Copyright (c) 2023-2025, Sergey Bronnikov.
4+
5+
6.9 – Operating System Facilities
6+
https://www.lua.org/manual/5.3/manual.html#6.9
7+
8+
LuaJIT 2.1 VM out of memory for `os.date`,
9+
https://github.com/LuaJIT/LuaJIT/issues/463
10+
11+
Checking a format for os.date may read pass the format string,
12+
https://www.lua.org/bugs.html#5.3.3-2
13+
14+
os.date throws an error when result is the empty string,
15+
https://www.lua.org/bugs.html#5.1.1-4
16+
17+
Synopsis: os.date([format [, time]])
18+
]]=]
19+
20+
local luzer = require("luzer")
21+
local test_lib = require("lib")
22+
23+
local function TestOneInput(buf)
24+
local fdp = luzer.FuzzedDataProvider(buf)
25+
os.setlocale(test_lib.random_locale(fdp), "all")
26+
-- TODO: Set `format`.
27+
os.date(buf)
28+
end
29+
30+
local args = {
31+
artifact_prefix = "os_date_",
32+
}
33+
luzer.Fuzz(TestOneInput, nil, args)

tests/lapi/os_difftime_test.lua

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--[[
2+
SPDX-License-Identifier: ISC
3+
Copyright (c) 2023-2025, Sergey Bronnikov.
4+
5+
6.9 – Operating System Facilities
6+
https://www.lua.org/manual/5.3/manual.html#6.9
7+
8+
Synopsis: os.difftime(t2, t1)
9+
]]
10+
11+
local luzer = require("luzer")
12+
local test_lib = require("lib")
13+
local MIN_INT = test_lib.MIN_INT64
14+
local MAX_INT = test_lib.MAX_INT64
15+
16+
local function TestOneInput(buf)
17+
local fdp = luzer.FuzzedDataProvider(buf)
18+
local t1 = fdp:consume_number(MIN_INT, MAX_INT)
19+
local t2 = fdp:consume_number(MIN_INT, MAX_INT)
20+
os.difftime(t1, t2)
21+
end
22+
23+
local args = {
24+
artifact_prefix = "os_difftime_",
25+
}
26+
luzer.Fuzz(TestOneInput, nil, args)

tests/lapi/os_getenv_test.lua

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--[[
2+
SPDX-License-Identifier: ISC
3+
Copyright (c) 2023-2025, Sergey Bronnikov.
4+
5+
6.9 – Operating System Facilities
6+
https://www.lua.org/manual/5.3/manual.html#6.9
7+
8+
Synopsis: os.getenv(varname)
9+
]]
10+
11+
12+
local luzer = require("luzer")
13+
14+
local function TestOneInput(buf)
15+
os.getenv(buf)
16+
end
17+
18+
local args = {
19+
artifact_prefix = "os_getenv_",
20+
}
21+
luzer.Fuzz(TestOneInput, nil, args)

tests/lapi/os_setlocale_test.lua

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--[[
2+
SPDX-License-Identifier: ISC
3+
Copyright (c) 2023-2025, Sergey Bronnikov.
4+
5+
6.9 – Operating System Facilities
6+
https://www.lua.org/manual/5.3/manual.html#6.9
7+
8+
Synopsis: os.setlocale(locale [, category])
9+
]]
10+
11+
local luzer = require("luzer")
12+
13+
local function TestOneInput(buf)
14+
os.setlocale(buf)
15+
end
16+
17+
local args = {
18+
artifact_prefix = "os_setlocale_",
19+
}
20+
luzer.Fuzz(TestOneInput, nil, args)

tests/lapi/os_time_test.lua

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--[[
2+
SPDX-License-Identifier: ISC
3+
Copyright (c) 2023-2025, Sergey Bronnikov.
4+
5+
6.9 – Operating System Facilities
6+
https://www.lua.org/manual/5.3/manual.html#6.9
7+
8+
Synopsis: os.time([table])
9+
]]
10+
11+
local luzer = require("luzer")
12+
local test_lib = require("lib")
13+
local MAX_INT = test_lib.MAX_INT64
14+
15+
local function TestOneInput(buf)
16+
local fdp = luzer.FuzzedDataProvider(buf)
17+
os.setlocale(test_lib.random_locale(fdp), "all")
18+
os.time({
19+
isdst = fdp:consume_boolean(),
20+
sec = fdp:consume_number(0, MAX_INT),
21+
min = fdp:consume_number(0, MAX_INT),
22+
hour = fdp:consume_number(0, MAX_INT),
23+
day = fdp:consume_number(0, MAX_INT),
24+
month = fdp:consume_number(0, MAX_INT),
25+
year = fdp:consume_number(0, MAX_INT),
26+
})
27+
end
28+
29+
local args = {
30+
artifact_prefix = "os_time_",
31+
}
32+
luzer.Fuzz(TestOneInput, nil, args)

0 commit comments

Comments
 (0)