aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2019-11-26 16:18:46 +0100
committerRomain Forlot <romain.forlot@iot.bzh>2019-11-28 16:11:47 +0100
commit420d8d0fee32599381db6e0cd663b16da34e03cd (patch)
treeaa80bc750d8204abc9f6688a9a1d5c0e8016bb9f /test
parent451598fa9ce4e57a00c9312c04839e0b3dcdf320 (diff)
Add tests for J1939 features.
This commit adds tests for the J1939 features. Bug-AGL: SPEC-2386 Bug-AGL: SPEC-2976 Signed-off-by: Arthur Guyader <arthur.guyader@iot.bzh> Change-Id: I2545eb2f9a27561714fc5efcbd885afcb237770d Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'test')
-rw-r--r--test/afb-test/etc/CMakeLists.txt6
-rw-r--r--test/afb-test/etc/aft-agl-service-low-can.json.in (renamed from test/afb-test/etc/aft-agl-service-low-can.json)2
-rw-r--r--test/afb-test/fixtures/testj1939.canreplay1
-rw-r--r--test/afb-test/tests/low-can_BasicAPITest.lua6
-rw-r--r--test/afb-test/tests/low-can_FilterTest01.lua4
-rw-r--r--test/afb-test/tests/low-can_J1939Test.lua163
6 files changed, 179 insertions, 3 deletions
diff --git a/test/afb-test/etc/CMakeLists.txt b/test/afb-test/etc/CMakeLists.txt
index cd4beb91..b4617ac8 100644
--- a/test/afb-test/etc/CMakeLists.txt
+++ b/test/afb-test/etc/CMakeLists.txt
@@ -20,8 +20,12 @@
# Low-CAN test configuration files
##################################################
PROJECT_TARGET_ADD(afb-test-config)
+ if(WITH_FEATURE_J1939)
+ set(J1939_TEST_CONFFILE ",\"low-can_J1939Test.lua\"")
+ endif()
- file(GLOB CONF_FILES "*.json")
+ configure_file("aft-agl-service-low-can.json.in" "aft-agl-service-low-can.json")
+ file(GLOB CONF_FILES "${CMAKE_CURRENT_BINARY_DIR}/*.json")
add_input_files("${CONF_FILES}")
diff --git a/test/afb-test/etc/aft-agl-service-low-can.json b/test/afb-test/etc/aft-agl-service-low-can.json.in
index ebe7ed47..88bd9199 100644
--- a/test/afb-test/etc/aft-agl-service-low-can.json
+++ 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"]
+ "files": ["low-can_BasicAPITest.lua", "low-can_FilterTest01.lua"@J1939_TEST_CONFFILE@]
}
}
}
diff --git a/test/afb-test/fixtures/testj1939.canreplay b/test/afb-test/fixtures/testj1939.canreplay
new file mode 100644
index 00000000..d73ee92c
--- /dev/null
+++ b/test/afb-test/fixtures/testj1939.canreplay
@@ -0,0 +1 @@
+(08255.460200) can2 0CF00203#CD402800043828FF
diff --git a/test/afb-test/tests/low-can_BasicAPITest.lua b/test/afb-test/tests/low-can_BasicAPITest.lua
index bebf057a..2076d878 100644
--- a/test/afb-test/tests/low-can_BasicAPITest.lua
+++ b/test/afb-test/tests/low-can_BasicAPITest.lua
@@ -19,6 +19,10 @@
NOTE: strict mode: every global variables should be prefixed by '_'
--]]
+print("\n##########################################")
+print("######### BEGIN BASIC TESTS #########")
+print("##########################################\n")
+
_AFT.setBeforeAll(function()
local can = io.open("/sys/class/net/can0")
if can == nil then
@@ -44,7 +48,7 @@ _AFT.testVerbStatusSuccess("low-can_auth", "low-can", "auth", {})
_AFT.testVerbStatusSuccess("low-can_write", "low-can", "write", { signal_name = "hvac.temperature.left", signal_value = 21})
_AFT.testVerbStatusSuccess("low-can_write_raw", "low-can", "write", { bus_name= "hs", frame= { can_id= 1568, can_dlc=8, can_data= {255,255,255,255,255,255,255,255}}})
-_AFT.testVerbStatusError("low-can_write_unwritable_signal", "low-can", "write", { signal_name = "engine.speed", signal_value = 1234})
+_AFT.testVerbStatusError("low-can_write_unwritable_signal", "low-can", "write", { signal_name = "vehicle.average.speed", signal_value = 1234})
_AFT.testVerbStatusError("low-can_write_wrong_name_key", "low-can", "write", { name = "hvac.temperature.left", signal_value = 21})
_AFT.testVerbStatusError("low-can_write_wrong_value_key", "low-can", "write", { signal_name = "hvac.temperature.left", value = 21})
_AFT.testVerbStatusError("low-can_write_raw_invalid_bus_key", "low-can", "write", { bus= "hs", frame= { can_id= 1568, can_dlc=8, can_data= {255,255,255,255,255,255,255,255}}})
diff --git a/test/afb-test/tests/low-can_FilterTest01.lua b/test/afb-test/tests/low-can_FilterTest01.lua
index 32e3c288..028358f6 100644
--- a/test/afb-test/tests/low-can_FilterTest01.lua
+++ b/test/afb-test/tests/low-can_FilterTest01.lua
@@ -18,6 +18,10 @@
NOTE: strict mode: every global variables should be prefixed by '_'
--]]
+print("\n##########################################")
+print("######### BEGIN FILTER TESTS #########")
+print("##########################################\n")
+
local api = "low-can"
local evt = "messages.engine.speed"
diff --git a/test/afb-test/tests/low-can_J1939Test.lua b/test/afb-test/tests/low-can_J1939Test.lua
new file mode 100644
index 00000000..fc7649f3
--- /dev/null
+++ b/test/afb-test/tests/low-can_J1939Test.lua
@@ -0,0 +1,163 @@
+
+--[[
+ Copyright (C) 2018 "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)
+
+--[[
+###########################################################
+####################### J1939 TESTS #######################
+###########################################################
+]]
+
+print("\n##########################################")
+print("######### BEGIN J1939 TESTS #########")
+print("##########################################\n")
+
+--[[
++++++++++++++++++++++++++++
+Tests subscribe/unsubscribe
++++++++++++++++++++++++++++
+]]
+
+
+--print("\n++++++++++++++++++++++++++++++++++++++++++")
+--print("++++ TESTS SUBSCRIBE / UNSUBSCRIBE ++++")
+--print("++++++++++++++++++++++++++++++++++++++++++\n")
+
+_AFT.describe("Test subscribe/unsubscribe", function()
+_AFT.testVerbStatusSuccess("low-can_subscribe_j1939_event", "low-can", "subscribe", {event= "Eng.Momentary.Overspeed.Enable"})
+_AFT.testVerbStatusSuccess("low-can_subscribe_j1939_events", "low-can", "subscribe", {event= "Eng.*"})
+_AFT.testVerbStatusSuccess("low-can_subscribe_j1939_pgn", "low-can", "subscribe", {pgn= 61442})
+_AFT.testVerbStatusSuccess("low-can_subscribe_j1939_all_pgn", "low-can", "subscribe", {pgn= "*"})
+_AFT.testVerbStatusSuccess("low-can_subscribe_j1939_id", "low-can", "subscribe", {id= 61442})
+_AFT.testVerbStatusSuccess("low-can_subscribe_j1939_all_id", "low-can", "subscribe", {id= "*"})
+_AFT.testVerbStatusSuccess("low-can_subscribe_j1939_event", "low-can", "unsubscribe", {event= "Eng.Momentary.Overspeed.Enable"})
+_AFT.testVerbStatusSuccess("low-can_subscribe_j1939_event", "low-can", "unsubscribe", {event= "*"})
+_AFT.testVerbStatusSuccess("low-can_subscribe_j1939_id", "low-can", "subscribe", {id= 61442})
+_AFT.testVerbStatusError("low-can_subscribe_j1939_no_event", "low-can", "subscribe", {event= ""})
+_AFT.testVerbStatusError("low-can_subscribe_j1939_no_event", "low-can", "subscribe", {id= ""})
+_AFT.testVerbStatusError("low-can_subscribe_j1939_no_event", "low-can", "subscribe", {pgn= ""})
+end)
+
+
+--[[
++++++++++++
+Tests write
++++++++++++
+]]
+
+--print("\n++++++++++++++++++++++++++")
+--print("++++ TESTS WRITE ++++")
+--print("++++++++++++++++++++++++++\n")
+
+_AFT.describe("Test write", function()
+_AFT.testVerbStatusError("low-can_write_wo_auth", "low-can", "write", { signal_name = "Eng.Momentary.Overspeed.Enable", signal_value = 1})
+_AFT.testVerbStatusSuccess("low-can_auth", "low-can", "auth", {})
+_AFT.testVerbStatusSuccess("low-can_write_signal", "low-can", "write", { signal_name = "Eng.Momentary.Overspeed.Enable", signal_value = 1})
+_AFT.testVerbStatusSuccess("low-can_write_frame", "low-can", "write", { bus_name= "j1939", frame= { pgn= 62420, length=8, data= {1,2,3,4,5,6,7,8}}})
+_AFT.testVerbStatusSuccess("low-can_write_frame_other_pgn", "low-can", "write", { bus_name= "j1939", frame= { pgn= 126208, length=8, data= {9,10,11,12,13,14,15,16}}})
+_AFT.testVerbStatusError("low-can_write_frame_invalid_pgn", "low-can", "write", { bus_name= "j1939", frame= { pgn= 1234, length=8, data= {9,10,11,12,13,14,15,16}}})
+_AFT.testVerbStatusSuccess("low-can_write_multi_frame", "low-can", "write", { bus_name= "j1939", frame= { pgn= 126208, length=9, data= {9,10,11,12,13,14,15,16,17}}})
+end)
+--[[
+++++++++++
+Tests read
+++++++++++
+]]
+
+local api = "low-can"
+local evt = "messages.Eng.Momentary.Overspeed.Enable"
+local evt2 = "messages.Actl.Eng.Prcnt.Trque.High.Resolution"
+
+_AFT.describe("Test subscribe read frame", function()
+ _AFT.addEventToMonitor(api .. "/" ..evt, function(eventname,data)
+ _AFT.assertEquals(eventname, api.."/"..evt)
+ end)
+
+ _AFT.assertVerbStatusSuccess(api ,"subscribe", { event = evt})
+ local ret = os.execute("bash ".._AFT.bindingRootDir.."/var/replay_launcher.sh ".._AFT.bindingRootDir.."/var/testj1939.canreplay");
+ _AFT.assertIsTrue(ret)
+
+ _AFT.assertEvtReceived(api .. "/" ..evt, 1000000)
+end,
+nil,
+function()
+ _AFT.callVerb(api, "unsubscribe", { event = evt})
+end)
+
+------------------------------------------------------------------------------
+
+_AFT.describe("Test subscribe not read all frame", function()
+ _AFT.addEventToMonitor(api .. "/" ..evt2, function(eventname,data)
+ _AFT.assertEquals(eventname, api.."/"..evt2)
+ end)
+
+ _AFT.assertVerbStatusSuccess(api ,"subscribe", { event = evt2})
+ local ret = os.execute("bash ".._AFT.bindingRootDir.."/var/replay_launcher.sh ".._AFT.bindingRootDir.."/var/testj1939.canreplay");
+ _AFT.assertIsTrue(ret)
+
+ _AFT.assertEvtNotReceived(api .. "/" ..evt2, 1000000)
+end,
+nil,
+function()
+ _AFT.callVerb(api, "unsubscribe", { event = evt2})
+end)
+
+
+---------------
+
+_AFT.describe("Test subscribe read frame low time", function()
+ _AFT.addEventToMonitor(api .. "/" ..evt, function(eventname,data)
+ _AFT.assertEquals(eventname, api.."/"..evt)
+ end)
+
+ _AFT.assertVerbStatusSuccess(api ,"subscribe", { event = evt})
+ local ret = os.execute("bash ".._AFT.bindingRootDir.."/var/replay_launcher.sh ".._AFT.bindingRootDir.."/var/testj1939.canreplay");
+ _AFT.assertIsTrue(ret)
+end,
+nil,
+function()
+ _AFT.callVerb(api, "unsubscribe", { event = evt})
+end)
+
+_AFT.exitAtEnd()