Пример #1
0
            if not parent:
                continue
            child = 'P' + str(next_proc)
            next_proc += 1
            sys.stdout.write('SPAWN ' + child + ' ' + parent + '\n')
            ref.spawn(child, parent)
        elif line == 'KILL':
            procs = ref.get_all_procs()
            procs.remove('INIT')
            victim = random_choice(line, procs)
            if not victim:
                continue
            sys.stdout.write('KILL ' + victim + '\n')
            ref.kill(victim)
        elif line == 'REGISTER':
            root_pid = 'P' + str(next_proc - 1)
            sys.stdout.write('REGISTER ' + root_pid + '\n')
            ref.register(root_pid, 0)
        elif line == 'UNREGISTER':
            families = ref.get_all_families()
            families.remove('INIT')
            root_pid = random_choice(line, families)
            if not root_pid:
                continue
            sys.stdout.write('UNREGISTER ' + root_pid + '\n')
            ref.unregister(root_pid)
        elif line == 'SNAPSHOT':
            sys.stdout.write('SNAPSHOT\n') 
        else:
            raise Exception('invalid command: ' + line)
Пример #2
0
class ProcDTester:
    def __init__(self):

        if platform.system() == 'Windows':
            pipe_name = '\\\\.\\pipe\\procd_pipe.' + str(os.getpid())
        else:
            pipe_name = 'procd_pipe'

        self.drone_tree = DroneTree()

        init_pid = self.drone_tree.get_init_pid()
        procd_pid = self.drone_tree.spawn(
            init_pid, "./condor_procd -A " + pipe_name + " -L procd_log -S -1")

        self.procd_reference = ProcDReference(init_pid)
        self.procd_reference.spawn(procd_pid, init_pid)

        self.procd_interface = ProcDInterface(pipe_name)

        self.tag_mappings = {'INIT': init_pid, 'PROCD': procd_pid}

    def spawn(self, tag, parent_tag):
        ppid = self.tag_mappings[parent_tag]
        pid = self.drone_tree.spawn(ppid)
        self.procd_reference.spawn(pid, ppid)
        self.tag_mappings[tag] = pid

    def kill(self, tag):
        pid = self.tag_mappings[tag]
        self.drone_tree.kill(pid)
        self.procd_reference.kill(pid)

    def register(self, tag, watcher):
        pid = self.tag_mappings[tag]
        watcher_pid = 0
        if watcher is not None:
            watcher_pid = self.tag_mappings[watcher]
        self.procd_interface.register(pid, watcher_pid)
        self.procd_reference.register(pid, watcher_pid)

    def unregister(self, tag):
        pid = self.tag_mappings[tag]
        self.procd_interface.unregister(pid)
        self.procd_reference.unregister(pid)

    def snapshot(self):
        self.procd_interface.snapshot()

    def show_state(self, procd_dump=None):
        if procd_dump is None:
            procd_dump = self.procd_interface.dump()
        print '------ ProcD State ------'
        procd_dump.dump()
        print '------ Reference State ------'
        self.procd_reference.dump()
        print '------ Tag-to-PID Mappings ------'
        for tag, pid in sorted(self.tag_mappings.iteritems()):
            print '%s: %s' % (tag, pid)
        print '------------------------------------'

    def check_state(self):
        dump = self.procd_interface.dump()
        if not dump.equals(self.procd_reference):
            print 'ProcD state is incorrect!'
            self.show_state(dump)
            return False
        return True

    # run the test; commands are read from the given file;
    # if interactive is True, the test will wait for "Enter"
    # to be pressed in between each command
    def run(self, filename, interactive):
        ok = True
        f = open(filename, 'r')
        while True:
            line = f.readline()
            tokens = line.split()
            if interactive:
                self.show_state()
            if not tokens:
                break
            print 'Next command: ' + line.rstrip()
            if interactive:
                raw_input()
            if tokens[0] == 'SPAWN':
                self.spawn(tokens[1], tokens[2])
            elif tokens[0] == 'KILL':
                self.kill(tokens[1])
            elif tokens[0] == 'REGISTER':
                watcher = None
                if len(tokens) > 2:
                    watcher = tokens[2]
                self.register(tokens[1], watcher)
                ok = self.check_state()
            elif tokens[0] == 'UNREGISTER':
                self.unregister(tokens[1])
                ok = self.check_state()
            elif tokens[0] == 'SNAPSHOT':
                self.snapshot()
                ok = self.check_state()
            if not ok:
                break
        f.close()
        self.procd_interface.quit()
        return ok
