1 /* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.hardware.cts; 18 19 import android.hardware.Sensor; 20 import android.hardware.SensorManager; 21 import android.hardware.cts.helpers.SensorCtsHelper; 22 import android.hardware.cts.helpers.SensorStats; 23 import android.hardware.cts.helpers.TestSensorEnvironment; 24 import android.hardware.cts.helpers.sensoroperations.TestSensorOperation; 25 import android.hardware.cts.helpers.sensorverification.EventBasicVerification; 26 import android.hardware.cts.helpers.sensorverification.ISensorVerification; 27 import android.hardware.cts.helpers.sensorverification.MeanLargerThanVerification; 28 29 import java.util.concurrent.TimeUnit; 30 31 /** 32 * Set of tests to verify that sensors operate correctly when operating in batching mode. 33 * This class defines tests for continuous sensors when the device is awake. 34 * On-change and special sensors are tested separately inside CtsVerifier, and they are defined in: 35 * {@link com.android.cts.verifier.sensors.BatchingTestActivity}. 36 * 37 * Each test is expected to pass even if batching is not supported for a particular sensor. This is 38 * usually achieved by ensuring that {@link ISensorVerification}s fallback accordingly. 39 * 40 * <p>To execute these test cases, the following command can be used:</p> 41 * <pre> 42 * adb shell am instrument -e class android.hardware.cts.SensorBatchingTests \ 43 * -w android.hardware.cts/android.test.AndroidJUnitRunner 44 * </pre> 45 */ 46 public class SensorBatchingTests extends SensorTestCase { 47 private static final String TAG = "SensorBatchingTests"; 48 49 private static final int BATCHING_PERIOD = 10; // sec 50 private static final int RATE_50HZ = 20000; 51 private static final int RATE_FASTEST = SensorManager.SENSOR_DELAY_FASTEST; 52 53 /** 54 * An arbitrary 'padding' time slot to wait for events after batching latency expires. 55 * This allows for the test to wait for event arrivals after batching was expected. 56 */ 57 private static final int BATCHING_PADDING_TIME_S = (int) Math.ceil(BATCHING_PERIOD * 0.1f + 2); 58 testAccelerometer_fastest_batching()59 public void testAccelerometer_fastest_batching() throws Throwable { 60 runBatchingSensorTest(Sensor.TYPE_ACCELEROMETER, RATE_FASTEST, BATCHING_PERIOD); 61 } 62 testAccelerometer_50hz_batching()63 public void testAccelerometer_50hz_batching() throws Throwable { 64 runBatchingSensorTest(Sensor.TYPE_ACCELEROMETER, RATE_50HZ, BATCHING_PERIOD); 65 } 66 testAccelerometer_fastest_flush()67 public void testAccelerometer_fastest_flush() throws Throwable { 68 runFlushSensorTest(Sensor.TYPE_ACCELEROMETER, RATE_FASTEST, BATCHING_PERIOD); 69 } 70 testAccelerometer_50hz_flush()71 public void testAccelerometer_50hz_flush() throws Throwable { 72 runFlushSensorTest(Sensor.TYPE_ACCELEROMETER, RATE_50HZ, BATCHING_PERIOD); 73 } 74 testAccelerometerUncalibrated_fastest_batching()75 public void testAccelerometerUncalibrated_fastest_batching() throws Throwable { 76 runBatchingSensorTest(Sensor.TYPE_ACCELEROMETER_UNCALIBRATED, 77 RATE_FASTEST, 78 BATCHING_PERIOD); 79 } 80 testAccelUncalibrated()81 public void testAccelUncalibrated() throws Throwable { 82 runBatchingSensorTest(Sensor.TYPE_ACCELEROMETER_UNCALIBRATED, 83 RATE_FASTEST, 84 BATCHING_PERIOD); 85 } 86 testAccelUncalibrated_50hz_batching()87 public void testAccelUncalibrated_50hz_batching() throws Throwable { 88 runBatchingSensorTest(Sensor.TYPE_ACCELEROMETER_UNCALIBRATED, RATE_50HZ, BATCHING_PERIOD); 89 } 90 testAccelUncalibrated_fastest_flush()91 public void testAccelUncalibrated_fastest_flush() throws Throwable { 92 runFlushSensorTest(Sensor.TYPE_ACCELEROMETER_UNCALIBRATED, RATE_FASTEST, BATCHING_PERIOD); 93 } 94 testAccelUncalibrated_50hz_flush()95 public void testAccelUncalibrated_50hz_flush() throws Throwable { 96 runFlushSensorTest(Sensor.TYPE_ACCELEROMETER_UNCALIBRATED, RATE_50HZ, BATCHING_PERIOD); 97 } 98 testAccelerometerLimitedAxes_fastest_batching()99 public void testAccelerometerLimitedAxes_fastest_batching() throws Throwable { 100 runBatchingSensorTest( 101 Sensor.TYPE_ACCELEROMETER_LIMITED_AXES, 102 RATE_FASTEST, 103 BATCHING_PERIOD); 104 } 105 testAccelerometerLimitedAxes_50hz_batching()106 public void testAccelerometerLimitedAxes_50hz_batching() throws Throwable { 107 runBatchingSensorTest(Sensor.TYPE_ACCELEROMETER_LIMITED_AXES, RATE_50HZ, BATCHING_PERIOD); 108 } 109 testAccelerometerLimitedAxes_fastest_flush()110 public void testAccelerometerLimitedAxes_fastest_flush() throws Throwable { 111 runFlushSensorTest(Sensor.TYPE_ACCELEROMETER_LIMITED_AXES, RATE_FASTEST, BATCHING_PERIOD); 112 } 113 testAccelerometerLimitedAxes_50hz_flush()114 public void testAccelerometerLimitedAxes_50hz_flush() throws Throwable { 115 runFlushSensorTest(Sensor.TYPE_ACCELEROMETER_LIMITED_AXES, RATE_50HZ, BATCHING_PERIOD); 116 } 117 testAccelerometerLimitedAxesUncalibrated_fastest_batching()118 public void testAccelerometerLimitedAxesUncalibrated_fastest_batching() throws Throwable { 119 runBatchingSensorTest(Sensor.TYPE_ACCELEROMETER_LIMITED_AXES_UNCALIBRATED, 120 RATE_FASTEST, 121 BATCHING_PERIOD); 122 } 123 testAccelerometerLimitedAxesUncalibrated()124 public void testAccelerometerLimitedAxesUncalibrated() throws Throwable { 125 runBatchingSensorTest(Sensor.TYPE_ACCELEROMETER_LIMITED_AXES_UNCALIBRATED, 126 RATE_FASTEST, 127 BATCHING_PERIOD); 128 } 129 testAccelerometerLimitedAxesUncalibrated_50hz_batching()130 public void testAccelerometerLimitedAxesUncalibrated_50hz_batching() throws Throwable { 131 runBatchingSensorTest( 132 Sensor.TYPE_ACCELEROMETER_LIMITED_AXES_UNCALIBRATED, 133 RATE_50HZ, 134 BATCHING_PERIOD); 135 } 136 testAccelerometerLimitedAxesUncalibrated_fastest_flush()137 public void testAccelerometerLimitedAxesUncalibrated_fastest_flush() throws Throwable { 138 runFlushSensorTest( 139 Sensor.TYPE_ACCELEROMETER_LIMITED_AXES_UNCALIBRATED, 140 RATE_FASTEST, 141 BATCHING_PERIOD); 142 } 143 testAccelerometerLimitedAxesUncalibrated_50hz_flush()144 public void testAccelerometerLimitedAxesUncalibrated_50hz_flush() throws Throwable { 145 runFlushSensorTest( 146 Sensor.TYPE_ACCELEROMETER_LIMITED_AXES_UNCALIBRATED, 147 RATE_50HZ, 148 BATCHING_PERIOD); 149 } 150 testMagneticField_fastest_batching()151 public void testMagneticField_fastest_batching() throws Throwable { 152 runBatchingSensorTest(Sensor.TYPE_MAGNETIC_FIELD, RATE_FASTEST, BATCHING_PERIOD); 153 } 154 testMagneticField_50hz_batching()155 public void testMagneticField_50hz_batching() throws Throwable { 156 runBatchingSensorTest(Sensor.TYPE_MAGNETIC_FIELD, RATE_50HZ, BATCHING_PERIOD); 157 } 158 testMagneticField_fastest_flush()159 public void testMagneticField_fastest_flush() throws Throwable { 160 runFlushSensorTest(Sensor.TYPE_MAGNETIC_FIELD, RATE_FASTEST, BATCHING_PERIOD); 161 } 162 testMagneticField_50hz_flush()163 public void testMagneticField_50hz_flush() throws Throwable { 164 runFlushSensorTest(Sensor.TYPE_MAGNETIC_FIELD, RATE_50HZ, BATCHING_PERIOD); 165 } 166 167 @SuppressWarnings("deprecation") testOrientation_fastest_batching()168 public void testOrientation_fastest_batching() throws Throwable { 169 runBatchingSensorTest(Sensor.TYPE_ORIENTATION, RATE_FASTEST, BATCHING_PERIOD); 170 } 171 172 @SuppressWarnings("deprecation") testOrientation_50hz_batching()173 public void testOrientation_50hz_batching() throws Throwable { 174 runBatchingSensorTest(Sensor.TYPE_ORIENTATION, RATE_50HZ, BATCHING_PERIOD); 175 } 176 177 @SuppressWarnings("deprecation") testOrientation_fastest_flush()178 public void testOrientation_fastest_flush() throws Throwable { 179 runFlushSensorTest(Sensor.TYPE_ORIENTATION, RATE_FASTEST, BATCHING_PERIOD); 180 } 181 182 @SuppressWarnings("deprecation") testOrientation_50hz_flush()183 public void testOrientation_50hz_flush() throws Throwable { 184 runFlushSensorTest(Sensor.TYPE_ORIENTATION, RATE_50HZ, BATCHING_PERIOD); 185 } 186 testGyroscope_fastest_batching()187 public void testGyroscope_fastest_batching() throws Throwable { 188 runBatchingSensorTest(Sensor.TYPE_GYROSCOPE, RATE_FASTEST, BATCHING_PERIOD); 189 } 190 testGyroscope_50hz_batching()191 public void testGyroscope_50hz_batching() throws Throwable { 192 runBatchingSensorTest(Sensor.TYPE_GYROSCOPE, RATE_50HZ, BATCHING_PERIOD); 193 } 194 testGyroscope_fastest_flush()195 public void testGyroscope_fastest_flush() throws Throwable { 196 runFlushSensorTest( 197 Sensor.TYPE_GYROSCOPE, 198 SensorManager.SENSOR_DELAY_FASTEST, 199 BATCHING_PERIOD); 200 } 201 testGyroscope_50hz_flush()202 public void testGyroscope_50hz_flush() throws Throwable { 203 runFlushSensorTest(Sensor.TYPE_GYROSCOPE, RATE_50HZ, BATCHING_PERIOD); 204 } 205 testGyroscopeLimitedAxes_fastest_batching()206 public void testGyroscopeLimitedAxes_fastest_batching() throws Throwable { 207 runBatchingSensorTest(Sensor.TYPE_GYROSCOPE_LIMITED_AXES, RATE_FASTEST, BATCHING_PERIOD); 208 } 209 testGyroscopeLimitedAxes_50hz_batching()210 public void testGyroscopeLimitedAxes_50hz_batching() throws Throwable { 211 runBatchingSensorTest(Sensor.TYPE_GYROSCOPE_LIMITED_AXES, RATE_50HZ, BATCHING_PERIOD); 212 } 213 testGyroscopeLimitedAxes_fastest_flush()214 public void testGyroscopeLimitedAxes_fastest_flush() throws Throwable { 215 runFlushSensorTest( 216 Sensor.TYPE_GYROSCOPE_LIMITED_AXES, 217 SensorManager.SENSOR_DELAY_FASTEST, 218 BATCHING_PERIOD); 219 } 220 testGyroscopeLimitedAxes_50hz_flush()221 public void testGyroscopeLimitedAxes_50hz_flush() throws Throwable { 222 runFlushSensorTest(Sensor.TYPE_GYROSCOPE_LIMITED_AXES, RATE_50HZ, BATCHING_PERIOD); 223 } 224 testPressure_fastest_batching()225 public void testPressure_fastest_batching() throws Throwable { 226 runBatchingSensorTest(Sensor.TYPE_PRESSURE, RATE_FASTEST, BATCHING_PERIOD); 227 } 228 testPressure_50hz_batching()229 public void testPressure_50hz_batching() throws Throwable { 230 runBatchingSensorTest(Sensor.TYPE_PRESSURE, RATE_50HZ, BATCHING_PERIOD); 231 } 232 testPressure_fastest_flush()233 public void testPressure_fastest_flush() throws Throwable { 234 runFlushSensorTest( 235 Sensor.TYPE_PRESSURE, 236 SensorManager.SENSOR_DELAY_FASTEST, 237 BATCHING_PERIOD); 238 } 239 testPressure_50hz_flush()240 public void testPressure_50hz_flush() throws Throwable { 241 runFlushSensorTest(Sensor.TYPE_PRESSURE, RATE_50HZ, BATCHING_PERIOD); 242 } 243 testGravity_fastest_batching()244 public void testGravity_fastest_batching() throws Throwable { 245 runBatchingSensorTest(Sensor.TYPE_GRAVITY, RATE_FASTEST, BATCHING_PERIOD); 246 } 247 testGravity_50hz_batching()248 public void testGravity_50hz_batching() throws Throwable { 249 runBatchingSensorTest(Sensor.TYPE_GRAVITY, RATE_50HZ, BATCHING_PERIOD); 250 } 251 testGravity_fastest_flush()252 public void testGravity_fastest_flush() throws Throwable { 253 runFlushSensorTest( 254 Sensor.TYPE_GRAVITY, 255 SensorManager.SENSOR_DELAY_FASTEST, 256 BATCHING_PERIOD); 257 } 258 testGravity_50hz_flush()259 public void testGravity_50hz_flush() throws Throwable { 260 runFlushSensorTest(Sensor.TYPE_GRAVITY, RATE_50HZ, BATCHING_PERIOD); 261 } 262 testRotationVector_fastest_batching()263 public void testRotationVector_fastest_batching() throws Throwable { 264 runBatchingSensorTest(Sensor.TYPE_ROTATION_VECTOR, RATE_FASTEST, BATCHING_PERIOD); 265 } 266 testRotationVector_50hz_batching()267 public void testRotationVector_50hz_batching() throws Throwable { 268 runBatchingSensorTest(Sensor.TYPE_ROTATION_VECTOR, RATE_50HZ, BATCHING_PERIOD); 269 } 270 testRotationVector_fastest_flush()271 public void testRotationVector_fastest_flush() throws Throwable { 272 runFlushSensorTest(Sensor.TYPE_ROTATION_VECTOR, RATE_FASTEST, BATCHING_PERIOD); 273 } 274 testRotationVector_50hz_flush()275 public void testRotationVector_50hz_flush() throws Throwable { 276 runFlushSensorTest(Sensor.TYPE_ROTATION_VECTOR, RATE_50HZ, BATCHING_PERIOD); 277 } 278 testMagneticFieldUncalibrated_fastest_batching()279 public void testMagneticFieldUncalibrated_fastest_batching() throws Throwable { 280 runBatchingSensorTest( 281 Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED, 282 RATE_FASTEST, 283 BATCHING_PERIOD); 284 } 285 testMagneticFieldUncalibrated_50hz_batching()286 public void testMagneticFieldUncalibrated_50hz_batching() throws Throwable { 287 runBatchingSensorTest(Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED, RATE_50HZ, BATCHING_PERIOD); 288 } 289 testMagneticFieldUncalibrated_fastest_flush()290 public void testMagneticFieldUncalibrated_fastest_flush() throws Throwable { 291 runFlushSensorTest(Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED, RATE_FASTEST, BATCHING_PERIOD); 292 } 293 testMagneticFieldUncalibrated_50hz_flush()294 public void testMagneticFieldUncalibrated_50hz_flush() throws Throwable { 295 runFlushSensorTest(Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED, RATE_50HZ, BATCHING_PERIOD); 296 } 297 testGameRotationVector_fastest_batching()298 public void testGameRotationVector_fastest_batching() throws Throwable { 299 runBatchingSensorTest(Sensor.TYPE_GAME_ROTATION_VECTOR, RATE_FASTEST, BATCHING_PERIOD); 300 } 301 testGameRotationVector_50hz_batching()302 public void testGameRotationVector_50hz_batching() throws Throwable { 303 runBatchingSensorTest(Sensor.TYPE_GAME_ROTATION_VECTOR, RATE_50HZ, BATCHING_PERIOD); 304 } 305 testGameRotationVector_fastest_flush()306 public void testGameRotationVector_fastest_flush() throws Throwable { 307 runFlushSensorTest(Sensor.TYPE_GAME_ROTATION_VECTOR, RATE_FASTEST, BATCHING_PERIOD); 308 } 309 testGameRotationVector_50hz_flush()310 public void testGameRotationVector_50hz_flush() throws Throwable { 311 runFlushSensorTest(Sensor.TYPE_GAME_ROTATION_VECTOR, RATE_50HZ, BATCHING_PERIOD); 312 } 313 testGyroscopeUncalibrated_fastest_batching()314 public void testGyroscopeUncalibrated_fastest_batching() throws Throwable { 315 runBatchingSensorTest(Sensor.TYPE_GYROSCOPE_UNCALIBRATED, RATE_FASTEST, BATCHING_PERIOD); 316 } 317 testGyroscopeUncalibrated_50hz_batching()318 public void testGyroscopeUncalibrated_50hz_batching() throws Throwable { 319 runBatchingSensorTest(Sensor.TYPE_GYROSCOPE_UNCALIBRATED, RATE_50HZ, BATCHING_PERIOD); 320 } 321 testGyroscopeUncalibrated_fastest_flush()322 public void testGyroscopeUncalibrated_fastest_flush() throws Throwable { 323 runFlushSensorTest(Sensor.TYPE_GYROSCOPE_UNCALIBRATED, RATE_FASTEST, BATCHING_PERIOD); 324 } 325 testGyroscopeUncalibrated_50hz_flush()326 public void testGyroscopeUncalibrated_50hz_flush() throws Throwable { 327 runFlushSensorTest(Sensor.TYPE_GYROSCOPE_UNCALIBRATED, RATE_50HZ, BATCHING_PERIOD); 328 } 329 testGyroscopeLimitedAxesUncalibrated_fastest_batching()330 public void testGyroscopeLimitedAxesUncalibrated_fastest_batching() throws Throwable { 331 runBatchingSensorTest( 332 Sensor.TYPE_GYROSCOPE_LIMITED_AXES_UNCALIBRATED, 333 RATE_FASTEST, 334 BATCHING_PERIOD); 335 } 336 testGyroscopeLimitedAxesUncalibrated_50hz_batching()337 public void testGyroscopeLimitedAxesUncalibrated_50hz_batching() throws Throwable { 338 runBatchingSensorTest( 339 Sensor.TYPE_GYROSCOPE_LIMITED_AXES_UNCALIBRATED, 340 RATE_50HZ, 341 BATCHING_PERIOD); 342 } 343 testGyroscopeLimitedAxesUncalibrated_fastest_flush()344 public void testGyroscopeLimitedAxesUncalibrated_fastest_flush() throws Throwable { 345 runFlushSensorTest( 346 Sensor.TYPE_GYROSCOPE_LIMITED_AXES_UNCALIBRATED, 347 RATE_FASTEST, 348 BATCHING_PERIOD); 349 } 350 testGyroscopeLimitedAxesUncalibrated_50hz_flush()351 public void testGyroscopeLimitedAxesUncalibrated_50hz_flush() throws Throwable { 352 runFlushSensorTest( 353 Sensor.TYPE_GYROSCOPE_LIMITED_AXES_UNCALIBRATED, 354 RATE_50HZ, 355 BATCHING_PERIOD); 356 } 357 testLinearAcceleration_fastest_batching()358 public void testLinearAcceleration_fastest_batching() throws Throwable { 359 runBatchingSensorTest(Sensor.TYPE_LINEAR_ACCELERATION, RATE_FASTEST, BATCHING_PERIOD); 360 } 361 testLinearAcceleration_50hz_batching()362 public void testLinearAcceleration_50hz_batching() throws Throwable { 363 runBatchingSensorTest(Sensor.TYPE_LINEAR_ACCELERATION, RATE_50HZ, BATCHING_PERIOD); 364 } 365 testLinearAcceleration_fastest_flush()366 public void testLinearAcceleration_fastest_flush() throws Throwable { 367 runFlushSensorTest(Sensor.TYPE_LINEAR_ACCELERATION, RATE_FASTEST, BATCHING_PERIOD); 368 } 369 testLinearAcceleration_50hz_flush()370 public void testLinearAcceleration_50hz_flush() throws Throwable { 371 runFlushSensorTest(Sensor.TYPE_LINEAR_ACCELERATION, RATE_50HZ, BATCHING_PERIOD); 372 } 373 testGeomagneticRotationVector_fastest_batching()374 public void testGeomagneticRotationVector_fastest_batching() throws Throwable { 375 runBatchingSensorTest( 376 Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR, 377 RATE_FASTEST, 378 BATCHING_PERIOD); 379 } 380 testGeomagneticRotationVector_50hz_batching()381 public void testGeomagneticRotationVector_50hz_batching() throws Throwable { 382 runBatchingSensorTest(Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR, RATE_50HZ, BATCHING_PERIOD); 383 } 384 testGeomagneticRotationVector_fastest_flush()385 public void testGeomagneticRotationVector_fastest_flush() throws Throwable { 386 runFlushSensorTest(Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR, RATE_FASTEST, BATCHING_PERIOD); 387 } 388 testGeomagneticRotationVector_50hz_flush()389 public void testGeomagneticRotationVector_50hz_flush() throws Throwable { 390 runFlushSensorTest(Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR, RATE_50HZ, BATCHING_PERIOD); 391 } 392 runBatchingSensorTest(int sensorType, int rateUs, int maxBatchReportLatencySec)393 private void runBatchingSensorTest(int sensorType, int rateUs, int maxBatchReportLatencySec) 394 throws Throwable { 395 int maxBatchReportLatencyUs = (int) TimeUnit.SECONDS.toMicros(maxBatchReportLatencySec); 396 int testDurationSec = maxBatchReportLatencySec + BATCHING_PADDING_TIME_S; 397 398 TestSensorEnvironment environment = new TestSensorEnvironment( 399 getContext(), 400 sensorType, 401 shouldEmulateSensorUnderLoad(), 402 rateUs, 403 maxBatchReportLatencyUs); 404 TestSensorOperation operation = 405 TestSensorOperation.createOperation(environment, testDurationSec, TimeUnit.SECONDS); 406 407 operation.addVerification( 408 EventBasicVerification.getDefault( 409 environment, TimeUnit.SECONDS.toMicros(testDurationSec) 410 ) 411 ); 412 if (sensorType == Sensor.TYPE_GYROSCOPE_UNCALIBRATED) { 413 // Checks gyroscope uncalibrated should not have high pass filter. 414 operation.addVerification( 415 MeanLargerThanVerification.getDefault(environment) 416 ); 417 } 418 executeTest(environment, operation, false /* flushExpected */); 419 } 420 runFlushSensorTest(int sensorType, int rateUs, int maxBatchReportLatencySec)421 private void runFlushSensorTest(int sensorType, int rateUs, int maxBatchReportLatencySec) 422 throws Throwable { 423 int maxBatchReportLatencyUs = (int) TimeUnit.SECONDS.toMicros(maxBatchReportLatencySec); 424 int flushDurationSec = maxBatchReportLatencySec / 2; 425 426 TestSensorEnvironment environment = new TestSensorEnvironment( 427 getContext(), 428 sensorType, 429 shouldEmulateSensorUnderLoad(), 430 rateUs, 431 maxBatchReportLatencyUs); 432 TestSensorOperation operation = TestSensorOperation 433 .createFlushOperation(environment, flushDurationSec, TimeUnit.SECONDS); 434 435 executeTest(environment, operation, true /* flushExpected */); 436 } 437 executeTest( TestSensorEnvironment environment, TestSensorOperation operation, boolean flushExpected)438 private void executeTest( 439 TestSensorEnvironment environment, 440 TestSensorOperation operation, 441 boolean flushExpected) throws Throwable { 442 SensorCtsHelper.sleep(3, TimeUnit.SECONDS); 443 operation.addDefaultVerifications(); 444 445 try { 446 operation.execute(getCurrentTestNode()); 447 } finally { 448 SensorStats stats = operation.getStats(); 449 stats.log(TAG); 450 451 String sensorRate; 452 if (environment.getRequestedSamplingPeriodUs() == SensorManager.SENSOR_DELAY_FASTEST) { 453 sensorRate = "fastest"; 454 } else { 455 sensorRate = String.format("%.0fhz", environment.getFrequencyHz()); 456 } 457 String batching = environment.getMaxReportLatencyUs() > 0 ? "_batching" : ""; 458 String flush = flushExpected ? "_flush" : ""; 459 String fileName = String.format( 460 "batching_%s_%s%s%s.txt", 461 SensorStats.getSanitizedSensorName(environment.getSensor()), 462 sensorRate, 463 batching, 464 flush); 465 stats.logToFile(environment.getContext(), fileName); 466 } 467 } 468 } 469