SensorBatching Test Fixes

* Ease up the passing bar to solve flakiness problem in this test for a
  few devices.
* Stopped an loop-hole in verification via the new
  EventBasicVerification.

Bug: b/23827274
Change-Id: Ie0d2f8b9adcedf1d364fc791c864c46de2cc8fbc
diff --git a/tests/tests/hardware/src/android/hardware/cts/SensorBatchingTests.java b/tests/tests/hardware/src/android/hardware/cts/SensorBatchingTests.java
index 7f7d4eb..4d4f3d3 100644
--- a/tests/tests/hardware/src/android/hardware/cts/SensorBatchingTests.java
+++ b/tests/tests/hardware/src/android/hardware/cts/SensorBatchingTests.java
@@ -22,6 +22,7 @@
 import android.hardware.cts.helpers.SensorStats;
 import android.hardware.cts.helpers.TestSensorEnvironment;
 import android.hardware.cts.helpers.sensoroperations.TestSensorOperation;
+import android.hardware.cts.helpers.sensorverification.EventBasicVerification;
 import android.hardware.cts.helpers.sensorverification.ISensorVerification;
 
 import java.util.concurrent.TimeUnit;
@@ -44,7 +45,7 @@
 public class SensorBatchingTests extends SensorTestCase {
     private static final String TAG = "SensorBatchingTests";
 
-    private static final int BATCHING_10S = 10;
+    private static final int BATCHING_PERIOD = 10;  // sec
     private static final int RATE_50HZ = 20000;
     private static final int RATE_FASTEST = SensorManager.SENSOR_DELAY_FASTEST;
 
@@ -52,202 +53,202 @@
      * An arbitrary 'padding' time slot to wait for events after batching latency expires.
      * This allows for the test to wait for event arrivals after batching was expected.
      */
-    private static final int BATCHING_PADDING_TIME_S = 2;
+    private static final int BATCHING_PADDING_TIME_S = (int) Math.ceil(BATCHING_PERIOD * 0.1f + 2);
 
     public void testAccelerometer_fastest_batching() throws Throwable {
-        runBatchingSensorTest(Sensor.TYPE_ACCELEROMETER, RATE_FASTEST, BATCHING_10S);
+        runBatchingSensorTest(Sensor.TYPE_ACCELEROMETER, RATE_FASTEST, BATCHING_PERIOD);
     }
 
     public void testAccelerometer_50hz_batching() throws Throwable {
-        runBatchingSensorTest(Sensor.TYPE_ACCELEROMETER, RATE_50HZ, BATCHING_10S);
+        runBatchingSensorTest(Sensor.TYPE_ACCELEROMETER, RATE_50HZ, BATCHING_PERIOD);
     }
 
     public void testAccelerometer_fastest_flush() throws Throwable {
-        runFlushSensorTest(Sensor.TYPE_ACCELEROMETER, RATE_FASTEST, BATCHING_10S);
+        runFlushSensorTest(Sensor.TYPE_ACCELEROMETER, RATE_FASTEST, BATCHING_PERIOD);
     }
 
     public void testAccelerometer_50hz_flush() throws Throwable {
-        runFlushSensorTest(Sensor.TYPE_ACCELEROMETER, RATE_50HZ, BATCHING_10S);
+        runFlushSensorTest(Sensor.TYPE_ACCELEROMETER, RATE_50HZ, BATCHING_PERIOD);
     }
 
     public void testMagneticField_fastest_batching() throws Throwable {
-        runBatchingSensorTest(Sensor.TYPE_MAGNETIC_FIELD, RATE_FASTEST, BATCHING_10S);
+        runBatchingSensorTest(Sensor.TYPE_MAGNETIC_FIELD, RATE_FASTEST, BATCHING_PERIOD);
     }
 
     public void testMagneticField_50hz_batching() throws Throwable {
-        runBatchingSensorTest(Sensor.TYPE_MAGNETIC_FIELD, RATE_50HZ, BATCHING_10S);
+        runBatchingSensorTest(Sensor.TYPE_MAGNETIC_FIELD, RATE_50HZ, BATCHING_PERIOD);
     }
 
     public void testMagneticField_fastest_flush() throws Throwable {
-        runFlushSensorTest(Sensor.TYPE_MAGNETIC_FIELD, RATE_FASTEST, BATCHING_10S);
+        runFlushSensorTest(Sensor.TYPE_MAGNETIC_FIELD, RATE_FASTEST, BATCHING_PERIOD);
     }
 
     public void testMagneticField_50hz_flush() throws Throwable {
-        runFlushSensorTest(Sensor.TYPE_MAGNETIC_FIELD, RATE_50HZ, BATCHING_10S);
+        runFlushSensorTest(Sensor.TYPE_MAGNETIC_FIELD, RATE_50HZ, BATCHING_PERIOD);
     }
 
     @SuppressWarnings("deprecation")
     public void testOrientation_fastest_batching() throws Throwable {
-        runBatchingSensorTest(Sensor.TYPE_ORIENTATION, RATE_FASTEST, BATCHING_10S);
+        runBatchingSensorTest(Sensor.TYPE_ORIENTATION, RATE_FASTEST, BATCHING_PERIOD);
     }
 
     @SuppressWarnings("deprecation")
     public void testOrientation_50hz_batching() throws Throwable {
-        runBatchingSensorTest(Sensor.TYPE_ORIENTATION, RATE_50HZ, BATCHING_10S);
+        runBatchingSensorTest(Sensor.TYPE_ORIENTATION, RATE_50HZ, BATCHING_PERIOD);
     }
 
     @SuppressWarnings("deprecation")
     public void testOrientation_fastest_flush() throws Throwable {
-        runFlushSensorTest(Sensor.TYPE_ORIENTATION, RATE_FASTEST, BATCHING_10S);
+        runFlushSensorTest(Sensor.TYPE_ORIENTATION, RATE_FASTEST, BATCHING_PERIOD);
     }
 
     @SuppressWarnings("deprecation")
     public void testOrientation_50hz_flush() throws Throwable {
-        runFlushSensorTest(Sensor.TYPE_ORIENTATION, RATE_50HZ, BATCHING_10S);
+        runFlushSensorTest(Sensor.TYPE_ORIENTATION, RATE_50HZ, BATCHING_PERIOD);
     }
 
     public void testGyroscope_fastest_batching() throws Throwable {
-        runBatchingSensorTest(Sensor.TYPE_GYROSCOPE, RATE_FASTEST, BATCHING_10S);
+        runBatchingSensorTest(Sensor.TYPE_GYROSCOPE, RATE_FASTEST, BATCHING_PERIOD);
     }
 
     public void testGyroscope_50hz_batching() throws Throwable {
-        runBatchingSensorTest(Sensor.TYPE_GYROSCOPE, RATE_50HZ, BATCHING_10S);
+        runBatchingSensorTest(Sensor.TYPE_GYROSCOPE, RATE_50HZ, BATCHING_PERIOD);
     }
 
     public void testGyroscope_fastest_flush() throws Throwable {
-        runFlushSensorTest(Sensor.TYPE_GYROSCOPE, SensorManager.SENSOR_DELAY_FASTEST, BATCHING_10S);
+        runFlushSensorTest(Sensor.TYPE_GYROSCOPE, SensorManager.SENSOR_DELAY_FASTEST, BATCHING_PERIOD);
     }
 
     public void testGyroscope_50hz_flush() throws Throwable {
-        runFlushSensorTest(Sensor.TYPE_GYROSCOPE, RATE_50HZ, BATCHING_10S);
+        runFlushSensorTest(Sensor.TYPE_GYROSCOPE, RATE_50HZ, BATCHING_PERIOD);
     }
 
     public void testPressure_fastest_batching() throws Throwable {
-        runBatchingSensorTest(Sensor.TYPE_PRESSURE, RATE_FASTEST, BATCHING_10S);
+        runBatchingSensorTest(Sensor.TYPE_PRESSURE, RATE_FASTEST, BATCHING_PERIOD);
     }
 
     public void testPressure_50hz_batching() throws Throwable {
-        runBatchingSensorTest(Sensor.TYPE_PRESSURE, RATE_50HZ, BATCHING_10S);
+        runBatchingSensorTest(Sensor.TYPE_PRESSURE, RATE_50HZ, BATCHING_PERIOD);
     }
 
     public void testPressure_fastest_flush() throws Throwable {
-        runFlushSensorTest(Sensor.TYPE_PRESSURE, SensorManager.SENSOR_DELAY_FASTEST, BATCHING_10S);
+        runFlushSensorTest(Sensor.TYPE_PRESSURE, SensorManager.SENSOR_DELAY_FASTEST, BATCHING_PERIOD);
     }
 
     public void testPressure_50hz_flush() throws Throwable {
-        runFlushSensorTest(Sensor.TYPE_PRESSURE, RATE_50HZ, BATCHING_10S);
+        runFlushSensorTest(Sensor.TYPE_PRESSURE, RATE_50HZ, BATCHING_PERIOD);
     }
 
     public void testGravity_fastest_batching() throws Throwable {
-        runBatchingSensorTest(Sensor.TYPE_GRAVITY, RATE_FASTEST, BATCHING_10S);
+        runBatchingSensorTest(Sensor.TYPE_GRAVITY, RATE_FASTEST, BATCHING_PERIOD);
     }
 
     public void testGravity_50hz_batching() throws Throwable {
-        runBatchingSensorTest(Sensor.TYPE_GRAVITY, RATE_50HZ, BATCHING_10S);
+        runBatchingSensorTest(Sensor.TYPE_GRAVITY, RATE_50HZ, BATCHING_PERIOD);
     }
 
     public void testGravity_fastest_flush() throws Throwable {
-        runFlushSensorTest(Sensor.TYPE_GRAVITY, SensorManager.SENSOR_DELAY_FASTEST, BATCHING_10S);
+        runFlushSensorTest(Sensor.TYPE_GRAVITY, SensorManager.SENSOR_DELAY_FASTEST, BATCHING_PERIOD);
     }
 
     public void testGravity_50hz_flush() throws Throwable {
-        runFlushSensorTest(Sensor.TYPE_GRAVITY, RATE_50HZ, BATCHING_10S);
+        runFlushSensorTest(Sensor.TYPE_GRAVITY, RATE_50HZ, BATCHING_PERIOD);
     }
 
     public void testRotationVector_fastest_batching() throws Throwable {
-        runBatchingSensorTest(Sensor.TYPE_ROTATION_VECTOR, RATE_FASTEST, BATCHING_10S);
+        runBatchingSensorTest(Sensor.TYPE_ROTATION_VECTOR, RATE_FASTEST, BATCHING_PERIOD);
     }
 
     public void testRotationVector_50hz_batching() throws Throwable {
-        runBatchingSensorTest(Sensor.TYPE_ROTATION_VECTOR, RATE_50HZ, BATCHING_10S);
+        runBatchingSensorTest(Sensor.TYPE_ROTATION_VECTOR, RATE_50HZ, BATCHING_PERIOD);
     }
 
     public void testRotationVector_fastest_flush() throws Throwable {
-        runFlushSensorTest(Sensor.TYPE_ROTATION_VECTOR, RATE_FASTEST, BATCHING_10S);
+        runFlushSensorTest(Sensor.TYPE_ROTATION_VECTOR, RATE_FASTEST, BATCHING_PERIOD);
     }
 
     public void testRotationVector_50hz_flush() throws Throwable {
-        runFlushSensorTest(Sensor.TYPE_ROTATION_VECTOR, RATE_50HZ, BATCHING_10S);
+        runFlushSensorTest(Sensor.TYPE_ROTATION_VECTOR, RATE_50HZ, BATCHING_PERIOD);
     }
 
     public void testMagneticFieldUncalibrated_fastest_batching() throws Throwable {
-        runBatchingSensorTest(Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED, RATE_FASTEST, BATCHING_10S);
+        runBatchingSensorTest(Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED, RATE_FASTEST, BATCHING_PERIOD);
     }
 
     public void testMagneticFieldUncalibrated_50hz_batching() throws Throwable {
-        runBatchingSensorTest(Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED, RATE_50HZ, BATCHING_10S);
+        runBatchingSensorTest(Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED, RATE_50HZ, BATCHING_PERIOD);
     }
 
     public void testMagneticFieldUncalibrated_fastest_flush() throws Throwable {
-        runFlushSensorTest(Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED, RATE_FASTEST, BATCHING_10S);
+        runFlushSensorTest(Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED, RATE_FASTEST, BATCHING_PERIOD);
     }
 
     public void testMagneticFieldUncalibrated_50hz_flush() throws Throwable {
-        runFlushSensorTest(Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED, RATE_50HZ, BATCHING_10S);
+        runFlushSensorTest(Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED, RATE_50HZ, BATCHING_PERIOD);
     }
 
     public void testGameRotationVector_fastest_batching() throws Throwable {
-        runBatchingSensorTest(Sensor.TYPE_GAME_ROTATION_VECTOR, RATE_FASTEST, BATCHING_10S);
+        runBatchingSensorTest(Sensor.TYPE_GAME_ROTATION_VECTOR, RATE_FASTEST, BATCHING_PERIOD);
     }
 
     public void testGameRotationVector_50hz_batching() throws Throwable {
-        runBatchingSensorTest(Sensor.TYPE_GAME_ROTATION_VECTOR, RATE_50HZ, BATCHING_10S);
+        runBatchingSensorTest(Sensor.TYPE_GAME_ROTATION_VECTOR, RATE_50HZ, BATCHING_PERIOD);
     }
 
     public void testGameRotationVector_fastest_flush() throws Throwable {
-        runFlushSensorTest(Sensor.TYPE_GAME_ROTATION_VECTOR, RATE_FASTEST, BATCHING_10S);
+        runFlushSensorTest(Sensor.TYPE_GAME_ROTATION_VECTOR, RATE_FASTEST, BATCHING_PERIOD);
     }
 
     public void testGameRotationVector_50hz_flush() throws Throwable {
-        runFlushSensorTest(Sensor.TYPE_GAME_ROTATION_VECTOR, RATE_50HZ, BATCHING_10S);
+        runFlushSensorTest(Sensor.TYPE_GAME_ROTATION_VECTOR, RATE_50HZ, BATCHING_PERIOD);
     }
 
     public void testGyroscopeUncalibrated_fastest_batching() throws Throwable {
-        runBatchingSensorTest(Sensor.TYPE_GYROSCOPE_UNCALIBRATED, RATE_FASTEST, BATCHING_10S);
+        runBatchingSensorTest(Sensor.TYPE_GYROSCOPE_UNCALIBRATED, RATE_FASTEST, BATCHING_PERIOD);
     }
 
     public void testGyroscopeUncalibrated_50hz_batching() throws Throwable {
-        runBatchingSensorTest(Sensor.TYPE_GYROSCOPE_UNCALIBRATED, RATE_50HZ, BATCHING_10S);
+        runBatchingSensorTest(Sensor.TYPE_GYROSCOPE_UNCALIBRATED, RATE_50HZ, BATCHING_PERIOD);
     }
 
     public void testGyroscopeUncalibrated_fastest_flush() throws Throwable {
-        runFlushSensorTest(Sensor.TYPE_GYROSCOPE_UNCALIBRATED, RATE_FASTEST, BATCHING_10S);
+        runFlushSensorTest(Sensor.TYPE_GYROSCOPE_UNCALIBRATED, RATE_FASTEST, BATCHING_PERIOD);
     }
 
     public void testGyroscopeUncalibrated_50hz_flush() throws Throwable {
-        runFlushSensorTest(Sensor.TYPE_GYROSCOPE_UNCALIBRATED, RATE_50HZ, BATCHING_10S);
+        runFlushSensorTest(Sensor.TYPE_GYROSCOPE_UNCALIBRATED, RATE_50HZ, BATCHING_PERIOD);
     }
 
     public void testLinearAcceleration_fastest_batching() throws Throwable {
-        runBatchingSensorTest(Sensor.TYPE_LINEAR_ACCELERATION, RATE_FASTEST, BATCHING_10S);
+        runBatchingSensorTest(Sensor.TYPE_LINEAR_ACCELERATION, RATE_FASTEST, BATCHING_PERIOD);
     }
 
     public void testLinearAcceleration_50hz_batching() throws Throwable {
-        runBatchingSensorTest(Sensor.TYPE_LINEAR_ACCELERATION, RATE_50HZ, BATCHING_10S);
+        runBatchingSensorTest(Sensor.TYPE_LINEAR_ACCELERATION, RATE_50HZ, BATCHING_PERIOD);
     }
 
     public void testLinearAcceleration_fastest_flush() throws Throwable {
-        runFlushSensorTest(Sensor.TYPE_LINEAR_ACCELERATION, RATE_FASTEST, BATCHING_10S);
+        runFlushSensorTest(Sensor.TYPE_LINEAR_ACCELERATION, RATE_FASTEST, BATCHING_PERIOD);
     }
 
     public void testLinearAcceleration_50hz_flush() throws Throwable {
-        runFlushSensorTest(Sensor.TYPE_LINEAR_ACCELERATION, RATE_50HZ, BATCHING_10S);
+        runFlushSensorTest(Sensor.TYPE_LINEAR_ACCELERATION, RATE_50HZ, BATCHING_PERIOD);
     }
 
     public void testGeomagneticRotationVector_fastest_batching() throws Throwable {
-        runBatchingSensorTest(Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR, RATE_FASTEST, BATCHING_10S);
+        runBatchingSensorTest(Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR, RATE_FASTEST, BATCHING_PERIOD);
     }
 
     public void testGeomagneticRotationVector_50hz_batching() throws Throwable {
-        runBatchingSensorTest(Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR, RATE_50HZ, BATCHING_10S);
+        runBatchingSensorTest(Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR, RATE_50HZ, BATCHING_PERIOD);
     }
 
     public void testGeomagneticRotationVector_fastest_flush() throws Throwable {
-        runFlushSensorTest(Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR, RATE_FASTEST, BATCHING_10S);
+        runFlushSensorTest(Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR, RATE_FASTEST, BATCHING_PERIOD);
     }
 
     public void testGeomagneticRotationVector_50hz_flush() throws Throwable {
-        runFlushSensorTest(Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR, RATE_50HZ, BATCHING_10S);
+        runFlushSensorTest(Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR, RATE_50HZ, BATCHING_PERIOD);
     }
 
     private void runBatchingSensorTest(int sensorType, int rateUs, int maxBatchReportLatencySec)
@@ -264,6 +265,12 @@
         TestSensorOperation operation =
                 TestSensorOperation.createOperation(environment, testDurationSec, TimeUnit.SECONDS);
 
+        operation.addVerification(
+                EventBasicVerification.getDefault(
+                        environment, TimeUnit.SECONDS.toMicros(testDurationSec)
+                )
+        );
+
         executeTest(environment, operation, false /* flushExpected */);
     }
 