Пример #3
0
            if not parent:
                continue
            child = 'P' + str(next_proc)
            next_proc += 1
            sys.stdout.write('SPAWN ' + child + ' ' + parent + '\n')
            ref.spawn(child, parent)
        elif line == 'KILL':
            procs = ref.get_all_procs()
            procs.remove('INIT')
            victim = random_choice(line, procs)
            if not victim:
                continue
            sys.stdout.write('KILL ' + victim + '\n')
            ref.kill(victim)
        elif line == 'REGISTER':
            root_pid = 'P' + str(next_proc - 1)
            sys.stdout.write('REGISTER ' + root_pid + '\n')
            ref.register(root_pid, 0)
        elif line == 'UNREGISTER':
            families = ref.get_all_families()
            families.remove('INIT')
            root_pid = random_choice(line, families)
            if not root_pid:
                continue
            sys.stdout.write('UNREGISTER ' + root_pid + '\n')
            ref.unregister(root_pid)
        elif line == 'SNAPSHOT':
            sys.stdout.write('SNAPSHOT\n')
        else:
            raise Exception('invalid command: ' + line)
Пример #4
0
class ProcDTester:

    def __init__(self):

        if platform.system() == 'Windows':
            pipe_name = '\\\\.\\pipe\\procd_pipe.' + str(os.getpid())
        else:
            pipe_name = 'procd_pipe'

        self.drone_tree = DroneTree()

        init_pid = self.drone_tree.get_init_pid()
        procd_pid = self.drone_tree.spawn(init_pid,
            "./condor_procd -A " + pipe_name + " -L procd_log -S -1")

        self.procd_reference = ProcDReference(init_pid)
        self.procd_reference.spawn(procd_pid, init_pid)

        self.procd_interface = ProcDInterface(pipe_name)

        self.tag_mappings = {'INIT': init_pid, 'PROCD': procd_pid}

    def spawn(self, tag, parent_tag):
        ppid = self.tag_mappings[parent_tag]
        pid = self.drone_tree.spawn(ppid)
        self.procd_reference.spawn(pid, ppid)
        self.tag_mappings[tag] = pid

    def kill(self, tag):
        pid = self.tag_mappings[tag]
        self.drone_tree.kill(pid)
        self.procd_reference.kill(pid)

    def register(self, tag, watcher):
        pid = self.tag_mappings[tag]
        watcher_pid = 0
        if watcher is not None:
            watcher_pid = self.tag_mappings[watcher]
        self.procd_interface.register(pid, watcher_pid)
        self.procd_reference.register(pid, watcher_pid)

    def unregister(self, tag):
        pid = self.tag_mappings[tag]
        self.procd_interface.unregister(pid)
        self.procd_reference.unregister(pid)

    def snapshot(self):
        self.procd_interface.snapshot()

    def show_state(self, procd_dump = None):
        if procd_dump is None:
            procd_dump = self.procd_interface.dump()
        print '------ ProcD State ------'
        procd_dump.dump()
        print '------ Reference State ------'
        self.procd_reference.dump()
        print '------ Tag-to-PID Mappings ------'
        for tag, pid in sorted(self.tag_mappings.iteritems()):
            print '%s: %s' % (tag, pid)
        print '------------------------------------'

    def check_state(self):
        dump = self.procd_interface.dump()
        if not dump.equals(self.procd_reference):
            print 'ProcD state is incorrect!'
            self.show_state(dump)
            return False
        return True

    # run the test; commands are read from the given file;
    # if interactive is True, the test will wait for "Enter"
    # to be pressed in between each command
    def run(self, filename, interactive):
        ok = True
        f = open(filename, 'r')
        while True:
            line = f.readline()
            tokens = line.split()
            if interactive:
                self.show_state()
            if not tokens:
                break
            print 'Next command: ' + line.rstrip()
            if interactive:
                raw_input()
            if tokens[0] == 'SPAWN':
                self.spawn(tokens[1], tokens[2])
            elif tokens[0] == 'KILL':
                self.kill(tokens[1])
            elif tokens[0] == 'REGISTER':
                watcher = None
                if len(tokens) > 2:
                    watcher = tokens[2]
                self.register(tokens[1], watcher)
                ok = self.check_state()
            elif tokens[0] == 'UNREGISTER':
                self.unregister(tokens[1])
                ok = self.check_state()
            elif tokens[0] == 'SNAPSHOT':
                self.snapshot()
                ok = self.check_state()
            if not ok:
                break
        f.close()
        self.procd_interface.quit()
        return ok