Пример #1
0
    def setUpClass(cls):
        """
        Sets up a little test Xpkg environment and builds the test toolset
        packages.
        """

        # Get all the basics setup
        TestBase.setUpClass()

        # Create a toolset repo directory
        cls.toolset_repo_dir = os.path.join(cls.storage_dir, 'toolset-repo')

        util.ensure_dir(cls.toolset_repo_dir)

        # Build our packages into it
        root_tree = os.path.join(root_dir, 'pkgs')

        for pkg_name in ['busybox', 'tcc', 'uclibc']:
            xpd_path = os.path.join(root_tree, pkg_name + '.xpd')

            args = ['build', xpd_path, '--dest', cls.toolset_repo_dir]

            cmd = [sys.executable, '-m', 'xpkg.main'] + args

            # Run build inside toolset dir so that the build logs don't pollute
            # Anything
            cwd = os.getcwd()
            with util.cd(cls.toolset_repo_dir):
                with util.save_env():
                    os.environ['PYTHONPATH'] = cwd

                    output = util.shellcmd(cmd, shell=False, stream=False)
Пример #2
0
    def setUpClass(cls):
        """
        Sets up a little test Xpkg environment and builds the test toolset
        packages.
        """

        # Get all the basics setup
        TestBase.setUpClass()

        # Create a toolset repo directory
        cls.toolset_repo_dir = os.path.join(cls.storage_dir, 'toolset-repo')

        util.ensure_dir(cls.toolset_repo_dir)

        # Build our packages into it
        root_tree = os.path.join(root_dir, 'pkgs')

        for pkg_name in ['busybox', 'tcc', 'uclibc']:
            xpd_path = os.path.join(root_tree, pkg_name + '.xpd')

            args = ['build', xpd_path, '--dest', cls.toolset_repo_dir]

            cmd = [sys.executable, '-m', 'xpkg.main'] + args

            # Run build inside toolset dir so that the build logs don't pollute
            # Anything
            cwd = os.getcwd()
            with util.cd(cls.toolset_repo_dir):
                with util.save_env():
                    os.environ['PYTHONPATH'] = cwd

                    output = util.shellcmd(cmd, shell=False, stream=False)
Пример #3
0
    def test_install(self):
        """
        Make sure the desired program was installed and works.
        """

        # Run the install
        self._xpkg_cmd(['install', self.hello_xpd])

        # Run our program to make sure it works
        output = util.shellcmd(self.hello_bin, echo=False)

        self.assertEqual('Hello, world!\n', output)
Пример #4
0
    def test_install(self):
        """
        Make sure the desired program was installed and works.
        """

        # Run the install
        self._xpkg_cmd(['install', self.hello_xpd])

        # Run our program to make sure it works
        output = util.shellcmd(self.hello_bin, echo=False)

        self.assertEqual('Hello, world!\n', output)
Пример #5
0
    def _xpkg_cmd(self, args, env_dir=None, use_var=True, should_fail=False):
        """
        Run Xpkg command and return the output.

          should_fail - if true, don't error out if the command returns != 0

        This sets the XPKG_ROOT environment var commands are executed with
        respected to self.env_dir directory.
        """

        # Setup arguments
        if env_dir is None:
            env_dir = self.env_dir

        if use_var:
            env_args = []
            os.environ[core.xpkg_root_var] = env_dir
        else:
            # Clear variable
            if core.xpkg_root_var in os.environ:
                del os.environ[core.xpkg_root_var]

            # Set out args
            env_args = ['--root',env_dir]

        # Have the tool return the full stack trace in debug mode
        if not should_fail:
            args.insert(0, '--debug')

        # Run the command directly calling the python xpkg implementation
        cmd = [sys.executable, '-m', 'xpkg.main'] + args + env_args

        try:
            output = util.shellcmd(cmd, shell=False, stream=False)

            # If we got here but we should of failed error out
            if should_fail:
                args = ' '.join(cmd)
                msg = 'Command "%s" did not return a non-zero exit code' % args
                self.fail(msg)

        except subprocess.CalledProcessError as c:
            # Capture this error, and only re throw if we were not excepting
            # an exception
            output = c.output

            if not should_fail:
                raise c

        return output
