Skip to content

Running tests on Android

paul99 edited this page Aug 22, 2012 · 4 revisions

This is one method to run JS tests from mjsunit, mozilla, test262 test suites with test/tools.py script on Android through 'adb'.

Building d8 shell

For running JS tests executable of d8 stand alone shell is required. Old v8shell is no longer used for executing JS tests.

To build d8 shell under Android build system Android.d8.mk file should be added with following content in v8 root directory:

#
# d8 shell
# ===================================================
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE := d8
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := EXECUTABLES

LOCAL_SRC_FILES += \
        src/d8.cc \
        src/d8-debug.cc \
        src/d8-posix.cc

V8_LOCAL_D8_JS_FILES := \
        src/d8.js

LOCAL_STATIC_LIBRARIES := libv8
LOCAL_SHARED_LIBRARIES := libstlport
include external/stlport/libstlport.mk
LOCAL_CPP_EXTENSION := .cc
LOCAL_SHARED_LIBRARIES += liblog

intermediates := $(call local-intermediates-dir)

LOCAL_D8_JS_FILES := $(addprefix $(LOCAL_PATH)/, $(V8_LOCAL_D8_JS_FILES))

# Copy js2c.py to intermediates directory and invoke there to avoid generating
# jsmin.pyc in the source directory
JS2C_PY := $(intermediates)/js2c.py $(intermediates)/jsmin.py
$(JS2C_PY): $(intermediates)/%.py : $(LOCAL_PATH)/tools/%.py | $(ACP)
        @echo "Copying $@"
        $(copy-file-to-target)

# Generate d8-js.cc
GEN5 := $(intermediates)/d8-js.cc
$(GEN5): SCRIPT := $(intermediates)/js2c.py
$(GEN5): $(LOCAL_D8_JS_FILES) $(JS2C_PY)
        @echo "Generating libraries.cc"
        @mkdir -p $(dir $@)
        python $(SCRIPT) $(GEN5) D8 off $(LOCAL_D8_JS_FILES)
LOCAL_GENERATED_SOURCES := $(GEN5)

LOCAL_CFLAGS := \
        -Wno-endif-labels \
        -Wno-import \
        -Wno-format \
        -fno-rtti \
        -DENABLE_DEBUGGER_SUPPORT \
        -DENABLE_LOGGING_AND_PROFILING \
        -DENABLE_VMSTATE_TRACKING \
        -DV8_NATIVE_REGEXP

ifeq ($(TARGET_ARCH),arm)
  LOCAL_CFLAGS += -DV8_TARGET_ARCH_ARM
endif

ifeq ($(TARGET_CPU_ABI),armeabi-v7a)
    ifeq ($(ARCH_ARM_HAVE_VFP),true)
        LOCAL_CFLAGS += -DCAN_USE_VFP_INSTRUCTIONS -DCAN_USE_ARMV7_INSTRUCTIONS
    endif
endif

ifeq ($(TARGET_ARCH),mips)
  LOCAL_CFLAGS += -DV8_TARGET_ARCH_MIPS
  LOCAL_CFLAGS += -DCAN_USE_FPU_INSTRUCTIONS
  LOCAL_CFLAGS += -Umips
  LOCAL_CFLAGS += -finline-limit=64
  LOCAL_CFLAGS += -fno-strict-aliasing
endif

ifeq ($(TARGET_ARCH),x86)
  LOCAL_CFLAGS += -DV8_TARGET_ARCH_IA32
endif

ifeq ($(DEBUG_V8),true)
        LOCAL_CFLAGS += -DDEBUG -UNDEBUG
endif

LOCAL_C_INCLUDES := $(LOCAL_PATH)/src

include $(BUILD_EXECUTABLE)

Also add this fix to Android.v8common.mk

diff --git a/Android.v8common.mk b/Android.v8common.mk
index 4c77a90..524e902 100644
--- a/Android.v8common.mk
+++ b/Android.v8common.mk
@@ -201,5 +201,6 @@ V8_LOCAL_JS_LIBRARY_FILES += \

V8_LOCAL_JS_EXPERIMENTAL_LIBRARY_FILES := \
        src/collection.js \
-       src/proxy.js
+       src/proxy.js \
+       src/macros.py

Finally, include Android.d8.mk file in Android.mk file.

Build d8 shell with "mm -j4" command.

Run the emulator

Make partition on Android writable in order to push files with command: adb remount

Transfer test files to device

Push the d8, test files from the test suite, and python files form tools directory. For example to transfer mjsunit files and tools files do:

adb push test/mjsunit /tmp/mjsunit

adb push tools /tmp/tools/

Run the test suite

Specific test suite (mjsunit for example) can be run on android device with:

tools/test.py --mode=release --verbose --timeout=480 --arch=mips --report --android --android-push-path /tmp --android-bin-path /tmp mjsunit

Where paths to test suite directory and d8 executable after --android-push-path and --android-bin-path command switches are specified respectively.

Clone this wiki locally