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# Test i2cadm scan behavior. This is generally designed for human output. First 19# verify that we can run a few scans on i2csim0 error free. After that send 20# parseable # output to files and check that specific entries have what we 21# expect. This is definitely written in the max power way. 22# 23 24. $(dirname $0)/common.ksh 25 26typeset -A scan_results 27 28function read_scan 29{ 30 typeset path="$1" 31 typeset scan_ifs="$IFS" 32 33 set -A scan_results 34 IFS=":" 35 while read -A value; do 36 scan_results[${value[0]}]=${value[1]} 37 done <<< $($I2CADM scan -Hpo addr,result $path) 38 IFS="$scan_ifs" 39} 40 41function check_one 42{ 43 typeset desc="$1" 44 typeset addr="$2" 45 typeset exp="$3" 46 47 if [[ ${scan_results[$addr]} != "$exp" ]]; then 48 warn "$desc: found $addr as ${scan_results[$addr]}, wanted $exp" 49 else 50 printf "TEST PASSED: %s 0x%x is %s\n" "$desc" "$addr" "$exp" 51 fi 52} 53 54i2cadm_pass scan i2csim0/0 55i2cadm_pass scan i2csim0/0/0x70/0 56i2cadm_pass scan i2csim0/0/0x70/7 57i2cadm_pass scan i2csim0/0/0x70/0/0x71/1 58i2cadm_pass scan i2csim0/0/0x70/0/0x71/6 59 60# 61# Basic scan. Verify reserved addresses. Spot check missing and present. We 62# explicitly hit the missing ones that'll be activated when we enable the mux. 63# 64read_scan i2csim0/0 65check_one "i2csim0/0" 0x00 reserved 66check_one "i2csim0/0" 0x01 reserved 67check_one "i2csim0/0" 0x02 reserved 68check_one "i2csim0/0" 0x03 reserved 69check_one "i2csim0/0" 0x04 reserved 70check_one "i2csim0/0" 0x05 reserved 71check_one "i2csim0/0" 0x06 reserved 72check_one "i2csim0/0" 0x07 reserved 73check_one "i2csim0/0" 0x78 reserved 74check_one "i2csim0/0" 0x79 reserved 75check_one "i2csim0/0" 0x7a reserved 76check_one "i2csim0/0" 0x7b reserved 77check_one "i2csim0/0" 0x7c reserved 78check_one "i2csim0/0" 0x7d reserved 79check_one "i2csim0/0" 0x7e reserved 80check_one "i2csim0/0" 0x7f reserved 81check_one "i2csim0/0" 0x10 found 82check_one "i2csim0/0" 0x20 found 83check_one "i2csim0/0" 0x21 found 84check_one "i2csim0/0" 0x22 found 85check_one "i2csim0/0" 0x23 found 86check_one "i2csim0/0" 0x70 found 87check_one "i2csim0/0" 0x71 missing 88check_one "i2csim0/0" 0x72 missing 89check_one "i2csim0/0" 0x42 missing 90check_one "i2csim0/0" 0x58 missing 91check_one "i2csim0/0" 0x6f missing 92 93read_scan i2csim0/0/0x70/0 94check_one "i2csim0/0/0x70/0" 0x42 missing 95check_one "i2csim0/0/0x70/0" 0x70 found 96check_one "i2csim0/0/0x70/0" 0x71 found 97check_one "i2csim0/0/0x70/0" 0x72 missing 98 99read_scan i2csim0/0/0x70/1 100check_one "i2csim0/0/0x70/1" 0x42 missing 101check_one "i2csim0/0/0x70/1" 0x70 found 102check_one "i2csim0/0/0x70/1" 0x71 found 103check_one "i2csim0/0/0x70/1" 0x72 missing 104 105read_scan i2csim0/0/0x70/2 106check_one "i2csim0/0/0x70/2" 0x42 missing 107check_one "i2csim0/0/0x70/2" 0x70 found 108check_one "i2csim0/0/0x70/2" 0x71 found 109check_one "i2csim0/0/0x70/2" 0x72 found 110 111read_scan i2csim0/0/0x70/3 112check_one "i2csim0/0/0x70/2" 0x42 missing 113check_one "i2csim0/0/0x70/2" 0x70 found 114check_one "i2csim0/0/0x70/2" 0x71 found 115check_one "i2csim0/0/0x70/2" 0x72 found 116 117read_scan i2csim0/0/0x70/7 118check_one "i2csim0/0/0x70/7" 0x10 found 119check_one "i2csim0/0/0x70/7" 0x20 found 120check_one "i2csim0/0/0x70/7" 0x70 found 121check_one "i2csim0/0/0x70/7" 0x71 missing 122check_one "i2csim0/0/0x70/7" 0x72 missing 123 124for port in {0..7}; do 125 read_scan i2csim0/0/0x70/0/0x71/$port 126 check_one "i2csim0/0/0x70/0/0x71/$port" 0x42 missing 127 check_one "i2csim0/0/0x70/0/0x71/$port" 0x70 found 128 check_one "i2csim0/0/0x70/0/0x71/$port" 0x71 found 129 check_one "i2csim0/0/0x70/0/0x71/$port" 0x72 found 130 check_one "i2csim0/0/0x70/0/0x71/$port" 0x73 missing 131done 132 133if (( i2c_exit == 0 )); then 134 printf "All tests passed successfully!\n" 135fi 136 137exit $i2c_exit 138