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 Hi3516DV300 --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``` 21./build.sh --product-name Hi3516DV300 --build-target ark_ts2abc_build 22``` 23 24**NOTE**: Run the compilation commands in the project root directory. 25 26### Running **hello-world.js** 27 28Create the **hello-world.js** file and write the following source code into the file: 29 30``` 31 print("Hello World!!!"); 32``` 33 34Run the **hello-world.js** file. 35 361. Use the ARK frontend to create the **hello-world.abc** file. 37 38 ``` 39 node --expose-gc /your code path/out/hi3516dv300/clang_x64/ark/ark/build/src/index.js hello-world.js 40 ``` 41 422. Run the **hello-world.abc** file. 43 1. Set the search path. 44 45 ``` 46 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 47 ``` 48 49 2. Run **ark\_js\_vm**. 50 51 ``` 52 /your code path/out/hi3516dv300/clang_x64/ark/ark_js_runtime/ark_js_vm hello-world.abc 53 ``` 54 55 The execution result is as follows: 56 57 ``` 58 Hello World!!! 59 ``` 60 61**NOTE**: In the preceding command, _your code path_ indicates the source code directory. 62 63### Disassembling **hello-world.abc** 64 65Run the following command to export the result to the **output** file: 66 67``` 68./your code path/out/hi3516dv300/clang_x64/ark/ark/ark_disasm hello-world.abc output 69``` 70 71The output is as follows: 72 73``` 74# 75# source binary: hello-world.abc 76# 77 78# ==================== 79# LITERALS 80 81# ==================== 82# RECORDS 83 84.record _ESAnnotation <external> 85 86.record _ESModuleMode { 87 u8 isModule 88} 89 90# ==================== 91# METHODS 92 93.function any func_main_0_any_any_any_any_(any a0, any a1, any a2) <static> { 94 mov.dyn v2, a2 95 mov.dyn v1, a1 96 mov.dyn v0, a0 97 builtin.acc 98 sta.dyn v5 99 builtin.idi "print", 0x0 // Load the print function. 100 sta.dyn v3 101 lda.str "Hello World!!!" // Load the Hello World!!! string. 102 sta.dyn v4 103 builtin.tern3 v3, v4 // Call the print function. 104 builtin.acc 105} 106``` 107 108## Performing Test Case Test262<a name="section118471435115815"></a> 109 110### Preparations 111 1121. Run the following command to compile ARK runtime: 113 114``` 115./build.sh --product-name Hi3516DV300 --build-target ark_js_host_linux_tools_packages 116``` 117 1182. Run the following command to compile the ARK frontend: 119 120``` 121./build.sh --product-name Hi3516DV300 --build-target ark_ts2abc_build 122``` 123 124**NOTE**: Run the compilation commands in the project root directory. 125 126### Running Test262 127 128Run the **run\_test262.py** script to download and run the Test262 test case. 129 130Command: 131 132``` 133python3 test262/run_test262.py [options] 134``` 135 136Run the script in _Project root directory_**/ark/ts2abc**. 137 138<a name="table11141827153017"></a> 139<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> 140</th> 141<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> 142</th> 143</tr> 144</thead> 145<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> 146</td> 147<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> 148</td> 149</tr> 150<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> 151</td> 152<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> 153</td> 154</tr> 155<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> 156</td> 157<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> 158</td> 159</tr> 160<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> 161</td> 162<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> 163<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> 164</td> 165</tr> 166<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> 167</td> 168<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> 169</td> 170</tr> 171<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> 172</td> 173<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> 174<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> 175<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> 176</td> 177</tr> 178<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> 179</td> 180<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> 181</td> 182</tr> 183<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> 184</td> 185<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> 186</td> 187</tr> 188<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> 189</td> 190<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> 191</td> 192</tr> 193<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> 194</td> 195<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> 196</td> 197</tr> 198<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> 199</td> 200<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> 201</td> 202</tr> 203<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> 204</td> 205<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> 206</td> 207</tr> 208<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> 209</td> 210<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> 211</td> 212</tr> 213<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> 214</td> 215<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> 216</td> 217</tr> 218<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> 219</td> 220<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> 221</td> 222</tr> 223<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> 224</td> 225<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> 226</td> 227</tr> 228</tbody> 229</table> 230 231### Example 232 233- Run test case ES51. 234 235 ``` 236 python3 test262/run_test262.py --es51 237 ``` 238 239- Run test case ES2015 only. 240 241 ``` 242 python3 test262/run_test262.py --es2015 only 243 ``` 244 245- Run all ES2015 and ES51 test cases. 246 247 ``` 248 python3 test262/run_test262.py --es2015 all 249 ``` 250 251- Run a test case. 252 253 ``` 254 python3 test262/run_test262.py --file test262/data/test_es5/language/statements/break/12.8-1.js 255 ``` 256 257- Run all test cases in a directory. 258 259 ``` 260 python3 test262/run_test262.py --dir test262/data/test_es5/language/statements 261 ``` 262 263 264- Use Babel to convert a test case into ES5 and then run the test case. 265 266 ``` 267 python3 test262/run_test262.py --babel --file test262/data/test_es5/language/statements/break/12.8-1.js 268 ``` 269 270 271### Test Output 272 273The 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: 274 275``` 276$python3 test262/run_test262.py --file test262/data/test_es2015/built-ins/Array/15.4.5.1-5-1.js 277 278Wait a moment.......... 279Test command: 280node 281 test262/harness/bin/run.js 282 --hostType=panda 283 --hostPath=python3 284 --hostArgs='-B test262/run_sunspider.py --ark-tool=/your code path/out/hi3516dv300/clang_x64/ark/ark_js_runtime/ark_js_vm --ark-frontend-tool=/your code path/out/hi3516dv300/clang_x64/ark/ark/build/src/index.js --libs-dir=/your code path/out/hi3516dv300/clang_x64/ark/ark:/your code path/out/hi3516dv300/clang_x64/global/i18n:/your code path/prebuilts/clang/ohos/linux-x86_64/llvm/lib/ --ark-frontend=ts2panda' 285 --threads=15 286 --mode=only strict mode 287 --timeout=60000 288 --tempDir=build/test262 289 --test262Dir=test262/data 290 --saveCompiledTests 291 test262/data/test_es5/language/statements/break/12.8-1.js 292 293PASS test262/data/test_es2015/built-ins/Array/15.4.5.1-5-1.js (strict mode) 294Ran 1 tests 2951 passed 2960 failed 297used time is: 0:01:04.439642 298``` 299 300