aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2018-08-24 15:59:18 +0200
committerJan-Simon Moeller <jsmoeller@linuxfoundation.org>2018-08-30 14:52:41 +0000
commite68181541d8dd6d0ca43d8cba7692997cbc26b6a (patch)
treec648d516121d5557f2859ae7ec0567598ffa65c0
parentd54d2b73f869e0e724689e89f1d4c10660370cf2 (diff)
Don't crash if lua test files aren't found
This protect the file read to avoid crashing if no file has been found and display an error. Protect with double-quote the path to avoid 'find' error if space are part of the path. Change-Id: I3a27ca9d2566edd5f1b9cd301153e0ab735a177a Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
-rw-r--r--conf.d/controller/lua.d/aft.lua20
1 files changed, 13 insertions, 7 deletions
diff --git a/conf.d/controller/lua.d/aft.lua b/conf.d/controller/lua.d/aft.lua
index 8f03e28..876af80 100644
--- a/conf.d/controller/lua.d/aft.lua
+++ b/conf.d/controller/lua.d/aft.lua
@@ -545,10 +545,20 @@ local function call_tests()
--end
end
+local function readOneFile(f)
+ local cmdHandle = io.popen('find "'.. _AFT.bindingRootDir..'" -name "'..f..'"')
+ local filehandle = cmdHandle:read()
+ if filehandle then
+ dofile(filehandle)
+ else
+ print('Error: file not found ', f)
+ end
+ cmdHandle:close()
+end
+
function _launch_test(context, args)
_AFT.context = context
_AFT.bindingRootDir = AFB:getrootdir(_AFT.context)
- local loadedfile = nil
-- Prepare the tests execution configuring the monitoring and loading
-- lua test files to execute in the Framework.
@@ -565,14 +575,10 @@ function _launch_test(context, args)
if args.files and type(args.files) == 'table' then
for _,f in pairs(args.files) do
- local cmdHandle = io.popen('find '.. _AFT.bindingRootDir..' -name '..f)
- loadedfile = dofile(cmdHandle:read())
- cmdHandle:close()
+ readOneFile(f)
end
elseif type(args.files) == 'string' then
- local cmdHandle = io.popen('find '.._AFT.bindingRootDir..' -name '..args.files)
- loadedfile = dofile(cmdHandle:read())
- cmdHandle:close()
+ readOneFile(args.files)
end
-- Execute the test within a context if given. We assume that the before