Skip to content

Commit

Permalink
Unit Tests For Adjusting SMF HOMER BAR
Browse files Browse the repository at this point in the history
This change introduces the unit tests for testing the helper functions
of the SMF functionality to move the HOMER BAR to secure memory.

Change-Id: I771240a554dbcef120fc476c26846f75d56592a0
RTC: 198825
Reviewed-on: http://rchgit01.rchland.ibm.com/gerrit1/68356
Tested-by: Jenkins Server <pfd-jenkins+hostboot@us.ibm.com>
Tested-by: Jenkins OP Build CI <op-jenkins+hostboot@us.ibm.com>
Tested-by: FSP CI Jenkins <fsp-CI-jenkins+hostboot@us.ibm.com>
Tested-by: Jenkins OP HW <op-hw-jenkins+hostboot@us.ibm.com>
Reviewed-by: Nicholas E. Bofferding <bofferdn@us.ibm.com>
Reviewed-by: Daniel M. Crowell <dcrowell@us.ibm.com>
  • Loading branch information
Ilya Smirnov authored and dcrowell77 committed Jan 9, 2019
1 parent 529e81c commit 4ba2815
Show file tree
Hide file tree
Showing 6 changed files with 538 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#
# OpenPOWER HostBoot Project
#
# Contributors Listed Below - COPYRIGHT 2010,2018
# Contributors Listed Below - COPYRIGHT 2010,2019
# [+] Google Inc.
# [+] International Business Machines Corp.
#
Expand Down Expand Up @@ -256,6 +256,7 @@ TESTCASE_MODULES += $(if $(CONFIG_VPO_COMPILE),,testruntime)
TESTCASE_MODULES += testintr
TESTCASE_MODULES += testfapi2
TESTCASE_MODULES += $(if $(CONFIG_FSP_BUILD),,testnvram)
TESTCASE_MODULES += testsmf

#******************************************************************
#KNOWN ISSUES (I might let these run but there is something wrong)
Expand Down
2 changes: 2 additions & 0 deletions src/usr/secureboot/smf/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,7 @@ MODULE = smf
OBJS += smf_utils.o
OBJS += smf.o

SUBDIRS += test.d

include ${ROOTPATH}/config.mk

33 changes: 33 additions & 0 deletions src/usr/secureboot/smf/test/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# IBM_PROLOG_BEGIN_TAG
# This is an automatically generated prolog.
#
# $Source: src/usr/secureboot/smf/test/makefile $
#
# OpenPOWER HostBoot Project
#
# Contributors Listed Below - COPYRIGHT 2018
# [+] 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
ROOTPATH = ../../../../..

MODULE = testsmf

TESTS = testsmfutils.H
TESTS += testmemutils.H

include ${ROOTPATH}/config.mk

