Exemplo n.º 1
0
    def testEmpty(self):
        mgr = DAQPool()

        runset = mgr.findRunset(1)
        self.failIf(runset is not None, 'Found set in empty manager')

        mgr.remove(MockComponent('foo', 0))
Exemplo n.º 2
0
    def testBuildMultiInput(self):
        mgr = DAQPool()

        compList = []

        comp = MockComponent('fooHub', 0)
        comp.addOutput('conn')
        compList.append(comp)

        comp = MockComponent('bar', 0)
        comp.addInput('conn', 123)
        compList.append(comp)

        comp = MockComponent('baz', 0)
        comp.addInput('conn', 456)
        compList.append(comp)

        self.assertEqual(len(mgr.pool), 0)

        nameList = []
        for c in compList:
            mgr.add(c)
            nameList.append(c.name)

        self.assertEqual(len(mgr.pool), len(compList))

        logger = MockLogger('main')
        runset = mgr.makeRunset(nameList, logger)

        self.assertEqual(len(mgr.pool), 0)

        found = mgr.findRunset(runset.id)
        self.failIf(found is None, "Couldn't find runset #" + str(runset.id))

        mgr.returnRunset(runset)

        self.assertEqual(len(mgr.pool), len(compList))

        for c in compList:
            mgr.remove(c)

        self.assertEqual(len(mgr.pool), 0)

        logger.checkStatus(10)
Exemplo n.º 3
0
    def testBuildMissingOneOutput(self):
        mgr = DAQPool()

        compList = []

        comp = MockComponent('fooHub', 0)
        comp.addOutput('aaa')
        comp.addInput('xxx', 123)
        compList.append(comp)

        comp = MockComponent('bar', 0)
        comp.addInput('aaa', 456)
        compList.append(comp)

        self.assertEqual(len(mgr.pool), 0)

        nameList = []
        for c in compList:
            mgr.add(c)
            nameList.append(c.name)

        self.assertEqual(len(mgr.pool), len(compList))

        logger = MockLogger('main')
        self.assertRaises(ValueError, mgr.makeRunset, nameList, logger)

        self.assertEqual(len(mgr.pool), len(compList))

        for c in compList:
            mgr.remove(c)

        self.assertEqual(len(mgr.pool), 0)

        logger.checkStatus(10)
Exemplo n.º 4
0
    def testBuildMultiMissing(self):
        mgr = DAQPool()

        compList = []

        comp = MockComponent('fooHub', 0)
        comp.addInput('xxx', 123)
        compList.append(comp)

        comp = MockComponent('bar', 0)
        comp.addOutput('xxx')
        compList.append(comp)

        comp = MockComponent('feeHub', 0)
        comp.addInput('xxx', 456)
        compList.append(comp)

        comp = MockComponent('baz', 0)
        comp.addOutput('xxx')
        compList.append(comp)

        self.assertEqual(len(mgr.pool), 0)

        nameList = []
        for c in compList:
            mgr.add(c)
            nameList.append(c.name)

        self.assertEqual(len(mgr.pool), len(compList))

        logger = MockLogger('main')
        try:
            mgr.makeRunset(nameList, logger)
            self.fail('Unexpected success')
        except ValueError:
            pass
        except:
            self.fail('Unexpected exception')

        self.assertEqual(len(mgr.pool), len(compList))

        for c in compList:
            mgr.remove(c)

        self.assertEqual(len(mgr.pool), 0)

        logger.checkStatus(10)
Exemplo n.º 5
0
    def testAddRemove(self):
        mgr = DAQPool()

        compList = []

        comp = MockComponent('foo', 0)
        compList.append(comp)

        comp = MockComponent('bar', 0)
        compList.append(comp)

        self.assertEqual(len(mgr.pool), 0)

        for c in compList:
            mgr.add(c)

        self.assertEqual(len(mgr.pool), len(compList))

        for c in compList:
            mgr.remove(c)

        self.assertEqual(len(mgr.pool), 0)
