diff options
author | Romain Forlot <romain.forlot@iot.bzh> | 2018-05-17 02:32:11 +0200 |
---|---|---|
committer | Romain Forlot <romain.forlot@iot.bzh> | 2018-07-10 17:12:13 +0200 |
commit | fd65ad40cb1a1b52b5207d45a58962b5f590046b (patch) | |
tree | e4672ca39036955444b76ca27f1246be0509255f /conf.d/project/lua.d/low-can-tests.lua | |
parent | 63df935362a9c25553696d72ce85089f5a1c7ed0 (diff) |
Adding more material to do tests
Make the lua interpreter find the luaunit module.
Find a way to use it from the controller.
Adding canreplayer file and write a script that could
launch in background the canplayer. No process handling
by now which have to done in the next step
Change-Id: I2d35472ba0e2fbb03ead121ff2587d831fe4ff17
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'conf.d/project/lua.d/low-can-tests.lua')
-rw-r--r-- | conf.d/project/lua.d/low-can-tests.lua | 62 |
1 files changed, 47 insertions, 15 deletions
diff --git a/conf.d/project/lua.d/low-can-tests.lua b/conf.d/project/lua.d/low-can-tests.lua index e724c38..985c343 100644 --- a/conf.d/project/lua.d/low-can-tests.lua +++ b/conf.d/project/lua.d/low-can-tests.lua @@ -18,14 +18,16 @@ NOTE: strict mode: every global variables should be prefixed by '_' --]] -EXPORT_ASSERT_TO_GLOBALS = true -require('luaunit') ---module( "low-can-testcase", lunit.testcase, package.seeall ) +package.path = package.path .. ';./var/?.lua' +local lu = require('luaunit') +local src = nil +local arg = nil -- Static variables should be prefixed with _ _EventHandle = {} -_engine_on_msg_received = false +local engine_off_evt_received = false +local engine_speed_evt_received = false local clock = os.clock function sleep(n) -- seconds @@ -36,24 +38,54 @@ end function _evt_catcher_ (source, action, event) local match = string.find(event.data.message, "is_engine_on: engine.speed CAN signal found, but engine seems off") if match ~= nil then - _engine_on_msg_received = true + engine_off_evt_received = true end + + match = string.find(event.data.message, "diagnostic_messages.engine.speed") + if match ~= nil then + engine_speed_evt_received = true + end +end + +function _start_afb_logging() + AFB:servsync(src, "monitor","set", { verbosity = "debug" }) + AFB:servsync(src, "monitor","trace", { add = { api = "low-can", daemon = "vverbose" }}) +end + +function _stop_afb_logging() + AFB:servsync(src, "monitor","trace", { drop = true}) end --- Display receive arguments and echo them to caller -function _launch_tests (source, args) - local responseJ = {} +Test_Engine = {} + function Test_Engine:test_detection_is_off() + local responseJ = {} - AFB:servsync(source, "monitor","set", { verbosity = "debug" }) - AFB:servsync(source, "monitor","trace", { add = { api = "low-can", daemon = "vverbose" }}) + _start_afb_logging() - local err,responseJ = AFB:servsync(source, "low-can","subscribe", { event = "diagnostic_messages.engine.speed" }) + local err,responseJ = AFB:servsync(src, "low-can","subscribe", { event = "diagnostic_messages.engine.speed" }) - assertStrMatches(responseJ.request.status, "success", nil, nil, "Correctly subscribed to engine.speed signal") + lu.assertStrMatches(responseJ.request.status, "success", nil, nil, "Correctly subscribed to engine.speed signal") + + _stop_afb_logging() + + lu.assertTrue(engine_off_evt_received, "Expected message did not comes up from binder log") + end + + function Test_Engine:Test_turning_on() + _start_afb_logging() + + local ret = os.execute("./var/replay_launcher.sh ./var/test1.canreplay") + lu.assertTrue(ret) + --sleep(60) + lu.assertTrue(engine_speed_evt_received, "Engine still off") + + _stop_afb_logging() + end - AFB:servsync(source, "monitor","trace", { drop = true}) - assertTrue(_engine_on_msg_received, "Ok, got the message indicating that engine is Off") +function _launch_test (source, args) + src = source + arg = args - return 0 -- happy end + os.exit(lu.LuaUnit.run()) -- run the tests! end |