xref: /illumos-gate/usr/src/test/i2c-tests/tests/i2cadm/i2cadm-map.ksh (revision 0cbe48189888d02563dba9c90132ac391ba233b6)
1#! /usr/bin/ksh
2#
3# This file and its contents are supplied under the terms of the
4# Common Development and Distribution License ("CDDL"), version 1.0.
5# You may only use this file in accordance with the terms of version
6# 1.0 of the CDDL.
7#
8# A full copy of the text of the CDDL should have accompanied this
9# source.  A copy of the CDDL is also available via the Internet at
10# http://www.illumos.org/license/CDDL.
11#
12
13#
14# Copyright 2025 Oxide Computer Company
15#
16
17#
18# Various tests that the data we have for the i2c port map command is what we
19# expect. This uses the full device profile and makes the following assumptions:
20#
21# 1. No one has snuck in and added or deleted devices.
22# 2. We have to be careful about devices that are manually claimed as they may
23#    be detached and therefore not listed in the port unless we have the device
24#    actively open.
25#
26# We don't currently fake up the DDR4 RDIMMs which are the main user of the
27# major-wide shared address binding, so there is no test for that here.
28#
29
30. $(dirname $0)/common.ksh
31
32typeset -A port_count
33typeset -A port_type
34typeset port_path=
35
36function read_map
37{
38	typeset path="$1"
39	typeset map_ifs="$IFS"
40
41	set -A port_count
42	set -A port_type
43	IFS=":"
44	while read -A value; do
45		port_count[${value[0]}]=${value[1]}
46		port_type[${value[0]}]=${value[2]}
47	done <<< $($I2CADM port map -Hpo addr,count,type $path)
48	IFS="$scan ifs"
49	port_path="$path"
50}
51
52function verify
53{
54	typeset addr="$1"
55	typeset ptype="$2"
56	typeset count="$3"
57	typeset valid=
58
59	if (( port_count[$addr] != count )); then
60		valid=no
61		warn "$addr on $port_path has count ${port_count[$addr]}, but" \
62		    "expected $count"
63	fi
64
65	if [[ "${port_type[$addr]}" != $ptype ]]; then
66		valid=no
67		warn "$addr on $port_path has type ${port_type[$addr]}, but" \
68		    "expected $ptype"
69	fi
70
71	if [[ -z "$valid" ]]; then
72		printf "TEST PASSED: %s on %s has type (%s) and count (%u)\n" \
73		    "$addr" "$port_path" "$ptype" "$count"
74	fi
75}
76
77#
78# We should find most things on the top-level port.
79#
80read_map i2csim0/0
81verify 0x0 none 0
82verify 0x10 local 1
83verify 0x20 local 1
84verify 0x33 none 0
85verify 0x70 local 1
86verify 0x71 downstream 4
87verify 0x72 downstream 10
88verify 0x7f none 0
89
90#
91# Moving onto the first port on the mux, we expect all of the older local
92# devices to no longer be there.
93#
94read_map i2csim0/0/0x70/0
95verify 0x10 none 0
96verify 0x20 none 0
97verify 0x30 none 0
98verify 0x71 local 1
99verify 0x72 downstream 8
100
101#
102# And even less if we go to one of the ports below it.
103#
104read_map i2csim0/0/0x70/0/0x71/0
105for i in {0..127}; do
106	(( i == 0x72 )) && continue
107	verify $i none 0
108done
109verify 0x72 local 1
110
111#
112# This port should be empty.
113#
114read_map i2csim0/0/0x70/6
115for i in {0..127}; do
116	verify $i none 0
117done
118
119
120if (( i2c_exit == 0 )); then
121	printf "All tests passed successfully!\n"
122fi
123
124exit $i2c_exit
125