def test_basic_sysroot_creation(platform_config, tmpdir): """Very simple smoke test to validate that syntax is correct.""" # Very simple smoke test to validate that all internal syntax is correct mock_docker_client = Mock() sysroot_dir, ros_workspace_dir = setup_mock_sysroot(tmpdir) creator = SysrootCreator(str(tmpdir), 'ros_ws', platform_config) creator.create_workspace_sysroot_image(mock_docker_client) assert mock_docker_client.build_image.call_count == 1
def test_sysroot_creator_constructor(platform_config, docker_config, tmpdir): """Test the SysrootCreator constructor assuming valid path setup.""" # Create mock directories and files sysroot_dir, ros_workspace_dir = setup_mock_sysroot(tmpdir) sysroot_creator = SysrootCreator(str(tmpdir), 'ros_ws', platform_config, docker_config) assert isinstance(sysroot_creator.get_build_setup_script_path(), Path) assert isinstance(sysroot_creator.get_system_setup_script_path(), Path)
def test_sysroot_creator_constructor_argument_validation(platform_config, tmpdir): """Make sure SysrootCreator constructor validates input types properly.""" sysroot_dir, ros_worspace_dir = setup_mock_sysroot(tmpdir) root = str(tmpdir) ws = 'ros_ws' with pytest.raises(TypeError): creator = SysrootCreator(tmpdir, ws, platform_config) with pytest.raises(TypeError): creator = SysrootCreator(root, Path(ws), platform_config) with pytest.raises(TypeError): creator = SysrootCreator(root, ws, 'not a Platform') creator = SysrootCreator(root, ws, platform_config) assert creator
def test_custom_data_dir(platform_config, tmpdir): sysroot_dir, ros_workspace_dir = setup_mock_sysroot(tmpdir) compiler = SysrootCreator( str(tmpdir), 'ros_ws', platform_config, custom_data_dir=os.path.join(THIS_SCRIPT_DIR, 'data')) assert compiler assert (sysroot_dir / 'user-custom-data' / 'arbitrary.txt').exists()
def test_custom_setup_script(platform_config, tmpdir): sysroot_dir, ros_workspace_dir = setup_mock_sysroot(tmpdir) compiler = SysrootCreator( str(tmpdir), 'ros_ws', platform_config, custom_setup_script_path=os.path.join(THIS_SCRIPT_DIR, 'custom-setup.sh')) assert compiler assert (sysroot_dir / 'user-custom-setup').exists()
def test_sysroot_creator_tree_additions(platform_config, tmpdir): sysroot_dir, ros_workspace_dir = setup_mock_sysroot(tmpdir) compiler = SysrootCreator(str(tmpdir), 'ros_ws', platform_config) assert compiler assert (sysroot_dir / ROS_DOCKERFILE_NAME).exists() assert (sysroot_dir / 'mixins' / 'cross-compile.mixin').exists() assert (sysroot_dir / 'mixins' / 'index.yaml').exists()
def main(): """Start the cross-compilation workflow.""" # Configuration args = parse_args(sys.argv[1:]) platform = Platform(args.arch, args.os, args.rosdistro, args.sysroot_base_image) sysroot_creator = SysrootCreator( cc_root_dir=args.sysroot_path, ros_workspace_dir=args.ros_workspace, platform=platform, docker_no_cache=args.sysroot_nocache, custom_setup_script_path=args.custom_setup_script, custom_data_dir=args.custom_data_dir) sysroot_creator.create_workspace_sysroot_image() ros_workspace_dir = os.path.join(args.sysroot_path, 'sysroot', args.ros_workspace) run_emulated_docker_build(platform.sysroot_image_tag, ros_workspace_dir)
def test_sysroot_creator_tree_validation(platform_config, docker_config, tmpdir): """ Ensure that the SysrootCreator constructor validates the workspace. Start with empty directory and add one piece at a time, expecting failures until all parts are present. """ kwargs = { 'cc_root_dir': str(tmpdir), 'ros_workspace_dir': 'ros_ws', 'platform': platform_config, 'docker_config': docker_config, 'custom_setup_script_path': None, } # There's no 'sysroot' at all yet with pytest.raises(FileNotFoundError): compiler = SysrootCreator(**kwargs) sysroot_dir = tmpdir / SYSROOT_DIR_NAME sysroot_dir.mkdir() # ROS2 ws and qemu dirs are missing with pytest.raises(FileNotFoundError): compiler = SysrootCreator(**kwargs) ros_workspace_dir = sysroot_dir / 'ros_ws' ros_workspace_dir.mkdir() # qemu dirs are missing with pytest.raises(FileNotFoundError): compiler = SysrootCreator(**kwargs) qemu_dir = sysroot_dir / QEMU_DIR_NAME qemu_dir.mkdir() # the qemu binary is still missing with pytest.raises(FileNotFoundError): compiler = SysrootCreator(**kwargs) qemu_binary_mock = qemu_dir / 'qemu' qemu_binary_mock.ensure() # everything is present now compiler = SysrootCreator(**kwargs) assert compiler
def test_parse_docker_build_output( platform_config, tmpdir): """Test the SysrootCreator constructor assuming valid path setup.""" # Create mock directories and files sysroot_dir, ros_workspace_dir = setup_mock_sysroot(tmpdir) sysroot_creator = SysrootCreator( str(tmpdir), 'ros_ws', platform_config, False, None) log_generator_without_errors = [ {'stream': ' ---\\u003e a9eb17255234\\n'}, {'stream': 'Step 1 : VOLUME /data\\n'}, {'stream': ' ---\\u003e Running in abdc1e6896c6\\n'}, {'stream': ' ---\\u003e 713bca62012e\\n'}, {'stream': 'Removing intermediate container abdc1e6896c6\\n'}, {'stream': 'Step 2 : CMD [\\"/bin/sh\\"]\\n'}, {'stream': ' ---\\u003e Running in dba30f2a1a7e\\n'}, {'stream': ' ---\\u003e 032b8b2855fc\\n'}, {'stream': 'Removing intermediate container dba30f2a1a7e\\n'}, {'stream': 'Successfully built 032b8b2855fc\\n'}, ] # Just expect it not to raise sysroot_creator._parse_build_output(log_generator_without_errors) log_generator_with_errors = [ {'stream': ' ---\\u003e a9eb17255234\\n'}, {'stream': 'Step 1 : VOLUME /data\\n'}, {'stream': ' ---\\u003e Running in abdc1e6896c6\\n'}, {'stream': ' ---\\u003e 713bca62012e\\n'}, {'stream': 'Removing intermediate container abdc1e6896c6\\n'}, {'stream': 'Step 2 : CMD [\\"/bin/sh\\"]\\n'}, {'error': ' ---\\COMMAND NOT FOUND\\n'}, ] with pytest.raises(docker.errors.BuildError): sysroot_creator._parse_build_output(log_generator_with_errors)