Source code for test_CMsgTimeWritten

#
#  ISC License
#
#  Copyright (c) 2023, Autonomous Vehicle Systems Lab, University of Colorado at Boulder
#
#  Permission to use, copy, modify, and/or distribute this software for any
#  purpose with or without fee is hereby granted, provided that the above
#  copyright notice and this permission notice appear in all copies.
#
#  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
#  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
#  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
#  ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
#  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
#  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
#  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#

from Basilisk.architecture import bskLogging
from Basilisk.moduleTemplates import cModuleTemplate
from Basilisk.utilities import SimulationBaseClass
from Basilisk.utilities import macros
from Basilisk.utilities import unitTestSupport as uts


[docs] def test_CMsgTimeWritten(): """ testing recording timeWritten in C-wrapped message """ bskLogging.setDefaultLogLevel(bskLogging.BSK_WARNING) testFailCount = 0 # zero unit test result counter testMessages = [] # create empty array to store test log messages # Create a sim module as an empty container scSim = SimulationBaseClass.SimBaseClass() # create the simulation process dynProcess = scSim.CreateNewProcess("dynamicsProcess") # create the dynamics task and specify the integration update time dynProcess.addTask(scSim.CreateNewTask("dynamicsTask", macros.sec2nano(1.))) # create modules mod1 = cModuleTemplate.cModuleTemplate() mod1.ModelTag = "cModule1" scSim.AddModelToTask("dynamicsTask", mod1) mod1.dataInMsg.subscribeTo(mod1.dataOutMsg) # setup message recording msgRec = mod1.dataOutMsg.recorder() scSim.AddModelToTask("dynamicsTask", msgRec) # initialize Simulation: scSim.InitializeSimulation() # configure a simulation stop time time and execute the simulation run scSim.ConfigureStopTime(macros.sec2nano(1.0)) scSim.ExecuteSimulation() testFailCount, testMessages = uts.compareVector(msgRec.timesWritten() , msgRec.times() , 0.01 , "recorded msg timesWritten was not correct." , testFailCount , testMessages) # each test method requires a single assert method to be called # this check below just makes sure no sub-test failures were found assert testFailCount < 1, testMessages
if __name__ == "__main__": CMsgTimeWritten()