summaryrefslogtreecommitdiffstats
path: root/src/usr/pnor/runtime/test/testpnor_rt.H
blob: a1a8777e43ab1ac4be60a514c00a86ac0db93fa3 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/pnor/runtime/test/testpnor_rt.H $                     */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2014,2016                        */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
#include <cxxtest/TestSuite.H>
#include <errl/errlmanager.H>
#include <errl/errlentry.H>
#include <devicefw/userif.H>

#include <pnor/pnorif.H>
#include "../../pnor_common.H"
#include "../rt_pnor.H"

#include <runtime/interface.h>
#include <trace/interface.H>

#include "../../ffs.h"           //Common header file with BuildingBlock.
#include "../../common/ffs_hb.H" //Hostboot def of user data in ffs_entry struct

extern trace_desc_t* g_trac_pnor;
using namespace TARGETING;

/*
 * these taest cases are turned off as they have dependency on pnorddtest cases
 */
class PnorRtTest : public CxxTest::TestSuite
{
    public:
    /**
     * @brief: testTOC
     *      tests that the TOC is read/parsed properly during runtime
     */
    void testTOC (void)
    {
#if 1
        TRACFCOMP(g_trac_pnor, "PnorRtTest::testTOC - skipping - as it"
                " adversly affects pnorddtests");
#else
        TRACFCOMP(g_trac_pnor, "PnorRtTest::testTOC Start" );
        errlHndl_t l_err = NULL;
        uint32_t l_proc = 0;
        uint64_t offset = 0;
        uint8_t* tocHeader = new uint8_t[PAGESIZE];
        uint8_t* tocEntry = new uint8_t[PAGESIZE];
        uint8_t* corruptBuffer = new uint8_t[PAGESIZE];

        // Corrupt both ffs header and first entry for each TOC
        for (uint32_t cur_TOC = 0; cur_TOC < PNOR::NUM_TOCS; ++cur_TOC)
        {
            uint32_t TOC_used = cur_TOC;
            offset = (cur_TOC == 0) ? PNOR::TOC_0_OFFSET : PNOR::TOC_1_OFFSET;

            // Read cur_TOC header data
            l_err = RtPnor::getInstance().readFromDevice(l_proc,PNOR::TOC,
                                  offset,PAGESIZE,false,tocHeader);
            if (l_err)
            {
                TS_FAIL("PnorRtTest::testTOC: readFromDevice failed");
                break;
            }

            // Corrupt cur_TOC header data
            memcpy(corruptBuffer, tocHeader, PAGESIZE);
            corruptBuffer[0] = 0xFF;
            corruptBuffer[1] = 0xFF;

            l_err = RtPnor::getInstance().writeToDevice(l_proc,PNOR::TOC,
                    offset,PAGESIZE,false,corruptBuffer);
            if (l_err)
            {
                TS_FAIL("PnorRtTest::testTOC: writeToDevice failed");
            }

            // Check if cur_TOC failed that other TOC is used
            l_err = RtPnor::getInstance().readTOC();
            if (l_err)
            {
                TS_FAIL("PnorRtTest::testTOC: readTOC failed");
            }

            TOC_used = RtPnor::getInstance().iv_TOC_used;
            TRACFCOMP(g_trac_pnor, "PnorRtTest::testTOC : TOC %d Corrupt"
                    " Header, Toc_used = %d", cur_TOC, TOC_used);

            if (TOC_used == cur_TOC)
            {
                TS_FAIL("PnorRtTest::testTOC>ERROR:TOC %d header is corrupted,"
                        " did not use other TOC");
                break;
            }
            // Fix cur_TOC header
            l_err = RtPnor::getInstance().writeToDevice(l_proc,PNOR::TOC,
                    offset,PAGESIZE,false,tocHeader);
            if (l_err)
            {
                TS_FAIL("PnorRtTest::testTOC: writeToDevice failed");
            }

            // Read cur_TOC first entry data
            l_err = RtPnor::getInstance().readFromDevice(l_proc,PNOR::TOC,
                                  offset+FFS_HDR_SIZE,PAGESIZE,false,tocEntry);
            if (l_err)
            {
                TS_FAIL("PnorRtTest::testTOC: readTOC failed");
                break;
            }

            // Corrupt cur_TOC header data
            memcpy(corruptBuffer, tocEntry, PAGESIZE);
            corruptBuffer[0] = 0xFF;
            corruptBuffer[1] = 0xFF;

            l_err = RtPnor::getInstance().writeToDevice(l_proc,PNOR::TOC,
                    offset+FFS_HDR_SIZE,PAGESIZE,false,corruptBuffer);
            if (l_err)
            {
                TS_FAIL("PnorRtTest::testTOC: writeToDevice failed");
            }

            // Check if cur_TOC failed that other TOC is used
            TOC_used = cur_TOC;
            l_err = RtPnor::getInstance().readTOC();
            if (l_err)
            {
                TS_FAIL("PnorRtTest::testTOC: readTOC failed");
            }
            TOC_used = RtPnor::getInstance().iv_TOC_used;
            TRACFCOMP(g_trac_pnor,"PnorRtTest::testTOC:TOC %d Corrupt"
                    " Entry, Toc_used = %d", cur_TOC, TOC_used);

            if (TOC_used == cur_TOC)
            {
                TS_FAIL("PnorRtTest::testTOC>ERROR: TOC %d entry is corrupted,"
                        " did not use other TOC", cur_TOC);
            }

            // Fix cur_TOC first entry
            l_err = RtPnor::getInstance().writeToDevice(l_proc,PNOR::TOC,
                    offset+FFS_HDR_SIZE,PAGESIZE,false,tocEntry);
            if (l_err)
            {
                TS_FAIL("PnorRtTest::testTOC: writeToDevice failed");
            }
        }
        delete tocHeader;
        delete tocEntry;
        delete corruptBuffer;

        TRACFCOMP(g_trac_pnor, "PnorRtTest::testTOC End");
#endif
    }

