Skip to content

Commit

Permalink
Merge pull request #103 from smartdevicelink/release/4.4.0
Browse files Browse the repository at this point in the history
Release/4.4.0
  • Loading branch information
jacobkeeler authored Oct 19, 2017
2 parents de0b908 + e20280a commit 61dba03
Show file tree
Hide file tree
Showing 39 changed files with 8,430 additions and 6,042 deletions.
11,005 changes: 6,031 additions & 4,974 deletions data/MOBILE_API.xml

Large diffs are not rendered by default.

142 changes: 129 additions & 13 deletions modules/SDL.lua
Original file line number Diff line number Diff line change
@@ -1,32 +1,105 @@
--- The module which is responsible for managing SDL from ATF
--
-- *Dependencies:* `os`, `sdl_logger`, `config`, `atf.util`
--
-- *Globals:* `sleep()`, `CopyFile()`, `CopyInterface()`, `xmlReporter`, `console`
-- @module SDL
-- @copyright [Ford Motor Company](https://smartdevicelink.com/partners/ford/) and [SmartDeviceLink Consortium](https://smartdevicelink.com/consortium/)
-- @license <https://github.com/smartdevicelink/sdl_core/blob/master/LICENSE>

require('os')
local sdl_logger = require('sdl_logger')
local config = require('config')
local console = require('console')
local SDL = { }

require('atf.util')

--- Table of SDL build options
SDL.buildOptions = {}
--- The flag responsible for stopping ATF in case of emergency completion of SDL
SDL.exitOnCrash = true
--- SDL state constant: SDL completed correctly
SDL.STOPPED = 0
--- SDL state constant: SDL works
SDL.RUNNING = 1
--- SDL state constant: SDL crashed
SDL.CRASH = -1

function sleep(n)
os.execute("sleep " .. tonumber(n))
--- Structure of SDL build options what to be set
local usedBuildOptions = {
remoteControl = {
sdlBuildParameter = "REMOTE_CONTROL",
defaultValue = "ON"
},
extendedPolicy = {
sdlBuildParameter = "EXTENDED_POLICY",
defaultValue = "PROPRIETARY"
}
}

--- Read specified parameter from CMakeCache.txt file
-- @tparam string paramName Parameter to read value
-- @treturn string The main result. Value read of parameter.
-- Can be nil in case parameter was not found.
-- @treturn string Type of read parameter
local function readParameterFromCMakeCacheFile(paramName)
local pathToFile = config.pathToSDL .. "/CMakeCache.txt"
if is_file_exists(pathToFile) then
local paramValue, paramType
for line in io.lines(pathToFile) do
paramType, paramValue = string.match(line, "^%s*" .. paramName .. ":(.+)=(%S*)")
if paramValue then
return paramValue, paramType
end
end
end
return nil
end

function CopyFile(file, newfile)
return os.execute (string.format('cp "%s" "%s"', file, newfile))
--- Set SDL build option as values of SDL module property
-- @tparam table self Reference to SDL module
-- @tparam string optionName Build option to set value
-- @tparam string sdlBuildParam SDL build parameter to read value
-- @tparam string defaultValue Default value of set option
local function setSdlBuildOption(self, optionName, sdlBuildParam, defaultValue)
local value, paramType = readParameterFromCMakeCacheFile(sdlBuildParam)
if value == nil then
value = defaultValue
local msg = "SDL build option " ..
sdlBuildParam .. " is unavailable.\nAssume that SDL was built with " ..
sdlBuildParam .. " = " .. defaultValue
print(console.setattr(msg, "cyan", 1))
else
if paramType == "UNINITIALIZED" then
value = nil
local msg = "SDL build option " ..
sdlBuildParam .. " is unsupported."
print(console.setattr(msg, "cyan", 1))
end
end
self.buildOptions[optionName] = value
end

function CopyInterface()
if config.pathToSDLInterfaces~="" and config.pathToSDLInterfaces~=nil then
local mobile_api = config.pathToSDLInterfaces .. '/MOBILE_API.xml'
local hmi_api = config.pathToSDLInterfaces .. '/HMI_API.xml'
CopyFile(mobile_api, 'data/MOBILE_API.xml')
CopyFile(hmi_api, 'data/HMI_API.xml')
--- Set all SDL build options for SDL module of ATF
-- @tparam table self Reference to SDL module
local function setAllSdlBuildOptions(self)
for option, data in pairs(usedBuildOptions) do
setSdlBuildOption(self, option, data.sdlBuildParameter, data.defaultValue)
end
end

--- A global function for organizing execution delays (using the OS)
-- @tparam number n The delay in ms
function sleep(n)
os.execute("sleep " .. tonumber(n))
end

--- Launch SDL from ATF
-- @tparam string pathToSDL Path to SDL
-- @tparam string smartDeviceLinkCore The name of the SDL to run
-- @tparam boolean ExitOnCrash Flag whether Stop ATF in case SDL shutdown
-- @treturn boolean The main result. Indicates whether the launch of SDL was successful
-- @treturn string Additional information on the main SDL startup result
function SDL:StartSDL(pathToSDL, smartDeviceLinkCore, ExitOnCrash)
if ExitOnCrash ~= nil then
self.exitOnCrash = ExitOnCrash
Expand All @@ -40,7 +113,6 @@ function SDL:StartSDL(pathToSDL, smartDeviceLinkCore, ExitOnCrash)
return false, msg
end

CopyInterface()
local result = os.execute ('./tools/StartSDL.sh ' .. pathToSDL .. ' ' .. smartDeviceLinkCore)

local msg
Expand All @@ -55,9 +127,11 @@ function SDL:StartSDL(pathToSDL, smartDeviceLinkCore, ExitOnCrash)
end
xmlReporter.AddMessage("StartSDL", {["message"] = msg})
return result, msg

end

--- Stop SDL from ATF (SIGINT is used)
-- @treturn nil The main result. Always nil.
-- @treturn string Additional information on the main result of stopping SDL
function SDL:StopSDL()
self.autoStarted = false
local status = self:CheckStatusSDL()
Expand All @@ -77,6 +151,14 @@ function SDL:StopSDL()
end
end

--- SDL status check
-- @treturn number SDL state
--
-- SDL.STOPPED = 0 Completed the work correctly
--
-- SDL.RUNNING = 1 Running
--
-- SDL.CRASH = -1 Crash
function SDL:CheckStatusSDL()
local testFile = os.execute ('test -e sdl.pid')
if testFile then
Expand All @@ -89,10 +171,44 @@ function SDL:CheckStatusSDL()
return self.STOPPED
end

--- Deleting an SDL process indicator file
function SDL:DeleteFile()
if os.execute ('test -e sdl.pid') then
os.execute('rm -f sdl.pid')
end
end

--- Update SDL log4cxx.properties in order SDL will be able to write logs through Telnet
local function updateSDLLogProperties()
if config.storeFullSDLLogs then
local pathToFile = config.pathToSDL .. "/log4cxx.properties"
local f = io.open(pathToFile, "r")
local content = f:read("*all")
f:close()

local paramsToUpdate = {
{
name = "log4j.rootLogger",
value = "ALL, SmartDeviceLinkCoreLogFile, TelnetLogging"
},
{
name = "log4j.appender.TelnetLogging.layout.ConversionPattern",
value = "%%-5p [%%d{yyyy-MM-dd HH-mm:ss,SSS}][%%t][%%c] %%F:%%L %%M: %%m"
}
}

for _, item in pairs(paramsToUpdate) do
content = string.gsub(content, item.name .. "=.-\n", item.name .. "=" .. item.value .. "\n")
end

f = io.open(pathToFile, "w")
f:write(content)
f:close()
end
end

setAllSdlBuildOptions(SDL)

updateSDLLogProperties()

return SDL
39 changes: 19 additions & 20 deletions modules/api_loader.lua
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
---- APIs validator loader.
--- Module which provides APIs validator loader.
--
-- Use `load_schema` for loading Mobile and HMI API validation schema.
-- Use `load_schema` for loading Mobile and HMI API validation schema.
--
-- For more detail design information refer to @{Validation|Validation SDD}
-- *Dependencies:* `xml`
--
-- Dependencies: `xml`
-- @module api_loader
-- @copyright [Ford Motor Company](https://smartdevicelink.com/partners/ford/) and [SmartDeviceLink Consortium](https://smartdevicelink.com/consortium/)
-- @license <https://github.com/smartdevicelink/sdl_core/blob/master/LICENSE>
-- *Globals:* `param_name`, `param_data`, `name`
-- @module api_loader
-- @copyright [Ford Motor Company](https://smartdevicelink.com/partners/ford/)
-- and [SmartDeviceLink Consortium](https://smartdevicelink.com/consortium/)
-- @license <https://github.com/smartdevicelink/sdl_core/blob/master/LICENSE>

local xml = require('xml')

--- @table api_loader
local module = { }
local apiLoader = { }

--- Include result codes that are elements in functions from Mobile Api.
-- Each function with paremeter resultCode that has type Result
Expand Down Expand Up @@ -64,7 +64,7 @@ local function LoadParamsInFunction(param, interface)
return name, data
end

--- Load Enums values
--- Load Enums values from API
local function LoadEnums(api, dest)
for first, v in pairs (dest.interface) do
for _, s in ipairs(v.body:children("enum")) do
Expand All @@ -85,7 +85,7 @@ end
end
end

--- Load structures
--- Load structures from API
local function LoadStructs(api, dest)
for first, v in pairs (dest.interface) do
for _, s in ipairs(v.body:children("struct")) do
Expand All @@ -104,7 +104,7 @@ end
end


--- Load functions with all fields
--- Load functions with all fields from API
local function LoadFunction( api, dest )
for first, v in pairs (dest.interface) do
for _, s in ipairs(v.body:children("function")) do
Expand Down Expand Up @@ -145,15 +145,14 @@ local function LoadInterfaces( api, dest )
end
end

--- Parse xml file to lua table.
--- Parse api file to lua table.
-- Each function, enum and struct will be
-- kept inside appropriate interface
-- @param path; path to the xml file
-- @param include_parent_name; parent name
-- @return lua table with all xml RPCs
-- @function api_loader.init
function module.init(path, include_parent_name)
module.include_parent_name = include_parent_name
-- @tparam string path Path to the xml file
-- @tparam string include_parent_name Parent name
-- @treturn table lua table with all xml RPCs
function apiLoader.init(path, include_parent_name)
apiLoader.include_parent_name = include_parent_name
local result = {}
result.interface = { }

Expand All @@ -168,4 +167,4 @@ end
return result
end

return module
return apiLoader
5 changes: 5 additions & 0 deletions modules/atf/stdlib/argument_parser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ function module.getopt(argv, opts)

return res
end

function module.declare_opt (shortname, longname, argument, description)
local arg = ''
if (argument == module.RequiredArgument) then
Expand All @@ -104,12 +105,15 @@ function module.declare_opt (shortname, longname, argument, description)
end

end

function module.declare_short_opt(shortname, argument, description)
module.declare_opt (shortname, '' , argument, description)
end

function module.declare_long_opt(longname, argument, description)
module.declare_opt('' ,longname , argument, description)
end

function module.PrintUsage()
local _usage = usage
for _, opt in ipairs(help) do
Expand All @@ -120,6 +124,7 @@ function module.PrintUsage()
print(_usage)
quit()
end

function module.PrintVersion()
print(version)
quit()
Expand Down
Loading

0 comments on commit 61dba03

Please sign in to comment.