324 changes: 324 additions & 0 deletions src/usr/secureboot/smf/test/testmemutils.H
Original file line number Diff line number Diff line change
@@ -0,0 +1,324 @@
/* IBM_PROLOG_BEGIN_TAG */
/* This is an automatically generated prolog. */
/* */
/* $Source: src/usr/secureboot/smf/test/testmemutils.H $ */
/* */
/* OpenPOWER HostBoot Project */
/* */
/* Contributors Listed Below - COPYRIGHT 2018 */
/* [+] 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 __TEST_MEM_UTILS_H
#define __TEST_MEM_UTILS_H

#include <cxxtest/TestSuite.H>

#include <isteps/mem_utils.H>
#include <targeting/common/target.H>
#include <targeting/common/targetservice.H>
#include <errl/errlmanager.H>
#include <hbotcompid.H>
#include <stdint.h>
#include <vfs/vfs.H>


class MemUtilsTestSuite : public CxxTest::TestSuite
{
public:

/**
* @brief Test get_top_mem_addr and get_bottom_mem_addr helper functions;
* test both calls with and without a proc argument.
*/
void testGetTopBotMemAddr() const
{
TS_INFO(ENTER_MRK "testGetTopBotMemAddr");
bool l_libsmf_loaded = false;
errlHndl_t l_errl = nullptr;

do {
const uint64_t TEST_TOP_MEM_SIZE = 0xdeadbeefbeefdead;
TARGETING::ATTR_PROC_MEM_SIZES_type l_mProcMemSizes = {
TEST_TOP_MEM_SIZE, 0, 0, 0, 0, 0, 0, 0};
TARGETING::ATTR_PROC_MEM_BASES_type l_mProcMemBases = {
0, 0, 0, 0, 0, 0, 0, 0};
TARGETING::ATTR_PROC_MEM_SIZES_type l_origMemSizes = {};
TARGETING::ATTR_PROC_MEM_BASES_type l_origMemBases = {};

TARGETING::Target* l_masterProc = nullptr;

l_errl = VFS::module_load("libsmf.so");
if(l_errl)
{
TS_FAIL("Could not load libsmf.so");
errlCommit(l_errl, CXXTEST_COMP_ID);
break;
}
l_libsmf_loaded = true;

l_errl = TARGETING::targetService()
.queryMasterProcChipTargetHandle(l_masterProc);
if(l_errl)
{
TS_FAIL("testGetTopBotMemAddr: could not get master proc");
errlCommit(l_errl, CXXTEST_COMP_ID);
break;
}

assert(l_masterProc->tryGetAttr<TARGETING::ATTR_PROC_MEM_SIZES>(l_origMemSizes),
"Could not get ATTR_PROC_MEM_SIZES from a proc target!");
assert(l_masterProc->tryGetAttr<TARGETING::ATTR_PROC_MEM_BASES>(l_origMemBases),
"Could not get ATTR_PROC_MEM_BASES from a proc target!");

uint64_t l_topMemAddr = ISTEP::get_top_mem_addr();
// Default top addr should be something different
if(l_topMemAddr == TEST_TOP_MEM_SIZE)
{
TS_FAIL("testGetTopBotMemAddr: unexpected default top address returned. Returned address: 0x%x", TEST_TOP_MEM_SIZE);
}

l_masterProc->setAttr<TARGETING::ATTR_PROC_MEM_SIZES>(l_mProcMemSizes);
l_masterProc->setAttr<TARGETING::ATTR_PROC_MEM_BASES>(l_mProcMemBases);

// Test the top system address
l_topMemAddr = ISTEP::get_top_mem_addr();
if(l_topMemAddr != TEST_TOP_MEM_SIZE)
{
TS_FAIL("testGetTopBotMemAddr: unexpected top address returned. Expected 0x%x, actual 0x%x", TEST_TOP_MEM_SIZE, l_topMemAddr);
}

// Test the top address of the master proc
l_topMemAddr = ISTEP::get_top_mem_addr(l_masterProc);
if(l_topMemAddr != TEST_TOP_MEM_SIZE)
{
TS_FAIL("testGetTopBotMemAddr: unexpected top address on master proc. Expected 0x%x, actual 0x%x", TEST_TOP_MEM_SIZE, l_topMemAddr);
}

const uint64_t BIG_MEM_BASE = 0x0fffffffffffffff;
const uint64_t TEST_BOT_MEM_BASE = 0x1;
TARGETING::ATTR_PROC_MEM_BASES_type l_mProcBotMemBases = {
BIG_MEM_BASE, BIG_MEM_BASE, BIG_MEM_BASE, BIG_MEM_BASE, BIG_MEM_BASE,
BIG_MEM_BASE, BIG_MEM_BASE, TEST_BOT_MEM_BASE };
TARGETING::ATTR_PROC_MEM_SIZES_type l_mProcBotMemSizes = {
1, 1, 1, 1, 1, 1, 1, 1 };

uint64_t l_bottomMemAddr = ISTEP::get_bottom_mem_addr();
// Default bottom address should be different
if(l_bottomMemAddr == TEST_BOT_MEM_BASE)
{
TS_FAIL("testGetTopBotMemAddr: unexpected default bottom address returned. Returned address: 0x%x", TEST_BOT_MEM_BASE);
}

l_masterProc->setAttr<TARGETING::ATTR_PROC_MEM_BASES>(l_mProcBotMemBases);
l_masterProc->setAttr<TARGETING::ATTR_PROC_MEM_SIZES>(l_mProcBotMemSizes);

// Test the bottom system address
l_bottomMemAddr = ISTEP::get_bottom_mem_addr();
if(l_bottomMemAddr != TEST_BOT_MEM_BASE)
{
TS_FAIL("testGetTopBotMemAddr: unexpected bottom address returned. Expected 0x%x, actual 0x%x", TEST_BOT_MEM_BASE, l_bottomMemAddr);
}

// Test the bottom address of the master proc
l_bottomMemAddr = ISTEP::get_bottom_mem_addr(l_masterProc);
if(l_bottomMemAddr != TEST_BOT_MEM_BASE)
{
TS_FAIL("testGetTopBotMemAddr: unexpected bottom address on master proc. Expected 0x%x, actual 0x%x", TEST_BOT_MEM_BASE, l_bottomMemAddr);
}


// Restore the originals in case something else wants to use them
l_masterProc->setAttr<TARGETING::ATTR_PROC_MEM_SIZES>(l_origMemSizes);
l_masterProc->setAttr<TARGETING::ATTR_PROC_MEM_BASES>(l_origMemBases);
} while(0);

if(l_libsmf_loaded)
{
l_errl = VFS::module_unload("libsmf.so");
if(l_errl)
{
TS_FAIL("Could not unload libsmf.so");
errlCommit(l_errl, CXXTEST_COMP_ID);
}
}

TS_INFO(EXIT_MRK "testGetTopBotMemAddr");
}

