git: 85242b59d17d - main - libc: tests: fix luacheck warnings in the fortification test generator
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 20 Mar 2025 04:44:32 UTC
The branch main has been updated by kevans:
URL: https://cgit.FreeBSD.org/src/commit/?id=85242b59d17dcbfbc82afea9d4232006df074210
commit 85242b59d17dcbfbc82afea9d4232006df074210
Author: Kyle Evans <kevans@FreeBSD.org>
AuthorDate: 2025-03-20 04:42:57 +0000
Commit: Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2025-03-20 04:44:25 +0000
libc: tests: fix luacheck warnings in the fortification test generator
All of these are simple shadowing that don't need to happen; we're
passing the shadowed value through in every case anyways, just use it
in the closure in a more lua-natural fashion.
While we're here, lint the generator every time we generate tests to
ensure that we don't regress without having to remember to manually
run luacheck.
Reported by: jlduran
Reviewed by: jlduran, markj
Differential Revision: https://reviews.freebsd.org/D49235
---
lib/libc/tests/secure/Makefile | 10 +++++++++-
lib/libc/tests/secure/generate-fortify-tests.lua | 12 ++++++------
2 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/lib/libc/tests/secure/Makefile b/lib/libc/tests/secure/Makefile
index ccf89afb1ad5..beaa01457cfe 100644
--- a/lib/libc/tests/secure/Makefile
+++ b/lib/libc/tests/secure/Makefile
@@ -18,10 +18,18 @@ FORTIFY_TCATS+= unistd
FORTIFY_TCATS+= wchar
# Manually run after updating the test generator.
-generate-tests: .PHONY
+lint-generator: .PHONY
+ @if ! which luacheck>/dev/null; then \
+ 1>&2 echo "devel/lua-luacheck is required to regenerate and lint these tests"; \
+ exit 1; \
+ fi
+ luacheck ${.CURDIR}/generate-fortify-tests.lua
+
+generate-tests: .PHONY lint-generator
.for tcat in ${FORTIFY_TCATS}
ATF_TESTS_C+= fortify_${tcat}_test
+.ORDER: lint-generator generate-tests-${tcat}
generate-tests: generate-tests-${tcat}
generate-tests-${tcat}: .PHONY
${.CURDIR}/generate-fortify-tests.lua ${tcat} > ${.CURDIR}/fortify_${tcat}_test.c
diff --git a/lib/libc/tests/secure/generate-fortify-tests.lua b/lib/libc/tests/secure/generate-fortify-tests.lua
index 0e46b8867862..ef9e0299dd48 100755
--- a/lib/libc/tests/secure/generate-fortify-tests.lua
+++ b/lib/libc/tests/secure/generate-fortify-tests.lua
@@ -1113,7 +1113,7 @@ local function configurable(def, idx)
end
local function generate_stackframe(buftype, bufsize, disposition, heap, def)
- local function len_offset(inverted, disposition)
+ local function len_offset(inverted)
-- Tests that don't use __len in their arguments may use an
-- inverted sense because we can't just specify a length that
-- would induce an access just after the end. Instead, we have
@@ -1128,7 +1128,7 @@ local function generate_stackframe(buftype, bufsize, disposition, heap, def)
end
end
- local function test_uses_len(def)
+ local function test_uses_len()
if def.uses_len then
return true
end
@@ -1151,8 +1151,8 @@ local function generate_stackframe(buftype, bufsize, disposition, heap, def)
local vars = "\tstruct {\n"
vars = vars .. "\t\tuint8_t padding_l;\n"
- local uses_len = test_uses_len(def)
- local bufsize_offset = len_offset(not uses_len, disposition)
+ local uses_len = test_uses_len()
+ local bufsize_offset = len_offset(not uses_len)
local buftype_elem = array_type(buftype)
local size_expr = bufsize
@@ -1230,7 +1230,7 @@ local function write_test(fh, func, disposition, heap, def)
return
end
- local function need_addr(buftype)
+ local function need_addr()
return not (buftype:match("%[%]") or buftype:match("%*"))
end
@@ -1292,7 +1292,7 @@ local function write_test(fh, func, disposition, heap, def)
end
if arg == "__buf" then
- if not heap and need_addr(buftype) then
+ if not heap and need_addr() then
body = body .. "&"
end