CI.lua
require("lib/strict")
local junit = require("modules/junit")
local logger = require("modules/logger")
local flashCommand = "cd /home/qoitech/myCoolProject && make -j flash > /dev/null 2>&1" local preFlashDelay = 250 local postFlashDelay = 5000 local recordDuration = 3100 local projectFile = "result.otii" local junitFile = "junit.xml"
tests = {{name="Boot", channel="me", target=0.021, start=290, stop=820, lowMargin=3, highMargin=3},
{name="Idle", channel="me", target=0.00007, start=2500, stop=3000, lowMargin=50, highMargin=0},
{name="Advertising", channel="me", target=0.0032, start=900, stop=1750, lowMargin=-1, highMargin=-1}
}
for _,test in ipairs(tests) do
junit.addTest(test.name, test.channel, test.target, test.start, test.stop, test.lowMargin, test.highMargin)
end
otii.clear()
local devices = otii.get_devices("Arc")
assert(#devices > 0, "No available devices")
local device = otii.open_device(devices[1].id)
assert(device ~= nil, "Cannot open device")
local project = otii.get_active_project()
if project == nil then
project = otii.create_project()
end
assert(project ~= nil, "Cannot open/create project")
device:enable_channel("mc", true)
device:set_range("low")
device:set_main_voltage(3.3) device:enable_main(true) device:enable_5v(true) device:set_gpo(1, true)
otii.msleep(preFlashDelay); otii.writeln("\nFlashing device...")
local flashResult = os.execute(flashCommand) assert(flashResult == true, "Failed to flash device")
device:set_gpo(1, false) device:enable_5v(false)
device:enable_main(false)
otii.writeln("Wait " .. postFlashDelay/1000.0 .. " seconds after power was cut.")
otii.msleep(postFlashDelay);
otii.writeln("Starting " .. recordDuration/1000.0 .. " seconds recording, turning power on.")
project:start()
device:enable_main(true)
otii.msleep(recordDuration);
project:stop()
device:enable_main(false)
local rec_id = project:get_last_recording_id()
local testResults = junit.evaluate(project, device, rec_id)
otii.writeln("")
otii.writeln("Total: " .. testResults.total .. ", passed: " .. testResults.passed .. ", failed: " .. testResults.failed .. ", disabled: " .. testResults.disabled)
for _,test in ipairs(testResults.tests) do
if test.state == "failed" then
otii.writeln(test.message)
end
end
assert(project:save(projectFile), "Failed to save project as " .. projectFile)
junit.saveReport(junitFile)