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