def getCPPDecoderTests(self, namespace = ''): """Returns the decoder tests. All the instruction patterns, including invalid patterns, are fed to the decoder and the decoding output checked. Random values are chosen for don't-care bits.""" import cxx_writer import random, math ranGen = random.SystemRandom() allTests = [] testCount = 0 for instrId, instruction in self.instrId.items(): code = namespace + '::Decoder dec;\n' pattern = instruction[0] try: pattern[0][0] pattern = pattern[0] except: pass for i in range(0, len(pattern)): if pattern[i] == None: if ranGen.random() > 0.5: pattern[i] = '1' else: pattern[i] = '0' else: pattern[i] = str(pattern[i]) if instrId == -1: expectedId = self.instrNum else: # Check for the presence of sub-instructions and possibly # adapt the expected test outcome. expectedId = None for instr in self.instrSub[instrId]: found = True revInstrPattern = instr.bitstring revInstrPattern.reverse() for i in range(0, len(pattern)): if revInstrPattern[i] != None and int(pattern[i]) != revInstrPattern[i]: found = False if found: expectedId = instr.id break if expectedId == None: expectedId = instrId pattern.reverse() if instrId != -1: code += '// Checking Instruction ' + self.instrName[instrId] + '.\n' else: code += '// Checking Invalid Instruction.\n' code += 'BOOST_CHECK_EQUAL(dec.decode(' + hex(int(''.join(pattern), 2)) + '), ' + str(expectedId) + ');\n' curTest = cxx_writer.Code(code) curTest.addInclude(['boost/test/test_tools.hpp', 'decoder.hpp']) if instrId != -1: testName = self.instrName[instrId] + '_' + str(testCount) + '_decode' else: testName = 'Invalid_' + str(testCount) + '_decode' curTestFunction = cxx_writer.Function(testName, curTest, cxx_writer.voidType) from procWriter import testNames testNames.append(testName) allTests.append(curTestFunction) testCount += 1 return allTests
def getCPPTests(self, namespace = ''): """Creates the tests for the decoder; I normally create the tests with boost_test_framework. What I have to do is feeding all the instruction patterns (including all the non valid ones) to the decoder and check that they are correctly decoded. I choose random values for the non-care bits""" import cxx_writer import random, math ranGen = random.SystemRandom() allTests = [] testCount = 0 for instrId, instruction in self.instrId.items(): code = namespace + '::Decoder dec;\n' pattern = instruction[0] try: pattern[0][0] pattern = pattern[0] except: pass for i in range(0, len(pattern)): if pattern[i] == None: if ranGen.random() > 0.5: pattern[i] = '1' else: pattern[i] = '0' else: pattern[i] = str(pattern[i]) if instrId == -1: expectedId = self.instrNum else: # Now I have to check for the presence of a sub-instruction and, in case, # correct the target of the test expectedId = None for instr in self.instrSub[instrId]: found = True revInstrPattern = instr.bitstring revInstrPattern.reverse() for i in range(0, len(pattern)): if revInstrPattern[i] != None and int(pattern[i]) != revInstrPattern[i]: found = False if found: expectedId = instr.id break if expectedId == None: expectedId = instrId pattern.reverse() if instrId != -1: code += '// Checking Instruction ' + self.instrName[instrId] + '\n' else: code += '// Checking Invalid Instruction\n' code += 'BOOST_CHECK_EQUAL(dec.decode( ' + hex(int(''.join(pattern), 2)) + ' ), ' + str(expectedId) + ');\n' curTest = cxx_writer.writer_code.Code(code) curTest.addInclude(['boost/test/test_tools.hpp', 'decoder.hpp']) if instrId != -1: testName = self.instrName[instrId] + '_' + str(testCount) + '_decode' else: testName = 'Invalid_' + str(testCount) + '_decode' curTestFunction = cxx_writer.writer_code.Function(testName, curTest, cxx_writer.writer_code.voidType) from procWriter import testNames testNames.append(testName) allTests.append(curTestFunction) testCount += 1 return allTests
def getCPPTests(self, namespace=''): """Creates the tests for the decoder; I normally create the tests with boost_test_framework. What I have to do is feeding all the instruction patterns (including all the non valid ones) to the decoder and check that they are correctly decoded. I choose random values for the non-care bits""" import cxx_writer import random, math ranGen = random.SystemRandom() allTests = [] testCount = 0 for instrId, instruction in self.instrId.items(): code = namespace + '::Decoder dec;\n' pattern = instruction[0] try: pattern[0][0] pattern = pattern[0] except: pass for i in range(0, len(pattern)): if pattern[i] == None: if ranGen.random() > 0.5: pattern[i] = '1' else: pattern[i] = '0' else: pattern[i] = str(pattern[i]) if instrId == -1: expectedId = self.instrNum else: # Now I have to check for the presence of a sub-instruction and, in case, # correct the target of the test expectedId = None for instr in self.instrSub[instrId]: found = True revInstrPattern = instr.bitstring revInstrPattern.reverse() for i in range(0, len(pattern)): if revInstrPattern[i] != None and int( pattern[i]) != revInstrPattern[i]: found = False if found: expectedId = instr.id break if expectedId == None: expectedId = instrId pattern.reverse() if instrId != -1: code += '// Checking Instruction ' + self.instrName[ instrId] + '\n' else: code += '// Checking Invalid Instruction\n' code += 'BOOST_CHECK_EQUAL(dec.decode( ' + hex( int(''.join(pattern), 2)) + ' ), ' + str(expectedId) + ');\n' curTest = cxx_writer.writer_code.Code(code) curTest.addInclude(['boost/test/test_tools.hpp', 'decoder.hpp']) if instrId != -1: testName = self.instrName[instrId] + '_' + str( testCount) + '_decode' else: testName = 'Invalid_' + str(testCount) + '_decode' curTestFunction = cxx_writer.writer_code.Function( testName, curTest, cxx_writer.writer_code.voidType) from procWriter import testNames testNames.append(testName) allTests.append(curTestFunction) testCount += 1 return allTests