Example #1
0
def test_create_unpackaged_bundle():
    """This tests that the packaged executable runs as expected. At the very least, this
    tests that the symbolic links and launcher are functioning correctly. Unfortunately,
    it doesn't really test the linker overrides unless the required libraries are not
    present on the current system. FWIW, the CircleCI docker image being used is
    incompatible, so the continuous integration tests are more meaningful."""
    root_directory = create_unpackaged_bundle(rename=[], executables=[executable], ldd=ldd)
    try:
        binary_path = os.path.join(root_directory, 'bin', os.path.basename(executable))

        process = Popen([binary_path], stdout=PIPE, stderr=PIPE)
        stdout, stderr = process.communicate()
        assert 'FIZZBUZZ' in stdout.decode('utf-8')
        assert len(stderr.decode('utf-8')) == 0
    finally:
        assert root_directory.startswith('/tmp/')
        shutil.rmtree(root_directory)
Example #2
0
def test_create_unpackaged_bundle_has_correct_args():
    root_directory = create_unpackaged_bundle(
        rename=[], executables=[echo_args_glibc_32], chroot=chroot)
    try:
        binary_path = os.path.join(root_directory, 'bin', os.path.basename(echo_args_glibc_32))

        process = Popen([binary_path, 'arg1', 'arg2'], stdout=PIPE, stderr=PIPE)
        stdout, stderr = process.communicate()
        assert len(stderr.decode('utf-8')) == 0
        args = stdout.decode('utf-8').split('\n')
        assert os.path.basename(args[0]) == '%s-x' % os.path.basename(echo_args_glibc_32), \
            'The value of argv[0] should correspond to the local symlink.'
        assert args[1] == 'arg1' and args[2] == 'arg2', \
            'The other arguments should be passed through to the child process.'
    finally:
        assert root_directory.startswith('/tmp/')
        shutil.rmtree(root_directory)
Example #3
0
def test_create_unpackaged_bundle_has_correct_proc_self_exe():
    root_directory = create_unpackaged_bundle(
        rename=[], executables=[echo_proc_self_exe_glibc_32], chroot=chroot)
    try:
        binary_path = os.path.join(root_directory, 'bin',
                                   os.path.basename(echo_proc_self_exe_glibc_32))

        process = Popen([binary_path], stdout=PIPE, stderr=PIPE)
        stdout, stderr = process.communicate()
        assert len(stderr.decode('utf-8')) == 0
        proc_self_exe = stdout.decode('utf-8').strip()
        assert os.path.basename(proc_self_exe).startswith('linker-'), \
            'The linker should be the executing process.'
        relative_path = os.path.relpath(proc_self_exe, root_directory)
        assert relative_path.startswith('bundles/'), \
            'The process should be in the bundles directory.'
    finally:
        assert root_directory.startswith('/tmp/')
        shutil.rmtree(root_directory)
Example #4
0
def test_create_unpackaged_bundle_detects_dependencies(detect):
    binary_name = 'ls'
    root_directory = create_unpackaged_bundle(
        rename=[], executables=[binary_name], detect=detect)
    try:
        # Determine the bundle root.
        binary_symlink = os.path.join(root_directory, 'bin', binary_name)
        binary_path = os.path.realpath(binary_symlink)
        dirname, basename = os.path.split(binary_path)
        while len(basename) != 64:
            dirname, basename = os.path.split(dirname)
        bundle_root = os.path.join(dirname, basename)

        man_directory = os.path.join(bundle_root, 'usr', 'share', 'man')
        assert os.path.exists(man_directory) == detect, \
            'The man directory should only exist when `detect=True`.'
    finally:
        assert root_directory.startswith('/tmp/')
        shutil.rmtree(root_directory)
Example #5
0
def test_find_executable():
    original_environment = os.environ.get('PATH')
    original_parent_directory = launchers.parent_directory

    root_directory = create_unpackaged_bundle(rename=[],
                                              executables=[echo_args_glibc_32],
                                              chroot=chroot)
    try:
        binary_name = os.path.basename(echo_args_glibc_32)
        binary_symlink = os.path.join(root_directory, 'bin', binary_name)
        binary_path = os.path.realpath(binary_symlink)
        # This is a pretend directory, but it doesn't check.
        launchers.parent_directory = os.path.join(os.path.dirname(binary_path),
                                                  'somewhere', 'else')
        os.environ['PATH'] = os.path.dirname(echo_args_glibc_32)
        assert find_executable(binary_name, skip_original_for_testing=True) == binary_path, \
            'It should have found the binary path "%s".' % binary_path
    finally:
        launchers.parent_directory = original_parent_directory
        os.environ['PATH'] = original_environment
        assert root_directory.startswith('/tmp/')
        shutil.rmtree(root_directory)