[BACK]Return to t_swsensor.sh CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / tests / dev / sysmon

Annotation of src/tests/dev/sysmon/t_swsensor.sh, Revision 1.5

1.5     ! pgoyette    1: # $NetBSD: t_swsensor.sh,v 1.4 2010/12/31 00:35:42 pgoyette Exp $
1.1       pgoyette    2:
                      3: get_sensor_info() {
                      4:        rump.envstat -x | \
                      5:        sed -e "\;swsensor;,\;/array;p" -e "d"
                      6: }
                      7:
                      8: get_sensor_key() {
                      9:        get_sensor_info | grep -A1 $1 | grep integer | sed -e 's;<[/a-z]*>;;g'
                     10: }
                     11:
                     12: get_powerd_event_count() {
                     13:        grep "not running" powerd.log | wc -l
                     14: }
                     15:
1.5     ! pgoyette   16: get_rnd_bits_count() {
        !            17:        env RUMPHIJACK=blanket=/dev/random:/dev/urandom \
        !            18:            RUMP_SERVER=unix://t_swsensor_socket        \
        !            19:            LD_PRELOAD=/usr/lib/librumphijack.so          rndctl -l | \
        !            20:        grep "swsensor-sensor" | \
        !            21:        awk '{print $2}'
        !            22: }
        !            23:
