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 */ testSensorProperties()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. testAccelerometer_fastest()141 public void testAccelerometer_fastest() throws Throwable { 142 runSensorTest(Sensor.TYPE_ACCELEROMETER, SensorManager.SENSOR_DELAY_FASTEST); 143 } 144 testAccelerometer_100hz()145 public void testAccelerometer_100hz() throws Throwable { 146 runSensorTest(Sensor.TYPE_ACCELEROMETER, RATE_100HZ); 147 } 148 testAccelerometer_200hz()149 public void testAccelerometer_200hz() throws Throwable { 150 runSensorTest(Sensor.TYPE_ACCELEROMETER, RATE_200HZ); 151 } 152 testAccelerometer_50hz()153 public void testAccelerometer_50hz() throws Throwable { 154 runSensorTest(Sensor.TYPE_ACCELEROMETER, RATE_50HZ); 155 } 156 testAccelerometer_25hz()157 public void testAccelerometer_25hz() throws Throwable { 158 runSensorTest(Sensor.TYPE_ACCELEROMETER, RATE_25HZ); 159 } 160 testAccelerometer_15hz()161 public void testAccelerometer_15hz() throws Throwable { 162 runSensorTest(Sensor.TYPE_ACCELEROMETER, RATE_15HZ); 163 } 164 testAccelerometer_10hz()165 public void testAccelerometer_10hz() throws Throwable { 166 runSensorTest(Sensor.TYPE_ACCELEROMETER, RATE_10HZ); 167 } 168 testAccelerometer_5hz()169 public void testAccelerometer_5hz() throws Throwable { 170 runSensorTest(Sensor.TYPE_ACCELEROMETER, RATE_5HZ); 171 } 172 testAccelerometer_1hz()173 public void testAccelerometer_1hz() throws Throwable { 174 runSensorTest(Sensor.TYPE_ACCELEROMETER, RATE_1HZ); 175 } 176 testMagneticField_fastest()177 public void testMagneticField_fastest() throws Throwable { 178 runSensorTest(Sensor.TYPE_MAGNETIC_FIELD, SensorManager.SENSOR_DELAY_FASTEST); 179 } 180 testMagneticField_200hz()181 public void testMagneticField_200hz() throws Throwable { 182 runSensorTest(Sensor.TYPE_MAGNETIC_FIELD, RATE_200HZ); 183 } 184 testMagneticField_100hz()185 public void testMagneticField_100hz() throws Throwable { 186 runSensorTest(Sensor.TYPE_MAGNETIC_FIELD, RATE_100HZ); 187 } 188 testMagneticField_50hz()189 public void testMagneticField_50hz() throws Throwable { 190 runSensorTest(Sensor.TYPE_MAGNETIC_FIELD, RATE_50HZ); 191 } 192 testMagneticField_25hz()193 public void testMagneticField_25hz() throws Throwable { 194 runSensorTest(Sensor.TYPE_MAGNETIC_FIELD, RATE_25HZ); 195 } 196 testMagneticField_15hz()197 public void testMagneticField_15hz() throws Throwable { 198 runSensorTest(Sensor.TYPE_MAGNETIC_FIELD, RATE_15HZ); 199 } 200 testMagneticField_10hz()201 public void testMagneticField_10hz() throws Throwable { 202 runSensorTest(Sensor.TYPE_MAGNETIC_FIELD, RATE_10HZ); 203 } 204 testMagneticField_5hz()205 public void testMagneticField_5hz() throws Throwable { 206 runSensorTest(Sensor.TYPE_MAGNETIC_FIELD, RATE_5HZ); 207 } 208 testMagneticField_1hz()209 public void testMagneticField_1hz() throws Throwable { 210 runSensorTest(Sensor.TYPE_MAGNETIC_FIELD, RATE_1HZ); 211 } 212 213 @SuppressWarnings("deprecation") testOrientation_fastest()214 public void testOrientation_fastest() throws Throwable { 215 runSensorTest(Sensor.TYPE_ORIENTATION, SensorManager.SENSOR_DELAY_FASTEST); 216 } 217 218 @SuppressWarnings("deprecation") testOrientation_200hz()219 public void testOrientation_200hz() throws Throwable { 220 runSensorTest(Sensor.TYPE_ORIENTATION, RATE_200HZ); 221 } 222 @SuppressWarnings("deprecation") testOrientation_100hz()223 public void testOrientation_100hz() throws Throwable { 224 runSensorTest(Sensor.TYPE_ORIENTATION, RATE_100HZ); 225 } 226 227 @SuppressWarnings("deprecation") testOrientation_50hz()228 public void testOrientation_50hz() throws Throwable { 229 runSensorTest(Sensor.TYPE_ORIENTATION, RATE_50HZ); 230 } 231 232 @SuppressWarnings("deprecation") testOrientation_25hz()233 public void testOrientation_25hz() throws Throwable { 234 runSensorTest(Sensor.TYPE_ORIENTATION, RATE_25HZ); 235 } 236 237 @SuppressWarnings("deprecation") testOrientation_15hz()238 public void testOrientation_15hz() throws Throwable { 239 runSensorTest(Sensor.TYPE_ORIENTATION, RATE_15HZ); 240 } 241 242 @SuppressWarnings("deprecation") testOrientation_10hz()243 public void testOrientation_10hz() throws Throwable { 244 runSensorTest(Sensor.TYPE_ORIENTATION, RATE_10HZ); 245 } 246 247 @SuppressWarnings("deprecation") testOrientation_5hz()248 public void testOrientation_5hz() throws Throwable { 249 runSensorTest(Sensor.TYPE_ORIENTATION, RATE_5HZ); 250 } 251 252 @SuppressWarnings("deprecation") testOrientation_1hz()253 public void testOrientation_1hz() throws Throwable { 254 runSensorTest(Sensor.TYPE_ORIENTATION, RATE_1HZ); 255 } 256 testGyroscope_fastest()257 public void testGyroscope_fastest() throws Throwable { 258 runSensorTest(Sensor.TYPE_GYROSCOPE, SensorManager.SENSOR_DELAY_FASTEST); 259 } 260 testGyroscope_200hz()261 public void testGyroscope_200hz() throws Throwable { 262 runSensorTest(Sensor.TYPE_GYROSCOPE, RATE_200HZ); 263 } 264 testGyroscope_100hz()265 public void testGyroscope_100hz() throws Throwable { 266 runSensorTest(Sensor.TYPE_GYROSCOPE, RATE_100HZ); 267 } 268 testGyroscope_50hz()269 public void testGyroscope_50hz() throws Throwable { 270 runSensorTest(Sensor.TYPE_GYROSCOPE, RATE_50HZ); 271 } 272 testGyroscope_25hz()273 public void testGyroscope_25hz() throws Throwable { 274 runSensorTest(Sensor.TYPE_GYROSCOPE, RATE_25HZ); 275 } 276 testGyroscope_15hz()277 public void testGyroscope_15hz() throws Throwable { 278 runSensorTest(Sensor.TYPE_GYROSCOPE, RATE_15HZ); 279 } 280 testGyroscope_10hz()281 public void testGyroscope_10hz() throws Throwable { 282 runSensorTest(Sensor.TYPE_GYROSCOPE, RATE_10HZ); 283 } 284 testGyroscope_5hz()285 public void testGyroscope_5hz() throws Throwable { 286 runSensorTest(Sensor.TYPE_GYROSCOPE, RATE_5HZ); 287 } 288 testGyroscope_1hz()289 public void testGyroscope_1hz() throws Throwable { 290 runSensorTest(Sensor.TYPE_GYROSCOPE, RATE_1HZ); 291 } 292 testPressure_fastest()293 public void testPressure_fastest() throws Throwable { 294 runSensorTest(Sensor.TYPE_PRESSURE, SensorManager.SENSOR_DELAY_FASTEST); 295 } 296 testPressure_200hz()297 public void testPressure_200hz() throws Throwable { 298 runSensorTest(Sensor.TYPE_PRESSURE, RATE_200HZ); 299 } 300 testPressure_100hz()301 public void testPressure_100hz() throws Throwable { 302 runSensorTest(Sensor.TYPE_PRESSURE, RATE_100HZ); 303 } 304 testPressure_50hz()305 public void testPressure_50hz() throws Throwable { 306 runSensorTest(Sensor.TYPE_PRESSURE, RATE_50HZ); 307 } 308 testPressure_25hz()309 public void testPressure_25hz() throws Throwable { 310 runSensorTest(Sensor.TYPE_PRESSURE, RATE_25HZ); 311 } 312 testPressure_15hz()313 public void testPressure_15hz() throws Throwable { 314 runSensorTest(Sensor.TYPE_PRESSURE, RATE_15HZ); 315 } 316 testPressure_10hz()317 public void testPressure_10hz() throws Throwable { 318 runSensorTest(Sensor.TYPE_PRESSURE, RATE_10HZ); 319 } 320 testPressure_5hz()321 public void testPressure_5hz() throws Throwable { 322 runSensorTest(Sensor.TYPE_PRESSURE, RATE_5HZ); 323 } 324 testPressure_1hz()325 public void testPressure_1hz() throws Throwable { 326 runSensorTest(Sensor.TYPE_PRESSURE, RATE_1HZ); 327 } 328 testGravity_fastest()329 public void testGravity_fastest() throws Throwable { 330 runSensorTest(Sensor.TYPE_GRAVITY, SensorManager.SENSOR_DELAY_FASTEST); 331 } 332 testGravity_200hz()333 public void testGravity_200hz() throws Throwable { 334 runSensorTest(Sensor.TYPE_GRAVITY, RATE_200HZ); 335 } 336 testGravity_100hz()337 public void testGravity_100hz() throws Throwable { 338 runSensorTest(Sensor.TYPE_GRAVITY, RATE_100HZ); 339 } 340 testGravity_50hz()341 public void testGravity_50hz() throws Throwable { 342 runSensorTest(Sensor.TYPE_GRAVITY, RATE_50HZ); 343 } 344 testGravity_25hz()345 public void testGravity_25hz() throws Throwable { 346 runSensorTest(Sensor.TYPE_GRAVITY, RATE_25HZ); 347 } 348 testGravity_15hz()349 public void testGravity_15hz() throws Throwable { 350 runSensorTest(Sensor.TYPE_GRAVITY, RATE_15HZ); 351 } 352 testGravity_10hz()353 public void testGravity_10hz() throws Throwable { 354 runSensorTest(Sensor.TYPE_GRAVITY, RATE_10HZ); 355 } 356 testGravity_5hz()357 public void testGravity_5hz() throws Throwable { 358 runSensorTest(Sensor.TYPE_GRAVITY, RATE_5HZ); 359 } 360 testGravity_1hz()361 public void testGravity_1hz() throws Throwable { 362 runSensorTest(Sensor.TYPE_GRAVITY, RATE_1HZ); 363 } 364 testRotationVector_fastest()365 public void testRotationVector_fastest() throws Throwable { 366 runSensorTest(Sensor.TYPE_ROTATION_VECTOR, SensorManager.SENSOR_DELAY_FASTEST); 367 } 368 testRotationVector_200hz()369 public void testRotationVector_200hz() throws Throwable { 370 runSensorTest(Sensor.TYPE_ROTATION_VECTOR, RATE_200HZ); 371 } 372 testRotationVector_100hz()373 public void testRotationVector_100hz() throws Throwable { 374 runSensorTest(Sensor.TYPE_ROTATION_VECTOR, RATE_100HZ); 375 } 376 testRotationVector_50hz()377 public void testRotationVector_50hz() throws Throwable { 378 runSensorTest(Sensor.TYPE_ROTATION_VECTOR, RATE_50HZ); 379 } 380 testRotationVector_25hz()381 public void testRotationVector_25hz() throws Throwable { 382 runSensorTest(Sensor.TYPE_ROTATION_VECTOR, RATE_25HZ); 383 } 384 testRotationVector_15hz()385 public void testRotationVector_15hz() throws Throwable { 386 runSensorTest(Sensor.TYPE_ROTATION_VECTOR, RATE_15HZ); 387 } 388 testRotationVector_10hz()389 public void testRotationVector_10hz() throws Throwable { 390 runSensorTest(Sensor.TYPE_ROTATION_VECTOR, RATE_10HZ); 391 } 392 testRotationVector_5hz()393 public void testRotationVector_5hz() throws Throwable { 394 runSensorTest(Sensor.TYPE_ROTATION_VECTOR, RATE_5HZ); 395 } 396 testRotationVector_1hz()397 public void testRotationVector_1hz() throws Throwable { 398 runSensorTest(Sensor.TYPE_ROTATION_VECTOR, RATE_1HZ); 399 } 400 testMagneticFieldUncalibrated_fastest()401 public void testMagneticFieldUncalibrated_fastest() throws Throwable { 402 runSensorTest(Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED, SensorManager.SENSOR_DELAY_FASTEST); 403 } 404 testMagneticFieldUncalibrated_200hz()405 public void testMagneticFieldUncalibrated_200hz() throws Throwable { 406 runSensorTest(Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED, RATE_200HZ); 407 } 408 testMagneticFieldUncalibrated_100hz()409 public void testMagneticFieldUncalibrated_100hz() throws Throwable { 410 runSensorTest(Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED, RATE_100HZ); 411 } 412 testMagneticFieldUncalibrated_50hz()413 public void testMagneticFieldUncalibrated_50hz() throws Throwable { 414 runSensorTest(Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED, RATE_50HZ); 415 } 416 testMagneticFieldUncalibrated_25hz()417 public void testMagneticFieldUncalibrated_25hz() throws Throwable { 418 runSensorTest(Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED, RATE_25HZ); 419 } 420 testMagneticFieldUncalibrated_15hz()421 public void testMagneticFieldUncalibrated_15hz() throws Throwable { 422 runSensorTest(Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED, RATE_15HZ); 423 } 424 testMagneticFieldUncalibrated_10hz()425 public void testMagneticFieldUncalibrated_10hz() throws Throwable { 426 runSensorTest(Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED, RATE_10HZ); 427 } 428 testMagneticFieldUncalibrated_5hz()429 public void testMagneticFieldUncalibrated_5hz() throws Throwable { 430 runSensorTest(Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED, RATE_5HZ); 431 } 432 testMagneticFieldUncalibrated_1hz()433 public void testMagneticFieldUncalibrated_1hz() throws Throwable { 434 runSensorTest(Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED, RATE_1HZ); 435 } 436 testGameRotationVector_fastest()437 public void testGameRotationVector_fastest() throws Throwable { 438 runSensorTest(Sensor.TYPE_GAME_ROTATION_VECTOR, SensorManager.SENSOR_DELAY_FASTEST); 439 } 440 testGameRotationVector_200hz()441 public void testGameRotationVector_200hz() throws Throwable { 442 runSensorTest(Sensor.TYPE_GAME_ROTATION_VECTOR, RATE_200HZ); 443 } 444 testGameRotationVector_100hz()445 public void testGameRotationVector_100hz() throws Throwable { 446 runSensorTest(Sensor.TYPE_GAME_ROTATION_VECTOR, RATE_100HZ); 447 } 448 testGameRotationVector_50hz()449 public void testGameRotationVector_50hz() throws Throwable { 450 runSensorTest(Sensor.TYPE_GAME_ROTATION_VECTOR, RATE_50HZ); 451 } 452 testGameRotationVector_25hz()453 public void testGameRotationVector_25hz() throws Throwable { 454 runSensorTest(Sensor.TYPE_GAME_ROTATION_VECTOR, RATE_25HZ); 455 } 456 testGameRotationVector_15hz()457 public void testGameRotationVector_15hz() throws Throwable { 458 runSensorTest(Sensor.TYPE_GAME_ROTATION_VECTOR, RATE_15HZ); 459 } 460 testGameRotationVector_10hz()461 public void testGameRotationVector_10hz() throws Throwable { 462 runSensorTest(Sensor.TYPE_GAME_ROTATION_VECTOR, RATE_10HZ); 463 } 464 testGameRotationVector_5hz()465 public void testGameRotationVector_5hz() throws Throwable { 466 runSensorTest(Sensor.TYPE_GAME_ROTATION_VECTOR, RATE_5HZ); 467 } 468 testGameRotationVector_1hz()469 public void testGameRotationVector_1hz() throws Throwable { 470 runSensorTest(Sensor.TYPE_GAME_ROTATION_VECTOR, RATE_1HZ); 471 } 472 testGyroscopeUncalibrated_fastest()473 public void testGyroscopeUncalibrated_fastest() throws Throwable { 474 runSensorTest(Sensor.TYPE_GYROSCOPE_UNCALIBRATED, SensorManager.SENSOR_DELAY_FASTEST); 475 } 476 testGyroscopeUncalibrated_200hz()477 public void testGyroscopeUncalibrated_200hz() throws Throwable { 478 runSensorTest(Sensor.TYPE_GYROSCOPE_UNCALIBRATED, RATE_200HZ); 479 } 480 testGyroscopeUncalibrated_100hz()481 public void testGyroscopeUncalibrated_100hz() throws Throwable { 482 runSensorTest(Sensor.TYPE_GYROSCOPE_UNCALIBRATED, RATE_100HZ); 483 } 484 testGyroscopeUncalibrated_50hz()485 public void testGyroscopeUncalibrated_50hz() throws Throwable { 486 runSensorTest(Sensor.TYPE_GYROSCOPE_UNCALIBRATED, RATE_50HZ); 487 } 488 testGyroscopeUncalibrated_25hz()489 public void testGyroscopeUncalibrated_25hz() throws Throwable { 490 runSensorTest(Sensor.TYPE_GYROSCOPE_UNCALIBRATED, RATE_25HZ); 491 } 492 testGyroscopeUncalibrated_15hz()493 public void testGyroscopeUncalibrated_15hz() throws Throwable { 494 runSensorTest(Sensor.TYPE_GYROSCOPE_UNCALIBRATED, RATE_15HZ); 495 } 496 testGyroscopeUncalibrated_10hz()497 public void testGyroscopeUncalibrated_10hz() throws Throwable { 498 runSensorTest(Sensor.TYPE_GYROSCOPE_UNCALIBRATED, RATE_10HZ); 499 } 500 testGyroscopeUncalibrated_5hz()501 public void testGyroscopeUncalibrated_5hz() throws Throwable { 502 runSensorTest(Sensor.TYPE_GYROSCOPE_UNCALIBRATED, RATE_5HZ); 503 } 504 testGyroscopeUncalibrated_1hz()505 public void testGyroscopeUncalibrated_1hz() throws Throwable { 506 runSensorTest(Sensor.TYPE_GYROSCOPE_UNCALIBRATED, RATE_1HZ); 507 } 508 testGeomagneticRotationVector_fastest()509 public void testGeomagneticRotationVector_fastest() throws Throwable { 510 runSensorTest(Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR, SensorManager.SENSOR_DELAY_FASTEST); 511 } 512 testLinearAcceleration_200hz()513 public void testLinearAcceleration_200hz() throws Throwable { 514 runSensorTest(Sensor.TYPE_LINEAR_ACCELERATION, RATE_200HZ); 515 } 516 testLinearAcceleration_100hz()517 public void testLinearAcceleration_100hz() throws Throwable { 518 runSensorTest(Sensor.TYPE_LINEAR_ACCELERATION, RATE_100HZ); 519 } 520 testLinearAcceleration_50hz()521 public void testLinearAcceleration_50hz() throws Throwable { 522 runSensorTest(Sensor.TYPE_LINEAR_ACCELERATION, RATE_50HZ); 523 } 524 testLinearAcceleration_25hz()525 public void testLinearAcceleration_25hz() throws Throwable { 526 runSensorTest(Sensor.TYPE_LINEAR_ACCELERATION, RATE_25HZ); 527 } 528 testLinearAcceleration_15hz()529 public void testLinearAcceleration_15hz() throws Throwable { 530 runSensorTest(Sensor.TYPE_LINEAR_ACCELERATION, RATE_15HZ); 531 } 532 testLinearAcceleration_10hz()533 public void testLinearAcceleration_10hz() throws Throwable { 534 runSensorTest(Sensor.TYPE_LINEAR_ACCELERATION, RATE_10HZ); 535 } 536 testLinearAcceleration_5hz()537 public void testLinearAcceleration_5hz() throws Throwable { 538 runSensorTest(Sensor.TYPE_LINEAR_ACCELERATION, RATE_5HZ); 539 } 540 testLinearAcceleration_1hz()541 public void testLinearAcceleration_1hz() throws Throwable { 542 runSensorTest(Sensor.TYPE_LINEAR_ACCELERATION, RATE_1HZ); 543 } 544 runSensorTest(int sensorType, int rateUs)545 private void runSensorTest(int sensorType, int rateUs) throws Throwable { 546 SensorCtsHelper.sleep(3, TimeUnit.SECONDS); 547 TestSensorEnvironment environment = new TestSensorEnvironment( 548 getContext(), 549 sensorType, 550 shouldEmulateSensorUnderLoad(), 551 rateUs); 552 TestSensorOperation op = 553 TestSensorOperation.createOperation(environment, 5, TimeUnit.SECONDS); 554 op.addDefaultVerifications(); 555 556 try { 557 op.execute(getCurrentTestNode()); 558 } finally { 559 SensorStats stats = op.getStats(); 560 stats.log(TAG); 561 562 String fileName = String.format( 563 "single_%s_%s.txt", 564 SensorStats.getSanitizedSensorName(environment.getSensor()), 565 environment.getFrequencyString()); 566 stats.logToFile(fileName); 567 } 568 } 569 } 570