diff options
author | Robert Mustacchi <rm@fingolfin.org> | 2020-07-24 11:42:23 -0700 |
---|---|---|
committer | Robert Mustacchi <rm@fingolfin.org> | 2020-09-14 08:27:28 -0700 |
commit | 1045e13a248d94941f864998aa859970ae3a4154 (patch) | |
tree | 74a50920d2acda91909767a9fd339e3917d3f5eb /usr/src/test/os-tests | |
parent | eee178623516e461188f137dc6e5e38875967e09 (diff) | |
download | illumos-gate-1045e13a248d94941f864998aa859970ae3a4154.tar.gz |
13079 Add ksensor support for voltage and current sensors
Reviewed by: Andy Fiddaman <andy@omniosce.org>
Reviewed by: Paul Winder <paul@winder.uk.net>
Approved by: Dan McDonald <danmcd@joyent.com>
Diffstat (limited to 'usr/src/test/os-tests')
4 files changed, 92 insertions, 57 deletions
diff --git a/usr/src/test/os-tests/tests/ksensor/ksensor_basic.c b/usr/src/test/os-tests/tests/ksensor/ksensor_basic.c index 35590df264..22f79d18a7 100644 --- a/usr/src/test/os-tests/tests/ksensor/ksensor_basic.c +++ b/usr/src/test/os-tests/tests/ksensor/ksensor_basic.c @@ -26,66 +26,101 @@ #include <unistd.h> #include <errno.h> #include <string.h> +#include <sys/sysmacros.h> -static const char *ksensor_path = "/dev/sensors/test/test.temp.0.1"; +typedef struct sensor_test { + const char *st_path; + uint64_t st_kind; + uint32_t st_unit; + int32_t st_gran; + uint32_t st_prec; + int64_t st_val; +} sensor_test_t; -int -main(void) +/* + * These values come from the dummy sensors in the ksensor_test driver. + */ +static sensor_test_t ksensor_basic_tests[] = { + { "/dev/sensors/test/test.temp.0.1", SENSOR_KIND_TEMPERATURE, + SENSOR_UNIT_CELSIUS, 4, -2, 23 }, + { "/dev/sensors/test/test.volt.0.1", SENSOR_KIND_VOLTAGE, + SENSOR_UNIT_VOLTS, 1000, 0, 3300 }, + { "/dev/sensors/test/test.current.0.1", SENSOR_KIND_CURRENT, + SENSOR_UNIT_AMPS, 10, 0, 5 }, +}; + +static boolean_t +ksensor_basic(sensor_test_t *st) { sensor_ioctl_kind_t kind; - sensor_ioctl_temperature_t temp; - int ret = 0; + sensor_ioctl_scalar_t scalar; + int fd; - int fd = open(ksensor_path, O_RDONLY); + fd = open(st->st_path, O_RDONLY); if (fd < 0) { - err(EXIT_FAILURE, "TEST FAILED: failed to open %s", - ksensor_path); + warn("TEST FAILED: failed to open %s", st->st_path); + return (B_FALSE); } arc4random_buf(&kind, sizeof (kind)); - arc4random_buf(&temp, sizeof (temp)); + arc4random_buf(&scalar, sizeof (scalar)); + + if (ioctl(fd, SENSOR_IOCTL_KIND, &kind) != 0) { + warn("TEST FAILED: %s: failed to get sensor kind", st->st_path); + goto err; + } - if (ioctl(fd, SENSOR_IOCTL_TYPE, &kind) != 0) { - warn("TEST FAILED: failed to get sensor type"); - ret = EXIT_FAILURE; + if (kind.sik_kind != st->st_kind) { + warnx("TEST FAILED: %s: expected kind %" PRIu64 ", found kind %" + PRIu64, st->st_path, st->st_kind, kind); + goto err; } - if (kind.sik_kind != SENSOR_KIND_TEMPERATURE) { - warnx("TEST FAILED: expected temperature sensor, found kind %d", - kind); - ret = EXIT_FAILURE; + if (ioctl(fd, SENSOR_IOCTL_SCALAR, &scalar) != 0) { + warn("TEST FAILED: %s: failed to read sensor", st->st_path); + goto err; } - if (ioctl(fd, SENSOR_IOCTL_TEMPERATURE, &temp) != 0) { - warn("TEST FAILED: failed to get sensor temperature"); - ret = EXIT_FAILURE; + if (scalar.sis_unit != st->st_unit) { + warnx("TEST FAILED: %s: expected unit %" PRIu32 ", but found " + "%" PRIu32, st->st_path, st->st_unit, scalar.sis_unit); + goto err; } - /* - * These values come from the dummy temperature sensor in ksensor_test. - */ - if (temp.sit_unit != SENSOR_UNIT_CELSIUS) { - warnx("TEST FAILED: expected temp unit %" PRIu32 ", but found " - "%" PRIu32, SENSOR_UNIT_CELSIUS, temp.sit_unit); - ret = EXIT_FAILURE; + if (scalar.sis_gran != st->st_gran) { + warnx("TEST FAILED: %s: expected gran %" PRId32 ", but found " + "%" PRId32, st->st_path, st->st_gran, scalar.sis_gran); + goto err; } - if (temp.sit_gran != 4) { - warnx("TEST FAILED: expected temp gran %" PRId32 ", but found " - "%" PRId32, 4, temp.sit_gran); - ret = EXIT_FAILURE; + if (scalar.sis_prec != st->st_prec) { + warnx("TEST FAILED: %s: expected prec %" PRIu32 ", but found " + "%" PRIu32, st->st_path, st->st_prec, scalar.sis_prec); + goto err; } - if (temp.sit_prec != -2) { - warnx("TEST FAILED: expected temp prec %" PRId32 ", but found " - "%" PRId32, -2, temp.sit_prec); - ret = EXIT_FAILURE; + if (scalar.sis_value != st->st_val) { + warnx("TEST FAILED: %s: expected value %" PRId64 ", but found " + "%" PRId64, st->st_path, st->st_val, scalar.sis_value); + goto err; } - if (temp.sit_temp != 23) { - warnx("TEST FAILED: expected temp %" PRId64 ", but found " - "%" PRId64, 23, temp.sit_temp); - ret = EXIT_FAILURE; + return (B_TRUE); +err: + (void) close(fd); + return (B_FALSE); +} + +int +main(void) +{ + size_t i; + int ret = EXIT_SUCCESS; + + for (i = 0; i < ARRAY_SIZE(ksensor_basic_tests); i++) { + if (!ksensor_basic(&ksensor_basic_tests[i])) { + ret = EXIT_FAILURE; + } } return (ret); diff --git a/usr/src/test/os-tests/tests/ksensor/ksensor_err.c b/usr/src/test/os-tests/tests/ksensor/ksensor_err.c index 2818327f78..784dc477d8 100644 --- a/usr/src/test/os-tests/tests/ksensor/ksensor_err.c +++ b/usr/src/test/os-tests/tests/ksensor/ksensor_err.c @@ -39,20 +39,20 @@ error_kind(int fd, int exp) arc4random_buf(&alt_kind, sizeof (alt_kind)); (void) memcpy(&kind, &alt_kind, sizeof (alt_kind)); - if (ioctl(fd, SENSOR_IOCTL_TYPE, &kind) == 0) { - warnx("TEST FAILED: SENSIOR_IOCTL_TYPE succeeded on EIO " + if (ioctl(fd, SENSOR_IOCTL_KIND, &kind) == 0) { + warnx("TEST FAILED: SENSOR_IOCTL_KIND succeeded on EIO " "sensor"); error_exit = EXIT_FAILURE; } if (errno != exp) { - warnx("TEST FAILED: SENSIOR_IOCTL_TYPE got errno %d, " + warnx("TEST FAILED: SENSOR_IOCTL_KIND got errno %d, " "expected %d", errno, exp); error_exit = EXIT_FAILURE; } if (memcmp(&kind, &alt_kind, sizeof (alt_kind)) != 0) { - warnx("TEST FAILED: SENSIOR_IOCTL_TYPE modified data on error"); + warnx("TEST FAILED: SENSOR_IOCTL_KIND modified data on error"); error_exit = EXIT_FAILURE; } } @@ -60,25 +60,25 @@ error_kind(int fd, int exp) static void error_temp(int fd, int exp) { - sensor_ioctl_temperature_t temp, alt_temp; + sensor_ioctl_scalar_t scalar, alt_scalar; - arc4random_buf(&alt_temp, sizeof (alt_temp)); - (void) memcpy(&temp, &alt_temp, sizeof (alt_temp)); + arc4random_buf(&alt_scalar, sizeof (alt_scalar)); + (void) memcpy(&scalar, &alt_scalar, sizeof (alt_scalar)); - if (ioctl(fd, SENSOR_IOCTL_TEMPERATURE, &temp) == 0) { - warnx("TEST FAILED: SENSIOR_IOCTL_TEMPERATURE suceeded on " + if (ioctl(fd, SENSOR_IOCTL_SCALAR, &scalar) == 0) { + warnx("TEST FAILED: SENSIOR_IOCTL_SCALAR suceeded on " "EIO sensor"); error_exit = EXIT_FAILURE; } if (errno != exp) { - warnx("TEST FAILED: SENSIOR_IOCTL_TEMPERATURE got errno %d, " + warnx("TEST FAILED: SENSIOR_IOCTL_SCALAR got errno %d, " "expected %d", errno, EIO); error_exit = EXIT_FAILURE; } - if (memcmp(&temp, &alt_temp, sizeof (alt_temp)) != 0) { - warnx("TEST FAILED: SENSIOR_IOCTL_TEMPERATURE modified " + if (memcmp(&scalar, &alt_scalar, sizeof (alt_scalar)) != 0) { + warnx("TEST FAILED: SENSIOR_IOCTL_SCALAR modified " "data on error"); error_exit = EXIT_FAILURE; } diff --git a/usr/src/test/os-tests/tests/ksensor/ksensor_sread.c b/usr/src/test/os-tests/tests/ksensor/ksensor_sread.c index fef8b78f73..42be85f10e 100644 --- a/usr/src/test/os-tests/tests/ksensor/ksensor_sread.c +++ b/usr/src/test/os-tests/tests/ksensor/ksensor_sread.c @@ -58,7 +58,7 @@ main(int argc, const char *argv[]) char buf[PATH_MAX]; uint32_t sens, inst; struct timespec ts; - sensor_ioctl_temperature_t temp; + sensor_ioctl_scalar_t scalar; /* 0s based */ sens = arc4random_uniform(nsensors); @@ -73,15 +73,15 @@ main(int argc, const char *argv[]) goto wait; } - bzero(&temp, sizeof (temp)); - if (ioctl(fd, SENSOR_IOCTL_TEMPERATURE, &temp) != 0) { - warn("failed to get sensor temp on %s", buf); + bzero(&scalar, sizeof (scalar)); + if (ioctl(fd, SENSOR_IOCTL_SCALAR, &scalar) != 0) { + warn("failed to get sensor temperature on %s", buf); } - if (temp.sit_unit != SENSOR_UNIT_CELSIUS) { + if (scalar.sis_unit != SENSOR_UNIT_CELSIUS) { warnx("data from sensor %s looks off, expected sensor " "to indicate Celsius, but instead %u", - temp.sit_unit); + scalar.sis_unit); } (void) close(fd); diff --git a/usr/src/test/os-tests/tests/ksensor/ksensor_stress.ksh b/usr/src/test/os-tests/tests/ksensor/ksensor_stress.ksh index 805e464eb0..9a27a151ff 100644 --- a/usr/src/test/os-tests/tests/ksensor/ksensor_stress.ksh +++ b/usr/src/test/os-tests/tests/ksensor/ksensor_stress.ksh @@ -50,7 +50,7 @@ fi if [[ ! -L "$sensor_base/test.temp.0.1" ]]; then - printf "missing ksensor test data, ksensor_temp driver loaded\n" 2>&1 + printf "missing ksensor test data, ksensor_tstp driver loaded?\n" 2>&1 exit 1 fi |