Esempio n. 1
0
class ModuleArrayTests(ModuleIOBaseTests):
    def setUp(self):
        self.mp = ModuleParser()

    def tearDown(self):
        pass

    def testModule2x1Grid(self):
        self.maxDiff = None
        self.mp.setGridSize(2, 1)
        self.mp.setClkName('clk_')
        self.mp.setRstName('rst_', Active.lo)
        self.mp.setTied(Active.hi)
        self.mp.setNumFlops(2)
        self.mp.parse(self.fileAsString('../test-files/poser-module0.v'))
        self.assertEqual(
            self.mp.moduleAsString(),
            self.fileAsString('../test-files/poser-module0-gold.v'))

    def testModule2x2GridMultipleIO(self):
        self.maxDiff = None
        self.mp.setGridSize(2, 2)
        self.mp.setClkName('clk_')
        self.mp.setRstName('rst_', Active.lo)
        self.mp.setTied(Active.hi)
        self.mp.setNumFlops(4)
        self.mp.parse(self.fileAsString('../test-files/poser-module1.v'))
        self.assertEqual(
            self.mp.moduleAsString(),
            self.fileAsString('../test-files/poser-module1-gold.v'))

    def testModule9x5GridMultipleIO(self):
        self.maxDiff = None
        self.mp.setGridSize(5, 9)
        self.mp.setClkName('clk_')
        self.mp.setRstName('rst_', Active.lo)
        self.mp.setTied(Active.hi)
        self.mp.setNumFlops(45)
        self.mp.parse(self.fileAsString('../test-files/poser-module4.v'))
        self.assertEqual(
            self.mp.moduleAsString(),
            self.fileAsString('../test-files/poser-module4-gold.v'))

    def testModule9x5AsyncGrid(self):
        self.maxDiff = None
        self.mp.setGridSize(2, 1)
        self.mp.setClkName('clk_')
        self.mp.setRstName('rst_', Active.lo)
        self.mp.setTied(Active.hi)
        self.mp.parse(self.fileAsString('../test-files/poser-module3.v'))
        self.assertEqual(
            self.mp.moduleAsString(),
            self.fileAsString('../test-files/poser-module3-gold.v'))

    def testModule3x1GridMultipleIO(self):
        self.maxDiff = None
        self.mp.setGridSize(3, 1)
        self.mp.setClkName('clk_')
        self.mp.setRstName('rst_', Active.lo)
        self.mp.setTied(Active.hi)
        self.mp.parse(self.fileAsString('../test-files/poser-module2.v'))
        self.assertEqual(
            self.mp.moduleAsString(),
            self.fileAsString('../test-files/poser-module2-gold.v'))

    def testModule2x1GridMultipleIO(self):
        self.maxDiff = None
        self.mp.setGridSize(2, 1)
        self.mp.setClkName('clk_')
        self.mp.setRstName('rst_', Active.lo)
        self.mp.setTied(Active.hi)
        self.mp.parse(self.fileAsString('../test-files/poser-module5.v'))
        self.assertEqual(
            self.mp.moduleAsString(),
            self.fileAsString('../test-files/poser-module5-gold.v'))

    def testModuleGridLargerThanIO(self):
        self.maxDiff = None
        self.mp.setGridSize(4, 1)
        self.mp.setClkName('clk_')
        self.mp.setRstName('rst_', Active.lo)
        self.mp.setTied(Active.hi)
        self.mp.parse(self.fileAsString('../test-files/poser-module6.v'))
        self.assertEqual(
            self.mp.moduleAsString(),
            self.fileAsString('../test-files/poser-module6-gold.v'))
Esempio n. 2
0
 def setUp(self):
     self.mp = ModuleParser()
