arkcompiler_ets_runtime/docs/development-example.md
DaiH dfb3f51634 Documentation Modifications About Compilation
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
2022-04-18 14:12:24 +08:00

13 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 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.

  1. 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
    
  2. Run the hello-world.abc file.

    1. 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
      
    2. 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

  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 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.

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 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