diff --git a/tests/tests/hardware/src/android/hardware/cts/helpers/SensorStats.java b/tests/tests/hardware/src/android/hardware/cts/helpers/SensorStats.java
index 413639a..ad9b0cd 100644
--- a/tests/tests/hardware/src/android/hardware/cts/helpers/SensorStats.java
+++ b/tests/tests/hardware/src/android/hardware/cts/helpers/SensorStats.java
@@ -50,6 +50,8 @@
             "event_time_synchronization_count";
     public static final String EVENT_TIME_SYNCHRONIZATION_POSITIONS_KEY =
             "event_time_synchronization_positions";
+    public static final String EVENT_COUNT_KEY = "event_count";
+    public static final String WRONG_SENSOR_KEY = "wrong_sensor_observed";
     public static final String FREQUENCY_KEY = "frequency";
     public static final String JITTER_95_PERCENTILE_PERCENT_KEY = "jitter_95_percentile_percent";
     public static final String MEAN_KEY = "mean";
diff --git a/tests/tests/hardware/src/android/hardware/cts/helpers/sensoroperations/TestSensorOperation.java b/tests/tests/hardware/src/android/hardware/cts/helpers/sensoroperations/TestSensorOperation.java
index 11fdc93..67dca68 100644
--- a/tests/tests/hardware/src/android/hardware/cts/helpers/sensoroperations/TestSensorOperation.java
+++ b/tests/tests/hardware/src/android/hardware/cts/helpers/sensoroperations/TestSensorOperation.java
@@ -31,6 +31,7 @@
 import android.hardware.cts.helpers.TestSensorManager;
 import android.hardware.cts.helpers.SuspendStateMonitor;
 import android.hardware.cts.helpers.reporting.ISensorTestNode;
