android12 VtsHalSensorsV1_0TargetTest fail
RK3399 android12 GMS测试 VtsHalSensorsV1_0TargetTest fail。
典型log:
PerInstance/SensorsHidlTest#AccelerometerSamplingPeriodHotSwitchOperation/0_default fail
hardware/interfaces/sensors/common/vts/utils/include/sensors-vts-utils/SensorsHidlTestBase.h:394: Failure
android.hardware.cts.SensorBatchingTests#testAccelerometer_fastest_flush fail
junit.framework.AssertionFailedError: VerifySensorOperation | sensor='Accelerometer sensor', samplingPeriod=0us, maxReportLatency=10000000us | 37 events gaps: position=2, delta_time=127.36ms; position=3, delta_time=126.51ms; position=4, delta_time=126.47ms; 34 more; (expected <12.60ms), Frequency out of range: Requested "Accelerometer sensor" at fastest (expecting between 128.57Hz and 314.29Hz, measured 7.90Hz)
fail 原因:
代码配置(期望)的采样率和机器实际测量出的采样率偏差过⼤,导致测试fail。解决办法就是让配置的采样率和实际的采样率相同(误差10%以内)。不同的sensor模块在不同平台上的表现可能差距很⼤,具体应该以实际测试为准,修改⽅法并不固定。
RK给的代码位置:
Android_SDK/hardware/rockchip/sensor/sensors.c static const struct sensor_t sSensorList[] = { #ifdef GRAVITY_SENSOR_SUPPORT { .name = "Accelerometer sensor", .vendor = "The Android Open Source Project", .version = 1, .handle = SENSORS_HANDLE_BASE+ID_A, .type = SENSOR_TYPE_ACCELEROMETER, .maxRange = 4.0f*9.80f, .resolution = (4.0f*9.80f)/4096.0f, .power = 0.2f, .minDelay = 7000, .fifoReservedEventCount = 0, .fifoMaxEventCount = 0, .stringType = SENSOR_STRING_TYPE_ACCELEROMETER, .requiredPermission = 0, .maxDelay = 200000, .flags = SENSOR_FLAG_CONTINUOUS_MODE, .reserved = {} }, #endif
Android_SDK/kernel-5.10/drivers/input/sensors/sensor-dev.c static int sensor_reset_rate(struct i2c_client *client, int rate) { struct sensor_private_data *sensor = (struct sensor_private_data *) i2c_get_clientdata(client); int result = 0; if (rate < 5) rate = 5; else if (rate > 200) rate = 200; dev_info(&client->dev, "set sensor poll time to %dms\n", rate); /* work queue is always slow, we need more quickly to match hal rate */ if (sensor->pdata->poll_delay_ms == (rate - 4)) return 0; sensor->pdata->poll_delay_ms = rate - 4; if (sensor->status_cur == SENSOR_ON) { if (!sensor->pdata->irq_enable) { sensor->stop_work = 1; cancel_delayed_work_sync(&sensor->delaywork); } sensor->ops->active(client, SENSOR_OFF, rate); result = sensor->ops->active(client, SENSOR_ON, rate); if (!sensor->pdata->irq_enable) { sensor->stop_work = 0; schedule_delayed_work(&sensor->delaywork,msecs_to_jiffies(sensor->pdata->poll_delay_ms)); } } return result; }
解决办法:
1. 配置minDelay,配合驱动的 rate - x ,将实际的轮询间隔调成1ms,即 sensor->pdata->poll_delay_ms = 0 ,以默认上层的 .minDelay = 7000 (微秒), 为例,这⾥先把 x 改成 6 ,即:
/* work queue is always slow, we need more quickly to match hal rate */ if (sensor->pdata->poll_delay_ms == (rate - 6)) return 0; sensor->pdata->poll_delay_ms = rate - 6;
2. 改后测试VTS: PerInstance/SensorsHidlTest#AccelerometerSamplingPeriodHotSwitchOperation/0_default , 打印 logcat ,找到:
sensors_hidl_hal_test: min/maxDelayAverageInterval = 8022630 200001824
这⾥单位是纳秒,即测量出来的是 min/max 为 8ms/200ms 。可以发现, minDelay 和HAL中配置的差距⽐较⼤,因此需要调整。
.minDelay = 7000, .maxDelay = 200000,
3. 以驱动为准,即驱动 poll_delay_ms = 1 (7-6) 时,实际测量出的 delay 为 8ms ,那么上层需要配置 minDelay = 8ms 才能符合标准。此时rate变成8ms,如果 x 还是6,那么 8-6=2 就不是之前的 poll_delay_ms = 1 了,
所以可以把 x 改成 7 ,这样 poll_delay_ms还是1 ,测试出来的值还是8ms,此时HAL的minDelay=8000 就和实际值基本⼀致了。
因为我们的机器只有Gsensor一个模块,skt8321。使用的驱动是stk8xxx.c驱动和RK的hal层代码。
当我们把poll_delay_ms 改为1ms,我们测试VTS抓取的log:
sensors_hidl_hal_test: min/maxDelayAverageInterval = 10622330 10834621
补丁如下:
Index: hardware/rockchip/sensor/st/sensors.c =================================================================== --- hardware/rockchip/sensor/st/sensors.c (revision 2289) +++ hardware/rockchip/sensor/st/sensors.c (revision 2290) @@ -40,12 +40,12 @@ .maxRange = 4.0f*9.80f, .resolution = (4.0f*9.80f)/4096.0f, .power = 0.2f, - .minDelay = 7000, + .minDelay = 10000, .fifoReservedEventCount = 0, .fifoMaxEventCount = 0, .stringType = SENSOR_STRING_TYPE_ACCELEROMETER, .requiredPermission = 0, - .maxDelay = 200000, + .maxDelay = 10000, .flags = SENSOR_FLAG_CONTINUOUS_MODE, .reserved = {} }, Index: kernel-4.19/drivers/input/misc/stk8xxx.c =================================================================== --- kernel-4.19/drivers/input/misc/stk8xxx.c (revision 2289) +++ kernel-4.19/drivers/input/misc/stk8xxx.c (revision 2290) @@ -3838,7 +3838,7 @@ #elif defined STK_POLLING_MODE /* polling accel data */ INIT_DELAYED_WORK(&stk->accel_delaywork, stk_accel_delay_work); - stk->poll_delay_ms = 120; + stk->poll_delay_ms = 1; //hrtimer_init(&stk->accel_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
测试的时候还有其他的传感器有fail。例如VTS PerInstance/SensorsHidlTest#AccelerometerStreamingOperationNormal/0_default 等。因为我们机器只有gsensor,其他不用的sensor需要关闭。
Index: device/rockchip/rk3399/rk3399_Android12/BoardConfig.mk =================================================================== --- device/rockchip/rk3399/rk3399_Android12/BoardConfig.mk (revision 2290) +++ device/rockchip/rk3399/rk3399_Android12/BoardConfig.mk (revision 2291) @@ -1,10 +1,10 @@ include device/rockchip/rk3399/BoardConfig.mk BOARD_SENSOR_ST := true -BOARD_SENSOR_COMPASS_AK8963-64 := true +BOARD_SENSOR_COMPASS_AK8963-64 := false BOARD_SENSOR_MPU_PAD := false -BOARD_COMPASS_SENSOR_SUPPORT := true -BOARD_GYROSCOPE_SENSOR_SUPPORT := true +BOARD_COMPASS_SENSOR_SUPPORT := false +BOARD_GYROSCOPE_SENSOR_SUPPORT := false CAMERA_SUPPORT_AUTOFOCUS:= false BOARD_CAMERA_SUPPORT := false Index: device/rockchip/rk3399/BoardConfig.mk =================================================================== --- device/rockchip/rk3399/BoardConfig.mk (revision 2290) +++ device/rockchip/rk3399/BoardConfig.mk (revision 2291) @@ -66,9 +66,9 @@ endif # Sensors -BOARD_SENSOR_ST := false +BOARD_SENSOR_ST := true BOARD_SENSOR_MPU_VR := false -BOARD_SENSOR_MPU_PAD := true +BOARD_SENSOR_MPU_PAD := false BOARD_USES_GENERIC_INVENSENSE := false @@ -100,7 +100,7 @@ BOARD_COMPASS_SENSOR_SUPPORT := false BOARD_GYROSCOPE_SENSOR_SUPPORT := false BOARD_PROXIMITY_SENSOR_SUPPORT := false -BOARD_LIGHT_SENSOR_SUPPORT := true +BOARD_LIGHT_SENSOR_SUPPORT := false BOARD_PRESSURE_SENSOR_SUPPORT := false BOARD_TEMPERATURE_SENSOR_SUPPORT := false BOARD_USB_HOST_SUPPORT := true