1.1       pgoyette   24: check_powerd_event() {
                     25:        event=$(grep "not running" powerd.log | \
                     26:                sed -e "$1p" -e "d" )
                     27:        event=${event##*//}
                     28:        script=${event%% *}
                     29:        event=${event#* }
                     30:        device=${event%% *}
                     31:        event=${event#* }
                     32:        state=${event%% *}
                     33:        sensor=${event#* }
                     34:        sensor=${sensor% *}
                     35:
                     36:        if [ "${script}" != "sensor_indicator" ] ; then
                     37:                echo "Event uses wrong script: ${script}"
                     38:        elif [ "${device}" != "swsensor" ] ; then
                     39:                echo "Event uses wrong device: ${device}"
                     40:        elif [ "${sensor}" != "sensor" ] ; then
                     41:                echo "Event uses wrong sensor: ${sensor}"
                     42:        elif [ "${state}" != "$2" ] ; then
                     43:                echo "Event uses wrong state: ${state}"
                     44:        fi
                     45: }
                     46:
                     47: # Start the rump server, then load the swsensor module with the
                     48: # requested properties
                     49:
                     50: start_rump() {
1.5     ! pgoyette   51:        rump_allserver -l rumpvfs -l rumpdev -l rumpdev_sysmon ${RUMP_SERVER}
1.1       pgoyette   52:        if [ $( get_sensor_info | wc -l ) -ne 0 ] ; then
                     53:                rump.modunload swsensor
                     54:                rump.modload -f $1 swsensor
                     55:        else
                     56:                rump.modload $1 swsensor
                     57:        fi
                     58:        return $?
                     59: }
                     60:
                     61: common_head() {
                     62:        atf_set descr           "$1"
                     63:        atf_set timeout         60
1.4       pgoyette   64:        atf_set require.progs   rump.powerd rump.envstat rump.modload   \
                     65:                                rump.halt   rump.sysctl  rump_server    \
1.5     ! pgoyette   66:                                sed         grep         awk            \
        !            67:                                rndctl      expr
1.1       pgoyette   68: }
                     69:
                     70: common_cleanup() {
                     71:        rump.modunload swsensor
                     72:        rump.halt
                     73: }
                     74:
                     75: create_envsys_conf_files() {
                     76:        cat << ENV0 > env0.conf
                     77:        swsensor {
                     78:                refresh-timeout = 2s;
                     79:        }
                     80: ENV0
                     81:        cat << ENV1 > env1.conf
                     82:        swsensor {
                     83:                sensor0 { critical-min = $(( $1 - $2 )); }
                     84:        }
                     85: ENV1
                     86:        cat << ENV2 > env2.conf
                     87:        swsensor {
                     88:                sensor0 { critical-min = $1; }
                     89:        }
                     90: ENV2
                     91: }
                     92:
                     93: # Test body common to all sensors
                     94: #      $1      sensor mode
                     95: #      $2      initial sensor value
                     96: #      $3      initial limit
                     97: #      $4      amount to lower limit
                     98: #      $5      difference from limit to trigger event
1.5     ! pgoyette   99: #      $6      sensor flags, for FHAS_ENTROPY and FMONNOTSUPP
1.1       pgoyette  100:
                    101: common_body() {
                    102:        # Start the rump-server process and load the module
1.5     ! pgoyette  103:        modload_args="-i mode=$1 -i value=$2 -i limit=$3 ${6:+-i flags=$6}"
        !           104:        start_rump "$modload_args"
1.1       pgoyette  105:
                    106:        # create configuration files for updates
                    107:        create_envsys_conf_files $3 $4
                    108:
                    109:        if [ $? -ne 0 ] ; then
                    110:                atf_skip "Cannot set-up rump environment"
                    111:        fi
                    112:
                    113:        # start powerd so we can detect sensor events
                    114:        rump.powerd -n -d > powerd.log 2>&1 &
                    115:        if [ -z "$(jobs)" ] ; then
                    116:                skip_events=1
                    117:                echo "Skipping event sub-tests - powerd did not start"
                    118:        else
                    119:                skip_events=0
                    120:                expected_event=1
                    121:        fi
                    122:
                    123:        # Step 0 - verify that sensor is registered
                    124:        get_sensor_info | grep -q swsensor ||
                    125:                atf_fail "0: Device swsensor not registered"
                    126:
                    127:        # Step 1 - update the refresh-timeout and verify
                    128:        # (use $(( ... )) since the timeout is displayed in hex!)
                    129:        rump.envstat -c env0.conf
                    130:        if [ $(( $( get_sensor_key refresh-timeout ) )) -ne 2 ] ; then
                    131:                atf_fail "1: Could not set refresh-timout to 2s"
                    132:        fi
                    133:
                    134:        # Step 2 - verify that we can read sensor's value
                    135:        if [ $1 -ne 0 -a $( get_sensor_key cur-value ) -ne $2 ] ; then
                    136:                atf_fail "2: Value not available"
                    137:        fi
                    138:
                    139:        # Step 3 - verify that changes in sensor value are seen
                    140:        rump.sysctl -w hw.swsensor.cur_value=$(( $2 + 1 ))
                    141:        if [ $( get_sensor_key cur-value ) -ne $(( $2 + 1 )) ] ; then
                    142:                atf_fail "3: Value not updated"
                    143:        fi
                    144:
                    145:        # Step 4 - if sensor provides hw limit, make sure we can read it
                    146:        if [ $1 -ne 0 ] ; then
                    147:                if [ $( get_sensor_key critical-min ) -ne $3 ] ; then
                    148:                        atf_fail "4: Limit not set by device"
                    149:                fi
                    150:        fi
                    151:
                    152:        # Step 5 - if sensor provides hw limit, make sure it works
                    153:        if [ $1 -ne 0 -a ${skip_events} -eq 0 ] ; then
                    154:                rump.sysctl -w hw.swsensor.cur_value=$(( $3 - $5 ))
1.3       pgoyette  155:                sleep 5
1.1       pgoyette  156:                cnt=$(get_powerd_event_count)
                    157:                if [ ${cnt} -lt ${expected_event} ] ; then
                    158:                        atf_fail "5: No event triggered"
                    159:                elif [ ${cnt} -gt ${expected_event} ] ; then
                    160:                        atf_fail "5: Multiple events triggered"
                    161:                fi
                    162:                evt=$( check_powerd_event ${cnt} "critical-under")
                    163:                if [ -n "${evt}" ] ; then
                    164:                        atf_fail "5: ${evt}"
                    165:                fi
                    166:                expected_event=$(( 1 + ${expected_event} ))
                    167:        fi
                    168:
                    169:        # Step 6 - verify that we return to normal state
                    170:        if [ $1 -ne 0 -a ${skip_events} -eq 0 ] ; then
                    171:                rump.sysctl -w hw.swsensor.cur_value=$(( $3 + $5 ))
                    172:                sleep 5
                    173:                cnt=$(get_powerd_event_count)
                    174:                if [ ${cnt} -lt ${expected_event} ] ; then
                    175:                        atf_fail "6: No event triggered"
                    176:                elif [ ${cnt} -gt ${expected_event} ] ; then
                    177:                        atf_fail "6: Multiple events triggered"
                    178:                fi
                    179:                evt=$( check_powerd_event ${cnt} "normal")
                    180:                if [ -n "${evt}" ] ; then
                    181:                        atf_fail "6: ${evt}"
                    182:                fi
                    183:                expected_event=$(( 1 + ${expected_event} ))
                    184:        fi
                    185:
                    186:        # Step 7 - verify that we can set our own limit
1.5     ! pgoyette  187:
        !           188:        # Steps 7 thru 12 are skipped if the sensor cannot be monitored
        !           189:        if [ $( expr \( 0$6 / 2048 \) % 2 ) -ne 1 ] ; then
        !           190:                rump.envstat -c env1.conf
        !           191:                if [ $( get_sensor_key critical-min ) -ne $(( $3 - $4 )) ] ; then
        !           192:                        atf_fail "7: Limit not set by envstat -c"
        !           193:                fi
1.1       pgoyette  194:
                    195:        # Step 8 - make sure user-set limit works
1.5     ! pgoyette  196:                if [ ${skip_events} -eq 0 ] ; then
        !           197:                        rump.sysctl -w hw.swsensor.cur_value=$(( $3 - $4 - $5 ))
        !           198:                        sleep 5
        !           199:                        cnt=$(get_powerd_event_count)
        !           200:                        if [ ${cnt} -lt ${expected_event} ] ; then
        !           201:                                atf_fail "8: No event triggered"
        !           202:                        elif [ ${cnt} -gt ${expected_event} ] ; then
        !           203:                                atf_fail "8: Multiple events triggered"
        !           204:                        fi
        !           205:                        evt=$( check_powerd_event ${cnt} "critical-under")
        !           206:                        if [ -n "${evt}" ] ; then
        !           207:                                atf_fail "8: ${evt}"
        !           208:                        fi
        !           209:                        expected_event=$(( 1 + ${expected_event} ))
        !           210:                fi
        !           211:
        !           212:        # Step 9 - verify that we return to normal state
        !           213:                if [ ${skip_events} -eq 0 ] ; then
        !           214:                        rump.sysctl -w hw.swsensor.cur_value=$(( $3 - $4 + $5 ))
        !           215:                        sleep 5
        !           216:                        cnt=$(get_powerd_event_count)
        !           217:                        if [ ${cnt} -lt ${expected_event} ] ; then
        !           218:                                atf_fail "9: No event triggered"
        !           219:                        elif [ ${cnt} -gt ${expected_event} ] ; then
        !           220:                                atf_fail "9: Multiple events triggered"
        !           221:                        fi
        !           222:                        evt=$( check_powerd_event ${cnt} "normal")
        !           223:                        if [ -n "${evt}" ] ; then
        !           224:                                atf_fail "9: ${evt}"
        !           225:                        fi
        !           226:                        expected_event=$(( 1 + ${expected_event} ))
        !           227:                fi
        !           228:
        !           229:        # Step 10 - reset to defaults
        !           230:                rump.envstat -S
        !           231:                if [ $1 -eq 0 ] ; then
        !           232:                        get_sensor_info | grep -q critical-min &&
        !           233:                                atf_fail "10: Failed to clear a limit with envstat -S"
        !           234:                else
        !           235:                        if [ $( get_sensor_key critical-min ) -ne $3 ] ; then
        !           236:                                atf_fail "10: Limit not reset to initial value"
        !           237:                        fi
1.1       pgoyette  238:                fi
1.5     ! pgoyette  239:
        !           240:        # Step 11 - see if more events occur
        !           241:                if [ ${skip_events} -eq 0 ] ; then
        !           242:                        rump.envstat -c env0.conf
        !           243:                        rump.sysctl -w hw.swsensor.cur_value=$(( $3 - $4 - $5 ))
        !           244:                        sleep 5
        !           245:                        cnt=$(get_powerd_event_count)
        !           246:                        if [ ${cnt} -ge ${expected_event} ] ; then
        !           247:                                if [ $1 -ne 2 ] ; then
        !           248:                                        atf_fail "11b Event triggered after reset"
        !           249:                                fi
        !           250:                                evt=$( check_powerd_event ${cnt} "critical-under")
        !           251:                                if [ -n "${evt}" ] ; then
        !           252:                                        atf_fail "11a: ${evt}"
        !           253:                                fi
        !           254:                        fi
1.1       pgoyette  255:                fi
                    256:
1.5     ! pgoyette  257:        # Step 12 - make sure we can set new limits once more
        !           258:                rump.envstat -c env2.conf
        !           259:                if [ $( get_sensor_key critical-min ) -ne $3 ] ; then
        !           260:                        atf_fail "12a: Limit not reset to same value"
1.1       pgoyette  261:                fi
1.5     ! pgoyette  262:                rump.envstat -c env1.conf
        !           263:                if [ $( get_sensor_key critical-min ) -ne $(( $3 - $4 )) ] ; then
        !           264:                        atf_fail "12b: Limit not reset to new value"
1.1       pgoyette  265:                fi
                    266:        fi
                    267:
1.5     ! pgoyette  268:        # Step 13 - confirm registration (or lack thereof) with rndctl
        !           269:        rnd_bits=$( get_rnd_bits_count )
        !           270:        if [ $( expr \( 0$6 / 8192 \) % 2 ) -eq 1 ] ; then
        !           271:                if [ -z "$rnd_bits" ] ; then
        !           272:                        atf_fail "13a: Not registered with rndctl"
        !           273:                fi
1.1       pgoyette  274:        else
1.5     ! pgoyette  275:                if [ -n "$rnd_bits" ] ; then
        !           276:                        atf_fail "13b: Wrongly registered with rndctl"
1.1       pgoyette  277:                fi
                    278:        fi
                    279:
1.5     ! pgoyette  280:        # Steps 14 and 15 are only if sensor is providing entropy
        !           281:        if [ $( expr \( 0$6 / 8192 \) % 2 ) -ne 1 ] ; then
        !           282:                return
        !           283:        fi
        !           284:
        !           285:        # Step 14 - make sure entropy collected when device is being polled
        !           286:        rump.envstat -c env0.conf
        !           287:        rump.sysctl -w hw.swsensor.cur_value=$3
        !           288:        sleep 5
        !           289:        rump.sysctl -w hw.swsensor.cur_value=$(( $3 + $4 ))
        !           290:        sleep 5
        !           291:        new_rnd_bits=$( get_rnd_bits_count )
        !           292:        if [ $new_rnd_bits -le $rnd_bits ] ; then
        !           293:                atf_fail "14a: entropy bits did not increase after polling"
        !           294:        fi
        !           295:        rnd_bits=$new_rnd_bits
        !           296:        sleep 5
        !           297:        new_rnd_bits=$( get_rnd_bits_count )
        !           298:        if [ $new_rnd_bits -gt $rnd_bits ] ; then
        !           299:                atf_fail "14b: entropy bits increased after poll with no value change"
1.1       pgoyette  300:        fi
                    301:
1.5     ! pgoyette  302:        # Step 15 - make sure entropy collected when device is interrogated
        !           303:        #
        !           304:        rump.envstat -c env0.conf
        !           305:        rump.sysctl -w hw.swsensor.cur_value=$3
        !           306:        get_sensor_key cur-value
        !           307:        rnd_bits=$( get_rnd_bits_count )
        !           308:        rump.sysctl -w hw.swsensor.cur_value=$(( $3 + $4 ))
        !           309:        get_sensor_key cur-value
        !           310:        new_rnd_bits=$( get_rnd_bits_count )
        !           311:        if [ $new_rnd_bits -le $rnd_bits ] ; then
        !           312:                atf_fail "15a: entropy bits did not increase after interrogation"
        !           313:        fi
        !           314:        rnd_bits=$new_rnd_bits
        !           315:        get_sensor_key cur-value
        !           316:        new_rnd_bits=$( get_rnd_bits_count )
        !           317:        if [ $new_rnd_bits -gt $rnd_bits ] ; then
        !           318:                atf_fail "15b: entropy bits increased after interrogation with no value change"
1.1       pgoyette  319:        fi
                    320: }
                    321:
                    322: atf_test_case simple_sensor cleanup
                    323: simple_sensor_head() {
                    324:        common_head "Test a simple sensor"
                    325: }
                    326:
                    327: simple_sensor_body() {
                    328:        common_body 0 50 30 10 1
                    329: }
                    330:
                    331: simple_sensor_cleanup() {
                    332:        common_cleanup
                    333: }
                    334:
                    335: atf_test_case limit_sensor cleanup
                    336: limit_sensor_head() {
                    337:        common_head "Test a sensor with internal limit"
                    338: }
                    339:
                    340: limit_sensor_body() {
                    341:        common_body 1 45 25 8 2
                    342: }
                    343:
                    344: limit_sensor_cleanup() {
                    345:        common_cleanup
                    346: }
                    347:
                    348: atf_test_case alarm_sensor cleanup
                    349: alarm_sensor_head() {
                    350:        common_head "Test a sensor with internal checking"
                    351: }
                    352:
                    353: alarm_sensor_body() {
                    354:        common_body 2 40 20 6 3
                    355: }
                    356:
                    357: alarm_sensor_cleanup() {
                    358:        common_cleanup
                    359: }
                    360:
1.5     ! pgoyette  361: atf_test_case entropy_polled_sensor cleanup
        !           362: entropy_polled_sensor_head() {
        !           363:        common_head "Test a simple sensor that provides entropy"
        !           364: }
        !           365:
        !           366: entropy_polled_sensor_body() {
        !           367:        common_body 0 50 30 10 1 8192
        !           368: }
        !           369:
        !           370: entropy_polled_sensor_cleanup() {
        !           371:        common_cleanup
        !           372: }
        !           373:
        !           374: atf_test_case entropy_interrupt_sensor cleanup
        !           375: entropy_interrupt_sensor_head() {
        !           376:        common_head "Test a sensor that provides entropy without polling"
        !           377: }
        !           378:
        !           379: entropy_interrupt_sensor_body() {
        !           380:        common_body 0 50 30 10 1 10240
        !           381: }
        !           382:
        !           383: entropy_interrupt_sensor_cleanup() {
        !           384:        common_cleanup
        !           385: }
        !           386:
1.1       pgoyette  387: atf_init_test_cases() {
1.2       pgoyette  388:        RUMP_SERVER="unix://t_swsensor_socket" ; export RUMP_SERVER
1.1       pgoyette  389:        atf_add_test_case simple_sensor
                    390:        atf_add_test_case limit_sensor
                    391:        atf_add_test_case alarm_sensor
1.5     ! pgoyette  392:        atf_add_test_case entropy_polled_sensor
        !           393:        atf_add_test_case entropy_interrupt_sensor
1.1       pgoyette  394: }

CVSweb <webmaster@jp.NetBSD.org>