Ejemplo n.º 1
0
    def display_addr_refs(self, refs, table_width):

        table = Table(num_cols=len(REF_COL_NAMES),
                      width=table_width,
                      alignment='right')
        table.header[:] = REF_COL_NAMES

        for ref in refs:

            if ref.tag is not None:
                ref_tag = ref.tag
            else:
                ref_tag = 'n/a'

            if ref.index is not None:
                ref_index = ref.index
            else:
                ref_index = 'n/a'

            if ref.offset is not None:
                ref_offset = ref.offset
            else:
                ref_offset = 'n/a'

            # Display data for each address as a row in the table
            table.rows.append(
                (ref.word_addr,
                 BinaryAddress.prettify(ref.bin_addr, MIN_BITS_PER_GROUP),
                 BinaryAddress.prettify(ref_tag, MIN_BITS_PER_GROUP),
                 BinaryAddress.prettify(ref_index, MIN_BITS_PER_GROUP),
                 BinaryAddress.prettify(ref_offset,
                                        MIN_BITS_PER_GROUP), ref.cache_status))

        print(table)
Ejemplo n.º 2
0
 def _test_str_align(self, alignment, just):
     table_width = 16
     num_cols = 2
     col_width = table_width // num_cols
     table = Table(
         num_cols=num_cols, width=table_width, alignment=alignment)
     table.header = ['First', 'Last']
     table.rows.append(['Bob', 'Smith'])
     table.rows.append(['John', 'Earl'])
     nose.assert_equal(str(table), '{}{}\n{}\n{}{}\n{}{}'.format(
         just('First', col_width), just('Last', col_width),
         '-' * table_width,
         just('Bob', col_width), just('Smith', col_width),
         just('John', col_width), just('Earl', col_width)))
Ejemplo n.º 3
0
 def _test_str_align(self, alignment, just):
     table_width = 16
     num_cols = 2
     col_width = table_width // num_cols
     table = Table(
         num_cols=num_cols, width=table_width, alignment=alignment)
     table.header = ['First', 'Last']
     table.rows.append(['Bob', 'Smith'])
     table.rows.append(['John', 'Earl'])
     nose.assert_equal(str(table), '{}{}\n{}\n{}{}\n{}{}'.format(
         just('First', col_width), just('Last', col_width),
         '-' * table_width,
         just('Bob', col_width), just('Smith', col_width),
         just('John', col_width), just('Earl', col_width)))
Ejemplo n.º 4
0
def test_init_optional():
    """should initialize table with optional parameters if supplied"""
    table = Table(num_cols=5, width=78, alignment='right', title='Cache')
    nose.assert_equal(table.num_cols, 5)
    nose.assert_equal(table.width, 78)
    nose.assert_equal(table.alignment, 'right')
    nose.assert_equal(table.title, 'Cache')
Ejemplo n.º 5
0
def test_init_default():
    """should initialize table with required parameters and default values"""
    table = Table(num_cols=5, width=78)
    nose.assert_equal(table.num_cols, 5)
    nose.assert_equal(table.width, 78)
    nose.assert_equal(table.alignment, 'left')
    nose.assert_equal(table.title, None)
    nose.assert_equal(table.header, [])
    nose.assert_equal(table.rows, [])
Ejemplo n.º 6
0
    def display_cache(self, cache, table_width):

        table = Table(num_cols=len(cache),
                      width=table_width,
                      alignment='center')
        table.title = 'Cache'

        cache_set_names = sorted(cache.keys())
        # A cache containing only one set is considered a fully associative
        # cache
        if len(cache) != 1:
            # Display set names in table header if cache is not fully
            # associative
            table.header[:] = cache_set_names

        # Add to table the cache entries for each block
        table.rows.append([])
        for index in cache_set_names:
            blocks = cache[index]
            table.rows[0].append(' '.join(','.join(map(str, entry['data']))
                                          for entry in blocks))

        print(table)
Ejemplo n.º 7
0
def test_str_no_title():
    """should not display title if not originally supplied"""
    table = Table(num_cols=5, width=12)
    nose.assert_equal(str(table).strip(), '')
Ejemplo n.º 8
0
def test_str_title():
    """should correctly display title"""
    table = Table(num_cols=5, width=12, title='Cache')
    nose.assert_regexp_matches(
        ''.join(('Cache'.center(12), '\n', ('-' * 12))), str(table))
Ejemplo n.º 9
0
def test_get_separator():
    """should return the correct ASCII separator string"""
    table = Table(num_cols=5, width=78)
    nose.assert_equal(table.get_separator(), '-' * 78)
Ejemplo n.º 10
0
def test_get_separator():
    """should return the correct ASCII separator string"""
    table = Table(num_cols=5, width=78)
    nose.assert_equal(table.get_separator(), '-' * 78)