+import android.hardware.cts.helpers.sensorverification.EventBasicVerification;
 import android.hardware.cts.helpers.sensorverification.EventGapVerification;
 import android.hardware.cts.helpers.sensorverification.EventOrderingVerification;
 import android.hardware.cts.helpers.sensorverification.EventTimestampSynchronizationVerification;
@@ -145,9 +146,9 @@
         for (ISensorVerification verification : mVerifications) {
             failed |= evaluateResults(collectedEvents, verification, sb);
         }
+
         if (failed) {
             trySaveCollectedEvents(parent, listener);
-
             String msg = SensorCtsHelper
                     .formatAssertionMessage("VerifySensorOperation", mEnvironment, sb.toString());
             getStats().addValue(SensorStats.ERROR, msg);
diff --git a/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/EventBasicVerification.java b/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/EventBasicVerification.java
new file mode 100644
index 0000000..c27cba1
--- /dev/null
+++ b/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/EventBasicVerification.java
@@ -0,0 +1,138 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package android.hardware.cts.helpers.sensorverification;
+
+import junit.framework.Assert;
+
+import android.hardware.Sensor;
+import android.hardware.SensorEvent;
+import android.hardware.cts.helpers.SensorStats;
+import android.hardware.cts.helpers.TestSensorEnvironment;
+import android.hardware.cts.helpers.TestSensorEvent;
+import android.os.SystemClock;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * A {@link ISensorVerification} which verifies if the collected sensor events have any obvious 
+ * problems, such as no sample, wrong sensor type, etc.
+ */
+public class EventBasicVerification extends AbstractSensorVerification {
+
+    public static final String PASSED_KEY = "event_basic_passed";
+    private static final long ALLOWED_SENSOR_DELIVERING_DELAY_US =
+            TimeUnit.MILLISECONDS.toMicros(1000);
+
+    private final long mExpectedMinNumEvent;
+    private final Object mSensor;
+    private long  mNumEvent;
+    private boolean mWrongSensorObserved;
+
+    /**
+     * Constructs an instance of {@link EventBasicVerification}.
+     *
+     * @param maximumSynchronizationErrorNs The valid threshold for timestamp synchronization.
+     * @param reportLatencyNs The latency on which batching events are received
+     */
+    public EventBasicVerification(
+            long expectedMinNumEvent,
+            Sensor sensor) {
+        mExpectedMinNumEvent = expectedMinNumEvent;
+        mSensor = sensor;
+
+        mNumEvent = 0;
+        mWrongSensorObserved = false;
+    }
+
+    /**
+     * Gets a default {@link EventBasicVerification}.
+     *
+     * @param environment The test environment
+     * @return The verification or null if the verification is not supported in the given
+     *         environment.
+     */
+    public static EventBasicVerification getDefault(
+            TestSensorEnvironment environment,
+            long testDurationUs) {
+
+        long minTestDurationUs;
+        long batchUs = environment.getMaxReportLatencyUs();
+        long sampleUs = environment.getExpectedSamplingPeriodUs();
+        if (batchUs > 0) {
+            // test duration deduct allowed delivering latency and portion of time to deliver batch
+            // (which will be 10% of the batching time)
+            long effectiveTime = testDurationUs - ALLOWED_SENSOR_DELIVERING_DELAY_US - batchUs/10;
+
+            // allow part of last batch to be partially delivered (>80%)
+            minTestDurationUs = Math.max(
+                    effectiveTime/batchUs * batchUs - batchUs/5,
+                    environment.getExpectedSamplingPeriodUs());
+        } else {
+            minTestDurationUs =
+                    Math.max(testDurationUs - ALLOWED_SENSOR_DELIVERING_DELAY_US,
+                             environment.getExpectedSamplingPeriodUs());
+        }
+
+        long expectedMinNumEvent = minTestDurationUs / environment.getExpectedSamplingPeriodUs();
+        return new EventBasicVerification(expectedMinNumEvent, environment.getSensor());
+    }
+
+    @Override
+    public void verify(TestSensorEnvironment environment, SensorStats stats) {
+        verify(stats);
+    }
+
+    /* visible to unit test */
+    void verify(SensorStats stats) {
+
+        stats.addValue(SensorStats.EVENT_COUNT_KEY, mNumEvent);
+        stats.addValue(SensorStats.WRONG_SENSOR_KEY, mWrongSensorObserved);
+
+        boolean enoughSample = mNumEvent >= mExpectedMinNumEvent;
+        boolean noWrongSensor = !mWrongSensorObserved;
+
+        boolean success = enoughSample && noWrongSensor;
+        stats.addValue(PASSED_KEY, success);
+
+        if (!success) {
+            Assert.fail(String.format("Failed due to (%s%s)",
+                        enoughSample?"":"insufficient events, ",
+                        noWrongSensor?"":"wrong sensor observed, "));
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public EventBasicVerification clone() {
+        return new EventBasicVerification( mExpectedMinNumEvent, (Sensor)mSensor );
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void addSensorEventInternal(TestSensorEvent event) {
+        if (event.sensor == mSensor) {
+            ++mNumEvent;
+        } else {
+            mWrongSensorObserved = true;
+        }
+    }
+
+}
diff --git a/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/EventBasicVerificationTest.java b/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/EventBasicVerificationTest.java
new file mode 100644
index 0000000..34be3c4
--- /dev/null
+++ b/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/EventBasicVerificationTest.java
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.hardware.cts.helpers.sensorverification;
+
+import junit.framework.TestCase;
+import android.content.Context;
+import android.hardware.Sensor;
+import android.hardware.SensorManager;
+import android.hardware.cts.helpers.SensorStats;
+import android.hardware.cts.helpers.TestSensorEnvironment;
+import android.hardware.cts.helpers.TestSensorEvent;
+import android.test.AndroidTestCase;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+/**
+ * Tests for {@link EventBasicVerification}.
+ */
+public class EventBasicVerificationTest extends AndroidTestCase {
+
+    /**
+     * Test {@link EventBasicVerification#verify(TestSensorEnvironment, SensorStats)}.
+     */
+    public void testVerify() {
+
+        /* Sensor contents is not used in this verification, use Object as mock */
+        SensorManager mgr = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE);
+
+        Sensor sensor1 = null;
+
+        // accelerometer is the most likely sensor to exist
+        Sensor sensor2 = mgr.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
+
+        SensorStats stats;
+
+        EventBasicVerification verification;
+
+        // case 1
+        verification = getVerification(10, sensor1, sensor1, new float[20][3]);
+        stats = new SensorStats();
+
+        verification.verify(stats);
+        assertEquals(true, stats.getValue(EventBasicVerification.PASSED_KEY));
+        assertEquals(20, (long) stats.getValue(SensorStats.EVENT_COUNT_KEY));
+        assertEquals(false, stats.getValue(SensorStats.WRONG_SENSOR_KEY));
+
+        // case 2
+        verification = getVerification(10, sensor1, sensor1, new float[5][3]);
+        stats = new SensorStats();
+
+        try {
+            verification.verify(stats);
+            fail("Expect an AssertionError due to insufficient samples");
+        } catch (AssertionError e) {
+            //Expected
+        }
+        assertEquals(false, stats.getValue(EventBasicVerification.PASSED_KEY));
+        assertEquals(5, (long) stats.getValue(SensorStats.EVENT_COUNT_KEY));
+        assertEquals(false, stats.getValue(SensorStats.WRONG_SENSOR_KEY));
+
+        // case 3
+        if (sensor1 != sensor2) {
+            // if we cannot even get a second sensor then do not bother this test.
+            verification = getVerification(10, sensor1, sensor2, new float[15][3]);
+            stats = new SensorStats();
+
+            try {
+                verification.verify(stats);
+                fail("Expect an AssertionError due to wrong sensor event");
+            } catch (AssertionError e) {
+                //Expected
+            }
+            assertEquals(false, stats.getValue(EventBasicVerification.PASSED_KEY));
+            // zero here because wrong sensor is used.
+            assertEquals(0, (long) stats.getValue(SensorStats.EVENT_COUNT_KEY));
+            assertEquals(true, stats.getValue(SensorStats.WRONG_SENSOR_KEY));
+        }
+    }
+
+    private static EventBasicVerification getVerification(
+            int expectedMinNumEvent, Sensor sensor, Sensor eventSensor, float[] ... values) {
+
+        Collection<TestSensorEvent> events = new ArrayList<>(values.length);
+        for (float[] value : values) {
+            events.add(new TestSensorEvent(eventSensor, 0, 0, value));
+        }
+        EventBasicVerification verification =
+                new EventBasicVerification(expectedMinNumEvent, sensor);
+        verification.addSensorEvents(events);
+        return verification;
+    }
+}
diff --git a/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/EventTimestampSynchronizationVerification.java b/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/EventTimestampSynchronizationVerification.java
index 15ff5c03..65d6fa5 100644
--- a/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/EventTimestampSynchronizationVerification.java
+++ b/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/EventTimestampSynchronizationVerification.java
@@ -38,7 +38,8 @@
     // number of indices to print in assertion message before truncating
     private static final int TRUNCATE_MESSAGE_LENGTH = 3;
 
-    private static final long DEFAULT_THRESHOLD_NS = TimeUnit.MILLISECONDS.toNanos(500);
+    private static final long DEFAULT_THRESHOLD_NS = TimeUnit.MILLISECONDS.toNanos(1000);
+    private static final float ALLOWED_LATENCY_ERROR = 0.1f; //10%
 
     private final ArrayList<TestSensorEvent> mCollectedEvents = new ArrayList<TestSensorEvent>();
 
@@ -87,9 +88,11 @@
         }
         // Add an additional filter delay which is a function of the samplingPeriod.
         long filterDelayUs = (long)(2.5 * maximumExpectedSamplingPeriodUs);
+
         long expectedSyncLatencyNs = TimeUnit.MICROSECONDS.toNanos(reportLatencyUs + filterDelayUs);
-        return new EventTimestampSynchronizationVerification(DEFAULT_THRESHOLD_NS,
-                                                              expectedSyncLatencyNs);
+        return new EventTimestampSynchronizationVerification(
+                (long) (DEFAULT_THRESHOLD_NS + ALLOWED_LATENCY_ERROR * reportLatencyUs * 1000),
+                expectedSyncLatencyNs);
     }
 
     @Override