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.content.Context; 20 import android.hardware.Sensor; 21 import android.hardware.SensorManager; 22 import android.hardware.cts.helpers.SensorCtsHelper; 23 import android.hardware.cts.helpers.SensorStats; 24 import android.hardware.cts.helpers.TestSensorEnvironment; 25 import android.hardware.cts.helpers.sensoroperations.TestSensorOperation; 26 import android.content.pm.PackageManager; 27 28 import java.util.HashMap; 29 import java.util.Map; 30 import java.util.Map.Entry; 31 import java.util.concurrent.TimeUnit; 32 33 /** 34 * Set of tests to verify that sensors operate correctly when operating alone. 35 * <p> 36 * To execute these test cases, the following command can be used: 37 * </p><pre> 38 * adb shell am instrument -e class android.hardware.cts.SingleSensorTests \ 39 * -w android.hardware.cts/android.test.AndroidJUnitRunner 40 * </pre><p> 41 * For each sensor that reports continuously, it takes a set of samples. The test suite verifies 42 * that the event ordering, frequency, and jitter pass for the collected sensor events. It 43 * additionally tests that the mean, standard deviation, and magnitude are correct for the sensor 44 * event values, where applicable for a device in a static environment. 45 * </p><p> 46 * The event ordering test verifies the ordering of the sampled data reported by the Sensor under 47 * test. This test is used to guarantee that sensor data is reported in the order it occurs, and 48 * that events are always reported in order. It verifies that each event's timestamp is in the 49 * future compared with the previous event. At the end of the validation, the full set of events is 50 * verified to be ordered by timestamp as they are generated. The test can be susceptible to errors 51 * if the sensor sampled data is not timestamped at the hardware level. Or events sampled at high 52 * rates are added to the FIFO without controlling the appropriate ordering of the events. 53 * </p><p> 54 * The frequency test verifies that the sensor under test can sample and report data at the maximum 55 * frequency (sampling rate) it advertises. The frequency between events is calculated by looking at 56 * the delta between the timestamps associated with each event to get the period. The test is 57 * susceptible to errors if the sensor is not capable to sample data at the maximum rate it 58 * supports, or the sensor events are not timestamped at the hardware level. 59 * </p><p> 60 * The jitter test verifies that the event jittering associated with the sampled data reported by 61 * the sensor under test aligns with the requirements imposed in the CDD. This test characterizes 62 * how the sensor behaves while sampling data at a specific rate. It compares the 95th percentile of 63 * the jittering with a certain percentage of the minimum period. The test is susceptible to errors 64 * if the sensor events are not timestamped at the hardware level. 65 * </p><p> 66 * The mean test verifies that the mean of a set of sampled data from a particular sensor falls into 67 * the expectations defined in the CDD. The verification applies to each axis of the sampled data 68 * reported by the sensor under test. This test is used to validate the requirement imposed by the 69 * CDD to Sensors in Android and characterizes how the Sensor behaves while static. The test is 70 * susceptible to errors if the device is moving while the test is running, or if the sensor's 71 * sampled data indeed varies from the expected mean. 72 * </p><p> 73 * The magnitude test verifies that the magnitude of the sensor data is close to the expected 74 * reference value. The units of the reference value are dependent on the type of sensor. 75 * This test is used to verify that the data reported by the sensor is close to the expected 76 * range and scale. The test calculates the Euclidean norm of the vector represented by the sampled 77 * data and compares it against the test expectations. The test is susceptible to errors when the 78 * sensor under test is uncalibrated, or the units between the data and expectations are different. 79 * </p><p> 80 * The standard deviation test verifies that the standard deviation of a set of sampled data from a 81 * particular sensor falls into the expectations defined in the CDD. The verification applies to 82 * each axis of the sampled data reported by the sensor under test. This test is used to validate 83 * the requirement imposed by the CDD to Sensors in Android and characterizes how the Sensor behaves 84 * while static. The test is susceptible to errors if the device is moving while the test is 85 * running, or if the sensor's sampled data indeed falls into a large standard deviation. 86 * </p> 87 */ 88 public class SingleSensorTests extends SensorTestCase { 89 private static final String TAG = "SingleSensorTests"; 90 91 private static final int RATE_200HZ = 5000; 92 private static final int RATE_100HZ = 10000; 93 private static final int RATE_50HZ = 20000; 94 private static final int RATE_25HZ = 40000; 95 private static final int RATE_15HZ = 66667; 96 private static final int RATE_10HZ = 100000; 97 private static final int RATE_5HZ = 200000; 98 private static final int RATE_1HZ = 1000000; 99 100 /** 101 * This test verifies that the sensor's properties complies with the required properties set in 102 * the CDD. 103 * <p> 104 * It checks that the sampling rate advertised by the sensor under test matches that which is 105 * required by the CDD. 106 * </p> 107 */ 108 public void testSensorProperties() { 109 // sensor type: [getMinDelay()] 110 Map<Integer, Object[]> expectedProperties = new HashMap<>(3); 111 if(getContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH)) { 112 expectedProperties.put(Sensor.TYPE_ACCELEROMETER, new Object[]{20000}); 113 expectedProperties.put(Sensor.TYPE_GYROSCOPE, new Object[]{20000}); 114 }else { 115 expectedProperties.put(Sensor.TYPE_ACCELEROMETER, new Object[]{10000}); 116 expectedProperties.put(Sensor.TYPE_GYROSCOPE, new Object[]{10000}); 117 } 118 expectedProperties.put(Sensor.TYPE_MAGNETIC_FIELD, new Object[]{100000}); 119 120 SensorManager sensorManager = 121 (SensorManager) getContext().getSystemService(Context.SENSOR_SERVICE); 122 assertNotNull("SensorManager not present in the system.", sensorManager); 123 for (Entry<Integer, Object[]> entry : expectedProperties.entrySet()) { 124 Sensor sensor = sensorManager.getDefaultSensor(entry.getKey()); 125 if (sensor != null) { 126 if (entry.getValue()[0] != null) { 127 int expected = (Integer) entry.getValue()[0]; 128 String msg = String.format( 129 "%s: min delay %dus expected to be less than or equal to %dus", 130 sensor.getName(), 131 sensor.getMinDelay(), 132 expected); 133 assertTrue(msg, sensor.getMinDelay() <= expected); 134 } 135 } 136 } 137 } 138 139 // TODO: Figure out if a better way to enumerate test cases programmatically exists that works 140 // with CTS framework. 141 public void testAccelerometer_fastest() throws Throwable { 142 runSensorTest(Sensor.TYPE_ACCELEROMETER, SensorManager.SENSOR_DELAY_FASTEST); 143 } 144 145 public void testAccelerometer_200hz() throws Throwable { 146 runSensorTest(Sensor.TYPE_ACCELEROMETER, RATE_200HZ); 147 } 148 149 public void testAccelerometer_100hz() throws Throwable { 150 runSensorTest(Sensor.TYPE_ACCELEROMETER, RATE_100HZ); 151 } 152 153 public void testAccelerometer_50hz() throws Throwable { 154 runSensorTest(Sensor.TYPE_ACCELEROMETER, RATE_50HZ); 155 } 156 157 public void testAccelerometer_25hz() throws Throwable { 158 runSensorTest(Sensor.TYPE_ACCELEROMETER, RATE_25HZ); 159 } 160 161 public void testAccelerometer_15hz() throws Throwable { 162 runSensorTest(Sensor.TYPE_ACCELEROMETER, RATE_15HZ); 163 } 164 165 public void testAccelerometer_10hz() throws Throwable { 166 runSensorTest(Sensor.TYPE_ACCELEROMETER, RATE_10HZ); 167 } 168 169 public void testAccelerometer_5hz() throws Throwable { 170 runSensorTest(Sensor.TYPE_ACCELEROMETER, RATE_5HZ); 171 } 172 173 public void testAccelerometer_1hz() throws Throwable { 174 runSensorTest(Sensor.TYPE_ACCELEROMETER, RATE_1HZ); 175 } 176 177 public void testAccelUncalibrated_fastest() throws Throwable { 178 runSensorTest(Sensor.TYPE_ACCELEROMETER_UNCALIBRATED, SensorManager.SENSOR_DELAY_FASTEST); 179 } 180 181 public void testAccelUncalibrated_200hz() throws Throwable { 182 runSensorTest(Sensor.TYPE_ACCELEROMETER_UNCALIBRATED, RATE_200HZ); 183 } 184 185 public void testAccelUncalibrated_100hz() throws Throwable { 186 runSensorTest(Sensor.TYPE_ACCELEROMETER_UNCALIBRATED, RATE_100HZ); 187 } 188 189 public void testAccelUncalibrated_50hz() throws Throwable { 190 runSensorTest(Sensor.TYPE_ACCELEROMETER_UNCALIBRATED, RATE_50HZ); 191 } 192 193 public void testAccelUncalibrated_25hz() throws Throwable { 194 runSensorTest(Sensor.TYPE_ACCELEROMETER_UNCALIBRATED, RATE_25HZ); 195 } 196 197 public void testAccelUncalibrated_15hz() throws Throwable { 198 runSensorTest(Sensor.TYPE_ACCELEROMETER_UNCALIBRATED, RATE_15HZ); 199 } 200 201 public void testAccelUncalibrated_10hz() throws Throwable { 202 runSensorTest(Sensor.TYPE_ACCELEROMETER_UNCALIBRATED, RATE_10HZ); 203 } 204 205 public void testAccelUncalibrated_5hz() throws Throwable { 206 runSensorTest(Sensor.TYPE_ACCELEROMETER_UNCALIBRATED, RATE_5HZ); 207 } 208 209 public void testAccelUncalibrated_1hz() throws Throwable { 210 runSensorTest(Sensor.TYPE_ACCELEROMETER_UNCALIBRATED, RATE_1HZ); 211 } 212 213 public void testMagneticField_fastest() throws Throwable { 214 runSensorTest(Sensor.TYPE_MAGNETIC_FIELD, SensorManager.SENSOR_DELAY_FASTEST); 215 } 216 217 public void testMagneticField_200hz() throws Throwable { 218 runSensorTest(Sensor.TYPE_MAGNETIC_FIELD, RATE_200HZ); 219 } 220 221 public void testMagneticField_100hz() throws Throwable { 222 runSensorTest(Sensor.TYPE_MAGNETIC_FIELD, RATE_100HZ); 223 } 224 225 public void testMagneticField_50hz() throws Throwable { 226 runSensorTest(Sensor.TYPE_MAGNETIC_FIELD, RATE_50HZ); 227 } 228 229 public void testMagneticField_25hz() throws Throwable { 230 runSensorTest(Sensor.TYPE_MAGNETIC_FIELD, RATE_25HZ); 231 } 232 233 public void testMagneticField_15hz() throws Throwable { 234 runSensorTest(Sensor.TYPE_MAGNETIC_FIELD, RATE_15HZ); 235 } 236 237 public void testMagneticField_10hz() throws Throwable { 238 runSensorTest(Sensor.TYPE_MAGNETIC_FIELD, RATE_10HZ); 239 } 240 241 public void testMagneticField_5hz() throws Throwable { 242 runSensorTest(Sensor.TYPE_MAGNETIC_FIELD, RATE_5HZ); 243 } 244 245 public void testMagneticField_1hz() throws Throwable { 246 runSensorTest(Sensor.TYPE_MAGNETIC_FIELD, RATE_1HZ); 247 } 248 249 @SuppressWarnings("deprecation") 250 public void testOrientation_fastest() throws Throwable { 251 runSensorTest(Sensor.TYPE_ORIENTATION, SensorManager.SENSOR_DELAY_FASTEST); 252 } 253 254 @SuppressWarnings("deprecation") 255 public void testOrientation_200hz() throws Throwable { 256 runSensorTest(Sensor.TYPE_ORIENTATION, RATE_200HZ); 257 } 258 @SuppressWarnings("deprecation") 259 public void testOrientation_100hz() throws Throwable { 260 runSensorTest(Sensor.TYPE_ORIENTATION, RATE_100HZ); 261 } 262 263 @SuppressWarnings("deprecation") 264 public void testOrientation_50hz() throws Throwable { 265 runSensorTest(Sensor.TYPE_ORIENTATION, RATE_50HZ); 266 } 267 268 @SuppressWarnings("deprecation") 269 public void testOrientation_25hz() throws Throwable { 270 runSensorTest(Sensor.TYPE_ORIENTATION, RATE_25HZ); 271 } 272 273 @SuppressWarnings("deprecation") 274 public void testOrientation_15hz() throws Throwable { 275 runSensorTest(Sensor.TYPE_ORIENTATION, RATE_15HZ); 276 } 277 278 @SuppressWarnings("deprecation") 279 public void testOrientation_10hz() throws Throwable { 280 runSensorTest(Sensor.TYPE_ORIENTATION, RATE_10HZ); 281 } 282 283 @SuppressWarnings("deprecation") 284 public void testOrientation_5hz() throws Throwable { 285 runSensorTest(Sensor.TYPE_ORIENTATION, RATE_5HZ); 286 } 287 288 @SuppressWarnings("deprecation") 289 public void testOrientation_1hz() throws Throwable { 290 runSensorTest(Sensor.TYPE_ORIENTATION, RATE_1HZ); 291 } 292 293 public void testGyroscope_fastest() throws Throwable { 294 runSensorTest(Sensor.TYPE_GYROSCOPE, SensorManager.SENSOR_DELAY_FASTEST); 295 } 296 297 public void testGyroscope_200hz() throws Throwable { 298 runSensorTest(Sensor.TYPE_GYROSCOPE, RATE_200HZ); 299 } 300 301 public void testGyroscope_100hz() throws Throwable { 302 runSensorTest(Sensor.TYPE_GYROSCOPE, RATE_100HZ); 303 } 304 305 public void testGyroscope_50hz() throws Throwable { 306 runSensorTest(Sensor.TYPE_GYROSCOPE, RATE_50HZ); 307 } 308 309 public void testGyroscope_25hz() throws Throwable { 310 runSensorTest(Sensor.TYPE_GYROSCOPE, RATE_25HZ); 311 } 312 313 public void testGyroscope_15hz() throws Throwable { 314 runSensorTest(Sensor.TYPE_GYROSCOPE, RATE_15HZ); 315 } 316 317 public void testGyroscope_10hz() throws Throwable { 318 runSensorTest(Sensor.TYPE_GYROSCOPE, RATE_10HZ); 319 } 320 321 public void testGyroscope_5hz() throws Throwable { 322 runSensorTest(Sensor.TYPE_GYROSCOPE, RATE_5HZ); 323 } 324 325 public void testGyroscope_1hz() throws Throwable { 326 runSensorTest(Sensor.TYPE_GYROSCOPE, RATE_1HZ); 327 } 328 329 public void testPressure_fastest() throws Throwable { 330 runSensorTest(Sensor.TYPE_PRESSURE, SensorManager.SENSOR_DELAY_FASTEST); 331 } 332 333 public void testPressure_200hz() throws Throwable { 334 runSensorTest(Sensor.TYPE_PRESSURE, RATE_200HZ); 335 } 336 337 public void testPressure_100hz() throws Throwable { 338 runSensorTest(Sensor.TYPE_PRESSURE, RATE_100HZ); 339 } 340 341 public void testPressure_50hz() throws Throwable { 342 runSensorTest(Sensor.TYPE_PRESSURE, RATE_50HZ); 343 } 344 345 public void testPressure_25hz() throws Throwable { 346 runSensorTest(Sensor.TYPE_PRESSURE, RATE_25HZ); 347 } 348 349 public void testPressure_15hz() throws Throwable { 350 runSensorTest(Sensor.TYPE_PRESSURE, RATE_15HZ); 351 } 352 353 public void testPressure_10hz() throws Throwable { 354 runSensorTest(Sensor.TYPE_PRESSURE, RATE_10HZ); 355 } 356 357 public void testPressure_5hz() throws Throwable { 358 runSensorTest(Sensor.TYPE_PRESSURE, RATE_5HZ); 359 } 360 361 public void testPressure_1hz() throws Throwable { 362 runSensorTest(Sensor.TYPE_PRESSURE, RATE_1HZ); 363 } 364 365 public void testGravity_fastest() throws Throwable { 366 runSensorTest(Sensor.TYPE_GRAVITY, SensorManager.SENSOR_DELAY_FASTEST); 367 } 368 369 public void testGravity_200hz() throws Throwable { 370 runSensorTest(Sensor.TYPE_GRAVITY, RATE_200HZ); 371 } 372 373 public void testGravity_100hz() throws Throwable { 374 runSensorTest(Sensor.TYPE_GRAVITY, RATE_100HZ); 375 } 376 377 public void testGravity_50hz() throws Throwable { 378 runSensorTest(Sensor.TYPE_GRAVITY, RATE_50HZ); 379 } 380 381 public void testGravity_25hz() throws Throwable { 382 runSensorTest(Sensor.TYPE_GRAVITY, RATE_25HZ); 383 } 384 385 public void testGravity_15hz() throws Throwable { 386 runSensorTest(Sensor.TYPE_GRAVITY, RATE_15HZ); 387 } 388 389 public void testGravity_10hz() throws Throwable { 390 runSensorTest(Sensor.TYPE_GRAVITY, RATE_10HZ); 391 } 392 393 public void testGravity_5hz() throws Throwable { 394 runSensorTest(Sensor.TYPE_GRAVITY, RATE_5HZ); 395 } 396 397 public void testGravity_1hz() throws Throwable { 398 runSensorTest(Sensor.TYPE_GRAVITY, RATE_1HZ); 399 } 400 401 public void testRotationVector_fastest() throws Throwable { 402 runSensorTest(Sensor.TYPE_ROTATION_VECTOR, SensorManager.SENSOR_DELAY_FASTEST); 403 } 404 405 public void testRotationVector_200hz() throws Throwable { 406 runSensorTest(Sensor.TYPE_ROTATION_VECTOR, RATE_200HZ); 407 } 408 409 public void testRotationVector_100hz() throws Throwable { 410 runSensorTest(Sensor.TYPE_ROTATION_VECTOR, RATE_100HZ); 411 } 412 413 public void testRotationVector_50hz() throws Throwable { 414 runSensorTest(Sensor.TYPE_ROTATION_VECTOR, RATE_50HZ); 415 } 416 417 public void testRotationVector_25hz() throws Throwable { 418 runSensorTest(Sensor.TYPE_ROTATION_VECTOR, RATE_25HZ); 419 } 420 421 public void testRotationVector_15hz() throws Throwable { 422 runSensorTest(Sensor.TYPE_ROTATION_VECTOR, RATE_15HZ); 423 } 424 425 public void testRotationVector_10hz() throws Throwable { 426 runSensorTest(Sensor.TYPE_ROTATION_VECTOR, RATE_10HZ); 427 } 428 429 public void testRotationVector_5hz() throws Throwable { 430 runSensorTest(Sensor.TYPE_ROTATION_VECTOR, RATE_5HZ); 431 } 432 433 public void testRotationVector_1hz() throws Throwable { 434 runSensorTest(Sensor.TYPE_ROTATION_VECTOR, RATE_1HZ); 435 } 436 437 public void testMagneticFieldUncalibrated_fastest() throws Throwable { 438 runSensorTest(Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED, SensorManager.SENSOR_DELAY_FASTEST); 439 } 440 441 public void testMagneticFieldUncalibrated_200hz() throws Throwable { 442 runSensorTest(Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED, RATE_200HZ); 443 } 444 445 public void testMagneticFieldUncalibrated_100hz() throws Throwable { 446 runSensorTest(Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED, RATE_100HZ); 447 } 448 449 public void testMagneticFieldUncalibrated_50hz() throws Throwable { 450 runSensorTest(Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED, RATE_50HZ); 451 } 452 453 public void testMagneticFieldUncalibrated_25hz() throws Throwable { 454 runSensorTest(Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED, RATE_25HZ); 455 } 456 457 public void testMagneticFieldUncalibrated_15hz() throws Throwable { 458 runSensorTest(Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED, RATE_15HZ); 459 } 460 461 public void testMagneticFieldUncalibrated_10hz() throws Throwable { 462 runSensorTest(Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED, RATE_10HZ); 463 } 464 465 public void testMagneticFieldUncalibrated_5hz() throws Throwable { 466 runSensorTest(Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED, RATE_5HZ); 467 } 468 469 public void testMagneticFieldUncalibrated_1hz() throws Throwable { 470 runSensorTest(Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED, RATE_1HZ); 471 } 472 473 public void testGameRotationVector_fastest() throws Throwable { 474 runSensorTest(Sensor.TYPE_GAME_ROTATION_VECTOR, SensorManager.SENSOR_DELAY_FASTEST); 475 } 476 477 public void testGameRotationVector_200hz() throws Throwable { 478 runSensorTest(Sensor.TYPE_GAME_ROTATION_VECTOR, RATE_200HZ); 479 } 480 481 public void testGameRotationVector_100hz() throws Throwable { 482 runSensorTest(Sensor.TYPE_GAME_ROTATION_VECTOR, RATE_100HZ); 483 } 484 485 public void testGameRotationVector_50hz() throws Throwable { 486 runSensorTest(Sensor.TYPE_GAME_ROTATION_VECTOR, RATE_50HZ); 487 } 488 489 public void testGameRotationVector_25hz() throws Throwable { 490 runSensorTest(Sensor.TYPE_GAME_ROTATION_VECTOR, RATE_25HZ); 491 } 492 493 public void testGameRotationVector_15hz() throws Throwable { 494 runSensorTest(Sensor.TYPE_GAME_ROTATION_VECTOR, RATE_15HZ); 495 } 496 497 public void testGameRotationVector_10hz() throws Throwable { 498 runSensorTest(Sensor.TYPE_GAME_ROTATION_VECTOR, RATE_10HZ); 499 } 500 501 public void testGameRotationVector_5hz() throws Throwable { 502 runSensorTest(Sensor.TYPE_GAME_ROTATION_VECTOR, RATE_5HZ); 503 } 504 505 public void testGameRotationVector_1hz() throws Throwable { 506 runSensorTest(Sensor.TYPE_GAME_ROTATION_VECTOR, RATE_1HZ); 507 } 508 509 public void testGyroscopeUncalibrated_fastest() throws Throwable { 510 runSensorTest(Sensor.TYPE_GYROSCOPE_UNCALIBRATED, SensorManager.SENSOR_DELAY_FASTEST); 511 } 512 513 public void testGyroscopeUncalibrated_200hz() throws Throwable { 514 runSensorTest(Sensor.TYPE_GYROSCOPE_UNCALIBRATED, RATE_200HZ); 515 } 516 517 public void testGyroscopeUncalibrated_100hz() throws Throwable { 518 runSensorTest(Sensor.TYPE_GYROSCOPE_UNCALIBRATED, RATE_100HZ); 519 } 520 521 public void testGyroscopeUncalibrated_50hz() throws Throwable { 522 runSensorTest(Sensor.TYPE_GYROSCOPE_UNCALIBRATED, RATE_50HZ); 523 } 524 525 public void testGyroscopeUncalibrated_25hz() throws Throwable { 526 runSensorTest(Sensor.TYPE_GYROSCOPE_UNCALIBRATED, RATE_25HZ); 527 } 528 529 public void testGyroscopeUncalibrated_15hz() throws Throwable { 530 runSensorTest(Sensor.TYPE_GYROSCOPE_UNCALIBRATED, RATE_15HZ); 531 } 532 533 public void testGyroscopeUncalibrated_10hz() throws Throwable { 534 runSensorTest(Sensor.TYPE_GYROSCOPE_UNCALIBRATED, RATE_10HZ); 535 } 536 537 public void testGyroscopeUncalibrated_5hz() throws Throwable { 538 runSensorTest(Sensor.TYPE_GYROSCOPE_UNCALIBRATED, RATE_5HZ); 539 } 540 541 public void testGyroscopeUncalibrated_1hz() throws Throwable { 542 runSensorTest(Sensor.TYPE_GYROSCOPE_UNCALIBRATED, RATE_1HZ); 543 } 544 545 public void testGeomagneticRotationVector_fastest() throws Throwable { 546 runSensorTest(Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR, SensorManager.SENSOR_DELAY_FASTEST); 547 } 548 549 public void testLinearAcceleration_200hz() throws Throwable { 550 runSensorTest(Sensor.TYPE_LINEAR_ACCELERATION, RATE_200HZ); 551 } 552 553 public void testLinearAcceleration_100hz() throws Throwable { 554 runSensorTest(Sensor.TYPE_LINEAR_ACCELERATION, RATE_100HZ); 555 } 556 557 public void testLinearAcceleration_50hz() throws Throwable { 558 runSensorTest(Sensor.TYPE_LINEAR_ACCELERATION, RATE_50HZ); 559 } 560 561 public void testLinearAcceleration_25hz() throws Throwable { 562 runSensorTest(Sensor.TYPE_LINEAR_ACCELERATION, RATE_25HZ); 563 } 564 565 public void testLinearAcceleration_15hz() throws Throwable { 566 runSensorTest(Sensor.TYPE_LINEAR_ACCELERATION, RATE_15HZ); 567 } 568 569 public void testLinearAcceleration_10hz() throws Throwable { 570 runSensorTest(Sensor.TYPE_LINEAR_ACCELERATION, RATE_10HZ); 571 } 572 573 public void testLinearAcceleration_5hz() throws Throwable { 574 runSensorTest(Sensor.TYPE_LINEAR_ACCELERATION, RATE_5HZ); 575 } 576 577 public void testLinearAcceleration_1hz() throws Throwable { 578 runSensorTest(Sensor.TYPE_LINEAR_ACCELERATION, RATE_1HZ); 579 } 580 581 private void runSensorTest(int sensorType, int rateUs) throws Throwable { 582 SensorCtsHelper.sleep(3, TimeUnit.SECONDS); 583 TestSensorEnvironment environment = new TestSensorEnvironment( 584 getContext(), 585 sensorType, 586 shouldEmulateSensorUnderLoad(), 587 rateUs); 588 TestSensorOperation op = 589 TestSensorOperation.createOperation(environment, 5, TimeUnit.SECONDS); 590 op.addDefaultVerifications(); 591 592 try { 593 op.execute(getCurrentTestNode()); 594 } finally { 595 SensorStats stats = op.getStats(); 596 stats.log(TAG); 597 598 String fileName = String.format( 599 "single_%s_%s.txt", 600 SensorStats.getSanitizedSensorName(environment.getSensor()), 601 environment.getFrequencyString()); 602 stats.logToFile(fileName); 603 } 604 } 605 } 606