Esempio n. 3
0
    class ModulePortTests(unittest.TestCase):
        moduleSinglePort = ''
        modulePortKeyword = ''
        moduleTwoPorts = ''
        moduleMultiplePorts = ''
        moduleMultipleVectorPorts = ''
        moduleSingleOutput = ''
        moduleIrregularSpacing = ''
        type = ''

        def setUp(self):
            self.mp = ModuleParser()

        def tearDown(self):
            pass

        def test1Port(self):
            p = self.mp.parsePorts(self.type,
                                   self.changePortType(self.moduleSinglePort))
            self.assertEqual(p, self.changePortType([IO('port', 'blah')]))

        def testPortKeyword(self):
            p = self.mp.parsePorts(self.type,
                                   self.changePortType(self.modulePortKeyword))
            self.assertEqual(p, self.changePortType([IO('port', 'wag')]))

        def test2Port(self):
            p = self.mp.parsePorts(self.type,
                                   self.changePortType(self.moduleTwoPorts))
            self.assertEqual(
                p, self.changePortType([IO('port', 'blah'),
                                        IO('port', 'wag')]))

        def testMultiPort(self):
            p = self.mp.parsePorts(
                self.type, self.changePortType(self.moduleMultiplePorts))
            self.assertEqual(
                p,
                self.changePortType(
                    [IO('port', 'blah'),
                     IO('port', 'wag'),
                     IO('port', 'bag')]))

        def testMultiVectorPort(self):
            p = self.mp.parsePorts(
                self.type, self.changePortType(self.moduleMultipleVectorPorts))
            self.assertEqual(
                p,
                self.changePortType([
                    IO('port', 'blah', '1', '0'),
                    IO('port', 'wag', '1', '0'),
                    IO('port', 'bag', '1', '0')
                ]))

        def testIrregularlySpacedPort(self):
            p = self.mp.parsePorts(
                self.type, self.changePortType(self.moduleIrregularSpacing))
            self.assertEqual(
                p,
                self.changePortType([
                    IO('port', 'blah', '1', '0'),
                    IO('port', 'wag', '1', '0'),
                    IO('port', 'bag', '1', '0'),
                    IO('port', 'dang'),
                    IO('port', 'biggy', 'flaGGs-54', '34'),
                ]))

        def changePortType(self, io):
            if isinstance(io, list):
                l = []
                for s in io:
                    if isinstance(s, IO):
                        l.append(IO(self.type, s.name, s.msb, s.lsb))
                    else:
                        l.append(re.sub('port', self.type, s))
                return l
            else:
                return re.sub('port', self.type, io)

        def setType(self, t):
            self.type = t
