summaryrefslogtreecommitdiffstats
path: root/src/usr/diag/attn/test/attnfakesys.H
blob: 2ab0c4ec7f6fff66de6a4d5b52ca0e884d3a6418 (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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
/*  IBM_PROLOG_BEGIN_TAG
 *  This is an automatically generated prolog.
 *
 *  $Source: src/usr/diag/attn/test/attnfakesys.H $
 *
 *  IBM CONFIDENTIAL
 *
 *  COPYRIGHT International Business Machines Corp. 2012
 *
 *  p1
 *
 *  Object Code Only (OCO) source materials
 *  Licensed Internal Code Source Materials
 *  IBM HostBoot Licensed Internal Code
 *
 *  The source code for this program is not published or other-
 *  wise divested of its trade secrets, irrespective of what has
 *  been deposited with the U.S. Copyright Office.
 *
 *  Origin: 30
 *
 *  IBM_PROLOG_END_TAG
 */
#ifndef __TEST_ATTNFAKESYS_H
#define __TEST_ATTNFAKESYS_H

/**
 * @file attnfakesys.H
 *
 * @brief HBATTN fake system class definition.
 */

#include "../attnfwd.H"
#include "../attnops.H"
#include "../attnprd.H"
#include "../attnresolv.H"
#include <map>

namespace ATTN
{

/**
 * @brief Event fake system event trace types.
 */
enum Event
{
    /**
     * @brief MASK_EVENT A simulated attention was masked.
     */
    MASK_EVENT,

    /**
     * @brief UNMASK_EVENT A simulated attention was unmasked.
     */
    UNMASK_EVENT,

    /**
     * @brief QUERY_EVENT A simulated attention was queried.
     */
    QUERY_EVENT,

    /**
     * @brief CALLPRD_EVENT A simulated attention was forwarded to PRD.
     */
    CALLPRD_EVENT,
};

/**
 * @brief FakeSystemProperties data associated with a simulated attention.
 */
struct FakeSystemProperties
{
    /**
     * @brief mask The mask state of the simulated attention.
     */
    bool mask;

    /**
     * @brief active The state of the simulated attention.
     */
    bool active;

    /**
     * @brief count The number of times the simulated attention has occurred.
     */
    uint64_t count;

    /**
     * @brief history Simlated aattention trace.
     */
    std::vector<uint64_t> history;

    /**
     * @brief ctor
     */
    FakeSystemProperties() : mask(false), active(false), count(0) {}
};

/**
 * @brief Comp Comparison functor for two PRDF::AttnData structs.
 */
struct Comp
{
    /**
     * @brief operator() Comparison functor for two PRDF::AttnData structs.
     *
     * @param[in] i_l One of two PRDF::AttnData structs to be compared.
     * @param[in] i_r One of two PRDF::AttnData structs to be compared.
     *
     * @return bool Comparison result.
     *
     * @retval[true] i_l < i_r;
     * @retval[false ] i_r < i_l;
     */
    bool operator()(const PRDF::AttnData & i_l,
            const PRDF::AttnData & i_r) const
    {
        return compare(i_l,  i_r) < 0;
    }
};

/**
 * @brief FakeSystem
 *
 * AttentionOps, Resolver and PRD implementations that simulate
 * normal system behavior.
 */
class FakeSystem :
    public AttentionOps,
    public Resolver,
    public PrdImpl
{
    public:

        /**
         * @brief mask Mask this attention.
         *
         * @param[in] i_data the attention to be masked.
         *
         * @return errlHndl_t Error log.
         *
         * @retval[0] No error.
         * @retval[!0] Unexpected error occurred.
         */
        virtual errlHndl_t mask(const PRDF::AttnData & i_data);

        /**
         * @brief unmask Unmask this attention.
         *
         * @param[in] i_data the attention to be unmasked.
         *
         * @return errlHndl_t Error log.
         *
         * @retval[0] No error.
         * @retval[!0] Unexpected error occurred.
         */
        virtual errlHndl_t unmask(const PRDF::AttnData & i_data);

        /**
         * @brief query Test to see if this attention is active.
         *
         * @param[in] i_data the attention to be queried.
         * @param[out] o_active true if attention is active.
         *
         * @return errlHndl_t Error log.
         *
         * @retval[0] No error.
         * @retval[!0] Unexpected error occurred.
         */
        virtual errlHndl_t query(const PRDF::AttnData & i_data,
                bool & o_active);

        /**
         * @brief resolve Find attentions of the supplied type on the
         *        supplied target.
         *
         * @param[in] i_proc The proc on which to look for attentions.
         * @param[out] o_attentions Where to put attentions when found.
         *
         * @return errlHndl_t Error log.
         *
         * @retval[0] No error.
         * @retval[!0] Unexpected error occurred.
         */
        virtual errlHndl_t resolve(
                TARGETING::TargetHandle_t i_proc,
                AttentionList & o_attentions);

        /**
         * @brief callPrd Simulate a call to PRD.
         *
         * @param[in] i_attentions List of attentions for PRD to analyze.
         *
         * @return errlHndl_t Error log.
         *
         * @retval[0] No error occurred.
         * @retval[!0] Unexpected error occurred.
         */
        virtual errlHndl_t callPrd(const AttentionList & i_attentions);

        /**
         * @brief install install this class as the prd and resolver
         *        implementation.
         */
        void install();

        /**
         * @brief raiseAttentions Attempt to raise random attentions.
         *
         * @param[in] i_q The message Q where simulated attention
         *                messages should be sent.
         * @param[i_count] The number of attentions to generate.
         *
         * @return The actual number of attentions raised.
         */
        uint64_t raiseAttentions(msg_q_t i_q, uint64_t i_count);

        /**
         * @brief validate Perform validation of the simulated system.
         *
         * @return The result of the validation.
         *
         * @retval[true] Result is valid.
         * @retval[false] Result is invalid.
         */
        virtual bool validate();

        /**
         * @brief ctor
         */
        FakeSystem();

        /**
         * @brief dtor
         */
        virtual ~FakeSystem();

    private:

        /**
         * @brief generateAttentions Generate random attentions.
         *
         * @param[in] i_count The number of attentions to generate.
         * @param[in/out] io_list Where generated attentions are placed.
         *
         * @return uint64_t The actual number of attentions generated.
         */
        uint64_t generateAttentions(uint64_t i_count, PRDF::AttnList & io_list);

        /**
         * @brief iv_map Attention <-> state association.
         */
        std::map<PRDF::AttnData, FakeSystemProperties, Comp> iv_map;

        /**
         * @brief iv_mutex iv_map protection.
         */
        mutex_t iv_mutex;
};
}
#endif
OpenPOWER on IntegriCloud