Skip to content

Commit

Permalink
WIP: Add unit tests for igd, interrupts, io, iommu utilcmds
Browse files Browse the repository at this point in the history
Signed-off-by: Sara Batllori <[email protected]>
  • Loading branch information
Sae86 committed Aug 5, 2024
1 parent 4e24c41 commit afd2cc2
Show file tree
Hide file tree
Showing 13 changed files with 437 additions and 0 deletions.
50 changes: 50 additions & 0 deletions tests/utilcmd/igd_cmd/igd_cmd_dmaread_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"read_pci_reg": {
"(0,2,0,2,2)": [
"18048"
],
"(0,2,0,24,4)": [
"12"
],
"(0,2,0,28,4)": [
"64"
],
"(0,2,0,20,4)": [
"96",
"96",
"96",
"96"
],
"(0,2,0,16,4)": [
"4",
"4",
"4",
"4"
]
},
"read_mmio_reg": {
"(412325249024,4)": [
"1283457025"
],
"(412325249028,4)": [
"0"
]
},
"write_mmio_reg": {
"(412325249024,4,536870913)": [
""
],
"(412325249028,4,0)": [
"",
""
],
"(412325249024,4,1283457025)": [
""
]
},
"read_phys_mem": {
"(274877906944,4)": [
"\u001c\ryF"
]
}
}
52 changes: 52 additions & 0 deletions tests/utilcmd/igd_cmd/igd_cmd_dmawrite_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"read_pci_reg": {
"(0,2,0,2,2)": [
"18048"
],
"(0,2,0,24,4)": [
"12"
],
"(0,2,0,28,4)": [
"64"
],
"(0,2,0,20,4)": [
"96",
"96",
"96",
"96"
],
"(0,2,0,16,4)": [
"4",
"4",
"4",
"4"
]
},
"read_mmio_reg": {
"(412325249024,4)": [
"1283457025"
],
"(412325249028,4)": [
"0"
]
},
"write_mmio_reg": {
"(412325249024,4,561975297)": [
""
],
"(412325249028,4,2)": [
""
],
"(412325249024,4,1283457025)": [
""
],
"(412325249028,4,0)": [
""
]
},
"write_phys_mem": {
"(274877906944,4,bytearray(b'\\xde\\xad\\xbe\\xef'))": [
""
]
}
}
46 changes: 46 additions & 0 deletions tests/utilcmd/igd_cmd/test_igd_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:
# [email protected]
#

""""
To execute: python[3] -m unittest tests.utilcmd.igd_cmd.test_igd_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 TestIgdUtilcmd(unittest.TestCase):
def test_dmaread(self) -> None:
init_replay_file = os.path.join(get_main_dir(), "tests", "utilcmd", "adlenumerate.json")
igd_dump_replay_file = os.path.join(get_main_dir(), "tests", "utilcmd", "igd_cmd", "igd_cmd_dmaread_1.json")
retval = setup_run_destroy_util(init_replay_file, "igd", "dmaread 0x20000000 4", util_replay_file=igd_dump_replay_file)
self.assertEqual(retval, ExitCode.OK)

def test_dmawrite(self) -> None:
init_replay_file = os.path.join(get_main_dir(), "tests", "utilcmd", "adlenumerate.json")
igd_dump_replay_file = os.path.join(get_main_dir(), "tests", "utilcmd", "igd_cmd", "igd_cmd_dmawrite_1.json")
retval = setup_run_destroy_util(init_replay_file, "igd", "dmawrite 0x2217F1000 0x4 deadbeef", util_replay_file=igd_dump_replay_file)
self.assertEqual(retval, ExitCode.OK)

if __name__ == '__main__':
unittest.main()
69 changes: 69 additions & 0 deletions tests/utilcmd/interrupts_cmd/interrupts_cmd_smi_count_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"get_threads_count": {
"()": [
"20"
]
},
"read_msr": {
"(0,52)": [
"(461, 0)"
],
"(1,52)": [
"(461, 0)"
],
"(2,52)": [
"(461, 0)"
],
"(3,52)": [
"(461, 0)"
],
"(4,52)": [
"(461, 0)"
],
"(5,52)": [
"(461, 0)"
],
"(6,52)": [
"(461, 0)"
],
"(7,52)": [
"(461, 0)"
],
"(8,52)": [
"(461, 0)"
],
"(9,52)": [
"(461, 0)"
],
"(10,52)": [
"(461, 0)"
],
"(11,52)": [
"(461, 0)"
],
"(12,52)": [
"(461, 0)"
],
"(13,52)": [
"(461, 0)"
],
"(14,52)": [
"(461, 0)"
],
"(15,52)": [
"(461, 0)"
],
"(16,52)": [
"(461, 0)"
],
"(17,52)": [
"(461, 0)"
],
"(18,52)": [
"(461, 0)"
],
"(19,52)": [
"(461, 0)"
]
}
}
10 changes: 10 additions & 0 deletions tests/utilcmd/interrupts_cmd/interrupts_cmd_smi_send_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"write_io_port": {
"(179,0,1)": [
"True"
],
"(178,222,1)": [
"True"
]
}
}
46 changes: 46 additions & 0 deletions tests/utilcmd/interrupts_cmd/test_interrupts_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:
# [email protected]
#

""""
To execute: python[3] -m unittest tests.utilcmd.interrupts_cmd.test_interrupts_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 TestInterruptsUtilcmd(unittest.TestCase):
def test_count(self) -> None:
init_replay_file = os.path.join(get_main_dir(), "tests", "utilcmd", "adlenumerate.json")
interrupts_dump_replay_file = os.path.join(get_main_dir(), "tests", "utilcmd", "interrupts_cmd", "interrupts_cmd_smi_count_1.json")
retval = setup_run_destroy_util(init_replay_file, "interrupts", "count", util_replay_file=interrupts_dump_replay_file)
self.assertEqual(retval, ExitCode.OK)

