1cb93a386Sopenharmony_ci# Prerequisites 2cb93a386Sopenharmony_ci 3cb93a386Sopenharmony_ciNode v14 or later is required to run tests. We use npm (the Node Package Manager) to install 4cb93a386Sopenharmony_citest dependencies. Recent installations of Node have npm as well. 5cb93a386Sopenharmony_ciCanvasKit has no other external source dependencies. 6cb93a386Sopenharmony_ci 7cb93a386Sopenharmony_ciTo compile CanvasKit, you will first need to [install `emscripten`][1]. This 8cb93a386Sopenharmony_ciwill set the environment `EMSDK` (among others) which is required for 9cb93a386Sopenharmony_cicompilation. Which version should you use? [`/infra/wasm-common/docker/emsdk-base/Dockerfile`][2] 10cb93a386Sopenharmony_cishows the version we build and test with. We try to use as recent a version of emscripten as 11cb93a386Sopenharmony_ciis reasonable. 12cb93a386Sopenharmony_ci 13cb93a386Sopenharmony_ci[1]: https://emscripten.org/docs/getting_started/downloads.html 14cb93a386Sopenharmony_ci[2]: https://github.com/google/skia/blob/main/infra/wasm-common/docker/emsdk-base/Dockerfile 15cb93a386Sopenharmony_ci 16cb93a386Sopenharmony_ciBe sure to both install **and** activate the correct version. For example: 17cb93a386Sopenharmony_ci``` 18cb93a386Sopenharmony_ci ./emsdk install 2.0.20 19cb93a386Sopenharmony_ci ./emsdk activate 2.0.20 20cb93a386Sopenharmony_ci``` 21cb93a386Sopenharmony_ci 22cb93a386Sopenharmony_ciThis document also assumes you have followed the instructions to download Skia and its deps 23cb93a386Sopenharmony_ci<https://skia.org/user/download>. 24cb93a386Sopenharmony_ci 25cb93a386Sopenharmony_ci## MacOS specific notes 26cb93a386Sopenharmony_ciMake sure you have Python3 installed, otherwise the downloading emscripten toolchain 27cb93a386Sopenharmony_cican fail with errors about SSL certificates. <https://github.com/emscripten-core/emsdk/pull/273> 28cb93a386Sopenharmony_ci 29cb93a386Sopenharmony_ciSee also <https://github.com/emscripten-core/emscripten/issues/9036#issuecomment-532092743> 30cb93a386Sopenharmony_cifor a solution to Python3 using the wrong certificates. 31cb93a386Sopenharmony_ci 32cb93a386Sopenharmony_ci# Compile and Run Local Example 33cb93a386Sopenharmony_ci 34cb93a386Sopenharmony_ci``` 35cb93a386Sopenharmony_ci# The following installs all npm dependencies and only needs to be when setting up 36cb93a386Sopenharmony_ci# or if our npm dependencies have changed (rarely). 37cb93a386Sopenharmony_cinpm ci 38cb93a386Sopenharmony_ci 39cb93a386Sopenharmony_cimake release # make debug is much faster and has better error messages 40cb93a386Sopenharmony_cimake local-example 41cb93a386Sopenharmony_ci``` 42cb93a386Sopenharmony_ci 43cb93a386Sopenharmony_ciThis will print a local endpoint for viewing the example. You can experiment 44cb93a386Sopenharmony_ciwith the CanvasKit API by modifying `./npm_build/example.html` and refreshing 45cb93a386Sopenharmony_cithe page. For some more experimental APIs, there's also `./npm_build/extra.html`. 46cb93a386Sopenharmony_ci 47cb93a386Sopenharmony_ciFor other available build targets, see `Makefile` and `compile.sh`. 48cb93a386Sopenharmony_ciFor example, building a stripped-down version of CanvasKit with no text support or 49cb93a386Sopenharmony_ciany of the "extras", one might run: 50cb93a386Sopenharmony_ci 51cb93a386Sopenharmony_ci ./compile.sh no_skottie no_particles no_font 52cb93a386Sopenharmony_ci 53cb93a386Sopenharmony_ciSuch a stripped-down version is about half the size of the default release build. 54cb93a386Sopenharmony_ci 55cb93a386Sopenharmony_ci# Unit tests, performance tests, and coverage. 56cb93a386Sopenharmony_ci 57cb93a386Sopenharmony_ciTo run unit tests and compute test coverage on a debug gpu build 58cb93a386Sopenharmony_ci 59cb93a386Sopenharmony_ci``` 60cb93a386Sopenharmony_cimake debug 61cb93a386Sopenharmony_cimake test-continuous 62cb93a386Sopenharmony_ci``` 63cb93a386Sopenharmony_ci 64cb93a386Sopenharmony_ciThis reads karma.conf.js, and opens a chrome browser and begins running all the test 65cb93a386Sopenharmony_ciin `test/` it will detect changes to the tests in that directory and automatically 66cb93a386Sopenharmony_cirun again, however it will automatically rebuild and reload canvaskit. Closing the 67cb93a386Sopenharmony_cichrome window will just cause it to re-opened. Kill the karma process to stop continuous 68cb93a386Sopenharmony_cimonitoring for changes. 69cb93a386Sopenharmony_ci 70cb93a386Sopenharmony_ciThe tests are run with whichever build of canvaskit you last made. be sure to also 71cb93a386Sopenharmony_citest with `release`, `debug_cpu`, and `release_cpu`. testing with release builds will 72cb93a386Sopenharmony_ciexpose problems in closure compilation and usually forgotten externs. 73cb93a386Sopenharmony_ci 74cb93a386Sopenharmony_ci## Coverage 75cb93a386Sopenharmony_ci 76cb93a386Sopenharmony_ciCoverage will be automatically computed when running test-continuous locally. Note that 77cb93a386Sopenharmony_cithe results will only be useful when testing a debug build. Open 78cb93a386Sopenharmony_ci`coverage/<browser version>/index.html` For a summary and detailed line-by-line result. 79cb93a386Sopenharmony_ci 80cb93a386Sopenharmony_ci## Measuring Performance 81cb93a386Sopenharmony_ci 82cb93a386Sopenharmony_ciWe use puppeteer to run a Chrome browser to gather performance data in a consistent way. 83cb93a386Sopenharmony_ciSee //tools/perf-canvaskit-puppeteer for more. 84cb93a386Sopenharmony_ci 85cb93a386Sopenharmony_ci## Adding tests 86cb93a386Sopenharmony_ci 87cb93a386Sopenharmony_ciThe tests in `tests/` are grouped into files by topic. 88cb93a386Sopenharmony_ciWithin each file there are `describe` blocks further organizing the tests, and within those 89cb93a386Sopenharmony_ci`it()` functions which test particular behaviors. `describe` and `it` are jasmine methods 90cb93a386Sopenharmony_ciwhich can both be temporarily renamed `fdescribe` and `fit`. Which causes jasmine to only those. 91cb93a386Sopenharmony_ci 92cb93a386Sopenharmony_ciWe have also defined `gm` which is a method for defining a test which draws something to a canvas 93cb93a386Sopenharmony_cithat is shapshotted and reported to gold.skia.org, where you can compare it with the snapshot at 94cb93a386Sopenharmony_cihead. 95cb93a386Sopenharmony_ci 96cb93a386Sopenharmony_ci## Testing from Gerrit 97cb93a386Sopenharmony_ci 98cb93a386Sopenharmony_ciWhen submitting a CL in gerrit, click "choose tryjobs" and type canvaskit to filter them. 99cb93a386Sopenharmony_ciselect all of them, which at the time of this writing is four jobs, for each combination 100cb93a386Sopenharmony_ciof perf/test gpu/cpu. 101cb93a386Sopenharmony_ci 102cb93a386Sopenharmony_ciThe performance results are reported to perf.skia.org 103cb93a386Sopenharmony_cigold results are reported to gold.skia.org 104cb93a386Sopenharmony_ci 105cb93a386Sopenharmony_ciCoverage is not measured while running tests this way. 106cb93a386Sopenharmony_ci 107cb93a386Sopenharmony_ci# Inspecting output WASM 108cb93a386Sopenharmony_ci 109cb93a386Sopenharmony_ciThe `wasm2wat` tool from [the WebAssembly Binary Toolkit](https://github.com/WebAssembly/wabt) 110cb93a386Sopenharmony_cican be used to produce a human-readable text version of a `.wasm` file. 111cb93a386Sopenharmony_ci 112cb93a386Sopenharmony_ciThe output of `wasm2wat --version` should be `1.0.13 (1.0.17)`. This version has been checked to 113cb93a386Sopenharmony_ciwork with the tools in `wasm_tools/SIMD/`. These tools programmatically inspect the `.wasm` output 114cb93a386Sopenharmony_ciof a CanvasKit build to detect the presence of [wasm SIMD](https://github.com/WebAssembly/simd) 115cb93a386Sopenharmony_cioperations. 116cb93a386Sopenharmony_ci 117cb93a386Sopenharmony_ci# Infrastructure Playbook 118cb93a386Sopenharmony_ci 119cb93a386Sopenharmony_ciWhen dealing with CanvasKit (or PathKit) on our bots, we use Docker. Check out 120cb93a386Sopenharmony_ci$SKIA_ROOT/infra/wasm-common/docker/README.md for more on building/editing the 121cb93a386Sopenharmony_ciimages used for building and testing. 122cb93a386Sopenharmony_ci 123cb93a386Sopenharmony_ci## Updating the version of Emscripten we build/test with 124cb93a386Sopenharmony_ci 125cb93a386Sopenharmony_ciThis presumes you have updated emscripten locally to a newer version of the 126cb93a386Sopenharmony_cisdk and verified/fixed any build issues that have arisen. 127cb93a386Sopenharmony_ci 128cb93a386Sopenharmony_ci 1. Edit `$SKIA_ROOT/infra/wasm-common/docker/emsdk-base/Dockerfile` to install 129cb93a386Sopenharmony_ci and activate the desired version of Emscripten. 130cb93a386Sopenharmony_ci 2. Edit `$SKIA_ROOT/infra/wasm-common/docker/Makefile` to have `EMSDK_VERSION` be 131cb93a386Sopenharmony_ci set to that desired version. If there is a suffix that is not `_v1`, reset 132cb93a386Sopenharmony_ci it to be `_v1`. If testing the image later does not work and edits are made 133cb93a386Sopenharmony_ci to the emsdk-base Dockerfile to correct that, increment to `_v2`,`_v3`, etc 134cb93a386Sopenharmony_ci to force the bots to pick up the new image. 135cb93a386Sopenharmony_ci 3. In `$SKIA_ROOT/infra/wasm-common/docker/`, run `make publish_emsdk_base` 136cb93a386Sopenharmony_ci 4. Edit `$SKIA_ROOT/infra/canvaskit/docker/canvaskit-emsdk/Dockerfile` to be based 137cb93a386Sopenharmony_ci off the new version from step 2. CanvasKit has its own docker image because 138cb93a386Sopenharmony_ci it needs a few extra dependencies to build with font support. 139cb93a386Sopenharmony_ci 5. Edit `$SKIA_ROOT/infra/canvaskit/docker/Makefile` to have the same version 140cb93a386Sopenharmony_ci from step 2. It's easiest to keep the `emsdk-base` and `canvaskit-emsdk` versions 141cb93a386Sopenharmony_ci be in lock-step. 142cb93a386Sopenharmony_ci 6. In `$SKIA_ROOT/infra/canvaskit/docker/`, run `make publish_canvaskit_emsdk`. 143cb93a386Sopenharmony_ci 7. In `$SKIA_ROOT/infra/bots/recipe_modules/build/`, update `canvaskit.py` 144cb93a386Sopenharmony_ci and `pathkit.py` to have `DOCKER_IMAGE` point to the desired tagged Docker 145cb93a386Sopenharmony_ci containers from steps 2 and 5 (which should be the same). 146cb93a386Sopenharmony_ci 8. In `$SKIA_ROOT/infra/bots/task_drivers/compile_wasm_gm_tests.go`, update dockerImage 147cb93a386Sopenharmony_ci to refer to the desired Docker containers from steps 2 and 5. 148cb93a386Sopenharmony_ci 9. In `$SKIA_ROOT/infra/bots/`, run `make train` to re-train the recipes. 149cb93a386Sopenharmony_ci 10. Optional: Run something like `git grep 1\\.38\\.` in `$SKIA_ROOT` to see if 150cb93a386Sopenharmony_ci there are any other references that need updating. 151cb93a386Sopenharmony_ci 11. Upload a CL with all the changes. Run all Test.+CanvasKit, Perf.+Puppeteer, 152cb93a386Sopenharmony_ci Test.+PathKit, Perf.+PathKit jobs to make sure the new builds pass all 153cb93a386Sopenharmony_ci tests and don't crash the perf harnesses. 154cb93a386Sopenharmony_ci 12. Send out CL for review. Feel free to point the reviewer at these steps. 155