Esempio n. 4
0
class ModuleParseTests(unittest.TestCase):
    def setUp(self):
        self.mp = ModuleParser()

    def tearDown(self):
        pass

    @patch('poser.ModuleParser.scrubModule',
           return_value='module blah endmodule')
    def testParseCallsScrub(self, mock_scrubModule):
        str = 'module grass(); shlub a dub dub endmodule'
        self.mp.parse(str)
        mock_scrubModule.assert_called_with(str)

    @patch('poser.ModuleParser.getModuleNameFromString',
           return_value='module blah endmodule')
    def testParseCallsGetModuleNameFromString(self,
                                              mock_getModuleNameFromString):
        str = 'module grass(); shlub a dub dub endmodule'
        self.mp.parse(str)
        mock_getModuleNameFromString.assert_called_with(str)

    @patch('poser.ModuleParser.parsePorts')
    def testParseCallsPorts(self, mock_nonAnsiPorts):
        calls = [
            call('input', 'module name(); sketchy jinx endmodule'),
            call('output', 'module name(); sketchy jinx endmodule')
        ]
        self.mp.parse('blah module name(); sketchy jinx endmodule input bag')
        mock_nonAnsiPorts.assert_has_calls(calls)

    def testIOAsString(self):
        self.mp.inputs = [IO('input', 'a'), IO('input', 'b')]
        self.mp.outputs = [IO('output', 'c')]
        self.assertEqual(self.mp.moduleIOAsString(), 'a, b, c')

    def testSimplePortListAsString(self):
        self.mp.inputs = [IO('input', 'a'), IO('input', 'b')]
        self.mp.outputs = [IO('output', 'c')]

        _expect = '  input a;\n'
        _expect += '  input b;\n'
        _expect += '  output c;\n'
        self.assertEqual(self.mp.modulePortsAsString(), _expect)

    def testVectorPortListAsString(self):
        self.mp.inputs = [
            IO('input', 'a', 'blah', 'jIb'),
            IO('input', 'b', '2', '0')
        ]
        self.mp.outputs = [IO('output', 'c', '5-1+`WHAT', '31')]

        _expect = '  input [blah:jIb] a;\n'
        _expect += '  input [2:0] b;\n'
        _expect += '  output [5-1+`WHAT:31] c;\n'
        self.assertEqual(self.mp.modulePortsAsString(), _expect)

    def testAnsiParametersAsString(self):
        self.mp.parse(
            'blah module name #(some stuff\n, yok=al\n) (); sketchy jinx endmodule input bag'
        )
        self.assertEqual(self.mp.ansiParametersAsString(),
                         'some stuff , yok=al ')

    def testNonAnsiParametersAsString(self):
        self.mp.parse(
            'blah module name  (); parameter ding = dong; boo-urns; parameter dkf==,,\n=\n=kdk; sketchy jinx endmodule input bag'
        )
        self.assertEqual(
            self.mp.nonAnsiParametersAsString(),
            '  parameter ding = dong;\n  parameter dkf==,, = =kdk;\n')

    def testPreambleAsString(self):
        self.mp.parse(
            'goats\nsome stuff\n`include bogus\n`define blah what\n module name();endmodule'
        )
        self.assertEqual(
            self.mp.preambleAsString(),
            'goats\nsome stuff\n`include bogus\n`define blah what\n')

    def testNoPreambleAsString(self):
        self.mp.parse(' module name();input something;endmodule')
        self.assertEqual(self.mp.preambleAsString(), '')

    def testPoserParams(self):
        self.mp.inputs = [IO('input', 'a'), IO('input', 'b')]
        self.mp.outputs = [IO('output', 'c')]
        self.mp.setTied(Active.hi)
        self.mp.setGridSize(2, 1)

        _expect = '  parameter poser_tied = 1\'b1;\n'
        _expect += '  parameter poser_width_in = 0+1+1;\n'
        _expect += '  parameter poser_width_out = 0+1;\n'
        _expect += '  parameter poser_grid_width = 2;\n'
        _expect += '  parameter poser_grid_depth = 1;\n'
        _expect += '  parameter [poser_grid_width-1:0] cellTypes [0:poser_grid_depth-1] = \'{ 2\'b00 };\n'
        self.assertEqual(self.mp.poserParamsAsString(), _expect)

    def testPoserParamsIgnoreClkRst(self):
        self.mp.inputs = [IO('input', 'a'), IO('input', 'b'), IO('input', 'd')]
        self.mp.outputs = [IO('output', 'c')]
        self.mp.setTied(Active.hi)
        self.mp.setClkName('a')
        self.mp.setRstName('b', Active.lo)
        self.mp.setGridSize(2, 1)

        _expect = '  parameter poser_tied = 1\'b1;\n'
        _expect += '  parameter poser_width_in = 0+1;\n'
        _expect += '  parameter poser_width_out = 0+1;\n'
        _expect += '  parameter poser_grid_width = 2;\n'
        _expect += '  parameter poser_grid_depth = 1;\n'
        _expect += '  parameter [poser_grid_width-1:0] cellTypes [0:poser_grid_depth-1] = \'{ 2\'b00 };\n'
        self.assertEqual(self.mp.poserParamsAsString(), _expect)

    def testPoserInputWidthWithVectors(self):
        self.mp.inputs = [
            IO('input', 'a', '8', '1'),
            IO('input', 'b', 'a', 'A')
        ]
        self.mp.outputs = [IO('output', 'c')]
        self.mp.setTied(Active.hi)
        self.mp.setGridSize(2, 1)

        _expect = '  parameter poser_tied = 1\'b1;\n'
        _expect += '  parameter poser_width_in = 0+8-1+1+a-A+1;\n'
        _expect += '  parameter poser_width_out = 0+1;\n'
        _expect += '  parameter poser_grid_width = 2;\n'
        _expect += '  parameter poser_grid_depth = 1;\n'
        _expect += '  parameter [poser_grid_width-1:0] cellTypes [0:poser_grid_depth-1] = \'{ 2\'b00 };\n'
        self.assertEqual(self.mp.poserParamsAsString(), _expect)

    def testPoserOutputWidthWithVectors(self):
        self.mp.inputs = [IO('input', 'c')]
        self.mp.outputs = [
            IO('output', 'a', '8', '1'),
            IO('input', 'b', 'a', 'A')
        ]
        self.mp.setTied(Active.hi)
        self.mp.setGridSize(2, 1)

        _expect = '  parameter poser_tied = 1\'b1;\n'
        _expect += '  parameter poser_width_in = 0+1;\n'
        _expect += '  parameter poser_width_out = 0+8-1+1+a-A+1;\n'
        _expect += '  parameter poser_grid_width = 2;\n'
        _expect += '  parameter poser_grid_depth = 1;\n'
        _expect += '  parameter [poser_grid_width-1:0] cellTypes [0:poser_grid_depth-1] = \'{ 2\'b00 };\n'
        self.assertEqual(self.mp.poserParamsAsString(), _expect)

    def testPoserNxMCellTypes(self):
        self.mp.inputs = [IO('input', 'c')]
        self.mp.outputs = [
            IO('output', 'a', '8', '1'),
            IO('input', 'b', 'a', 'A')
        ]
        self.mp.setTied(Active.hi)
        self.mp.setGridSize(3, 2)

        _expect = '  parameter poser_tied = 1\'b1;\n'
        _expect += '  parameter poser_width_in = 0+1;\n'
        _expect += '  parameter poser_width_out = 0+8-1+1+a-A+1;\n'
        _expect += '  parameter poser_grid_width = 3;\n'
        _expect += '  parameter poser_grid_depth = 2;\n'
        _expect += '  parameter [poser_grid_width-1:0] cellTypes [0:poser_grid_depth-1] = \'{ 3\'b000,3\'b000 };\n'
        self.assertEqual(self.mp.poserParamsAsString(), _expect)

    def getNumFlops(self):
        _numFlops = 0
        for i in range(len(self.mp.cellTypes)):
            _numFlops += len([x for x in self.mp.cellTypes[i] if x == '1'])
        return _numFlops

    def testSet0Flops(self):
        self.mp.setGridSize(3, 2)
        self.mp.setNumFlops(0)
        self.assertEqual(self.getNumFlops(), 0)

    def testSet1Flop(self):
        self.mp.setGridSize(3, 2)
        self.mp.setNumFlops(1)
        self.assertEqual(self.getNumFlops(), 1)

    def testSetNFlops(self):
        self.mp.setGridSize(100, 50)
        self.mp.setNumFlops(50)
        self.assertEqual(self.getNumFlops(), 50)

    def testSetAllFlops(self):
        self.mp.setGridSize(3, 9)
        self.mp.setNumFlops(27)
        self.assertEqual(self.getNumFlops(), 27)

    def testPoser1InternalInputs(self):
        self.mp.inputs = [IO('input', 'c')]
        self.assertEqual(
            self.mp.poserInternalInputsAsString(),
            '  wire [poser_width_in-1:0] poser_inputs;\n  assign poser_inputs = { c };\n'
        )

    def testPoser1InternalInputsIgnoreClkRst(self):
        self.mp.inputs = [
            IO('input', 'c'),
            IO('input', 'clk'),
            IO('input', 'rst')
        ]
        self.mp.setClkName('clk')
        self.mp.setRstName('rst', Active.lo)
        self.assertEqual(
            self.mp.poserInternalInputsAsString(),
            '  wire [poser_width_in-1:0] poser_inputs;\n  assign poser_inputs = { c };\n'
        )

    def testPoserMultipleInternalInputs(self):
        self.mp.inputs = [IO('input', 'c'), IO('input', 'd')]
        self.assertEqual(
            self.mp.poserInternalInputsAsString(),
            '  wire [poser_width_in-1:0] poser_inputs;\n  assign poser_inputs = { c,d };\n'
        )

    def testPoser1InternalOutputs(self):
        self.mp.outputs = [IO('output', 'c')]
        self.assertEqual(
            self.mp.poserInternalOutputsAsString(),
            '  wire [poser_width_out-1:0] poser_outputs;\n  assign { c } = poser_outputs;\n'
        )

    def testPoserMultipleInternalOutputs(self):
        self.mp.outputs = [IO('output', 'c'), IO('output', 'd')]
        self.assertEqual(
            self.mp.poserInternalOutputsAsString(),
            '  wire [poser_width_out-1:0] poser_outputs;\n  assign { c,d } = poser_outputs;\n'
        )

    def testPoserGridIODepthN(self):
        self.mp.setGridSize(1, 4)
        _expect = '  wire [poser_grid_width-1:0] poser_grid_output [0:poser_grid_depth-1];\n'
        self.assertEqual(self.mp.poserGridOutputsAsString(), _expect)