def test_send(self) -> None:
init_replay_file = os.path.join(get_main_dir(), "tests", "utilcmd", "adlenumerate.json")
interrupts_dump_replay_file = os.path.join(get_main_dir(), "tests", "utilcmd", "interrupts_cmd", "interrupts_cmd_smi_send_1.json")
retval = setup_run_destroy_util(init_replay_file, "interrupts", "send 0x0 0xDE 0x0", util_replay_file=interrupts_dump_replay_file)
self.assertEqual(retval, ExitCode.OK)

if __name__ == '__main__':
unittest.main()
17 changes: 17 additions & 0 deletions tests/utilcmd/io_cmd/io_cmd_list_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"read_pci_reg": {
"(0,31,2,32,4)": [
"4294967295",
"4294967295"
],
"(0,31,4,80,4)": [
"1025"
],
"(0,31,0,72,4)": [
"0"
],
"(0,31,4,32,4)": [
"61345"
]
}
}
7 changes: 7 additions & 0 deletions tests/utilcmd/io_cmd/io_cmd_read_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"read_io_port": {
"(97,1)": [
"48"
]
}
}
7 changes: 7 additions & 0 deletions tests/utilcmd/io_cmd/io_cmd_write_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"write_io_port": {
"(1072,0,1)": [
"True"
]
}
}
52 changes: 52 additions & 0 deletions tests/utilcmd/io_cmd/test_io_cmd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# 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:
# [email protected]
#

""""
To execute: python[3] -m unittest tests.utilcmd.io_cmd.test_io_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 TestIoUtilcmd(unittest.TestCase):
def test_list(self) -> None:
init_replay_file = os.path.join(get_main_dir(), "tests", "utilcmd", "adlenumerate.json")
io_dump_replay_file = os.path.join(get_main_dir(), "tests", "utilcmd", "io_cmd", "io_cmd_list_1.json")
retval = setup_run_destroy_util(init_replay_file, "io", "list", util_replay_file=io_dump_replay_file)
self.assertEqual(retval, ExitCode.OK)

def test_read(self) -> None:
init_replay_file = os.path.join(get_main_dir(), "tests", "utilcmd", "adlenumerate.json")
io_dump_replay_file = os.path.join(get_main_dir(), "tests", "utilcmd", "io_cmd", "io_cmd_read_1.json")
retval = setup_run_destroy_util(init_replay_file, "io", "read", util_replay_file=io_dump_replay_file)
self.assertEqual(retval, ExitCode.OK)

def test_write(self) -> None:
init_replay_file = os.path.join(get_main_dir(), "tests", "utilcmd", "adlenumerate.json")
io_dump_replay_file = os.path.join(get_main_dir(), "tests", "utilcmd", "io_cmd", "io_cmd_write_1.json")
retval = setup_run_destroy_util(init_replay_file, "io", "write", util_replay_file=io_dump_replay_file)
self.assertEqual(retval, ExitCode.OK)

if __name__ == '__main__':
unittest.main()
1 change: 1 addition & 0 deletions tests/utilcmd/iommu_cmd/iommu_cmd_list_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Loading

0 comments on commit afd2cc2

Please sign in to comment.