Remove old EventLog tests from here, they will be replaced by a
(better) EventLog test in CTS.
Fix some minor errors in the handling of too-large event log values.
diff --git a/core/java/android/util/EventLog.java b/core/java/android/util/EventLog.java
index ce0b954..a5029c0 100644
--- a/core/java/android/util/EventLog.java
+++ b/core/java/android/util/EventLog.java
@@ -138,6 +138,7 @@
case LIST_TYPE:
int length = mBuffer.get();
+ if (length < 0) length += 256; // treat as signed byte
Object[] array = new Object[length];
for (int i = 0; i < length; ++i) array[i] = decodeObject();
return array;
diff --git a/core/jni/android_util_EventLog.cpp b/core/jni/android_util_EventLog.cpp
index 78356cf..75f6cb2 100644
--- a/core/jni/android_util_EventLog.cpp
+++ b/core/jni/android_util_EventLog.cpp
@@ -21,6 +21,9 @@
#include "jni.h"
#include "cutils/logger.h"
+// The size of the tag number comes out of the payload size.
+#define MAX_EVENT_PAYLOAD (LOGGER_ENTRY_MAX_PAYLOAD - sizeof(int32_t))
+
namespace android {
static jclass gCollectionClass;
@@ -66,7 +69,7 @@
*/
static jint android_util_EventLog_writeEvent_String(JNIEnv* env, jobject clazz,
jint tag, jstring value) {
- uint8_t buf[LOGGER_ENTRY_MAX_PAYLOAD];
+ uint8_t buf[MAX_EVENT_PAYLOAD];
// Don't throw NPE -- I feel like it's sort of mean for a logging function
// to be all crashy if you pass in NULL -- but make the NULL value explicit.
@@ -94,12 +97,12 @@
return android_util_EventLog_writeEvent_String(env, clazz, tag, NULL);
}
- uint8_t buf[LOGGER_ENTRY_MAX_PAYLOAD];
+ uint8_t buf[MAX_EVENT_PAYLOAD];
const size_t max = sizeof(buf) - 1; // leave room for final newline
size_t pos = 2; // Save room for type tag & array count
jsize copied = 0, num = env->GetArrayLength(value);
- for (; copied < num && copied < 256; ++copied) {
+ for (; copied < num && copied < 255; ++copied) {
jobject item = env->GetObjectArrayElement(value, copied);
if (item == NULL || env->IsInstanceOf(item, gStringClass)) {
if (pos + 1 + sizeof(jint) > max) break;
diff --git a/tests/framework-tests/src/android/test/FrameworkTests.java b/tests/framework-tests/src/android/test/FrameworkTests.java
index b5f6292..623e294 100644
--- a/tests/framework-tests/src/android/test/FrameworkTests.java
+++ b/tests/framework-tests/src/android/test/FrameworkTests.java
@@ -1,8 +1,6 @@
package android.test;
import com.android.internal.os.LoggingPrintStreamTest;
-import android.util.EventLogFunctionalTest;
-import android.util.EventLogTest;
import junit.framework.TestSuite;
import com.android.internal.http.multipart.MultipartTest;
import com.android.internal.policy.impl.LockPatternKeyguardViewTest;
@@ -18,8 +16,6 @@
TestSuite suite = new TestSuite(FrameworkTests.class.getName());
suite.addTestSuite(MultipartTest.class);
- suite.addTestSuite(EventLogTest.class);
- suite.addTestSuite(EventLogFunctionalTest.class);
suite.addTestSuite(LoggingPrintStreamTest.class);
suite.addTestSuite(LockPatternKeyguardViewTest.class);
diff --git a/tests/framework-tests/src/android/util/EventLogFunctionalTest.java b/tests/framework-tests/src/android/util/EventLogFunctionalTest.java
deleted file mode 100644
index 8afe35f..0000000
--- a/tests/framework-tests/src/android/util/EventLogFunctionalTest.java
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * Copyright (C) 2007 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.util;
-
-import android.os.Process;
-
-import com.google.android.collect.Lists;
-
-import junit.framework.TestCase;
-import junit.framework.Assert;
-
-import java.util.ArrayList;
-
-/**
- * Functional tests of EventLog.
- */
-
-public class EventLogFunctionalTest extends TestCase {
- private static final String TAG = "EventLogFunctionalTest";
-
- private static final int TAG_SIZE = 4;
- private static final int TYPE_FIELD_SIZE = 1;
- private static final int STARTING_POS_OF_PAYLOAD = TAG_SIZE + TYPE_FIELD_SIZE;
-
- private static final int TEST_TAG = 42;
- private static final int TEST_TAG2 = 314;
-
- //todo: For now all we do is test the returned length. More to come.
- public void testLogOfPosInt() throws Exception {
- final int numBytes = EventLog.writeEvent(TEST_TAG, 0x01020304);
- Assert.assertEquals(STARTING_POS_OF_PAYLOAD + 4, numBytes);
- }
-
- //todo: For now all we do is test the returned length. More to come.
- public void testLogOfPosLong() throws Exception {
- final int numBytes = EventLog.writeEvent(TEST_TAG2, 0x0102030405060708L);
- Assert.assertEquals(STARTING_POS_OF_PAYLOAD + 8, numBytes);
- }
-
- //todo: For now all we do is test the returned length. More to come.
- public void testLogOfString() throws Exception {
- final String valueStr = "foo bar baz";
- final int numBytes = EventLog.writeEvent(TEST_TAG, valueStr);
- Assert.assertEquals(STARTING_POS_OF_PAYLOAD + 4 + valueStr.length() + 1, numBytes);
- }
-
- public void testLogOfListWithOneInt() throws Exception {
- final int numBytes = EventLog.writeEvent(TEST_TAG, new Object[] {1234});
- Assert.assertEquals(STARTING_POS_OF_PAYLOAD + 1 + 1 + 4 + 1, numBytes);
- }
-
- public void testLogOfListWithMultipleInts() throws Exception {
- final int numBytes = EventLog.writeEvent(TEST_TAG, new Object[] {1234, 2345, 3456});
- Assert.assertEquals(STARTING_POS_OF_PAYLOAD + 1 + 1 + 4 + 1 + 4 + 1 + 4 + 1, numBytes);
- }
-
- public void testEventLargerThanInitialBufferCapacity() throws Exception {
- final Integer[] array = new Integer[127];
- for (int i = 0; i < array.length; i++) {
- array[i] = i;
- }
- final int numBytes = EventLog.writeEvent(TEST_TAG, (Object[]) array);
- Assert.assertEquals(STARTING_POS_OF_PAYLOAD + 1 + (5 * array.length) + 1, numBytes);
- }
-
- // This test is obsolete. See http://b/issue?id=1262082
- public void disableTestReadSimpleEvent() throws Exception {
- long when = System.currentTimeMillis();
- EventLog.writeEvent(2718, 12345);
- Log.i(TAG, "Wrote simple event at T=" + when);
-
- ArrayList<EventLog.Event> list = new ArrayList<EventLog.Event>();
- EventLog.readEvents(new int[] { 2718 }, list);
-
- boolean found = false;
- for (EventLog.Event event : list) {
- assertEquals(event.getTag(), 2718);
- long eventTime = event.getTimeNanos() / 1000000;
- Log.i(TAG, " Found event T=" + eventTime);
- if (eventTime > when - 100 && eventTime < when + 1000) {
- assertEquals(event.getProcessId(), Process.myPid());
- assertEquals(event.getThreadId(), Process.myTid());
- assertEquals(event.getData(), 12345);
-
- assertFalse(found);
- found = true;
- }
- }
-
- assertTrue(found);
- }
-
- // This test is obsolete. See http://b/issue?id=1262082
- public void disableTestReadCompoundEntry() throws Exception {
- long when = System.currentTimeMillis();
- EventLog.writeEvent(2719, 1l, "2", 3);
- Log.i(TAG, "Wrote compound event at T=" + when);
-
- ArrayList<EventLog.Event> list = new ArrayList<EventLog.Event>();
- EventLog.readEvents(new int[] { 2719 }, list);
-
- boolean found = false;
- for (EventLog.Event event : list) {
- long eventTime = event.getTimeNanos() / 1000000;
- Log.i(TAG, " Found event T=" + eventTime);
- if (eventTime > when - 100 && eventTime < when + 1000) {
- Object[] data = (Object[]) event.getData();
- assertEquals(data.length, 3);
- assertEquals(data[0], 1l);
- assertEquals(data[1], "2");
- assertEquals(data[2], 3);
- assertFalse(found);
- found = true;
- }
- }
-
- assertTrue(found);
- }
-
- public void testEventLogTagsFile() throws Exception {
- EventLogTags tags = new EventLogTags();
- assertEquals(tags.get("answer").mTag, 42);
- assertEquals(tags.get("pi").mTag, 314);
- assertEquals(tags.get("e").mTag, 2718);
- assertEquals(tags.get(42).mName, "answer");
- assertEquals(tags.get(314).mName, "pi");
- assertEquals(tags.get(2718).mName, "e");
- }
-}
diff --git a/tests/framework-tests/src/android/util/EventLogTest.java b/tests/framework-tests/src/android/util/EventLogTest.java
deleted file mode 100644
index 2a9e9cd..0000000
--- a/tests/framework-tests/src/android/util/EventLogTest.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright (C) 2007 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.util;
-
-import com.google.android.collect.Lists;
-
-import junit.framework.Assert;
-import junit.framework.TestCase;
-
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-
-/**
- * tests for {@link EventLog}
- */
-
-public class EventLogTest extends TestCase {
- private static final int TEST_TAG = 42;
-
- public void testIllegalListTypesThrowException() throws Exception {
- try {
- EventLog.writeEvent(TEST_TAG, new Object[]{new Object()});
- fail("Can't create List with any old Object");
- } catch (IllegalArgumentException e) {
- // expected
- }
- try {
- EventLog.writeEvent(TEST_TAG, new Object[]{(byte) 1});
- fail("Can't create List with any old byte");
- } catch (IllegalArgumentException e) {
- // expected
- }
- }
-
- void assertIntInByteArrayEquals(int expected, byte[] buf, int pos) {
- ByteBuffer computedBuf = ByteBuffer.wrap(buf).order(ByteOrder.nativeOrder());
- int computed = computedBuf.getInt(pos);
- Assert.assertEquals(expected, computed);
- }
-
- void assertLongInByteArrayEquals(long expected, byte[] buf, int pos) {
- ByteBuffer computedBuf = ByteBuffer.wrap(buf).order(ByteOrder.nativeOrder());
- long computed = computedBuf.getLong(pos);
- Assert.assertEquals(expected, computed);
- }
-
- void assertStringInByteArrayEquals(String expected, byte[] buf, int pos) {
- byte[] expectedBytes = expected.getBytes();
- Assert.assertTrue(expectedBytes.length <= buf.length - pos);
- for (byte expectedByte : expectedBytes) {
- Assert.assertEquals(expectedByte, buf[pos++]);
- }
- }
-}