Esempio n. 1
0
                # full
                log_out_deq.out[0] >> main.AddLogseg()

        nic_rx('nic_rx',
               device=target.CAVIUM,
               cores=[nic_tx_threads + i for i in range(nic_rx_threads)])
        process_eq('process_eq', process='app')
        init_segment('init_segment', process='app')
        create_segment('create_segment', process='app')
        nic_tx('nic_tx', device=target.CAVIUM, cores=range(nic_tx_threads))


master_process('app')

######################## Run test #######################
c = Compiler(main)
c.include = r'''
#include "nicif.h"
#include "iokvs.h"
#include "protocol_binary.h"
'''
c.init = r'''
  settings_init(argv);  // TODO: settings_init must be called before other inits.
  //ialloc_init();
  '''
c.generate_code_as_header()
c.depend = {
    "test_app": ['jenkins_hash', 'hashtable', 'ialloc', 'settings', 'app']
}
c.compile_and_run(["test_app"])
Esempio n. 2
0
                check_packet.slowpath >> arp >> to_net
                arp.drop >> from_net_free
                check_packet.drop >> from_net_free

                # send
                prepare_header >> display >> hton2 >> to_net

                # clean log
                clean_log = main.CleanLog()

                run_order(save_id, from_net)
                run_order([to_net, from_net_free, drop], clean_log)

        process_one_pkt('process_one_pkt',
                        process='dpdk',
                        cores=range(n_cores))


master_process('dpdk')

######################## Run test #######################
c = Compiler(main)
c.include = r'''
#include "nicif.h"
#include "iokvs.h"
#include "protocol_binary.h"
'''
c.generate_code_as_header()
c.depend = ['jenkins_hash', 'hashtable', 'ialloc', 'settings', 'dpdk']
c.compile_and_run('test_no_steer')
Esempio n. 3
0
                # send
                local_or_remote.out_send >> PreparePkt() >> get_buff
                # local
                local_or_remote.out_local >> GetCore(
                ) >> rx_enq >> get_buff  #CountTuple() >> get_buff

                get_buff >> tx_release

        nic_tx('nic_tx', process='dpdk', cores=range(n_nic_tx))
        # nic_tx('nic_tx', device=target.CAVIUM, cores=[4,5,6,7])


inqueue_get('inqueue_get', process='dpdk')
inqueue_advance('inqueue_advance', process='dpdk')
outqueue_put('outqueue_put', process='dpdk')
get_dccp_stat('get_dccp_stat', process='dpdk')

