Skip to content

Commit 70e14f8

Browse files
committed
Fix LPC memmap, add device tests
1 parent 707dc88 commit 70e14f8

File tree

2 files changed

+47
-4
lines changed

2 files changed

+47
-4
lines changed

cros_ec_python/lpc.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
def ec_init(address: Int32 = EC_LPC_ADDR_MEMMAP):
8-
if portio.ioperm(EC_LPC_ADDR_MEMMAP, EC_MEMMAP_SIZE, True):
8+
if portio.ioperm(address, EC_MEMMAP_SIZE, True):
99
print("Permission denied. Try running as root.")
1010
exit(1)
1111

@@ -17,6 +17,7 @@ def ec_readmem(offset: Int32, num_bytes: Int32, address: Int32 = EC_LPC_ADDR_MEM
1717
@param num_bytes: Number of bytes to read.
1818
@return: Bytes read from the EC.
1919
"""
20-
buf = None
21-
print(portio.insb(address + offset, buf, num_bytes))
22-
return buf
20+
data = bytearray()
21+
for i in range(num_bytes):
22+
data.append(portio.inb(address + offset + i))
23+
return bytes(data)

tests/devices.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import unittest
2+
from cros_ec_python import CrOS_EC, DeviceTypes, general
3+
from cros_ec_python.constants import MEMMAP
4+
5+
ec: CrOS_EC | None = None
6+
7+
8+
class TestLinuxDev(unittest.TestCase):
9+
def test1_init(self):
10+
global ec
11+
ec = CrOS_EC(DeviceTypes.LinuxDev)
12+
self.assertIsNotNone(ec)
13+
14+
def test2_memmap(self):
15+
resp = ec.memmap(MEMMAP.EC_MEMMAP_ID, 2)
16+
self.assertEqual(resp, b'EC')
17+
18+
def test3_hello(self):
19+
data = b'ECEC'
20+
resp = ec.command(0, general.EC_CMD_HELLO, len(data), 4, data)
21+
self.assertEqual(resp, (int.from_bytes(data, "little") + 0x01020304).to_bytes(4, "little"))
22+
23+
24+
class TestLPC(unittest.TestCase):
25+
def test1_init(self):
26+
global ec
27+
ec = CrOS_EC(DeviceTypes.LPC, address=0xE00)
28+
self.assertIsNotNone(ec)
29+
30+
def test2_memmap(self):
31+
resp = ec.memmap(MEMMAP.EC_MEMMAP_ID, 2)
32+
self.assertEqual(resp, b'EC')
33+
34+
@unittest.skip("Not implemented")
35+
def test3_hello(self):
36+
data = b'ECEC'
37+
resp = ec.command(0, general.EC_CMD_HELLO, len(data), 4, data)
38+
self.assertEqual(resp, (int.from_bytes(data, "little") + 0x01020304).to_bytes(4, "little"))
39+
40+
41+
if __name__ == '__main__':
42+
unittest.main()

0 commit comments

Comments
 (0)