summaryrefslogtreecommitdiffstats
path: root/src/usr/isteps/expupd/test/expupdatetest.H
blob: 45c70cab2b4b6bd6b1201bc90bfe45c3c78aa943 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/isteps/expupd/test/expupdatetest.H $                  */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2019                             */
/* [+] 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                                                     */

#ifndef __EXPUPDATETEST_H
#define __EXPUPDATETEST_H

/**
 *  @file expupdatetest.H
 *
 *  @brief Test cases for explorer chip firmware update
 */

#include <cxxtest/TestSuite.H>
#include <errl/errlmanager.H>
#include <errl/errlentry.H>
#include <fapi2.H>
#include <plat_hwp_invoker.H>
#include <lib/inband/exp_inband.H>
#include <exp_data_structs.H>
#include <exp_fw_update.H>
#include <generic/memory/lib/utils/endian_utils.H>
#ifndef __HOSTBOOT_RUNTIME
#include <vfs/vfs.H> // module_is_loaded & module_load
#endif
#include <test/exptest_utils.H>

const char MSS_LIBRARY_NAME[] = "libisteps_mss.so";
const char EXPUPD_LIBRARY_NAME[] = "libexpupd.so";

/**
 * @brief Generic function to load a module
 * @param o_module_loaded - returns true if module is loaded by this function
 * @param i_modName - module name to load
 * @return error handle if module_load call fails
 */
errlHndl_t loadModule(bool & o_module_loaded, const char * i_modName)
{
    errlHndl_t err = nullptr;
    o_module_loaded = false;

// VFS functions only compilable in non-runtime environment
#ifndef __HOSTBOOT_RUNTIME
    if(!VFS::module_is_loaded(i_modName))
    {
        err = VFS::module_load(i_modName);
        if(err)
        {
            TS_FAIL("loadModule() - %s load failed", i_modName );
        }
        else
        {
            o_module_loaded = true;
            TS_TRACE("loadModule: %s loaded", i_modName);
        }
    }
#endif
    return err;
}

/**
 * @brief Generic function to unload a module
 * @param i_modName - module name to load
 * @return error handle if module_unload call fails
 */
errlHndl_t unloadModule(const char * i_modName)
{
    errlHndl_t err = nullptr;

// VFS function only compilable in non-runtime environment
#ifndef __HOSTBOOT_RUNTIME
    err = VFS::module_unload(i_modName);
    if(err)
    {
        TS_FAIL("unloadExplorerModule() - %s unload failed", i_modName );
    }
    else
    {
        TS_TRACE("unloadModule: %s unloaded", i_modName);
    }
#endif
    return err;
}

class ExpUpdateTest: public CxxTest::TestSuite
{
  public:

    /**
     *  @brief Test the explorer firmware update procedure
     */
    void  testExpFwUpdate( void )
    {
        errlHndl_t l_errl = nullptr;

        uint8_t l_dataBuffer[4096] = {0};

        // Create a vector of TARGETING::Target pointers
        TARGETING::TargetHandleList l_chipList;

        // Get a list of all of the functioning ocmb chips
        TARGETING::getAllChips(l_chipList, TARGETING::TYPE_OCMB_CHIP, true);

        TARGETING::HB_MUTEX_SERIALIZE_TEST_LOCK_ATTR l_mutex = exptest::getTestMutex();
        if (l_mutex == nullptr)
        {
            TS_FAIL("testExpFwUpdate: unable to get test mutex");
        }
        else
        {
            for (const auto & l_ocmb: l_chipList)
            {
                fapi2::Target<fapi2::TARGET_TYPE_OCMB_CHIP>l_fapi2_target(l_ocmb);

                // Inband operations can't be run at the same time
                // atomic section >>
                mutex_lock(l_mutex);

                // Invoke procedure
                FAPI_INVOKE_HWP(l_errl, exp_fw_update, l_fapi2_target,
                                l_dataBuffer, sizeof(l_dataBuffer));

                // << atomic section
                mutex_unlock(l_mutex);
                if (l_errl)
                {
#if 0  // skipping exp_fw_update error until simics is changed - @fixme:RTC-209865
                    TS_FAIL("Error from exp_fw_update for 0x%.8X target",
                        TARGETING::get_huid(l_ocmb));
#endif
                    break;
                }
            }

            if (l_errl)
            {
                errlCommit(l_errl, CXXTEST_COMP_ID);
            }
        }

        TS_INFO("testExpFwUpdate: exiting");
    };

    /**
     * @brief Constructor
     */
    ExpUpdateTest() : CxxTest::TestSuite()
    {
        mss_module_loaded = false;
        expupd_module_loaded = false;

        // All modules are loaded by runtime,
        // so testcase loading of modules is not required
#ifndef __HOSTBOOT_RUNTIME
        errlHndl_t err = nullptr;

        err = loadModule(mss_module_loaded, MSS_LIBRARY_NAME);
        if(err)
        {
            TS_FAIL("ExpUpdateTest() - Constuctor: failed to load MSS module");
            errlCommit( err, CXXTEST_COMP_ID );
        }
        err = loadModule(expupd_module_loaded, EXPUPD_LIBRARY_NAME);
        if(err)
        {
            TS_FAIL("ExpUpdateTest() - Constuctor: failed to load EXPUPD module");
            errlCommit( err, CXXTEST_COMP_ID );
        }
#endif
    };


    /**
     * @brief Destructor
     */
    ~ExpUpdateTest()
    {
        errlHndl_t err = nullptr;
        if (mss_module_loaded)
        {
            err = unloadModule(MSS_LIBRARY_NAME);
            if(err)
            {
                TS_FAIL("~ExpUpdateTest() - Destructor: failed to unload MSS module");
                errlCommit( err, CXXTEST_COMP_ID );
            }
        }
        if (expupd_module_loaded)
        {
            err = unloadModule(EXPUPD_LIBRARY_NAME);
            if(err)
            {
                TS_FAIL("~ExpUpdateTest() - Destructor: failed to unload EXPUPD module");
                errlCommit( err, CXXTEST_COMP_ID );
            }
        }

    };

    private:
      // use this to keep track of if we need to unload any
      // modules loaded by this testcase
      bool mss_module_loaded;
      bool expupd_module_loaded;
};

#endif
OpenPOWER on IntegriCloud