mirror of
https://github.com/openharmony/ark_js_runtime.git
synced 2026-07-22 07:35:27 -04:00
509bf16b32
Signed-off-by: wanyanglan <wanyanglan1@huawei.com> Change-Id: Ic65aaef94f79ce8134a96ceb8908c374844b0eb4
12 KiB
12 KiB
开发实例
本章节将介绍基于方舟运行时的开发测试实例。
HelloWorld
运行前准备
- 编译方舟运行时,编译命令:
./build.sh --product-name Hi3516DV300 --build-target ark_js_runtime # arm平台
./build.sh --product-name Hi3516DV300 --build-target ark_js_host_linux_tools_packages # host端运行工具
- 编译方舟前端,编译命令:
./build.sh --product-name Hi3516DV300 --build-target ark_ts2abc_build
说明:编译命令执行路径为项目根目录。
运行hello-world.js
新建hello-world.js文件,写入以下源码:
print("Hello World!!!");
运行步骤:
-
通过方舟前端生成hello-world.abc文件,编译命令:
node --expose-gc /your code path/out/ohos-arm-release/clang_x64/ark/ark/build/src/index.js hello-world.js -
执行hello-world.abc文件:
-
设置搜索路径:
export LD_LIBRARY_PATH=/your code path/prebuilts/clang/ohos/linux-x86_64/llvm/lib/:/your code path/out/ohos-arm-release/clang_x64/ark/ark:/your code path/out/ohos-arm-release/clang_x64/global/i18n_standard -
执行ark_js_vm:
/your code path/out/ohos-arm-release/clang_x64/ark/ark_js_runtime//ark_js_vm hello-world.abc _GLOBAL::func_main_0执行结果如下:
Hello World!!!
-
说明:此处“your code path”为源码目录路径。
反汇编hello-world.abc
执行如下命令,结果输出到output文件中:
./your code path/out/ohos-arm-release/clang_x64/ark/ark/ark_disasm hello-world.abc output
hello-world.abc反汇编结果如下:
#
# source binary: hello-world.abc
#
# ====================
# LITERALS
# ====================
# RECORDS
.record _ESAnnotation <external>
.record _ESModuleMode {
u8 isModule
}
# ====================
# METHODS
.function any func_main_0_any_any_any_any_(any a0, any a1, any a2) <static> {
mov.dyn v2, a2
mov.dyn v1, a1
mov.dyn v0, a0
builtin.acc
sta.dyn v5
builtin.idi "print", 0x0 // 加载print函数
sta.dyn v3
lda.str "Hello World!!!" // 加载Hello World!!!字符串
sta.dyn v4
builtin.tern3 v3, v4 // 调用print函数
builtin.acc
}
运行Test262测试用例
运行前准备
- 编译方舟运行时,编译命令:
./build.sh --product-name Hi3516DV300 --build-target ark_js_host_linux_tools_packages
- 编译方舟前端,编译命令:
./build.sh --product-name Hi3516DV300 --build-target ark_ts2abc_build
说明:编译命令执行路径为项目根目录。
运行Test262
运行run_test262.py脚本,下载及运行Test262用例。
命令行格式:
python3 test262/run_test262.py [options]
执行路径为:项目根目录/ark/ts2abc。
测试运行示例
-
运行ES51测试用例:
python3 test262/run_test262.py --es51 -
仅运行ES2015测试用:
python3 test262/run_test262.py --es2015 only -
运行ES2015和ES51所有测试用例:
python3 test262/run_test262.py --es2015 all -
运行单一测试用例:
python3 test262/run_test262.py --file test262/data/test_es5/language/statements/break/12.8-1.js -
运行某目录下所有测试用例:
python3 test262/run_test262.py --dir test262/data/test_es5/language/statements -
使用`babel`把单个测试用例转换成es5后再运行:
python3 test262/run_test262.py --babel --file test262/data/test_es5/language/statements/break/12.8-1.js
测试输出
Test262所有用例的测试结果位于项目根目录/ark/ts2abc/out下。shell中测试输出结果如下:
$python3 test262/run_test262.py --file test262/data/test_es2015/built-ins/Array/15.4.5.1-5-1.js
Wait a moment..........
Test command:
node
test262/harness/bin/run.js
--hostType=panda
--hostPath=python3
--hostArgs='-B test262/run_sunspider.py --ark-tool=/your code path/out/ohos-arm-release/clang_x64/ark/ark_js_runtime/ark_js_vm --ark-frontend-tool=/your code path/out/ohos-arm-release/clang_x64/ark/ark/build/src/index.js --libs-dir=/your code path/out/ohos-arm-release/clang_x64/ark/ark:/your code path/out/ohos-arm-release/clang_x64/global/i18n:/your code path/prebuilts/clang/ohos/linux-x86_64/llvm/lib/ --ark-frontend=ts2panda'
--threads=15
--mode=only strict mode
--timeout=60000
--tempDir=build/test262
--test262Dir=test262/data
--saveCompiledTests
test262/data/test_es5/language/statements/break/12.8-1.js
PASS test262/data/test_es2015/built-ins/Array/15.4.5.1-5-1.js (strict mode)
Ran 1 tests
1 passed
0 failed
used time is: 0:01:04.439642