Esempio n. 5
0
class ModuleNameParseTests(unittest.TestCase):
    moduleSingleLine = "module singleLine();endmodule"
    moduleWhiteSpace = "  module    whiteSpace  ()  ;endmodule"
    moduleLeadingChars = "blah blah blah\nmodule leadingChars();endmodule"
    moduleLineComment = "// module bmodule blah\nmodule lineComment();\n// module bogus\nendmodule"
    moduleOpenCloseComment = "/*\nmodule not\n*/m/**/odule ocC/*blah */omme/* blat */nt();/*\nmodule not\n*/endmodule"
    moduleMultiLine = "module\n_2lineName();endmodule"
    moduleMultiLineWithComment = "module//biggle\n_2lineName();endmodule"
    moduleWireRegLogic = "module wire reg logic logicwireregbiggle();endmodule"

    def setUp(self):
        self.mp = ModuleParser()

    def tearDown(self):
        pass

    def testSingleLineModuleName(self):
        self.mp.parse(self.moduleSingleLine)
        self.assertEqual(self.mp.getModuleName(), 'singleLine')

    def testSingleLineModuleNameWithWhitespace(self):
        self.mp.parse(self.moduleWhiteSpace)
        self.assertEqual(self.mp.getModuleName(), 'whiteSpace')

    def testModuleNotFirstLine(self):
        self.mp.parse(self.moduleLeadingChars)
        self.assertEqual(self.mp.getModuleName(), 'leadingChars')

    def testModuleOpenningLineComment(self):
        self.mp.parse(self.moduleLineComment)
        self.assertEqual(self.mp.getModuleName(), 'lineComment')

    def testModuleOpenCloseComment(self):
        self.mp.parse(self.moduleOpenCloseComment)
        self.assertEqual(self.mp.getModuleName(), 'ocComment')

    def testModuleNameTwoLines(self):
        self.mp.parse(self.moduleMultiLine)
        self.assertEqual(self.mp.getModuleName(), '_2lineName')

    def testModuleNameTwoLinesWithComment(self):
        self.mp.parse(self.moduleMultiLineWithComment)
        self.assertEqual(self.mp.getModuleName(), '_2lineName')

    def testWireRegLogicAreScrubbed(self):
        self.mp.parse(self.moduleWireRegLogic)
        self.assertEqual(self.mp.getModuleName(), 'logicwireregbiggle')
