Skip to content

Commit

Permalink
Merge branch 'benmaidel-feature/cmd_option_checkbehaviors' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
pschillinger committed Mar 1, 2020
2 parents 6519de5 + fd8fafd commit d45efc7
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 40 deletions.
45 changes: 35 additions & 10 deletions bin/test_report
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,44 @@
import yaml
import unittest


def generate_test(test_type, test_data):
def test_method(self):
test_function = getattr(self, test_type)
if isinstance(test_data, list):
test_function(*test_data)
else:
test_function(test_data)
return test_method


class TestReport(unittest.TestCase):

def test_report(self):
try:
with open("/tmp/flexbe_app_report.log", 'r') as f:
report = yaml.load(f)
except IOError:
return # skip test since there is no report to evaluate
for test_type, tests in report.items():
for test_name, test_data in tests.items():
if test_type == "assertTrue":
self.assertTrue(test_data, test_name)
def test_report(self):
try:
with open("/tmp/flexbe_app_report.log", 'r') as f:
report = yaml.load(f)
except IOError:
return # skip test since there is no report to evaluate
for test_type, tests in report.items():
for test_name, test_data in tests.items():
if test_type == "assertTrue":
self.assertTrue(test_data, test_name)


if __name__ == '__main__':
try:
with open("/tmp/flexbe_app_behavior_report.log", 'r') as f:
report = yaml.safe_load(f)
except IOError:
pass # add no tests because there is no report to evaluate
else:
for test_type, tests in report.items():
for test_name, test_data in tests.items():
function_name = "test_%s_%s" % (test_name, test_type)
test_function = generate_test(test_type, test_data)
test_function.__name__ = function_name
setattr(TestReport, function_name, test_function)

