1# Development Example<a name="EN-US_TOPIC_0000001128096218"></a> 2 3- [HelloWorld](#section105987593810) 4- [Performing Test Case Test262](#section118471435115815) 5 6This section describes how to develop and test ARK runtime. 7 8## HelloWorld<a name="section105987593810"></a> 9 10### Preparations 11 121. Run the following command to compile ARK runtime: 13 14 ``` 15 ./build.sh --product-name rk3568 --build-target ark_js_host_linux_tools_packages # arm platform and host side running tool 16 ``` 17 182. Run the following command to compile the ARK frontend: 19 20 x64: 21 ``` 22 ./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 23 ``` 24 25 arm64: 26 ``` 27 ./build.sh --product-name ohos_arm64 --build-target ark_js_packages --build-target ld-musl-aarch64.so.1 28 ``` 29 30 arm32: 31 ``` 32 ./build.sh --product-name rk3568 --build-target ark_js_runtime --build-target ld-musl-arm.so.1 33 ``` 34 35**NOTE**: Run the compilation commands in the project root directory. 36 37 38### Running **hello-world.js** 39 40Create the **hello-world.js** file and write the following source code into the file: 41 42``` 43 print("Hello World!!!"); 44``` 45 46Run the **hello-world.js** file. 47 481. Use the ARK frontend to create the **hello-world.abc** file. 49 50 ``` 51 node --expose-gc /your_code_path/out/rk3568/clang_x64/arkcompiler/ets_frontend/build/src/index.js hello-world.js 52 ``` 53 542. Run the **hello-world.abc** file. 55 1. Set the search path. 56 57 ``` 58 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 59 ``` 60 61 2. Run **ark\_js\_vm**. 62 63 ``` 64 /your_code_path/out/rk3568/clang_x64/arkcompiler/ets_runtime/ark_js_vm hello-world.abc 65 ``` 66 67 The execution result is as follows: 68 69 ``` 70 Hello World!!! 71 ``` 72 73**NOTE**: In the preceding command, _your code path_ indicates the source code directory. 74 75### Disassembling **hello-world.abc** 76 77Run the following command to export the result to the **output** file: 78 79``` 80./your code path/out/rk3568/clang_x64/arkcompiler/runtime_core/ark_disasm hello-world.abc output 81``` 82 83The output is as follows: 84 85``` 86# 87# source binary: hello-world.abc 88# 89 90# ==================== 91# LITERALS 92 93# ==================== 94# RECORDS 95 96.record _ESAnnotation <external> 97 98.record _ESModuleMode { 99 u8 isModule 100} 101 102# ==================== 103# METHODS 104 105.function any func_main_0_any_any_any_any_(any a0, any a1, any a2) <static> { 106 mov v2, a2 107 mov v1, a1 108 mov v0, a0 109 builtin.acc 110 sta v5 111 builtin.idi "print", 0x0 // Load the print function. 112 sta v3 113 lda.str "Hello World!!!" // Load the Hello World!!! string. 114 sta v4 115 builtin.tern3 v3, v4 // Call the print function. 116 builtin.acc 117} 118``` 119 120## Performing Test Case Test262<a name="section118471435115815"></a> 121 122### Preparations 123 1241. Run the following command to compile ARK runtime: 125 126``` 127./build.sh --product-name rk3568 --build-target ark_js_host_linux_tools_packages 128``` 129 1302. Run the following command to compile the ARK frontend: 131 132``` 133./build.sh --product-name rk3568 --build-target ets_frontend_build 134``` 135 136**NOTE**: Run the compilation commands in the project root directory. 137 138### Running Test262 139 140Run the **run\_test262.py** script to download and run the Test262 test case. 141 142Command: 143 144``` 145python3 test262/run_test262.py [options] 146``` 147 148Run the script in _Project root directory_**/arkcompiler/ets_frontend**. 149 150<a name="table11141827153017"></a> 151<table><thead align="left"><tr id="row101462717303"><th class="cellrowborder" valign="top" width="50%" id="mcps1.1.3.1.1"><p id="p51552743010"><a name="p51552743010"></a><a name="p51552743010"></a>Option</p> 152</th> 153<th class="cellrowborder" valign="top" width="50%" id="mcps1.1.3.1.2"><p id="p11592710304"><a name="p11592710304"></a><a name="p11592710304"></a>Description</p> 154</th> 155</tr> 156</thead> 157<tbody><tr id="row2015172763014"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p171592710306"><a name="p171592710306"></a><a name="p171592710306"></a>--h, --help</p> 158</td> 159<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p13151527133011"><a name="p13151527133011"></a><a name="p13151527133011"></a>Displays help information.</p> 160</td> 161</tr> 162<tr id="row1015527173015"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p1615182712308"><a name="p1615182712308"></a><a name="p1615182712308"></a>--dir DIR</p> 163</td> 164<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p9556101593120"><a name="p9556101593120"></a><a name="p9556101593120"></a>Specifies the directory to test.</p> 165</td> 166</tr> 167<tr id="row1015112763020"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p1815182733012"><a name="p1815182733012"></a><a name="p1815182733012"></a>--file FILE</p> 168</td> 169<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p1615627173019"><a name="p1615627173019"></a><a name="p1615627173019"></a>Specifies the file to test.</p> 170</td> 171</tr> 172<tr id="row131515277307"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p111572716304"><a name="p111572716304"></a><a name="p111572716304"></a>--mode [{1, 2, 3}]</p> 173</td> 174<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p1820821404711"><a name="p1820821404711"></a><a name="p1820821404711"></a>Specifies the mode, which can be any of the following:</p> 175<a name="ul136633170477"></a><a name="ul136633170477"></a><ul id="ul136633170477"><li><strong id="b12807202010471"><a name="b12807202010471"></a><a name="b12807202010471"></a>1</strong>: default</li><li><strong id="b16343325154719"><a name="b16343325154719"></a><a name="b16343325154719"></a>2</strong>: strict mode only</li><li><strong id="b19742163854610"><a name="b19742163854610"></a><a name="b19742163854610"></a>3</strong>: default and strict modes</li></ul> 176</td> 177</tr> 178<tr id="row1815112753020"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p2151927193015"><a name="p2151927193015"></a><a name="p2151927193015"></a>--es51</p> 179</td> 180<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p1715312588115"><a name="p1715312588115"></a><a name="p1715312588115"></a>Runs Test262 ES5.1.</p> 181</td> 182</tr> 183<tr id="row1915182703012"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p17151527133017"><a name="p17151527133017"></a><a name="p17151527133017"></a>--es2015 [{all, only}]</p> 184</td> 185<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p536992675017"><a name="p536992675017"></a><a name="p536992675017"></a>Runs Test262 ES2015.</p> 186<p id="p205288299503"><a name="p205288299503"></a><a name="p205288299503"></a><strong id="b2052812914503"><a name="b2052812914503"></a><a name="b2052812914503"></a>all</strong>: all cases</p> 187<p id="p1392723585014"><a name="p1392723585014"></a><a name="p1392723585014"></a><strong id="b15128193544910"><a name="b15128193544910"></a><a name="b15128193544910"></a>only</strong>: only ES2015</p> 188</td> 189</tr> 190<tr id="row10924204611109"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p18924846111013"><a name="p18924846111013"></a><a name="p18924846111013"></a>--esnext</p> 191</td> 192<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p15495042191410"><a name="p15495042191410"></a><a name="p15495042191410"></a>Runs <strong id="b13144135817502"><a name="b13144135817502"></a><a name="b13144135817502"></a>Test262-ES.next</strong>.</p> 193</td> 194</tr> 195<tr id="row5161145010105"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p716125071020"><a name="p716125071020"></a><a name="p716125071020"></a>--engine FILE</p> 196</td> 197<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p121612050181014"><a name="p121612050181014"></a><a name="p121612050181014"></a>Runs other engines and specifies binary files (such as d8, hermes, jsc, and qjs).</p> 198</td> 199</tr> 200<tr id="row1325585931120"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p112561595112"><a name="p112561595112"></a><a name="p112561595112"></a>--babel</p> 201</td> 202<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p32561959111112"><a name="p32561959111112"></a><a name="p32561959111112"></a>Specifies whether to use Babel to convert code.</p> 203</td> 204</tr> 205<tr id="row95230818126"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p12523158191210"><a name="p12523158191210"></a><a name="p12523158191210"></a>--timeout TIMEOUT</p> 206</td> 207<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p65233871210"><a name="p65233871210"></a><a name="p65233871210"></a>Specifies the test timeout period in ms.</p> 208</td> 209</tr> 210<tr id="row474911612120"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p1274912166123"><a name="p1274912166123"></a><a name="p1274912166123"></a>--threads THREADS</p> 211</td> 212<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p4749121631210"><a name="p4749121631210"></a><a name="p4749121631210"></a>Specifies the number of concurrent threads.</p> 213</td> 214</tr> 215<tr id="row561512363122"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p26152036191218"><a name="p26152036191218"></a><a name="p26152036191218"></a>--hostArgs HOSTARGS</p> 216</td> 217<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p156151636161215"><a name="p156151636161215"></a><a name="p156151636161215"></a>Specifies the command line parameters sent to the eshost.</p> 218</td> 219</tr> 220<tr id="row77091648111210"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p18709164871213"><a name="p18709164871213"></a><a name="p18709164871213"></a>--ark-tool ARK_TOOL</p> 221</td> 222<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p16709194812126"><a name="p16709194812126"></a><a name="p16709194812126"></a>Specifies the binary tool of ARK runtime.</p> 223</td> 224</tr> 225<tr id="row3767145231210"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p3767155201216"><a name="p3767155201216"></a><a name="p3767155201216"></a>--ark-frontend-tool ARK_FRONTEND_TOOL</p> 226</td> 227<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p4767195251220"><a name="p4767195251220"></a><a name="p4767195251220"></a>Specifies the ARK front-end conversion tool.</p> 228</td> 229</tr> 230<tr id="row753817001311"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p553870111318"><a name="p553870111318"></a><a name="p553870111318"></a>--libs-dir LIBS_DIR</p> 231</td> 232<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p35384041313"><a name="p35384041313"></a><a name="p35384041313"></a>Specifies the set of .so dependency file paths, separated by colons (:).</p> 233</td> 234</tr> 235<tr id="row08504716135"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p11851747161314"><a name="p11851747161314"></a><a name="p11851747161314"></a>--ark-frontend [{ts2panda, es2panda}]</p> 236</td> 237<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p1085144712137"><a name="p1085144712137"></a><a name="p1085144712137"></a>Specifies the frontend.</p> 238</td> 239</tr> 240</tbody> 241</table> 242 243### Example 244 245- Run test case ES51. 246 247 ``` 248 python3 test262/run_test262.py --es51 249 ``` 250 251- Run test case ES2015 only. 252 253 ``` 254 python3 test262/run_test262.py --es2015 255 ``` 256 257- Run test case ES2021 only. 258 259 ``` 260 python3 test262/run_test262.py --es2021 only 261 262- Run all ES2015 and ES51 and ES2021 test cases. 263 264 ``` 265 python3 test262/run_test262.py --es2021 all 266 ``` 267 268- Run a test case. 269 270 ``` 271 python3 test262/run_test262.py --file test262/data/test_es5/language/statements/break/12.8-1.js 272 ``` 273 274- Run all test cases in a directory. 275 276 ``` 277 python3 test262/run_test262.py --dir test262/data/test_es5/language/statements 278 ``` 279 280 281- Use Babel to convert a test case into ES5 and then run the test case. 282 283 ``` 284 python3 test262/run_test262.py --babel --file test262/data/test_es5/language/statements/break/12.8-1.js 285 ``` 286 287 288### Test Output 289 290The 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: 291 292``` 293$python3 test262/run_test262.py --file test262/data/test_es2015/built-ins/Array/15.4.5.1-5-1.js 294 295Wait a moment.......... 296Test command: 297node 298 test262/harness/bin/run.js 299 --hostType=panda 300 --hostPath=python3 301 --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' 302 --threads=15 303 --mode=only strict mode 304 --timeout=60000 305 --tempDir=build/test262 306 --test262Dir=test262/data 307 --saveCompiledTests 308 test262/data/test_es5/language/statements/break/12.8-1.js 309 310PASS test262/data/test_es2015/built-ins/Array/15.4.5.1-5-1.js (strict mode) 311Ran 1 tests 3121 passed 3130 failed 314used time is: 0:01:04.439642 315``` 316 317