summaryrefslogtreecommitdiff
path: root/cesar/maximus/sci/utest/server/src/TestSciServer.cpp
blob: 7d76ccf1f6ef5d037001cb8dd2be33abc2265c7e (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
/* Maximus project {{{
 *
 * Copyright (C) 2012 MStar Semiconductor
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    maximus/sci/utest/server/src/TestSciServer.cpp
 * \ingroup maximus_sci_utest_server
 *
 */
#include <cppunit/extensions/TestFactoryRegistry.h>

#include "maximus/interface/station/inc/Station.h"
#include "maximus/sci/inc/SciServer.h"
#include "maximus/utils/inc/Error.h"

#include "inc/TestSciServer.h"
#include "inc/fake_Maximus.h"
#include "inc/PipoProcessor.h"
#include "inc/PipoSciMsg.h"

CPPUNIT_TEST_SUITE_REGISTRATION (TestSciServer);

void
TestSciServer::setUp ()
{
    server = new SciServer (sta_list);
    max = new Maximus ();
}

void
TestSciServer::tearDown ()
{
    delete server;
    delete max;
    max = NULL;
    server = NULL;
}

void
TestSciServer::test_pipe_bidir ()
{
    std::cout << __func__  << ": 0% .." << std::flush;
    Network_Clock_Tick time = 0;

    static const size_t progress[3] = {
        /* 25% */
        SCI_MSG_MAX_SIZE / 4,
        /* 50% */
        SCI_MSG_MAX_SIZE / 2,
        /* 75% */
        (3 * SCI_MSG_MAX_SIZE) / 4,
    };

    try
    {
        PipoProcessor *pipo_proc = new PipoProcessor (*server, *max);
        server->register_current_tick_addr (&time);

        Station *fake_sta = new Station (*max,
            "noexec", 0, SCI_MSG_MAX_SIZE);
        sta_list.push_back (fake_sta);

        PipoSciMsg *msg = NULL;
        for (size_t i = 0; i < SCI_MSG_MAX_SIZE; i++)
        {
            if (i == progress[0])
                std::cout << "25% .." << std::flush;
            if (i == progress[1])
                std::cout << "50% .." << std::flush;
            if (i == progress[2])
                std::cout << "75% .." << std::flush;

            msg = new PipoSciMsg (i);
            msg->set_sci_stationid (fake_sta->getStationId ());

            msg->setup_and_send (*server);
            delete msg;
            msg = NULL;

            do
            {
                server->process ();
            } while (!pipo_proc->is_msg_received ());


            /* Is the message have been drive to pipo_proc. */
            CPPUNIT_ASSERT (pipo_proc->is_good_size (i));
        }
        std::cout << "100%" << std::endl;

        sta_list.clear ();
        delete fake_sta;
        delete pipo_proc;
    }
    catch (Error &e)
    {
        e.display ();
        CPPUNIT_FAIL ("Error catched !");
    }
}