import rosunit
rosunit.unitrun("flexbe_app", "test_report", TestReport)
31 changes: 31 additions & 0 deletions src/_test/checkbehaviorsreport.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
CheckBehaviorsReport = new (function() {

var report = {'assertTrue': {}};

this.checkAllBehaviors = function(callback) {
var behaviors = WS.Behaviorlib.getBehaviorList();

var next = function(){
if (behaviors.length == 0){
IO.Filesystem.createFile('/tmp', "flexbe_app_behavior_report.log", JSON.stringify(report), callback);
} else {
var behavior = behaviors.shift();
var m = WS.Behaviorlib.getByName(behavior).getBehaviorManifest();

IO.BehaviorLoader.loadBehavior(m, function(error_string) {
console.log(error_string);
if (error_string != undefined) {
report.assertTrue["behavior_"+behavior] = [false, error_string];
console.log(behavior+" is false");
}
else{
report.assertTrue["behavior_"+behavior] = true;
console.log(behavior+" is true");
}
next();
});
}
}
next();
}
})();
25 changes: 18 additions & 7 deletions src/io/io_behaviorloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,35 @@ IO.BehaviorLoader = new (function() {
var path = require('path');


var parseCode = function(file_content, manifest_data) {
var parseCode = function(file_content, manifest_data, callback) {
callback = callback || console.error;
var parsingResult;
try {
parsingResult = IO.CodeParser.parseCode(file_content);
T.logInfo("Code parsing completed.");
} catch (err) {
T.logError("Code parsing failed: " + err);
var error_string = "Code parsing failed: " + err;
T.logError(error_string);
callback(error_string);
return;
}
try {
applyParsingResult(parsingResult, manifest_data);
T.logInfo("Behavior " + parsingResult.behavior_name + " loaded.");
} catch (err) {
var error_string = "Code parsing failed: " + err;
T.logError(error_string);
callback(error_string);
return;
}
applyParsingResult(parsingResult, manifest_data);
T.logInfo("Behavior " + parsingResult.behavior_name + " loaded.");

var error_string = Checking.checkBehavior();
if (error_string != undefined) {
T.logError("The loaded behavior contains errors! Please fix and save:");
T.logError(error_string);
RC.Controller.signalChanged();
}
callback(error_string);
}

var applyParsingResult = function(result, manifest) {
Expand All @@ -32,7 +43,7 @@ IO.BehaviorLoader = new (function() {
Behavior.setStatemachine(sm);
UI.Statemachine.resetStatemachine();
T.logInfo("Behavior state machine built.");

ActivityTracer.resetActivities();

ROS.getPackagePath(manifest.rosnode_name, (package_path) => {
Expand All @@ -55,7 +66,7 @@ IO.BehaviorLoader = new (function() {
UI.Panels.setActivePanel(UI.Panels.NO_PANEL);
}

this.loadBehavior = function(manifest) {
this.loadBehavior = function(manifest, callback) {
T.clearLog();
UI.Panels.Terminal.show();

Expand All @@ -64,7 +75,7 @@ IO.BehaviorLoader = new (function() {
var file_path = path.join(manifest.codefile_path, manifest.codefile_name);
IO.Filesystem.readFile(file_path, (content) => {
T.logInfo("Parsing sourcecode...");
parseCode(content, manifest);
parseCode(content, manifest, callback);
});
}

Expand Down
43 changes: 22 additions & 21 deletions src/window.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<script src="ext/d3.min.js"></script>
<script src="ext/json_parse_raw.js"></script>
<script src="ext/yaml.min.js"></script>

<script src="window.js"></script>

<script src="events.js"></script>
Expand Down Expand Up @@ -78,6 +78,7 @@
<script src="_test/scripts.js"></script>
<script src="_test/testreport.js"></script>
<script src="_test/statelib.test.js"></script>
<script src="_test/checkbehaviorsreport.js"></script>

<link rel="stylesheet" href="style/main.css" type="text/css" />
<link rel="stylesheet" href="style/dashboard.css" type="text/css" />
Expand Down Expand Up @@ -113,7 +114,7 @@
<div class="category_button" id="button_to_se"><img src="img/se.png" width="32" height="32" /> Configuration</div>
</td><td id="title_button_panel">

</td></tr></table>
</td></tr></table>
</div>

<div id="flexbe_about" title="About FlexBE">
Expand Down Expand Up @@ -166,7 +167,7 @@ <h2>About FlexBE</h2>

<div id="properties_autocomplete" class="sidepanel_autocomplete" style="display: none;" idx="0"></div>

<div id="dashboard">
<div id="dashboard">

<div class="box">
<h1>Overview</h1>
Expand Down Expand Up @@ -205,13 +206,13 @@ <h1>Private Configuration</h1>
<table class="box_table"><tr><td>
<input id="input_db_variable_key_add" type="text" class="input_field" />
</td><td>
&nbsp;&nbsp;=&nbsp;
&nbsp;&nbsp;=&nbsp;
</td><td width="60%">
<input id="input_db_variable_value_add" type="text" class="input_field" />
</td><td>
<input id="button_db_variable_add" type="button" value="Add" />
</td></tr></table>

</div>

<div class="box">
Expand All @@ -221,7 +222,7 @@ <h1>State Machine Userdata</h1>
<table class="box_table"><tr><td>
<input id="input_db_userdata_key_add" type="text" class="input_field" />
</td><td>
&nbsp;&nbsp;=&nbsp;
&nbsp;&nbsp;=&nbsp;
</td><td>
<input id="input_db_userdata_value_add" type="text" class="input_field" />
</td><td>
Expand Down Expand Up @@ -637,25 +638,25 @@ <h1>Behavior Synthesis</h1>
<div id="panel_prop_parameters" class="sidepanel_category">
<b>Parameters</b>
<table id="panel_prop_parameters_content" class="sidepanel_table">

</table>
</div>
<div id="panel_prop_autonomy" class="sidepanel_category">
<b>Required Autonomy Levels</b>
<table id="panel_prop_autonomy_content" class="sidepanel_table">

</table>
</div>
<div id="panel_prop_input_keys" class="sidepanel_category">
<b>Input Key Mapping</b>
<table id="panel_prop_input_keys_content" class="sidepanel_table">

</table>
</div>
<div id="panel_prop_output_keys" class="sidepanel_category">
<b>Output Key Mapping</b>
<table id="panel_prop_output_keys_content" class="sidepanel_table">

</table>
</div>

Expand Down Expand Up @@ -683,26 +684,26 @@ <h1>Behavior Synthesis</h1>
<div id="panel_prop_be_parameters" class="sidepanel_category">
<b>Parameters</b>
<table id="panel_prop_be_parameters_content" class="sidepanel_table">

</table>
</div>

<div id="panel_prop_be_autonomy" class="sidepanel_category">
<b>Required Autonomy Levels</b>
<table id="panel_prop_be_autonomy_content" class="sidepanel_table">

</table>
</div>
<div id="panel_prop_be_input_keys" class="sidepanel_category">
<b>Input Key Mapping</b>
<table id="panel_prop_be_input_keys_content" class="sidepanel_table">

</table>
</div>
<div id="panel_prop_be_output_keys" class="sidepanel_category">
<b>Output Key Mapping</b>
<table id="panel_prop_be_output_keys_content" class="sidepanel_table">

</table>
</div>

Expand All @@ -716,7 +717,7 @@ <h1>Behavior Synthesis</h1>
<input id="input_prop_sm_name" class="inline_title_text_edit" type="text" />
</div>
<div style="font-style: italic; padding: 0px 5px; margin-top: 5px; color: gray;">
Type:
Type:
<select id="select_container_type">
<option value="statemachine">Statemachine</option>
<option value="concurrency">Concurrency</option>
Expand Down Expand Up @@ -754,7 +755,7 @@ <h1>Behavior Synthesis</h1>
<div id="panel_prop_sm_autonomy" class="sidepanel_category">
<b>Outcomes</b>
<table id="panel_prop_sm_outcomes_content" class="sidepanel_table">

</table>
<table class="sidepanel_table"><tr><td>
<input id="input_prop_outcome_add" type="text" class="input_field" />
Expand All @@ -765,7 +766,7 @@ <h1>Behavior Synthesis</h1>
<div id="panel_prop_sm_input_keys" class="sidepanel_category">
<b>Input Keys</b>
<table id="panel_prop_sm_input_keys_content" class="sidepanel_table">

</table>
<table class="sidepanel_table"><tr><td>
<input id="input_prop_input_key_add" type="text" class="input_field" />
Expand All @@ -776,7 +777,7 @@ <h1>Behavior Synthesis</h1>
<div id="panel_prop_sm_output_keys" class="sidepanel_category">
<b>Output Keys</b>
<table id="panel_prop_sm_output_keys_content" class="sidepanel_table">

</table>
<table class="sidepanel_table"><tr><td>
<input id="input_prop_output_key_add" type="text" class="input_field" />
Expand Down Expand Up @@ -829,7 +830,7 @@ <h1>Behavior Synthesis</h1>
<div class="sidepanel_title_text">
Select Behavior
</div>

<div class="sidepanel_category">
<table class="sidepanel_table">
<tr>
Expand All @@ -851,15 +852,15 @@ <h1>Behavior Synthesis</h1>
</div>

<div id="terminal">

</div>

<div class="emptypage">

</div>

<div id="add_state_panel" style="display: none; position: absolute; top: 100px; left: 100px; background-color: white; border: 1px solid black;">

</div>

<div id="tool_overlay">
Expand Down
10 changes: 8 additions & 2 deletions src/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ window.onload = function() {
var gui = require('nw.gui');

Behavior.resetBehavior();

// Initialize gui panel
UI.Statemachine.initialize();
UI.Menu.toDashboardClicked();
Expand All @@ -11,7 +11,7 @@ window.onload = function() {
UI.Dashboard.addBehaviorOutcome('failed');
ActivityTracer.resetActivities();
UI.RuntimeControl.displayLockBehavior();

RC.Controller.initialize();

// Initialize runtime control
Expand All @@ -31,4 +31,10 @@ window.onload = function() {
TestReport.runAllTests(status => gui.App.quit());
}, 5 * 1000);
}

else if (gui.App.argv.contains('--check-behaviors')) {
setTimeout(() => {
CheckBehaviorsReport.checkAllBehaviors(gui.App.quit);
}, 5 * 1000);
}
}

0 comments on commit d45efc7

Please sign in to comment.