~ubuntu-branches/ubuntu/dapper/simulavr/dapper

« back to all changes in this revision

Viewing changes to regress/test_opcodes/test_ST_X.py

  • Committer: Bazaar Package Importer
  • Author(s): Shaun Jackman
  • Date: 2004-04-10 13:54:17 UTC
  • Revision ID: james.westby@ubuntu.com-20040410135417-zywapjyz252y65se
Tags: upstream-0.1.2.1
ImportĀ upstreamĀ versionĀ 0.1.2.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/env python
 
2
###############################################################################
 
3
#
 
4
# simulavr - A simulator for the Atmel AVR family of microcontrollers.
 
5
# Copyright (C) 2001, 2002  Theodore A. Roth
 
6
#
 
7
# This program is free software; you can redistribute it and/or modify
 
8
# it under the terms of the GNU General Public License as published by
 
9
# the Free Software Foundation; either version 2 of the License, or
 
10
# (at your option) any later version.
 
11
#
 
12
# This program is distributed in the hope that it will be useful,
 
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
# GNU General Public License for more details.
 
16
#
 
17
# You should have received a copy of the GNU General Public License
 
18
# along with this program; if not, write to the Free Software
 
19
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
20
#
 
21
###############################################################################
 
22
#
 
23
# $Id: test_ST_X.py,v 1.1 2002/04/04 22:16:54 troth Exp $
 
24
#
 
25
 
 
26
"""Test the ST_X opcode.
 
27
"""
 
28
 
 
29
import base_test
 
30
from registers import Reg, SREG
 
31
 
 
32
class ST_X_TestFail(base_test.TestFail): pass
 
33
 
 
34
class base_ST_X(base_test.opcode_test):
 
35
        """Generic test case for testing ST_X opcode.
 
36
 
 
37
        ST_X - Store Indirect to data space from Register using index X
 
38
 
 
39
        Operation: (X) <- Rd
 
40
 
 
41
        opcode is '1001 001d dddd 1100' where 0 <= d <= 31
 
42
 
 
43
        Only registers PC should be changed.
 
44
        """
 
45
        def setup(self):
 
46
                # Set the register values
 
47
                self.setup_regs[self.Rd] = self.Vd
 
48
                self.setup_regs[Reg.R26] = (self.X & 0xff)
 
49
                self.setup_regs[Reg.R27] = (self.X >> 8)
 
50
 
 
51
                # Return the raw opcode
 
52
                return 0x920C | (self.Rd << 4)
 
53
 
 
54
        def analyze_results(self):
 
55
                # check that result is correct
 
56
 
 
57
                # FIXME: [TRoth 2002/04/04] Is this really what we should expect?
 
58
                if self.Rd == Reg.R26:
 
59
                        expect = self.setup_regs[Reg.R26]
 
60
                elif self.Rd == Reg.R27:
 
61
                        expect = self.setup_regs[Reg.R27]
 
62
                else:                   
 
63
                        expect = self.Vd
 
64
 
 
65
                got = self.mem_byte_read( self.X )
 
66
                
 
67
                if expect != got:
 
68
                        self.fail('ST_X: expect=%02x, got=%02x' % (expect, got))
 
69
 
 
70
#
 
71
# Template code for test case.
 
72
# The fail method will raise a test specific exception.
 
73
#
 
74
template = """
 
75
class ST_X_r%02d_X%04x_v%02x_TestFail(ST_X_TestFail): pass
 
76
 
 
77
class test_ST_X_r%02d_X%04x_v%02x(base_ST_X):
 
78
        Rd = %d
 
79
        X = 0x%x
 
80
        Vd = 0x%x
 
81
        def fail(self,s):
 
82
                raise ST_X_r%02d_X%04x_v%02x_TestFail, s
 
83
"""
 
84
 
 
85
#
 
86
# automagically generate the test_ST_X_* class definitions.
 
87
#
 
88
code = ''
 
89
for d in range(0,32):
 
90
        for x in (0x10f, 0x1ff):
 
91
                for v in (0xaa, 0x55):
 
92
                        args = (d,x,v)*4
 
93
                        code += template % args
 
94
exec code