arkcompiler_ets_runtime/docs/development-example.md
DaiHN 8c8d2b19d2 Path changes for the compiled product
Signed-off-by: DaiHN <daihuina1@huawei.com>
2021-12-24 17:04:42 +08:00

13 KiB

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 Hi3516DV300 --build-target ark_js_host_linux_tools_packages  # arm platform and host side running tool
  1. Run the following command to compile the ARK frontend:
./build.sh --product-name Hi3516DV300 --build-target ark_ts2abc_build

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/hi3516dv300/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/hi3516dv300/clang_x64/ark/ark:out/hi3516dv300/clang_x64/ark/ark_js_runtime:out/hi3516dv300/clang_x64/global/i18n_standard:prebuilts/clang/ohos/linux-x86_64/llvm/lib
      
    2. Run ark_js_vm.

      /your code path/out/hi3516dv300/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/hi3516dv300/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 Hi3516DV300 --build-target ark_js_host_linux_tools_packages
  1. Run the following command to compile the ARK frontend:
./build.sh --product-name Hi3516DV300 --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/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