/**
* @brief Test get_top_smf_mem_addr; test both calls with and without
* a proc argument.
*/
void testGetTopSmfMemAddr() const
{
TS_INFO(ENTER_MRK "testGetTopSmfMemAddr");
bool l_libsmf_loaded = false;
errlHndl_t l_errl = nullptr;

do {
const uint64_t TEST_SMF_MEM_SIZE = 0xbeefdeaddeadbeef;
const uint64_t TEST_SMF_BAR = 0;

TARGETING::Target* l_masterProc = nullptr;

l_errl = VFS::module_load("libsmf.so");
if(l_errl)
{
TS_FAIL("Could not load libsmf.so");
errlCommit(l_errl, CXXTEST_COMP_ID);
break;
}
l_libsmf_loaded = true;

l_errl = TARGETING::targetService()
.queryMasterProcChipTargetHandle(l_masterProc);
if(l_errl)
{
TS_FAIL("testGetTopSmfMemAddr: could not get master proc");
errlCommit(l_errl, CXXTEST_COMP_ID);
break;
}

const auto l_origSmfMemBar =
l_masterProc->getAttr<TARGETING::ATTR_PROC_SMF_BAR_BASE_ADDR>();
const auto l_origSmfMemSize =
l_masterProc->getAttr<TARGETING::ATTR_PROC_SMF_BAR_SIZE>();

l_masterProc->
setAttr<TARGETING::ATTR_PROC_SMF_BAR_BASE_ADDR>(TEST_SMF_BAR);
l_masterProc->
setAttr<TARGETING::ATTR_PROC_SMF_BAR_SIZE>(TEST_SMF_MEM_SIZE);

uint64_t l_topSmfAddr = ISTEP::get_top_smf_mem_addr();
if(l_topSmfAddr != TEST_SMF_MEM_SIZE)
{
TS_FAIL("testGetTopSmfMemAddr: unexpected top SMF address on the system. Expected 0x%x, actual 0x%x", TEST_SMF_MEM_SIZE, l_topSmfAddr);
}

l_topSmfAddr = ISTEP::get_top_smf_mem_addr(l_masterProc);
if(l_topSmfAddr != TEST_SMF_MEM_SIZE)
{
TS_FAIL("testGetTopSmfMemAddr: unexpected top SMF address on master proc. Expected 0x%x, actual 0x%x", TEST_SMF_MEM_SIZE, l_topSmfAddr);
}

l_masterProc->
setAttr<TARGETING::ATTR_PROC_SMF_BAR_BASE_ADDR>(l_origSmfMemBar);
l_masterProc->
setAttr<TARGETING::ATTR_PROC_SMF_BAR_SIZE>(l_origSmfMemSize);
} while(0);

if(l_libsmf_loaded)
{
l_errl = VFS::module_unload("libsmf.so");
if(l_errl)
{
TS_FAIL("Could not unload libsmf.so");
errlCommit(l_errl, CXXTEST_COMP_ID);
}
}

TS_INFO(EXIT_MRK "testGetTopSmfMemAddr");
}

