--[[ Copyright (C) 2018 "IoT.bzh" Author Romain Forlot 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 '_' --]] local lu = require('luaunit') lu.LuaUnit:setOutputType('TAP') lu.LuaUnit.fname = "xUnitResults.xml" _AFT = { exit = {0, code}, context = _ctx, bindingRootDir = nil, tests_list = {}, event_history = false, monitored_events = {}, beforeEach = nil, afterEach = nil, beforeAll = nil, afterAll = nil, } function _AFT.enableEventHistory() _AFT.event_history = true end function _AFT.setJunitFile(filePath) lu.LuaUnit.fname = filePath end function _AFT.setOutputFile(filePath) local file = assert(io.open(filePath, "w+")) io.output(file) io.stdout = file end function _AFT.exitAtEnd(code) _AFT.exit = {1, code} end -- Use our own print function to redirect it to a file in the workdir of the -- binder instead of the standard output. _AFT.setOutputFile("test_results.log") _standard_print = print print = function(...) io.write(... .. '\n') _standard_print(...) end --[[ Events listener and assertion functions to test correctness of received event data. Check are in 2 times. First you need to register the event that you want to monitor then you test that it has been correctly received. Notice that there is a difference between log and event. Logs are daemon messages normally handled by the host log system (journald, syslog...) and events are generated by the apis to communicate and send informations to the subscribed listeners. ]] function _AFT.addEventToMonitor(eventName, callback) _AFT.monitored_events[eventName] = { cb = callback, receivedCount = 0 } end function _AFT.incrementCount(dict) if dict.receivedCount then dict.receivedCount = dict.receivedCount + 1 else dict.receivedCount = 1 end end function _AFT.registerData(dict, eventData) local dataCpy = deep_copy(eventData) if dict.data and type(dict.data) == 'table' then if _AFT.event_history == true then table.insert(dict.data, dataCpy) else dict.data[1] = dataCpy end else dict.data = {} table.insert(dict.data, dataCpy) end end function _AFT.triggerEvtCallback(eventName) if _AFT.monitored_events[eventName].cb then if _AFT.monitored_events[eventName].data ~= nil then local data_n = table_size(_AFT.monitored_events[eventName].data) if _AFT.event_history == true then _AFT.monitored_events[eventName].cb(eventName, _AFT.monitored_events[eventName].data[data_n], _AFT.monitored_events[eventName].data) else _AFT.monitored_events[eventName].cb(eventName, _AFT.monitored_events[eventName].data[data_n]) end end end end function _AFT.bindingEventHandler(eventObj, uid) local eventName = nil local eventListeners = nil local data = nil if uid then eventName = uid data = eventObj elseif eventObj.event.name then eventName = eventObj.event.name eventListeners = eventObj.data.result -- Remove from event to hold the bare event data and be able to assert it eventObj.data.result = nil data = eventObj.data.data end if type(_AFT.monitored_events[eventName]) == 'table' then if eventListeners then _AFT.monitored_events[eventName].eventListeners = eventListeners end _AFT.incrementCount(_AFT.monitored_events[eventName]) _AFT.registerData(_AFT.monitored_events[eventName], data) end end function _evt_catcher_(source, action, eventObj) local uid = AFB:getuid(source) if uid == "monitor/trace" then if eventObj.type == "event" then _AFT.bindingEventHandler(eventObj) end --else -- _AFT.bindingEventHandler(eventObj, uid) end end function _AFT.lockWait(eventName, timeout) if type(eventName) ~= "string" then print("Error: wrong argument given to wait an event. 1st argument should be a string") return 0 end local count = 0 if _AFT.monitored_events[eventName].receivedCount and timeout then count = _AFT.monitored_events[eventName].receivedCount end while timeout > 0 do timeout = AFB:lockwait(_AFT.context, timeout) AFB:lockwait(_AFT.context, 0) --without it _evt_catcher_ cannot received event if _AFT.monitored_events[eventName].receivedCount == count + 1 then return 1 end end return 0 end function _AFT.lockWaitGroup(eventGroup, timeout) if type(eventGroup) ~= "table" then print("Error: wrong argument given to wait a group of events. 1st argument should be a table") return 0 end -- Copy and compute the expected as it may have already received events -- you should add the expected count to the actual received counter to be -- accurate. local eventGroupCpy = {} for event,expectedCount in pairs(eventGroup) do eventGroupCpy[event] = expectedCount + _AFT.monitored_events[event].receivedCount end local total = 0 local matched = nil while timeout > 0 do timeout = AFB:lockwait(_AFT.context, timeout) AFB:lockwait(_AFT.context, 0) --without it _evt_catcher_ cannot received event for name,expectedCount in pairs(eventGroupCpy) do if _AFT.monitored_events[name].receivedCount >= expectedCount then total = total + _AFT.monitored_events[name].receivedCount matched = name end end if matched then eventGroupCpy[matched] = nil matched = nil end if table_size(eventGroupCpy) == 0 then return total end end return 0 end --[[ Assert and test functions about the event part. ]] f
DESCRIPTION = "lin-config tool for the sllin driver module"
LICENSE = "GPLv2"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/GPL-2.0;md5=801f80980d171dd6425610833a22dbe6"

DEPENDS += "libnl libxml2"

SRC_URI = "git://github.com/trainman419/linux-lin.git;protocol=https"
SRCREV = "155d885e8ccc907a56f6c86c4b159fac27ef6fec"
S = "${WORKDIR}/git/lin_config/src"

SRC_URI_append = " \
	file://0001-Change-Makefile-to-use-pkg-config-for-libxml-2.0.patch \
	file://0002-Change-Makefile-to-use-LDFLAGS.patch \
	"

inherit pkgconfig

PV = "0.1+git${SRCPV}"

do_configure[noexec] = "1"

do_install_append() {
    install -d ${D}/${bindir}
    install -m 755 ${S}/lin_config ${D}/${bindir}
}
ctly. Look at the log and retry."}) end else call_tests() end -- Keep the context unset function to be executed after all no matter if -- tests have been executed or not. if _AFT.afterAll then if _AFT.afterAll() ~= 0 then print('Unsetting the tests context failed.') end end if _AFT.exit[1] == 1 then os.exit(_AFT.exit[2]) end end