3 Copyright (C) 2018 "IoT.bzh"
4 Author Arthur Guyader <arthur.guyader@iot.bzh>
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
19 NOTE: strict mode: every global variables should be prefixed by '_'
23 _AFT.setBeforeAll(function()
24 local can = io.open("/sys/class/net/can2")
26 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 ")
32 _AFT.setBeforeEach(function() print("~~~~~ Begin Test ~~~~~") end)
34 _AFT.setAfterEach(function()
35 os.execute("pkill canplayer")
36 os.execute("pkill linuxcan-canpla")
37 print("~~~~~ End Test ~~~~~")
40 _AFT.setAfterAll( function()
41 os.execute("pkill canplayer")
42 os.execute("pkill linuxcan-canpla")
47 ###########################################################
48 ####################### J1939 TESTS #######################
49 ###########################################################
52 print("\n##########################################")
53 print("######### BEGIN J1939 TESTS #########")
54 print("##########################################\n")
57 +++++++++++++++++++++++++++
58 Tests subscribe/unsubscribe
59 +++++++++++++++++++++++++++
63 --print("\n++++++++++++++++++++++++++++++++++++++++++")
64 --print("++++ TESTS SUBSCRIBE / UNSUBSCRIBE ++++")
65 --print("++++++++++++++++++++++++++++++++++++++++++\n")
67 _AFT.describe("Test subscribe/unsubscribe", function()
68 _AFT.testVerbStatusSuccess("low-can_subscribe_j1939_event", "low-can", "subscribe", {event= "Eng.Momentary.Overspeed.Enable"})
69 _AFT.testVerbStatusSuccess("low-can_subscribe_j1939_events", "low-can", "subscribe", {event= "Eng.*"})
70 _AFT.testVerbStatusSuccess("low-can_subscribe_j1939_pgn", "low-can", "subscribe", {pgn= 61442})
71 _AFT.testVerbStatusSuccess("low-can_subscribe_j1939_all_pgn", "low-can", "subscribe", {pgn= "*"})
72 _AFT.testVerbStatusSuccess("low-can_subscribe_j1939_id", "low-can", "subscribe", {id= 61442})
73 _AFT.testVerbStatusSuccess("low-can_subscribe_j1939_all_id", "low-can", "subscribe", {id= "*"})
74 _AFT.testVerbStatusSuccess("low-can_subscribe_j1939_event", "low-can", "unsubscribe", {event= "Eng.Momentary.Overspeed.Enable"})
75 _AFT.testVerbStatusSuccess("low-can_subscribe_j1939_event", "low-can", "unsubscribe", {event= "*"})
76 _AFT.testVerbStatusSuccess("low-can_subscribe_j1939_id", "low-can", "subscribe", {id= 61442})
77 _AFT.testVerbStatusError("low-can_subscribe_j1939_no_event", "low-can", "subscribe", {event= ""})
78 _AFT.testVerbStatusError("low-can_subscribe_j1939_no_event", "low-can", "subscribe", {id= ""})
79 _AFT.testVerbStatusError("low-can_subscribe_j1939_no_event", "low-can", "subscribe", {pgn= ""})
89 --print("\n++++++++++++++++++++++++++")
90 --print("++++ TESTS WRITE ++++")
91 --print("++++++++++++++++++++++++++\n")
93 _AFT.describe("Test write", function()
94 _AFT.testVerbStatusError("low-can_write_wo_auth", "low-can", "write", { signal_name = "Eng.Momentary.Overspeed.Enable", signal_value = 1})
95 _AFT.testVerbStatusSuccess("low-can_auth", "low-can", "auth", {})
96 _AFT.testVerbStatusSuccess("low-can_write_signal", "low-can", "write", { signal_name = "Eng.Momentary.Overspeed.Enable", signal_value = 1})
97 _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}}})
98 _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}}})
99 _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}}})
100 _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}}})
108 local api = "low-can"
109 local evt = "messages.Eng.Momentary.Overspeed.Enable"
110 local evt2 = "messages.Actl.Eng.Prcnt.Trque.High.Resolution"
112 _AFT.describe("Test subscribe read frame", function()
113 _AFT.addEventToMonitor(api .. "/" ..evt, function(eventname, data)
114 _AFT.assertEquals(eventname, api.."/"..evt)
117 _AFT.assertVerbStatusSuccess(api ,"subscribe", { event = evt})
118 local ret = os.execute("bash ".._AFT.bindingRootDir.."/var/replay_launcher.sh ".._AFT.bindingRootDir.."/var/testj1939.canreplay");
119 _AFT.assertIsTrue(ret)
121 _AFT.assertEvtReceived(api .. "/" ..evt, 1000000)
125 _AFT.callVerb(api, "unsubscribe", { event = evt})
128 ------------------------------------------------------------------------------
130 _AFT.describe("Test subscribe not read all frame", function()
131 _AFT.addEventToMonitor(api .. "/" ..evt2, function(eventname, data)
132 _AFT.assertEquals(eventname, api.."/"..evt2)
135 _AFT.assertVerbStatusSuccess(api ,"subscribe", { event = evt2})
136 local ret = os.execute("bash ".._AFT.bindingRootDir.."/var/replay_launcher.sh ".._AFT.bindingRootDir.."/var/testj1939.canreplay");
137 _AFT.assertIsTrue(ret)
139 _AFT.assertEvtNotReceived(api .. "/" ..evt2, 1000000)
143 _AFT.callVerb(api, "unsubscribe", { event = evt2})
149 _AFT.describe("Test subscribe read frame low time", function()
150 _AFT.addEventToMonitor(api .. "/" ..evt, function(eventname, data)
151 _AFT.assertEquals(eventname, api.."/"..evt)
154 _AFT.assertVerbStatusSuccess(api ,"subscribe", { event = evt})
155 local ret = os.execute("bash ".._AFT.bindingRootDir.."/var/replay_launcher.sh ".._AFT.bindingRootDir.."/var/testj1939.canreplay");
156 _AFT.assertIsTrue(ret)
160 _AFT.callVerb(api, "unsubscribe", { event = evt})