Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UTs for ec_cmd and config_cmd #2156

Merged
merged 1 commit into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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"
]
}
}