Пример #6
0
    def _xpkg_cmd(self, args, env_dir=None, use_var=True, should_fail=False):
        """
        Run Xpkg command and return the output.

          should_fail - if true, don't error out if the command returns != 0

        This sets the XPKG_ROOT environment var commands are executed with
        respected to self.env_dir directory.
        """

        # Setup arguments
        if env_dir is None:
            env_dir = self.env_dir

        if use_var:
            env_args = []
            os.environ[core.xpkg_root_var] = env_dir
        else:
            # Clear variable
            if core.xpkg_root_var in os.environ:
                del os.environ[core.xpkg_root_var]

            # Set out args
            env_args = ['--root', env_dir]

        # Have the tool return the full stack trace in debug mode
        if not should_fail:
            args.insert(0, '--debug')

        # Run the command directly calling the python xpkg implementation
        cmd = [sys.executable, '-m', 'xpkg.main'] + args + env_args

        try:
            output = util.shellcmd(cmd, shell=False, stream=False)

            # If we got here but we should of failed error out
            if should_fail:
                args = ' '.join(cmd)
                msg = 'Command "%s" did not return a non-zero exit code' % args
                self.fail(msg)

        except subprocess.CalledProcessError as c:
            # Capture this error, and only re throw if we were not excepting
            # an exception
            output = c.output

            if not should_fail:
                raise c

        return output
Пример #7
0
    def test_basic(self):
        """
        Makes sure our basic toolset package works.
        """

        # Setup the environment to use our testing toolset
        self._xpkg_cmd(['init', self.env_dir, 'test-env', '--toolset', 'Test'])

        # Make sure we can locate of packages
        os.environ[core.xpkg_tree_var] = self.tree_dir
        os.environ[core.xpkg_repo_var] = self.toolset_repo_dir

        # Install the program
        self._xpkg_cmd(['install', '--verbose', 'toolset-basic'])

        # Can we run our program
        basic_bin = os.path.join(self.env_dir, 'bin', 'basic')

        output = util.shellcmd([basic_bin], shell=False, stream=False)

        self.assertEqual('Hello, world!\n', output)
Пример #8
0
    def test_local_elf_interp(self):
        """
        Makes sure we have a custom elf interp that links to the system one.
        """

        # Run the install
        self._xpkg_cmd(['install', 'basic', '--tree', self.tree_dir])

        # Make sure the program exists
        basic_bin = os.path.join(self.env_dir, 'bin', 'basic')
        self.assertPathExists(basic_bin)

        # Run our program to make sure it works
        output = util.shellcmd([basic_bin], shell=False, stream=False)

        self.assertEqual('Hello, world!\n', output)

        # Now make sure it has the proper elf interp
        expected = os.path.join(self.env_dir, 'lib', 'ld-linux-xpkg.so')
        interp_path = linux.readelf_interp(basic_bin)
        self.assertEquals(expected, interp_path)
Пример #9
0
    def test_basic(self):
        """
        Makes sure our basic toolset package works.
        """

        # Setup the environment to use our testing toolset
        self._xpkg_cmd(['init', self.env_dir, 'test-env', '--toolset', 'Test'])

        # Make sure we can locate of packages
        os.environ[core.xpkg_tree_var] = self.tree_dir
        os.environ[core.xpkg_repo_var] = self.toolset_repo_dir

        # Install the program
        self._xpkg_cmd(['install', '--verbose', 'toolset-basic'])

        # Can we run our program
        basic_bin = os.path.join(self.env_dir, 'bin', 'basic')

        output = util.shellcmd([basic_bin], shell=False, stream=False)

        self.assertEqual('Hello, world!\n', output)
Пример #10
0
    def test_local_elf_interp(self):
        """
        Makes sure we have a custom elf interp that links to the system one.
        """

        # Run the install
        self._xpkg_cmd(['install', 'basic', '--tree', self.tree_dir])

        # Make sure the program exists
        basic_bin = os.path.join(self.env_dir, 'bin', 'basic')
        self.assertPathExists(basic_bin)

        # Run our program to make sure it works
        output = util.shellcmd([basic_bin], shell=False, stream=False)

        self.assertEqual('Hello, world!\n', output)

        # Now make sure it has the proper elf interp
        expected = os.path.join(self.env_dir, 'lib', 'ld-linux-xpkg.so')
        interp_path = linux.readelf_interp(basic_bin)
        self.assertEquals(expected, interp_path)