File: unittest_irq.cpp

package info (click to toggle)
simulavr 1.0.0%2Bgit20160221.e53413b-1
  • links: PTS
  • area: main
  • in suites: buster
  • size: 5,748 kB
  • sloc: cpp: 35,491; python: 6,991; ansic: 3,567; makefile: 1,072; sh: 653; asm: 414; tcl: 320
file content (97 lines) | stat: -rw-r--r-- 3,791 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <iostream>
using namespace std;

#include "gtest.h"

#include "avrdevice.h"
#include "atmega16_32.h"
#include "systemclock.h"

TEST( SESSION_IRQ, IRQ1 )
{
   AvrDevice *dev1= new AvrDevice_atmega32;
   dev1->Load("session_irq_check/check.atmega32.o");
   dev1->SetClockFreq(136);    // 7.3728
   dev1->RegisterTerminationSymbol("stopsim");
   SystemClock::Instance().Add(dev1);
   SystemClock::Instance().Endless(); 

   EXPECT_EQ(0x08, (unsigned char)(*(dev1->rw[0x5e]))) << "Wrong Stack pointer SPH found" << endl;
   EXPECT_EQ(0x5b, (unsigned char)(*(dev1->rw[0x5d]))) << "Wrong Stack pointer SPL found" << endl;
}

TEST( SESSION_IRQ, TC1)
{
   AvrDevice *dev1= new AvrDevice_atmega32;
   dev1->Load("session_irq_check/tc1.atmega32.o");
   dev1->SetClockFreq(136);    // 7.3728
   dev1->RegisterTerminationSymbol("stopsim");
   dev1->RegisterTerminationSymbol("exit");
   SystemClock::Instance().Add(dev1);
   SystemClock::Instance().Endless();

   EXPECT_EQ( 0x55, (unsigned char)(*(dev1->rw[0x38]))) << "Wrong PORTB value" << endl;
}
TEST( SESSION_IRQ, TC2)
{
   AvrDevice *dev1= new AvrDevice_atmega32;
   dev1->Load("session_irq_check/tc2.atmega32.o");
   dev1->SetClockFreq(136);    // 7.3728
   dev1->RegisterTerminationSymbol("stopsim");
   dev1->RegisterTerminationSymbol("exit");
   SystemClock::Instance().Add(dev1);
   SystemClock::Instance().Endless();

   EXPECT_EQ( 0x55, (unsigned char)(*(dev1->rw[0x38]))) << "Wrong PORTB value" << endl;
}

TEST( SESSION_IRQ, TC3)
{
   AvrDevice *dev1= new AvrDevice_atmega32;
   dev1->Load("session_irq_check/tc3.atmega32.o");
   dev1->SetClockFreq(136);    // 7.3728
   dev1->RegisterTerminationSymbol("stopsim");
   dev1->RegisterTerminationSymbol("exit");
   SystemClock::Instance().Add(dev1);
   SystemClock::Instance().Endless();

   EXPECT_EQ( 0x55, (unsigned char)(*(dev1->rw[0x38]))) << "Wrong PORTB value" << endl;
}

TEST( SESSION_IRQ, TC4)
{
   AvrDevice *dev1= new AvrDevice_atmega32;
   dev1->Load("session_irq_check/tc4.atmega32.o");
   dev1->SetClockFreq(136);    // 7.3728
   dev1->RegisterTerminationSymbol("stopsim");
   dev1->RegisterTerminationSymbol("exit");
   SystemClock::Instance().Add(dev1);
   SystemClock::Instance().Endless();

   EXPECT_EQ( 0xff, (unsigned char)(*(dev1->rw[0x38]))) << "Wrong PORTB value" << endl;
   EXPECT_EQ( 0x01, (unsigned char)(*(dev1->rw[18]  ))) << "Wrong value in R18" << endl;
   EXPECT_EQ( 0x02, (unsigned char)(*(dev1->rw[19]  ))) << "Wrong value in R19" << endl;
   EXPECT_EQ( 0x00, (unsigned char)(*(dev1->rw[20]  ))) << "Wrong value in R20" << endl;
}

TEST( SESSION_IRQ, TC5)
{
   AvrDevice *dev1= new AvrDevice_atmega32;
   dev1->Load("session_irq_check/tc5.atmega32.o");
   dev1->SetClockFreq(136);    // 7.3728
   dev1->RegisterTerminationSymbol("stopsim");
   dev1->RegisterTerminationSymbol("exit");
   SystemClock::Instance().Add(dev1);
   SystemClock::Instance().Endless();

   unsigned int addr_of_vector = 0x62; // TODO: get address of vector from file symbol!
   EXPECT_EQ( 0x0f, (unsigned char)(*(dev1->rw[addr_of_vector++]))) << "Wrong IRQ Order " << endl;
   EXPECT_EQ( 0x0e, (unsigned char)(*(dev1->rw[addr_of_vector++]))) << "Wrong IRQ Order " << endl;
   EXPECT_EQ( 0x0c, (unsigned char)(*(dev1->rw[addr_of_vector++]))) << "Wrong IRQ Order " << endl;
   EXPECT_EQ( 0x08, (unsigned char)(*(dev1->rw[addr_of_vector++]))) << "Wrong IRQ Order " << endl;
   EXPECT_EQ( 0x0f, (unsigned char)(*(dev1->rw[addr_of_vector++]))) << "Wrong IRQ Order " << endl;
   EXPECT_EQ( 0x0d, (unsigned char)(*(dev1->rw[addr_of_vector++]))) << "Wrong IRQ Order " << endl;
   EXPECT_EQ( 0x0c, (unsigned char)(*(dev1->rw[addr_of_vector++]))) << "Wrong IRQ Order " << endl;
   EXPECT_EQ( 0x08, (unsigned char)(*(dev1->rw[addr_of_vector++]))) << "Wrong IRQ Order " << endl;
}