c = Compiler(NicRxFlow, NicTxFlow)
c.include = r'''
#include <rte_memcpy.h>
#include "worker.h"
#include "storm.h"
#include "dccp.h"
'''
c.depend = {
    "test_storm":
    ['list', 'hash', 'hash_table', 'spout', 'count', 'rank', 'worker', 'dpdk']
}
c.generate_code_as_header("dpdk")
c.compile_and_run([("test_storm", workerid[test])])
class App:
    def __init__(self, parts: List[Part], student_dir, compiler_dir):
        assert_uids(parts)
        self.part_to_pos = {p: ii for ii, p in enumerate(parts)}
        self.pos_to_part = parts
        self.part_count = len(parts)
        self.parts = {p.uid: p for p in parts}
        self.students = {}
        # make uids comparable
        uids = reduce(operator.add, ([(p.uid, s.uid) for s in p.steps.values()]
                                     for p in parts))
        self.start = uids[0]
        self.uid_progress = {uid: ii for ii, uid in enumerate(uids)}
        print(self.uid_progress)
        self.app_html: Optional[Template] = None
        # command list
        self.cmds = {'next': self.next, 'answer': self.answer, 'run': self.run}
        # student directory
        assert os.path.isdir(student_dir)
        self.student_dir = student_dir
        # compiler
        self.comp = Compiler(working_dir=compiler_dir)
        # converter
        self.conv = Ansi2HTMLConverter()

    # load

    def load_assets(self, app_html):
        assert self.app_html is None
        with open(app_html) as ff:
            self.app_html = Template(ff.read())

    def load_students(self, student_dir):
        assert os.path.isdir(student_dir)
        assert len(self.students) == 0, "cannot load students twice!"
        _, _, files = next(os.walk(student_dir))
        for filename in files:
            if filename.endswith('.json'):
                stud = Student.load(os.path.join(student_dir, filename),
                                    self.start)
                self.students[stud.uid] = stud
                for (part, step), answer in stud.answers.items():
                    self.parts[part].steps[step].answers[stud.uid] = answer

    # run

    def parse_student_path(self, student_id, path):
        if len(path) == 0:
            path = self.start
        if student_id not in self.students: return Error("unknown student")
        if len(path) != 2: return Error("path needs to be (part, step)")
        try:
            part = str(path[0])
            step = str(path[1])
        except ValueError:
            return Error(f"invalid path {path}")
        if part not in self.parts: return Error(f"unknown part: {part}")
        if step not in self.parts[part].steps:
            return Error(f"unknown step {step} for part {part}")
        path_id = PathId(part=part, step=step, app=self)
        student = self.students[student_id]
        if student.progress < path_id.progress:
            return Error("student is not at this step yet")
        part = self.parts[path_id.part]
        step = part.steps[path_id.step]
        return Success((student, part, step))

    def ret2html(self, ret):
        if len(ret) == 0: return ret

        #print(f"ret2html({ret})")
        def escape(out):
            return self.conv.convert(out, full=False)

        return {
            'ret': ret['ret'],
            'stdout': escape(ret['stdout']),
            'stderr': escape(ret['stderr']),
        }

    def run2html(self, run):
        if run is None or len(run) < 1: return run
        rr = dict(run)
        rr['compile'] = self.ret2html(run['compile'])
        rr['run'] = self.ret2html(run['run'])
        return rr

    def view(self, student_id, path_list):
        ret = self.parse_student_path(student_id, path_list)
        if is_error(ret): return ret
        else: student, part, step = ret.dat
        rr = student.runs.get((part.uid, step.uid), None)
        dd = {
            'student_id': student_id,
            'part': part.to_dict(),
            'step': step.to_dict(),
            'run': self.run2html(rr),
            'flags': selected_flags(rr),
            'version': self.comp.versions,
        }
        return Success(self.app_html.render(dd))

    def exec(self, cmd, student_id, path_list, content):
        ret = self.parse_student_path(student_id, path_list)
        if is_error(ret): return ret
        if cmd not in self.cmds: return Error(f"unknown command: {cmd}")
        return self.cmds[cmd](*ret.dat, content)

    def run(self, student, part, step, content):
        can_run = isinstance(step, RunStep) or isinstance(step, ModifyStep)
        if not can_run: return Error("cannot run in this step")
        if isinstance(step, RunStep): main_src = part.program
        else: main_src = content['code'][0]
        compiler = content['compiler'][0]
        flags = content.get('flag', [])
        rr = self.comp.compile_and_run(compiler=compiler,
                                       flags=flags,
                                       source=main_src)
        if rr is None:
            return Error(f'Invalid compile and run command: {content}')
        rr.update({'flags': flags, 'source': main_src, 'compiler': compiler})
        step_id = (part.uid, step.uid)
        student.runs[step_id] = rr
        student.save(self.student_dir)
        return Redirect('/'.join(['', student.uid, part.uid, step.uid]))

    def next_part(self, part):
        next_pos = self.part_to_pos.get(part, self.part_count - 1) + 1
        if next_pos >= self.part_count: return None
        return self.pos_to_part[next_pos]

    def next(self, student, part, step, content):
        # find next step and update student progress
        next_step = part.next_step(step)
        if next_step is None:
            next_part = self.next_part(part)
            if next_part is None:
                return Error("Done. No next step.")
            next_step = next_part.pos_to_step[0]
        else:
            next_part = part
        student.progress = self.uid_progress[(next_part.uid, next_step.uid)]
        return Redirect('/'.join(
            ['', student.uid, next_part.uid, next_step.uid]))

    def answer(self, student, part, step, content):
        if not isinstance(step, QuestionStep):
            return Error("Wrong step type! Cannot accept an answer.")
        text = content['answer'][0]
        step_id = (part.uid, step.uid)
        student.answers[step_id] = text
        student.save(self.student_dir)
        step.answers[student.uid] = text
        return Redirect('/'.join(['', student.uid, part.uid, step.uid]))