arkcompiler_ets_runtime/docs/development-example.md
wuhailong 721f5fa159 Update README
Signed-off-by: wuhailong <wuhailong19@huawei.com>
2023-09-07 15:30:11 +08:00

14 KiB
Raw Blame History

Development Example

This section describes how to develop and test ARK runtime.

HelloWorld

Preparations

  1. 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
    
  2. 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 ets_frontend_build  # arm platform and host side running tool
    

    arm64

    ./build.sh --product-name ohos_arm64 --build-target ark_js_packages --build-target ld-musl-aarch64.so.1
    

    arm32:

    ./build.sh --product-name rk3568 --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.

  1. Use the ARK frontend to create the hello-world.abc file.

    /your_code_path/out/rk3568/clang_x64/arkcompiler/ets_frontend/es2abc hello-world.js
    
  2. Run the hello-world.abc file.

    1. Set the search path.

      export LD_LIBRARY_PATH=/your_code_path/out/rk3568/clang_x64/arkcompiler/ets_runtime:/your_code_path/out/rk3568/clang_x64/global/i18n_standard:/your_code_path/prebuilts/clang/ohos/linux-x86_64/llvm/lib:/your_code_path/out/rk3568/clang_x64/thirdparty/zlib
      
    2. Run ark_js_vm.

      /your_code_path/out/rk3568/clang_x64/arkcompiler/ets_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/arkcompiler/runtime_core/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 v2, a2
	mov v1, a1
	mov v0, a0
	builtin.acc
	sta v5
	builtin.idi "print", 0x0 // Load the print function.
	sta v3
	lda.str "Hello World!!!"  // Load the Hello World!!! string.
	sta v4
	builtin.tern3 v3, v4  // Call the print function.
	builtin.acc
}

Performing Test Case Test262

Preparations

  1. Run the following command to compile ARK runtime:
./build.sh --product-name rk3568 --build-target ark_js_host_linux_tools_packages
  1. Run the following command to compile the ARK frontend:
./build.sh --product-name rk3568 --build-target ets_frontend_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/arkcompiler/ets_frontend.

Option

Description

--h, --help

Displays help information.

--dir DIR

Specifies the directory to test.

--file FILE

Specifies the file to test.

--mode [{1, 2, 3}]

Specifies the mode, which can be any of the following:

  • 1: default
  • 2: strict mode only
  • 3: default and strict modes

--es51

Runs Test262 ES5.1.

--es2015 [{all, only}]

Runs Test262 ES2015.

all: all cases

only: only ES2015

--esnext

Runs Test262-ES.next.

--engine FILE

Runs other engines and specifies binary files (such as d8, hermes, jsc, and qjs).

--babel

Specifies whether to use Babel to convert code.

--timeout TIMEOUT

Specifies the test timeout period in ms.

--threads THREADS

Specifies the number of concurrent threads.

--hostArgs HOSTARGS

Specifies the command line parameters sent to the eshost.

--ark-tool ARK_TOOL

Specifies the binary tool of ARK runtime.

--ark-frontend-tool ARK_FRONTEND_TOOL

Specifies the ARK front-end conversion tool.

--libs-dir LIBS_DIR

Specifies the set of .so dependency file paths, separated by colons (:).

--ark-frontend [{ts2panda, es2panda}]

Specifies the frontend.

Example

  • Run test case ES51.

     python3 test262/run_test262.py --es51
    
  • Run test case ES2015 only.

     python3 test262/run_test262.py --es2015
    
  • Run test case ES2021 only.

     python3 test262/run_test262.py --es2021 only
    
    
  • Run all ES2015 and ES51 and ES2021 test cases.

     python3 test262/run_test262.py --es2021 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/arkcompiler/ets_frontend/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/arkcompiler/ets_runtime/ark_js_vm --ark-frontend-tool=/your_code_path/out/rk3568/clang_x64/arkcompiler/ets_frontend/build/src/index.js --libs-dir=/your_code_path/out/rk3568/clang_x64/global/i18n:/your_code_path/prebuilts/clang/ohos/linux-x86_64/llvm/lib:/your_code_path/out/rk3568/clang_x64/thirdparty/zlib/ --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