Skip to content

Commit

Permalink
Add UTs for ec_cmd and config_cmd
Browse files Browse the repository at this point in the history
Signed-off-by: Nathaniel Mitchell <nathaniel.p.mitchell@intel.com>
  • Loading branch information
npmitche authored and dscott90 committed May 28, 2024
1 parent 677ee1d commit 39cf4bb
Show file tree
Hide file tree
Showing 11 changed files with 273,544 additions and 4 deletions.
3 changes: 1 addition & 2 deletions chipsec/utilcmd/config_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@
from chipsec.command import BaseCommand, toLoad
from typing import Any, Dict


class CONFIGCommand(BaseCommand):

def requirements(self) -> toLoad:
return toLoad.Config
return toLoad.All

def parse_arguments(self) -> None:
parser = ArgumentParser(usage=__doc__)
Expand Down
4 changes: 2 additions & 2 deletions chipsec/utilcmd/ec_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def parse_arguments(self) -> None:
parser_dump = subparsers.add_parser('dump', parents=[parser_sz])
parser_dump.set_defaults(func=self.dump, size=0x160)

parser_read = subparsers.add_parser('read', parents=[parser_offset])
parser_read = subparsers.add_parser('read', parents=[parser_offset, parser_sz])
parser_read.set_defaults(func=self.read, size=None)

parser_write = subparsers.add_parser('write', parents=[parser_offset])
Expand Down Expand Up @@ -103,7 +103,7 @@ def read(self) -> None:
else:
val = self._ec.read_memory(
self.offset) if self.offset < 0x100 else self._ec.read_memory_extended(self.offset)
self.logger.log(f'[CHIPSEC] EC memory read: offset 0x{self.start_offset:X} = 0x{val:X}')
self.logger.log(f'[CHIPSEC] EC memory read: offset 0x{self.offset:X} = 0x{val:X}')

def write(self) -> None:
self.logger.log(f'[CHIPSEC] EC memory write: offset 0x{self.offset:X} = 0x{self.wval:X}')
Expand Down
1 change: 1 addition & 0 deletions tests/utilcmd/config_cmd/config_cmd_show_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
46 changes: 46 additions & 0 deletions tests/utilcmd/config_cmd/test_config_cmd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# CHIPSEC: Platform Security Assessment Framework
# Copyright (c) 2024, Intel Corporation
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; Version 2.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# Contact information:
# chipsec@intel.com
#

""""
To execute: python[3] -m unittest tests.utilcmd.config_cmd.test_config_cmd
"""

import unittest
import os

from chipsec.library.file import get_main_dir
from tests.utilcmd.run_chipsec_util import setup_run_destroy_util
from chipsec.testcase import ExitCode

class TestConfigUtilcmd(unittest.TestCase):
def test_show_all(self) -> None:
init_replay_file = os.path.join(get_main_dir(), "tests", "utilcmd", "adlenumerate.json")
config_cmd_show_all_replay_file = os.path.join(get_main_dir(), "tests", "utilcmd", "config_cmd", "config_cmd_show_1.json")
retval = setup_run_destroy_util(init_replay_file, "config", "show ALL", util_replay_file=config_cmd_show_all_replay_file)
self.assertEqual(retval, ExitCode.OK)

def test_show_mmio_bars(self) -> None:
init_replay_file = os.path.join(get_main_dir(), "tests", "utilcmd", "adlenumerate.json")
config_cmd_show_all_replay_file = os.path.join(get_main_dir(), "tests", "utilcmd", "config_cmd", "config_cmd_show_1.json")
retval = setup_run_destroy_util(init_replay_file, "config", "show MMIO_BARS", util_replay_file=config_cmd_show_all_replay_file)
self.assertEqual(retval, ExitCode.OK)

if __name__ == '__main__':
unittest.main()
12 changes: 12 additions & 0 deletions tests/utilcmd/ec_cmd/ec_cmd_command_1_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"read_io_port": {
"(102,1)": [
"0"
]
},
"write_io_port": {
"(102,1,1)": [
"True"
]
}
}

0 comments on commit 39cf4bb

Please sign in to comment.