From 7b46de3e278353689738353bbdbfd5987ab44c07 Mon Sep 17 00:00:00 2001 From: Anton Gomez Alvedro Date: Sun, 1 Jun 2014 18:08:30 +0200 Subject: [PATCH] Code review comments and bugfixes - Making run_tests accept a target namespace as an argument. - Fixed asynchronous trigger callback mechanism. MCBF triggers working again. - Fixed numerical problems when calculating standard deviation for rand triggers. --- Aircraft/Generic/Systems/Tests/test.nas | 10 ++++++---- Aircraft/Generic/Systems/failures.nas | 8 +++++--- Nasal/FailureMgr/private.nas | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Aircraft/Generic/Systems/Tests/test.nas b/Aircraft/Generic/Systems/Tests/test.nas index 1d46d6766..0a13ca1e7 100644 --- a/Aircraft/Generic/Systems/Tests/test.nas +++ b/Aircraft/Generic/Systems/Tests/test.nas @@ -63,9 +63,11 @@ var TestSuite = { cleanup: func 0 }; -# run_tests() +# run_tests([namespace]) +# +# Executes all test suites found in the given namespace. If no namespace is +# specified, then the namespace where run_tests is defined is used by default. # -# Executes all test suites found in the namespace where run_tests is defined. # An effective way to work with the framework is to just include the framework # from your test files: # @@ -82,9 +84,9 @@ var TestSuite = { # well if it was io.include'd in my_test_suite.nas. Finally, all test suites # in the "test" namespace are executed. -var run_tests = func () { +var run_tests = func(namespace=nil) { - var ns = closure(run_tests, 1); + var ns = namespace != nil ? namespace : closure(run_tests, 1); var passed = 0; var failed = 0; diff --git a/Aircraft/Generic/Systems/failures.nas b/Aircraft/Generic/Systems/failures.nas index 4bcc415e3..998539e9c 100644 --- a/Aircraft/Generic/Systems/failures.nas +++ b/Aircraft/Generic/Systems/failures.nas @@ -33,6 +33,9 @@ var set_unserviceable = func(path) { var prop = path ~ "/serviceable"; + if (props.globals.getNode(prop) == nil) + props.globals.initNode(prop, 1, "BOOL"); + return { parents: [FailureMgr.FailureActuator], set_failure_level: func(level) setprop(prop, level > 0 ? 0 : 1), @@ -209,9 +212,8 @@ var MtbfTrigger = { reset: func { call(FailureMgr.Trigger.reset, [], me); # TODO: use an elapsed time prop that accounts for speed-up and pause - var std = math.sqrt(me.params["mtbf"] / 10 - 1); me.fire_time = getprop(me._time_prop) - + norm_rand(me.params["mtbf"], std); + + norm_rand(me.params["mtbf"], me.params["mtbf"] / 10); }, to_str: func { @@ -343,7 +345,7 @@ var McbfTrigger = { call(FailureMgr.Trigger.reset, [], me); me.counter.reset(); me.activation_cycles = - norm_rand(me.params["mcbf"], math.sqrt(me.params["mcbf"] / 10)); + norm_rand(me.params["mcbf"], me.params["mcbf"] / 10); me.enabled and me.counter.enable(); }, diff --git a/Nasal/FailureMgr/private.nas b/Nasal/FailureMgr/private.nas index ca0257dd9..d124acf95 100644 --- a/Nasal/FailureMgr/private.nas +++ b/Nasal/FailureMgr/private.nas @@ -190,7 +190,7 @@ var _failmgr = { if (trigger == nil) return; trigger.bind(proproot ~ mode_id); - trigger.on_fire = func me.on_trigger_activated(trigger); + trigger.on_fire = func _failmgr.on_trigger_activated(trigger); trigger.reset(); if (trigger.requires_polling) {