Esempio n. 1
0
    def __init__(self, name):
        self.tutorial_dir = common.get_tutorial_dir()
        self.build_config_parent_dir = os.path.realpath(
            os.path.join(self.tutorial_dir, 'build-config'))
        self.project_root_dir = common.get_project_root()
        self.app_dir = os.path.realpath(
            os.path.join(self.tutorial_dir, 'templates'))

        self.tutorial_dir_rel = os.path.relpath(self.tutorial_dir, self.project_root_dir)
        self.build_config_parent_dir_rel = os.path.relpath(self.build_config_parent_dir,
                                                      self.project_root_dir)

        self.name = name

        if self.name == 'camkes':
            self.suffix = '-camkes'
        elif self.name == 'sel4':
            self.suffix = '-sel4'
        else:
            raise Exception("unknown environment name %s" % name)

        self.build_re = re.compile(r'(?P<name>.*)%s' % self.suffix)

        self.local_solution_dir = os.path.realpath(
            os.path.join(self.project_root_dir, 'apps%s-solutions' % self.suffix))

        self.local_exercise_dir = os.path.realpath(
            os.path.join(self.project_root_dir, 'apps%s-exercises' % self.suffix))

        self.local_template_dir = os.path.realpath(
            os.path.join(self.project_root_dir, 'apps%s-templates' % self.suffix))

        self.local_solution_dir_rel = os.path.relpath(
            self.app_dir, self.local_solution_dir)

        self.local_app_symlink = os.path.join(self.project_root_dir, 'apps')

        self.template_ctx = TemplateCtx()
Esempio n. 2
0
# Builds and runs all tutorial solutions, comparing output with expected
# completion text.

import sys, os, argparse, re, pexpect, subprocess, tempfile, logging
import signal
import psutil
import shutil
import os.path
import xml.sax.saxutils
import sh

import common

# this assumes this script is in a directory inside the tutorial directory
TUTORIAL_DIR = common.get_tutorial_dir()
TOP_LEVEL_DIR = common.get_project_root()

# timeout per test in seconds
DEFAULT_TIMEOUT = 1800

# Completion text for each test
COMPLETION = {
    "hello-1": "hello world",
    "hello-2": "(thread_2: hallo wereld)|(main: hello world)",
    "hello-2-nolibs": "(thread_2: hallo wereld)|(main: hello world)",
    "hello-3": "main: got a reply: 0xffff*9e9e",
    "hello-3-nolibs": "main: got a reply: 0xffff*9e9e",
    "hello-4": "process_2: got a reply: 0xffff*9e9e",
    "hello-timer": "timer client wakes up: got the current timer tick:",
    "hello-camkes-0": "Hello CAmkES World",
Esempio n. 3
0
 def __init__(self):
     self.template_dir = common.get_tutorial_dir()
     self.env = jinja2.Environment(
         loader=jinja2.FileSystemLoader(self.template_dir),
         block_start_string='/*-',
         block_end_string='-*/')
Esempio n. 4
0
def handle_publish(args):
    git_uri = args.git
    branch_name = args.branch
    temp_dir = tempfile.mkdtemp(prefix='sel4-tutorials-')
    logger.info("Temporary directory created at: %s" % temp_dir)
    atexit.register(shutil.rmtree, temp_dir)

    git = sh.git.bake('-C', temp_dir, _out=sys.stdout)
    git.init()

    logger.info('git add origin %s', git_uri)
    git.remote.add('origin', git_uri)
    logger.info('git fetch origin')
    git.fetch('origin')

    logger.info('git checkout %s' % branch_name)
    if git.checkout('%s' % branch_name, _ok_code=[0,1]).exit_code == 1:
        logger.critical('Branch %s does not exist' % branch_name)
        return

    logger.debug("Removing existing repository files")
    for f in os.listdir(temp_dir):
        if f != '.git':
            path = os.path.join(temp_dir, f)
            sh.rm('-rf', path)

    # copy dirs/files that can be copied literally
    DIRS_TO_COPY = ['docs', 'build-config']
    FILES_TO_COPY = ['LICENSE_BSD2.txt', 'Prerequisites.md', 'CMakeLists.txt']

    tutorial_dir = common.get_tutorial_dir()

    for d in DIRS_TO_COPY:
        src = os.path.join(tutorial_dir, d)
        dst = os.path.join(temp_dir, d)
        logger.info("Copying directory: %s -> %s" % (src, dst))
        shutil.copytree(src, dst)

    for f in FILES_TO_COPY:
        src = os.path.join(tutorial_dir, f)
        dst = os.path.join(temp_dir, f)
        logger.info("Copying file: %s -> %s" % (src, dst))
        shutil.copyfile(src, dst)

    # copy the readme and rename
    src = os.path.join(tutorial_dir, 'README-tutorials.md')
    dst = os.path.join(temp_dir, 'README.md')
    logger.info("Copying file: %s -> %s" % (src, dst))
    shutil.copyfile(src, dst)

    # copy the licenseignore
    src = os.path.join(tutorial_dir, '.licenseignore')
    dst = os.path.join(temp_dir, '.licenseignore')
    logger.info("Copying file: %s -> %s" % (src, dst))
    shutil.copyfile(src, dst)

    template_ctx = TemplateCtx()
    template_dir = os.path.join(tutorial_dir, 'templates')
    solution_dir = os.path.join(temp_dir, 'solutions')
    exercise_dir = os.path.join(temp_dir, 'exercises')

    logger.info("Instantiating solution templates in: %s" % solution_dir)
    template_ctx.copy_instantiating_templates(template_dir, solution_dir, solution=True)

    logger.info("Instantiating exercise templates in: %s" % exercise_dir)
    template_ctx.copy_instantiating_templates(template_dir, exercise_dir, solution=False)

    logger.info("Starting interactive shell in git repository: %s" % temp_dir)
    logger.info("Press ctrl+d when done.")

    # give the user a shell in the new directory
    cwd = os.getcwd()
    os.chdir(temp_dir)
    sh.Command(os.getenv("SHELL", "/bin/sh"))(_fg=True)
    os.chdir(cwd)