Daniel Erat | 599e024 | 2018-09-15 00:52:55 | [diff] [blame] | 1 | # Tast Quickstart (go/tast-quickstart) |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 2 | |
| 3 | [TOC] |
| 4 | |
| 5 | ## Prerequisites |
| 6 | |
Daniel Erat | fe12369 | 2018-09-05 20:17:35 | [diff] [blame] | 7 | You'll need a [Chrome OS chroot]. If you've only done Chrome development so far, |
| 8 | note that this is different from the Chrome checkout described in the [Simple |
| 9 | Chrome] documentation. |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 10 | |
| 11 | You'll also need a Chrome OS device running a system image built with the `test` |
| 12 | flag that's reachable from your workstation via SSH. An image running in a |
Daniel Erat | fe12369 | 2018-09-05 20:17:35 | [diff] [blame] | 13 | [virtual machine] will also work. If you're using a test image that you |
| 14 | downloaded rather than one built in your chroot, make sure that it's a recent |
| 15 | version. |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 16 | |
Daniel Erat | 69966c1 | 2017-09-29 23:39:17 | [diff] [blame] | 17 | ## Run a prebuilt test |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 18 | |
| 19 | In your chroot, run the following: |
| 20 | |
| 21 | ```sh |
Kevin Shelton | 4deb189 | 2018-05-18 19:40:41 | [diff] [blame] | 22 | tast -verbose run -build=false <test-device-ip> ui.ChromeLogin |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 23 | ``` |
| 24 | |
| 25 | You should see output scroll by on your workstation, and on the Chrome OS |
| 26 | device, the test should log in and load a webpage. After the test is done, take |
| 27 | a look at the results in `/tmp/tast/results/latest` in your chroot. |
| 28 | |
Daniel Erat | 69966c1 | 2017-09-29 23:39:17 | [diff] [blame] | 29 | ## Build and run a test |
| 30 | |
| 31 | The previous step ran a test that was already built into your device's system |
| 32 | image, but you can also use the `tast` command to quickly rebuild all tests and |
| 33 | push them to the device. |
| 34 | |
| 35 | In your chroot, run the same command as before **but without the `-build=false` |
| 36 | argument**: |
| 37 | |
| 38 | ```sh |
Kevin Shelton | 4deb189 | 2018-05-18 19:40:41 | [diff] [blame] | 39 | tast -verbose run <test-device-ip> ui.ChromeLogin |
Daniel Erat | 69966c1 | 2017-09-29 23:39:17 | [diff] [blame] | 40 | ``` |
| 41 | |
| 42 | This time, the command will take a bit longer (but build objects will be |
| 43 | cached). The test should succeed again. |
| 44 | |
| 45 | > The first time you run this, or after you sync your checkout, you may see an |
| 46 | > error similar to the following: |
| 47 | ``` |
| 48 | To install missing dependencies, run: |
| 49 | |
| 50 | sudo emerge -j 16 \ |
| 51 | =dev-go/cdp-0.9.1-r1 \ |
| 52 | =dev-go/dbus-0.0.2-r5 |
| 53 | ``` |
| 54 | > This is expected: to speed things up, `tast` is building the tests directly |
Daniel Erat | d777300 | 2017-12-30 11:11:34 | [diff] [blame] | 55 | > instead of emerging the `tast-local-tests-cros` package, so it needs some help |
| 56 | > from you to make sure that all required dependencies are installed. If you run |
| 57 | > the provided `emerge` command, the `tast` command should work when re-run. |
Daniel Erat | 69966c1 | 2017-09-29 23:39:17 | [diff] [blame] | 58 | |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 59 | See [Running Tests] for more information. |
| 60 | |
| 61 | ## Modify a test |
| 62 | |
Daniel Erat | 69966c1 | 2017-09-29 23:39:17 | [diff] [blame] | 63 | Now, let's modify the test. In your Chrome OS checkout, go to |
Daniel Erat | d777300 | 2017-12-30 11:11:34 | [diff] [blame] | 64 | `src/platform/tast-tests/src/chromiumos/tast/local/bundles/cros/ui` and open |
Kevin Shelton | b922f1e | 2018-05-18 20:17:56 | [diff] [blame] | 65 | `chrome_login.go` (for convenience, there's also a `local_tests` symlink at the |
Kevin Shelton | 4deb189 | 2018-05-18 19:40:41 | [diff] [blame] | 66 | top of `tast-tests`). The `ChromeLogin` function here will run directly on the |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 67 | test device. |
| 68 | |
| 69 | At the end of the function, add the following code: |
| 70 | |
| 71 | ```go |
Daniel Erat | f5b0258 | 2018-09-30 17:53:54 | [diff] [blame] | 72 | if _, err = cr.NewConn(ctx, "https://www.google.com/"); err != nil { |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 73 | s.Error("Failed to open page: ", err) |
| 74 | } |
| 75 | ``` |
| 76 | |
Daniel Erat | 69966c1 | 2017-09-29 23:39:17 | [diff] [blame] | 77 | Back in your chroot, run `tast` again: |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 78 | |
| 79 | ```sh |
Kevin Shelton | 4deb189 | 2018-05-18 19:40:41 | [diff] [blame] | 80 | tast -verbose run <test-device-ip> ui.ChromeLogin |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 81 | ``` |
| 82 | |
Daniel Erat | 69966c1 | 2017-09-29 23:39:17 | [diff] [blame] | 83 | This time, the test should additionally open a Google search page. |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 84 | |
| 85 | Return to the test file and add the following statement at the end of the |
| 86 | function: |
| 87 | |
| 88 | ```go |
| 89 | s.Error("This is an intentional error") |
| 90 | ``` |
| 91 | |
| 92 | If you build and run the test again, you should see it fail. |
| 93 | |
Daniel Erat | fe12369 | 2018-09-05 20:17:35 | [diff] [blame] | 94 | See [Writing Tests] for more information, and explore the [tast-tests |
| 95 | repository] to see existing tests and related packages. |
| 96 | |
| 97 | ## Next steps |
| 98 | |
| 99 | Additional Tast documentation is available in the [tast repository]. |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 100 | |
| 101 | Many resources are available for learning more about Go. Here are a few: |
| 102 | |
| 103 | * [A Tour of Go] - In-browser introduction to Go's core features. |
| 104 | * [Official Go documentation] - Package documentation, specifications, blog |
| 105 | posts, and recorded talks. |
Daniel Erat | 396132f | 2018-09-23 15:46:43 | [diff] [blame^] | 106 | * [Go at Google: Language Design in the Service of Software Engineering] - |
| 107 | High-level overview of Go's features and design philosophy. |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 108 | * [Community Learn wiki] - Links to external resources. |
| 109 | |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 110 | [Chrome OS chroot]: http://www.chromium.org/chromium-os/quick-start-guide |
Daniel Erat | fe12369 | 2018-09-05 20:17:35 | [diff] [blame] | 111 | [Simple Chrome]: https://chromium.googlesource.com/chromiumos/docs/+/master/simple_chrome_workflow.md |
| 112 | [virtual machine]: https://chromium.googlesource.com/chromiumos/docs/+/master/cros_vm.md |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 113 | [Running Tests]: running_tests.md |
| 114 | [Writing Tests]: writing_tests.md |
Daniel Erat | fe12369 | 2018-09-05 20:17:35 | [diff] [blame] | 115 | [tast-tests repository]: https://chromium.googlesource.com/chromiumos/platform/tast-tests/ |
| 116 | [tast repository]: https://chromium.googlesource.com/chromiumos/platform/tast/ |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 117 | [A Tour of Go]: https://tour.golang.org/ |
| 118 | [Official Go documentation]: https://golang.org/doc/ |
Daniel Erat | 396132f | 2018-09-23 15:46:43 | [diff] [blame^] | 119 | [Go at Google: Language Design in the Service of Software Engineering]: https://talks.golang.org/2012/splash.article |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 120 | [Community Learn wiki]: https://github.com/golang/go/wiki/Learn |