Signed-off-by: DaiH <daihuina1@huawei.com> https://gitee.com/openharmony/ark_js_runtime/issues/I53710?from=project-issue Documentation Modifications About Compilation 1. Update compilation order 2. "hi3516dv300" -> "rk3568" Change-Id: I3a9f5bc91cda12546ac3cf6cefafb969f5510bdb
13 KiB
Development Example
This section describes how to develop and test ARK runtime.
HelloWorld
Preparations
-
Run the following command to compile ARK runtime:
./build.sh --product-name rk3568 --build-target ark_js_host_linux_tools_packages # arm platform and host side running tool
-
Run the following command to compile the ARK frontend:
x64:
./build.sh --product-name rk3568 --build-target ark_js_host_linux_tools_packages --build-target ark_ts2abc_build # arm平台和host端运行工具
arm64:
./build.sh --product-name ohos_arm64 --build-target ark_js_vm --build-target ld-musl-aarch64.so.1
arm32:
./build.sh --product-name rk3568 --build-target libarkruntime --build-target ark_js_runtime --build-target ld-musl-arm.so.1
NOTE: Run the compilation commands in the project root directory.
Running hello-world.js
Create the hello-world.js file and write the following source code into the file:
print("Hello World!!!");
Run the hello-world.js file.
-
Use the ARK frontend to create the hello-world.abc file.
node --expose-gc /your code path/out/rk3568/clang_x64/ark/ark/build/src/index.js hello-world.js
-
Run the hello-world.abc file.
-
Set the search path.
export LD_LIBRARY_PATH= out/rk3568/clang_x64/ark/ark:out/rk3568/clang_x64/ark/ark_js_runtime:out/rk3568/clang_x64/global/i18n_standard:prebuilts/clang/ohos/linux-x86_64/llvm/lib
-
Run ark_js_vm.
/your code path/out/rk3568/clang_x64/ark/ark_js_runtime/ark_js_vm hello-world.abc
The execution result is as follows:
Hello World!!!
-
NOTE: In the preceding command, your code path indicates the source code directory.
Disassembling hello-world.abc
Run the following command to export the result to the output file:
./your code path/out/rk3568/clang_x64/ark/ark/ark_disasm hello-world.abc output
The output is as follows:
#
# 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 // Load the print function.
sta.dyn v3
lda.str "Hello World!!!" // Load the Hello World!!! string.
sta.dyn v4
builtin.tern3 v3, v4 // Call the print function.
builtin.acc
}
Performing Test Case Test262
Preparations
- Run the following command to compile ARK runtime:
./build.sh --product-name rk3568 --build-target ark_js_host_linux_tools_packages
- Run the following command to compile the ARK frontend:
./build.sh --product-name rk3568 --build-target ark_ts2abc_build
NOTE: Run the compilation commands in the project root directory.
Running Test262
Run the run_test262.py script to download and run the Test262 test case.
Command:
python3 test262/run_test262.py [options]
Run the script in Project root directory/ark/ts2abc.
Example
-
Run test case ES51.
python3 test262/run_test262.py --es51
-
Run test case ES2015 only.
python3 test262/run_test262.py --es2015 only
-
Run all ES2015 and ES51 test cases.
python3 test262/run_test262.py --es2015 all
-
Run a test case.
python3 test262/run_test262.py --file test262/data/test_es5/language/statements/break/12.8-1.js
-
Run all test cases in a directory.
python3 test262/run_test262.py --dir test262/data/test_es5/language/statements
-
Use Babel to convert a test case into ES5 and then run the test case.
python3 test262/run_test262.py --babel --file test262/data/test_es5/language/statements/break/12.8-1.js
Test Output
The results of all Test262 test cases are available in the Project root directory/ark/ts2abc/out. The test result in the shell is as follows:
$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/rk3568/clang_x64/ark/ark_js_runtime/ark_js_vm --ark-frontend-tool=/your code path/out/rk3568/clang_x64/ark/ark/build/src/index.js --libs-dir=/your code path/out/rk3568/clang_x64/ark/ark:/your code path/out/rk3568/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