summaryrefslogtreecommitdiff
path: root/maximus/ethernet/src/EthernetProcessorTest.cpp
blob: 8fee360a58bdff3ac512a1fe33fdec1f04b79fbc (plain)
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include "EthernetProcessorTest.h"

#include "EthernetProcessor.h"
#include "CoreEngine.h"
#include "ISystem.h"
#include "EtherSciMsg.h"

#include "Logger.h"
#include "Error.h"

using namespace std;

CPPUNIT_TEST_SUITE_REGISTRATION (EthernetProcessorTest);

bool bTest = false;

void interfaceCbTest ( EtherSciMsg & ether )
{
  logTest();

  bTest = true;
}


void EthernetProcessorTest::setUp (void)
{
  logTest();

  mpCoreEngine = new CoreEngine();
  mpEthernetProcessor = (EthernetProcessor *)mpCoreEngine->getEthernet();
  CPPUNIT_ASSERT_MESSAGE ( "Ethernet processor pointer is NULL", NULL != mpEthernetProcessor );
}


void EthernetProcessorTest::tearDown (void) 
{
  logTest();

  if (NULL != mpEthernetProcessor)
  {
    mpEthernetProcessor = NULL;
  }
  if (NULL != mpCoreEngine)
  {
    delete (mpCoreEngine);
    mpCoreEngine = NULL;
  }
}


void EthernetProcessorTest::initTest (void)
{
  logTest();

  CPPUNIT_ASSERT_MESSAGE ( "init failed", mpEthernetProcessor->init(&interfaceCbTest) );
}


void EthernetProcessorTest::createEtherTest (void)
{
  logTest();

  EtherSciMsg * pEtherSciMsg = mpEthernetProcessor->createEther();
  CPPUNIT_ASSERT_MESSAGE ( "createEther failed", NULL != pEtherSciMsg );

  delete (pEtherSciMsg);
  pEtherSciMsg = NULL;
}


void EthernetProcessorTest::sendEtherTest (void)
{
  logTest();

  EtherSciMsg * pEtherSciMsg = mpEthernetProcessor->createEther();
  CPPUNIT_ASSERT_MESSAGE ( "Ether SCI message pointer is NULL", NULL != pEtherSciMsg );

  // create the destination station
  Sci_Msg_Station_Id stationId = mpCoreEngine->getSystem()->createStation(mpCoreEngine->getSystem()->getDefaultStationExecutable());
  mpCoreEngine->getSystem()->updateStationStatus(stationId, MAXIMUS_STATION_STATUS_IDLE);
  pEtherSciMsg->setSciMsgStationId(stationId);

  CPPUNIT_ASSERT_MESSAGE ( "Ether SCI message has not been sent", mpEthernetProcessor->sendEther(*pEtherSciMsg) );

  mpCoreEngine->getSystem()->removeStation(stationId);

  if (NULL != pEtherSciMsg)
  {
    delete (pEtherSciMsg);
    pEtherSciMsg = NULL;
  }
}


void EthernetProcessorTest::receiveEtherTest (void)
{
  logTest();

  EtherSciMsg * pEtherSciMsg = mpEthernetProcessor->createEther();

  unsigned long length = 100;
  unsigned char payload[length];
  memset(payload, 'M', length);
  pEtherSciMsg->setSpecializedSciMsgDataLength(length);
  pEtherSciMsg->setSpecializedSciMsgData(payload);

  // create the destination station
  Sci_Msg_Station_Id stationId = mpCoreEngine->getSystem()->createStation(mpCoreEngine->getSystem()->getDefaultStationExecutable());

  CPPUNIT_ASSERT_MESSAGE ( "receiveEther failed",
                           mpEthernetProcessor->receiveEther(*pEtherSciMsg) );

  mpCoreEngine->getSystem()->removeStation(stationId);

  if (NULL != pEtherSciMsg)
  {
    delete (pEtherSciMsg);
    pEtherSciMsg = NULL;
  }
}


void EthernetProcessorTest::allocTapTest (void)
{
  logTest();

  try
  {
    char dev[] = "tap0\0";
    CPPUNIT_ASSERT_MESSAGE ( "allocTap failed",
                             0 <= mpEthernetProcessor->allocTap(dev) );
  }
  catch (...)
  {
    CPPUNIT_ASSERT_MESSAGE ( "allocTap failed", (EPERM == errno) || (EACCES == errno) );
  }
}