Exemplo n.º 6
0
    def testStartRun(self):
        mgr = DAQPool()

        a = MockComponent('aHub', 0)
        a.addOutput('ab')

        b = MockComponent('b', 0)
        b.addInput('ab', 123)
        b.addOutput('bc')

        c = MockComponent('c', 0)
        c.addInput('bc', 456)

        compList = [c, a, b]

        self.assertEqual(len(mgr.pool), 0)

        nameList = []
        for c in compList:
            mgr.add(c)
            nameList.append(c.name)

        self.assertEqual(len(mgr.pool), len(compList))

        logger = MockLogger('main')
        runset = mgr.makeRunset(nameList, logger)

        self.assertEqual(len(mgr.pool), 0)
        self.assertEqual(len(runset.set), len(compList))

        runset.configure('abc')

        ordered = True
        prevName = None
        for s in runset.set:
            if not prevName:
                prevName = s.name
            elif prevName > s.name:
                ordered = False

        self.failIf(ordered, 'Runset sorted before startRun()')

        runset.startRun(1)

        ordered = True
        prevName = None
        for s in runset.set:
            if not prevName:
                prevName = s.name
            elif prevName < s.name:
                ordered = False

        self.failUnless(ordered, 'Runset was not sorted by startRun()')

        runset.stopRun()

        ordered = True
        prevName = None
        for s in runset.set:
            if not prevName:
                prevName = s.name
            elif prevName > s.name:
                ordered = False

        self.failUnless(ordered, 'Runset was not reversed by stopRun()')

        mgr.returnRunset(runset)

        self.assertEqual(runset.id, None)
        self.assertEqual(runset.configured, False)
        self.assertEqual(runset.runNumber, None)

        self.assertEqual(len(mgr.pool), len(compList))
        self.assertEqual(len(runset.set), 0)

        logger.checkStatus(10)
Exemplo n.º 7
0
    def buildRunset(self, nodeList):
        if LOUD:
            print '-- Nodes'
            for node in nodeList:
                print node.getDescription()

        nodeLog = {}

        pool = DAQPool()
        port = -1
        for node in nodeList:
            key = '%s#%d' % (node.name, node.num)
            nodeLog[key] = MockAppender('Log-%s' % key)
            pool.add(MockDAQClient(node.name, node.num, None, port, 0,
                                   node.getConnections(), nodeLog[key],
                                   node.outLinks))
            port -= 1

        if LOUD:
            print '-- Pool has ' + str(len(pool.pool)) + ' comps'
            for k in pool.pool.keys():
                print '  ' + str(k)
                for c in pool.pool[k]:
                    print '    ' + str(c)

        numComps = len(pool.pool)

        nameList = []
        for node in nodeList:
            nameList.append(node.name + '#' + str(node.num))

        logger = MockLogger('main')
        runset = pool.makeRunset(nameList, logger)

        chkId = ConnectionTest.EXP_ID
        ConnectionTest.EXP_ID += 1

        self.assertEquals(len(pool.pool), 0)
        self.assertEquals(len(pool.sets), 1)
        self.assertEquals(pool.sets[0], runset)

        self.assertEquals(runset.id, chkId)
        self.assertEquals(len(runset.set), len(nodeList))

        # copy node list
        #
        tmpList = nodeList[:]

        # validate all components in runset
        #
        for comp in runset.set:
            node = None
            for t in tmpList:
                if comp.name == t.name and comp.num == t.num:
                    node = t
                    tmpList.remove(t)
                    break

            self.failIf(not node, 'Could not find component ' + str(comp))

            # copy connector list
            #
            compConn = comp.connectors[:]

            # remove all output connectors
            #
            for typ in node.outLinks:
                conn = None
                for c in compConn:
                    if not c.isInput() and c.type == typ:
                        conn = c
                        compConn.remove(c)
                        break

                self.failIf(not conn, 'Could not find connector ' + typ +
                            ' for component ' + str(comp))

            # remove all input connectors
            #
            for typ in node.inLinks:
                conn = None
                for c in compConn:
                    if c.isInput and c.type == typ:
                        conn = c
                        compConn.remove(c)
                        break

                self.failIf(not conn, 'Could not find connector ' + typ +
                            ' for component ' + str(comp))

            # whine if any connectors are left
            #
            self.assertEquals(len(compConn), 0, 'Found extra connectors in ' +
                              str(compConn))

        # whine if any components are left
        #
        self.assertEquals(len(tmpList), 0, 'Found extra components in ' +
                          str(tmpList))

        if LOUD:
            print '-- SET: ' + str(runset)

        for key in nodeLog:
            nodeLog[key].addExpectedExact('End of log')
        pool.returnRunset(runset)
        self.assertEquals(len(pool.pool), numComps)
        self.assertEquals(len(pool.sets), 0)

        logger.checkStatus(10)

        for key in nodeLog:
            nodeLog[key].checkStatus(10)