Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decouple MATLAB Functions Test from Controller.def #6752

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/controller/c/webots/supervisor.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,10 @@ void wb_supervisor_simulation_revert() WB_DEPRECATED; // please us
void wb_supervisor_load_world(const char *filename) WB_DEPRECATED; // please use wb_supervisor_world_load() instead
bool wb_supervisor_save_world(const char *filename) WB_DEPRECATED; // please use wb_supervisor_world_save() instead

// deprecated since Webots 8.6.0, plesae use wb_supervisor_field_remove_mf_item() instead
// deprecated since Webots 8.6.0, please use wb_supervisor_field_remove_mf() instead
void wb_supervisor_field_remove_mf_node(WbFieldRef field, int position) WB_DEPRECATED;

// deprecated since Webots 8.0.0, plesae use wb_supervisor_simulation_reset_physics() instead
// deprecated since Webots 8.0.0, pleaae use wb_supervisor_simulation_reset_physics() instead
void wb_supervisor_simulation_physics_reset() WB_DEPRECATED;

// deprecated since Webots 8.4.0 please use wb_supervisor_movie_is_ready and wb_supervisor_movie_failed
Expand Down
88 changes: 61 additions & 27 deletions tests/sources/test_matlab_functions.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -14,54 +14,88 @@
# See the License for the specific language governing permissions and
# limitations under the License.

"""Test that all the required Matlab functions are defined."""
"""Test that all the required MATLAB functions are defined."""
import unittest
import glob
import os
import re
import subprocess
import sys

WEBOTS_HOME = os.path.normpath(os.environ['WEBOTS_HOME'])
sys.path.append(os.path.join(WEBOTS_HOME, 'src', 'controller', 'matlab'))
import mgenerate # noqa: E402


class TestMatlabFunctions(unittest.TestCase):
"""Unit test for checking that all the required Matlab functions are defined."""
"""Unit test for checking that all the required MATLAB functions are defined."""

def setUp(self):
if sys.version_info[0] >= 3:
mgenerate.UPDATE = False
mgenerate.main()
"""Get all the required function."""
"""Get all the required functions."""
skippedLines = [
'wbr',
'microphone',
'remote_control',
'robot',
'wb_device_get_type',
'wb_node_get_name',
'wbu_string',
'lookup_table_size',
'EXPORTS'
# Patterns
'.*_H', # Header Guards
'.*_', # Some comments use the ..._* pattern to refer to a group of functions ;
# grep will filter the *, but no function should end with _
'wb_camera_image_get_.*', # The MATLAB API exposes the image data as a multidimensional array,
# so these functions are not needed
'wb_(microphone|radio)_.*', # Experimental Node Types
'wb_remote_control_.*', 'wbr_.*', # Remote Control Plugin
'wb_robot_.*', # Many robot functions are used internally by the C API (e.x. wb_robot_mutex_*)
'.*_lookup_table_size', # MATLAB lets you get the size of an array, so these functions are not needed
'wbu_string_.*', # String manipulation functions are not needed

# Specific Functions

# Non-Function Macros
'WB_ALLOW_MIXING_C_AND_CPP_API',
'WB_DEPRECATED',
'WB_MATLAB_LOADLIBRARY',
'WB_USING_C(PP)?_API',

# These functions are used internally by the MATLAB API
'wb_camera_recognition_get_object',
'wb_lidar_get_point',
'wb_mouse_get_state_pointer',
'wb_radar_get_target',

'wb_device_get_type', # Deprecated since 8.0.0
'wb_node_get_name', # C API Only

# Not Yet Implemented
'wbu_system_tmpdir',
'wbu_system_webots_instance_path',
]
self.functions = []
filename = os.path.join(WEBOTS_HOME, 'src', 'controller', 'c', 'Controller.def')
self.assertTrue(
os.path.isfile(filename),
msg='Missing "%s" file.' % filename
)
with open(filename) as file:
for line in file:
if not any(skippedLine in line for skippedLine in skippedLines) and not line[3:].isupper():
self.functions.append(line.replace('\n', ''))

symbolSearch = subprocess.run([
# Search for webots definitions
'grep', '-Ehio', r'\bwb_\w+\b',
# In the controller headers
*glob.glob(os.path.join(WEBOTS_HOME, 'include', 'controller', 'c', 'webots', '*.h')),
*glob.glob(os.path.join(WEBOTS_HOME, 'include', 'controller', 'c', 'webots', 'utils', '*.h'))
], capture_output=True, text=True)
if symbolSearch.returncode != 0:
self.fail(f'Failed to generate function list:\n{symbolSearch.stdout}')

for line in symbolSearch.stdout.splitlines():
if not any(re.match(f'^{skippedLine}$', line) for skippedLine in skippedLines) and line not in self.functions:
self.functions.append(line)

@unittest.skipIf(sys.version_info[0] < 3, "not supported by Python 2.7")
def test_matlab_function_exists(self):
"""Test that the function file exists."""
for function in self.functions:
filename = os.path.join(WEBOTS_HOME, 'lib', 'controller', 'matlab', function + '.m')
self.assertTrue(
os.path.isfile(filename),
msg='Missing "%s" file.' % filename
)
expectedFiles = (os.path.join(WEBOTS_HOME, 'lib', 'controller', 'matlab', function + '.m')
for function in self.functions)
missingFiles = [file for file in expectedFiles if not os.path.isfile(file)]

self.assertTrue(
not missingFiles,
msg='Missing files: %s' % ', '.join(missingFiles)
)


if __name__ == '__main__':
Expand Down
Loading