Esempio n. 6
0
 def setUp(self):
   self.mp = ModuleParser()
Esempio n. 7
0
class ModuleArrayTests(ModuleIOBaseTests):
  def setUp(self):
    self.mp = ModuleParser()

  def tearDown(self):
    pass

  def testModule2x1Grid(self):
    self.maxDiff = None
    self.mp.setGridSize(2, 1)
    self.mp.setClkName('clk_')
    self.mp.setRstName('rst_', Active.lo)
    self.mp.setTied(Active.hi)
    self.mp.setNumFlops(2)
    self.mp.parse(self.fileAsString('../test-files/poser-module0.v'))
    self.assertEqual(self.mp.moduleAsString(), self.fileAsString('../test-files/poser-module0-gold.v'))

  def testModule2x2GridMultipleIO(self):
    self.maxDiff = None
    self.mp.setGridSize(2, 2)
    self.mp.setClkName('clk_')
    self.mp.setRstName('rst_', Active.lo)
    self.mp.setTied(Active.hi)
    self.mp.setNumFlops(4)
    self.mp.parse(self.fileAsString('../test-files/poser-module1.v'))
    self.assertEqual(self.mp.moduleAsString(), self.fileAsString('../test-files/poser-module1-gold.v'))

  def testModule9x5GridMultipleIO(self):
    self.maxDiff = None
    self.mp.setGridSize(5, 9)
    self.mp.setClkName('clk_')
    self.mp.setRstName('rst_', Active.lo)
    self.mp.setTied(Active.hi)
    self.mp.setNumFlops(45)
    self.mp.parse(self.fileAsString('../test-files/poser-module4.v'))
    self.assertEqual(self.mp.moduleAsString(), self.fileAsString('../test-files/poser-module4-gold.v'))

  def testModule9x5AsyncGrid(self):
    self.maxDiff = None
    self.mp.setGridSize(2, 1)
    self.mp.setClkName('clk_')
    self.mp.setRstName('rst_', Active.lo)
    self.mp.setTied(Active.hi)
    self.mp.parse(self.fileAsString('../test-files/poser-module3.v'))
    self.assertEqual(self.mp.moduleAsString(), self.fileAsString('../test-files/poser-module3-gold.v'))

  def testModule3x1GridMultipleIO(self):
    self.maxDiff = None
    self.mp.setGridSize(3, 1)
    self.mp.setClkName('clk_')
    self.mp.setRstName('rst_', Active.lo)
    self.mp.setTied(Active.hi)
    self.mp.parse(self.fileAsString('../test-files/poser-module2.v'))
    self.assertEqual(self.mp.moduleAsString(), self.fileAsString('../test-files/poser-module2-gold.v'))

  def testModule2x1GridMultipleIO(self):
    self.maxDiff = None
    self.mp.setGridSize(2, 1)
    self.mp.setClkName('clk_')
    self.mp.setRstName('rst_', Active.lo)
    self.mp.setTied(Active.hi)
    self.mp.parse(self.fileAsString('../test-files/poser-module5.v'))
    self.assertEqual(self.mp.moduleAsString(), self.fileAsString('../test-files/poser-module5-gold.v'))

  def testModuleGridLargerThanIO(self):
    self.maxDiff = None
    self.mp.setGridSize(4, 1)
    self.mp.setClkName('clk_')
    self.mp.setRstName('rst_', Active.lo)
    self.mp.setTied(Active.hi)
    self.mp.parse(self.fileAsString('../test-files/poser-module6.v'))
    self.assertEqual(self.mp.moduleAsString(), self.fileAsString('../test-files/poser-module6-gold.v'))