/**
* @brief test the get_top_homer_mem_addr helper function when SMF is
* enabled and disabled
*/
void testGetTopHomerMemAddr() const
{
TS_INFO(ENTER_MRK"testGetTopHomerMemAddr");
bool l_libsmf_loaded = false;
errlHndl_t l_errl = nullptr;

do {
const uint64_t TEST_SMF_BAR = 0;
const uint64_t TEST_SMF_BAR_SIZE = 0xdeadbeefdeadbeef;

TARGETING::Target* l_sys = nullptr;
TARGETING::Target* l_masterProc = nullptr;

l_errl = VFS::module_load("libsmf.so");
if(l_errl)
{
TS_FAIL("Could not load libsmf.so");
errlCommit(l_errl, CXXTEST_COMP_ID);
break;
}
l_libsmf_loaded = true;

l_errl = TARGETING::targetService()
.queryMasterProcChipTargetHandle(l_masterProc);
if(l_errl)
{
TS_FAIL("testGetTopHomerMemAddr: could not get master proc");
errlCommit(l_errl, CXXTEST_COMP_ID);
break;
}

TARGETING::targetService().getTopLevelTarget(l_sys);
assert(l_sys, "testGetTopHomerMemAddr: could not get top level target");

const auto l_origSmfMemBar =
l_masterProc->getAttr<TARGETING::ATTR_PROC_SMF_BAR_BASE_ADDR>();
const auto l_origSmfMemSize =
l_masterProc->getAttr<TARGETING::ATTR_PROC_SMF_BAR_SIZE>();

l_masterProc->
setAttr<TARGETING::ATTR_PROC_SMF_BAR_BASE_ADDR>(TEST_SMF_BAR);
l_masterProc->
setAttr<TARGETING::ATTR_PROC_SMF_BAR_SIZE>(TEST_SMF_BAR_SIZE);

l_sys->setAttr<TARGETING::ATTR_SMF_ENABLED>(false);

uint64_t l_topHomerAddr = ISTEP::get_top_homer_mem_addr();
if(l_topHomerAddr == TEST_SMF_BAR_SIZE)
{
// We should have gotten something different with SMF disabled
TS_FAIL("testGetTopHomerMemAddr: unexpected address returned from get_top_homer_mem_addr while SMF is DISABLED. Returned address: 0x%x", l_topHomerAddr);
}

l_sys->setAttr<TARGETING::ATTR_SMF_ENABLED>(true);
l_topHomerAddr = ISTEP::get_top_homer_mem_addr();
if(l_topHomerAddr != TEST_SMF_BAR_SIZE)
{
TS_FAIL("testGetTopHomerMemAddr: unexpected address returned from get_top_homer_mem_addr while SMF is ENABLED. Expected 0x%x, actual 0x%x", TEST_SMF_BAR_SIZE, l_topHomerAddr);
}

// Restore originals
l_masterProc->
setAttr<TARGETING::ATTR_PROC_SMF_BAR_BASE_ADDR>(l_origSmfMemBar);
l_masterProc->
setAttr<TARGETING::ATTR_PROC_SMF_BAR_SIZE>(l_origSmfMemSize);
l_sys->setAttr<TARGETING::ATTR_SMF_ENABLED>(false);
} while(0);

if(l_libsmf_loaded)
{
l_errl = VFS::module_unload("libsmf.so");
if(l_errl)
{
TS_FAIL("Could not unload libsmf.so");
errlCommit(l_errl, CXXTEST_COMP_ID);
}
}

TS_INFO(EXIT_MRK"testGetTopHomerMemAddr");
}

};

#endif

0 comments on commit 4ba2815

Please sign in to comment.