aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArthur Guyader <arthur.guyader@iot.bzh>2019-12-13 13:47:05 +0100
committerRomain Forlot <romain.forlot@iot.bzh>2020-01-09 16:25:36 +0100
commit23e350e7c5f193edd5944239f5a2e12af401c228 (patch)
treec8b9ad512863577437c973d7a2ddf377f1ea02b3
parent03807d4379c31b345ea4d512305ed12757b63e53 (diff)
tests: Test the value of signals decoded
This commit adds test to check if the value of signals is well decoded. Change-Id: I64f489d6428bf593dfda08dc6aacbdacd9d18d73 Signed-off-by: Arthur Guyader <arthur.guyader@iot.bzh> Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
-rw-r--r--test/afb-test/etc/CMakeLists.txt2
-rw-r--r--test/afb-test/etc/aft-agl-service-low-can.json.in2
-rw-r--r--test/afb-test/fixtures/testValueCAN_1.canreplay1
-rw-r--r--test/afb-test/fixtures/testValueCAN_2.canreplay1
-rw-r--r--test/afb-test/fixtures/testValueCAN_3.canreplay1
-rw-r--r--test/afb-test/fixtures/testValueJ1939_1.canreplay1
-rw-r--r--test/afb-test/tests/low-can_ValueJ1939Test.lua137
-rw-r--r--test/afb-test/tests/low-can_ValueTestCan.lua120
8 files changed, 263 insertions, 2 deletions
diff --git a/test/afb-test/etc/CMakeLists.txt b/test/afb-test/etc/CMakeLists.txt
index b4617ac8..bb7d3319 100644
--- a/test/afb-test/etc/CMakeLists.txt
+++ b/test/afb-test/etc/CMakeLists.txt
@@ -21,7 +21,7 @@
##################################################
PROJECT_TARGET_ADD(afb-test-config)
if(WITH_FEATURE_J1939)
- set(J1939_TEST_CONFFILE ",\"low-can_J1939Test.lua\"")
+ set(J1939_TEST_CONFFILE ",\"low-can_J1939Test.lua\",\"low-can_ValueJ1939Test.lua\"")
endif()
configure_file("aft-agl-service-low-can.json.in" "aft-agl-service-low-can.json")
diff --git a/test/afb-test/etc/aft-agl-service-low-can.json.in b/test/afb-test/etc/aft-agl-service-low-can.json.in
index 88bd9199..407600e3 100644
--- a/test/afb-test/etc/aft-agl-service-low-can.json.in
+++ b/test/afb-test/etc/aft-agl-service-low-can.json.in
@@ -16,7 +16,7 @@
"action": "lua://AFT#_launch_test",
"args": {
"trace": "low-can",
- "files": ["low-can_BasicAPITest.lua", "low-can_FilterTest01.lua"@J1939_TEST_CONFFILE@]
+ "files": ["low-can_BasicAPITest.lua", "low-can_FilterTest01.lua", "low-can_ValueTestCan.lua"@J1939_TEST_CONFFILE@]
}
}
}
diff --git a/test/afb-test/fixtures/testValueCAN_1.canreplay b/test/afb-test/fixtures/testValueCAN_1.canreplay
new file mode 100644
index 00000000..4d740377
--- /dev/null
+++ b/test/afb-test/fixtures/testValueCAN_1.canreplay
@@ -0,0 +1 @@
+(1481581765.766257) can0 3E9#0400 \ No newline at end of file
diff --git a/test/afb-test/fixtures/testValueCAN_2.canreplay b/test/afb-test/fixtures/testValueCAN_2.canreplay
new file mode 100644
index 00000000..b9072417
--- /dev/null
+++ b/test/afb-test/fixtures/testValueCAN_2.canreplay
@@ -0,0 +1 @@
+(1491154074.555941) can0 7E8#04410C1FF5000000 \ No newline at end of file
diff --git a/test/afb-test/fixtures/testValueCAN_3.canreplay b/test/afb-test/fixtures/testValueCAN_3.canreplay
new file mode 100644
index 00000000..1624853c
--- /dev/null
+++ b/test/afb-test/fixtures/testValueCAN_3.canreplay
@@ -0,0 +1 @@
+(1491154074.817723) can0 7E8#0341048C00000000 \ No newline at end of file
diff --git a/test/afb-test/fixtures/testValueJ1939_1.canreplay b/test/afb-test/fixtures/testValueJ1939_1.canreplay
new file mode 100644
index 00000000..4685c39b
--- /dev/null
+++ b/test/afb-test/fixtures/testValueJ1939_1.canreplay
@@ -0,0 +1 @@
+(1481581765.346271) can2 09FD0202#EC5D0087C2FAFFFF
diff --git a/test/afb-test/tests/low-can_ValueJ1939Test.lua b/test/afb-test/tests/low-can_ValueJ1939Test.lua
new file mode 100644
index 00000000..7fd6da67
--- /dev/null
+++ b/test/afb-test/tests/low-can_ValueJ1939Test.lua
@@ -0,0 +1,137 @@
+
+--[[
+ Copyright (C) 2019 "IoT.bzh"
+ Author Arthur Guyader <arthur.guyader@iot.bzh>
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+ NOTE: strict mode: every global variables should be prefixed by '_'
+--]]
+
+
+
+_AFT.setBeforeAll(function()
+ local can = io.open("/sys/class/net/can2")
+ if can == nil then
+ print("# You do not have 'can2' device set. Please run the following command:\n### sudo modprobe vcan; sudo ip link add can2 type vcan; sudo ip link set can2 up ")
+ return -1
+ end
+ return 0
+end)
+
+_AFT.setBeforeEach(function() print("~~~~~ Begin Test ~~~~~") end)
+
+_AFT.setAfterEach(function()
+ os.execute("pkill canplayer")
+ os.execute("pkill linuxcan-canpla")
+ print("~~~~~ End Test ~~~~~")
+end)
+
+_AFT.setAfterAll( function()
+ os.execute("pkill canplayer")
+ os.execute("pkill linuxcan-canpla")
+ return 0
+end)
+
+
+--[[
+##################################################################
+####################### VALUES J1939 TESTS #######################
+##################################################################
+]]
+
+print("\n########################################################################")
+print("####################### BEGIN VALUES J1939 TESTS #######################")
+print("########################################################################\n")
+
+--[[
+++++++++++++++++
+Tests n2k values
+++++++++++++++++
+]]
+
+local api = "low-can"
+local evt1 = "messages.Wind.Data.Reference"
+local evt2 = "messages.Wind.Data.Sid"
+local evt3 = "messages.Wind.Data.Wind.Angle"
+local evt4 = "messages.Wind.Data.Wind.Speed"
+
+
+_AFT.describe("Value_Test_N2K_1", function()
+ _AFT.addEventToMonitor(api .. "/" ..evt1, function(eventname, data)
+ _AFT.assertEquals(eventname, api.."/"..evt1)
+ _AFT.assertIsTrue(data.value == "Apparent")
+ end)
+
+ _AFT.assertVerbStatusSuccess(api ,"subscribe", { event = evt1 })
+ local ret = os.execute("bash ".._AFT.bindingRootDir.."/var/replay_launcher.sh ".._AFT.bindingRootDir.."/var/testValueJ1939_1.canreplay");
+ _AFT.assertIsTrue(ret)
+
+ _AFT.assertEvtReceived(api .. "/" ..evt1, 1000000)
+end,
+nil,
+function()
+ _AFT.callVerb(api, "unsubscribe", { event = evt1 })
+end)
+
+_AFT.describe("Value_Test_N2K_2", function()
+ _AFT.addEventToMonitor(api .. "/" ..evt2, function(eventname, data)
+ _AFT.assertEquals(eventname, api.."/"..evt2)
+ _AFT.assertIsTrue(data.value == 236)
+ end)
+
+ _AFT.assertVerbStatusSuccess(api ,"subscribe", { event = evt2 })
+ local ret = os.execute("bash ".._AFT.bindingRootDir.."/var/replay_launcher.sh ".._AFT.bindingRootDir.."/var/testValueJ1939_1.canreplay");
+ _AFT.assertIsTrue(ret)
+
+ _AFT.assertEvtReceived(api .. "/" ..evt2, 1000000)
+end,
+nil,
+function()
+ _AFT.callVerb(api, "unsubscribe", { event = evt2 })
+end)
+
+_AFT.describe("Value_Test_N2K_3", function()
+ _AFT.addEventToMonitor(api .. "/" ..evt3, function(eventname, data)
+ _AFT.assertEquals(eventname, api.."/"..evt3)
+ _AFT.assertIsTrue(math.abs(data.value - 4.9798998832703) < 0.00000001)
+ end)
+
+ _AFT.assertVerbStatusSuccess(api ,"subscribe", { event = evt3 })
+ local ret = os.execute("bash ".._AFT.bindingRootDir.."/var/replay_launcher.sh ".._AFT.bindingRootDir.."/var/testValueJ1939_1.canreplay");
+ _AFT.assertIsTrue(ret)
+
+ _AFT.assertEvtReceived(api .. "/" ..evt3, 1000000)
+end,
+nil,
+function()
+ _AFT.callVerb(api, "unsubscribe", { event = evt3 })
+end)
+
+_AFT.describe("Value_Test_N2K_4", function()
+ _AFT.addEventToMonitor(api .. "/" ..evt4, function(eventname, data)
+ _AFT.assertEquals(eventname, api.."/"..evt4)
+ _AFT.assertIsTrue(math.abs(data.value - 0.93000000715256) < 0.00000001)
+ end)
+
+ _AFT.assertVerbStatusSuccess(api ,"subscribe", { event = evt4 })
+ local ret = os.execute("bash ".._AFT.bindingRootDir.."/var/replay_launcher.sh ".._AFT.bindingRootDir.."/var/testValueJ1939_1.canreplay");
+ _AFT.assertIsTrue(ret)
+
+ _AFT.assertEvtReceived(api .. "/" ..evt4, 1000000)
+end,
+nil,
+function()
+ _AFT.callVerb(api, "unsubscribe", { event = evt4 })
+end) \ No newline at end of file
diff --git a/test/afb-test/tests/low-can_ValueTestCan.lua b/test/afb-test/tests/low-can_ValueTestCan.lua
new file mode 100644
index 00000000..093ccf95
--- /dev/null
+++ b/test/afb-test/tests/low-can_ValueTestCan.lua
@@ -0,0 +1,120 @@
+
+--[[
+ Copyright (C) 2019 "IoT.bzh"
+ Author Arthur Guyader <arthur.guyader@iot.bzh>
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+ NOTE: strict mode: every global variables should be prefixed by '_'
+--]]
+
+
+
+_AFT.setBeforeAll(function()
+ local can = io.open("/sys/class/net/can2")
+ if can == nil then
+ print("# You do not have 'can2' device set. Please run the following command:\n### sudo modprobe vcan; sudo ip link add can2 type vcan; sudo ip link set can2 up ")
+ return -1
+ end
+ return 0
+end)
+
+_AFT.setBeforeEach(function() print("~~~~~ Begin Test ~~~~~") end)
+
+_AFT.setAfterEach(function()
+ os.execute("pkill canplayer")
+ os.execute("pkill linuxcan-canpla")
+ print("~~~~~ End Test ~~~~~")
+end)
+
+_AFT.setAfterAll( function()
+ os.execute("pkill canplayer")
+ os.execute("pkill linuxcan-canpla")
+ return 0
+end)
+
+
+--[[
+################################################################
+####################### VALUES CAN TESTS #######################
+################################################################
+]]
+
+print("\n######################################################################")
+print("####################### BEGIN VALUES CAN TESTS #######################")
+print("######################################################################\n")
+
+--[[
+++++++++++++++++++++++
+Tests basic can values
+++++++++++++++++++++++
+]]
+
+local api = "low-can"
+local evt = "messages.vehicle.average.speed"
+local evt2 = "diagnostic_messages.engine.speed"
+local evt3 = "diagnostic_messages.engine.load"
+
+_AFT.describe("Value_Test_Can", function()
+ _AFT.addEventToMonitor(api .. "/" ..evt, function(eventname, data)
+ _AFT.assertEquals(eventname, api.."/"..evt)
+ _AFT.assertIsTrue(data.value == 8)
+ end)
+
+ _AFT.assertVerbStatusSuccess(api ,"subscribe", { event = evt })
+ local ret = os.execute("bash ".._AFT.bindingRootDir.."/var/replay_launcher.sh ".._AFT.bindingRootDir.."/var/testValueCAN_1.canreplay");
+ _AFT.assertIsTrue(ret)
+
+ _AFT.assertEvtReceived(api .. "/" ..evt, 1000000)
+end,
+nil,
+function()
+ _AFT.callVerb(api, "unsubscribe", { event = evt })
+end)
+
+
+_AFT.describe("Value_Test_Can2", function()
+ _AFT.addEventToMonitor(api .. "/" ..evt2, function(eventname, data)
+ _AFT.assertEquals(eventname, api.."/"..evt2)
+ _AFT.assertIsTrue(math.abs(data.value - 2045.25) < 0.00000001)
+ end)
+
+ _AFT.assertVerbStatusSuccess(api ,"subscribe", { event = evt2 })
+ local ret = os.execute("bash ".._AFT.bindingRootDir.."/var/replay_launcher.sh ".._AFT.bindingRootDir.."/var/testValueCAN_2.canreplay");
+ _AFT.assertIsTrue(ret)
+
+ _AFT.assertEvtReceived(api .. "/" ..evt2, 1000000)
+end,
+nil,
+function()
+ _AFT.callVerb(api, "unsubscribe", { event = evt2 })
+end)
+
+
+_AFT.describe("Value_Test_Can3", function()
+ _AFT.addEventToMonitor(api .. "/" ..evt3, function(eventname, data)
+ _AFT.assertEquals(eventname, api.."/"..evt3)
+ _AFT.assertIsTrue(math.abs(data.value - 54.901962280273438) < 0.00000001)
+ end)
+
+ _AFT.assertVerbStatusSuccess(api ,"subscribe", { event = evt3 })
+ local ret = os.execute("bash ".._AFT.bindingRootDir.."/var/replay_launcher.sh ".._AFT.bindingRootDir.."/var/testValueCAN_3.canreplay");
+ _AFT.assertIsTrue(ret)
+
+ _AFT.assertEvtReceived(api .. "/" ..evt3, 1000000)
+end,
+nil,
+function()
+ _AFT.callVerb(api, "unsubscribe", { event = evt3 })
+end)