    /**
     * @brief RtPnor::testPnorReadWrite
     *       Compares the values read and written by runtime interfaces and
     *       IPL interfaces
     */
    void testPnorReadWrite(void)
    {
        TRACFCOMP(g_trac_pnor, ENTER_MRK"testPnorReadWrite");
        do {
            errlHndl_t l_err = NULL;
            uint32_t   l_proc = 0;
            uint64_t   l_offset = PNOR::pnorTestSec_rt_readwrite_offset;
            uint64_t   l_writeData = 0x0123456789ABCDEF;
            PNOR::SectionId l_id = PNOR::TEST;
            PNOR::SectionInfo_t l_info;

            size_t l_sizeBytes = (RtPnor::getInstance().iv_TOC[l_id].size) -
                                 l_offset;
            void*  l_readData  = malloc (l_sizeBytes);

            //read via hostInterfaces
            l_err = RtPnor::getInstance().readFromDevice(l_proc,l_id,l_offset,
                                          l_sizeBytes,true,l_readData);
            if(l_err)
            {
                TS_FAIL("testPnorReadWrite: readFromDevice failed");
                break;
            }

            //read using getSectionInfo
            l_err = PNOR::getSectionInfo(l_id, l_info);
            if (l_err)
            {
                TS_FAIL("testPnorReadWrite: getSectionInfo failed");
                break;
            }

            void* l_gData = reinterpret_cast<void*> (l_info.vaddr);

            //verify that data is read correctly
            if (0 != memcmp (l_readData, l_gData, l_sizeBytes))
            {
                TS_FAIL("testPnorReadWrite: read failed");
                break;
            }
            TRACFCOMP(g_trac_pnor, "testPnorReadWrite: read successfull");

            /***********************************************************/
            //make changes to the getSectionInfo pointer and call flush
            uint8_t* l_vaddr =  reinterpret_cast<uint8_t*>(l_info.vaddr);

            memcpy(l_vaddr, &l_writeData, 4);
            memcpy(l_vaddr+PAGESIZE+20, &l_writeData, 4);

            l_err = PNOR::flush(l_id);
            if (l_err)
            {
                TS_FAIL("testPnorReadWrite: flush failed");
                break;
            }

            /***********************************************************/
            //calling read again to make sure data was written properly
            //using pnor_wirte
            l_err = RtPnor::getInstance().readFromDevice(l_proc,l_id,l_offset,
                                                l_sizeBytes,true,l_readData);
            if(l_err)
            {
                TS_FAIL("testPnorReadWrite: readFromDevice failed");
                break;
            }

            if (0 != memcmp (l_readData, l_gData, l_sizeBytes))
            {
                TS_FAIL("testPnorReadWrite: flush failed");
                break;
            }
            TRACFCOMP(g_trac_pnor, "testPnorReadWrite: flush passed");

        } while (0);
        TRACFCOMP(g_trac_pnor, EXIT_MRK"testPnorReadWrite");
    }

};
OpenPOWER on IntegriCloud