github.com/nya3jp/tast@v0.0.0-20230601000426-85c8e4d83a9b/docs/debugger.md (about) 1 # Tast: Debugging tests with a debugger (go/debug-tast-tests) 2 3 [TOC] 4 5 ## Prerequisites 6 7 * Have VScode installed 8 * Able to run a tast test ([running tests](running_tests.md)) 9 * Access to a DUT. 10 11 ## Step 1: Confirm that your DUT can run delve 12 13 SSH into your DUT and run “dlv” on it. If it doesn't work, delve likely isn't supported for your DUT, and you can try two things: 14 * Try running `emerge-${BOARD} dev-go/delve && cros deploy dut dev-go/delve` 15 * Try installing the 64-bit version of your image (eg. atlas64 instead of atlas). Delve is unsupported for arm32 ([github bug](http://github.com/go-delve/delve/issues/2051)).. 16 17 ## Step 2: Install the debugger on your host machine (outside the chroot) 18 Instructions to install delve are [here](https://github.com/go-delve/delve/blob/HEAD/Documentation/installation/README.md), but TLDR is: 19 ``` 20 $ git clone https://github.com/go-delve/delve 21 $ cd delve 22 $ go install github.com/go-delve/delve/cmd/dlv 23 $ rm -rf ../delve 24 ``` 25 26 ## Step 3: Check that the debugger is working 27 1) In your chroot, run `tast run -attachdebugger=local:2345 <DUT ip> meta.LocalPass` 28 29 2) Wait for it to say “Waiting for debugger on port 2345”. 30 31 3) Outside, the chroot, run `dlv connect :2345` 32 33 4) Once you see (dlv) prompt, type "c" (without quotes) and press enter. 34 35 5) Check that the tast command completed successfully 36 37 Note that people have had issues with vscode’s SSH extension with this. If this failed with vscode with the SSH extension open, then close vscode and try again. 38 39 ## Step 4: Ensure you have a working gopath 40 If you haven't already, follow the instructions in the [quickstart guide](quickstart.md#ide) to get your gopath working 41 42 ## Step 5: Set up vscode 43 1) Open up the folder `$CHROMEOS_SRC/src/platform/tast-tests` in vscode (or reload vscode if it’s already open) 44 45 2) If you don’t have a tasks.json, press control-shift-p, then select the option “tasks: configure task” -> “create tasks.json file from template”, select any template, then delete all of your tasks it created for you. 46 47 3) If you don't have a launch.json, click Run -> Add configuration -> select any configuration, then delete the configuration it created for you. 48 49 4) Replace tasks.json with the following (or if you already had useful tasks, merge the files). Make sure to swap out DUT_IP for your own DUT’s IP 50 ``` 51 { 52 // See https://go.microsoft.com/fwlink/?LinkId=733558 53 // for the documentation about the tasks.json format 54 "version": "2.0.0", 55 "tasks": [ 56 { 57 "label": "prep debugger", 58 "type": "shell", 59 "command": "cros_sdk -- /mnt/host/source/src/platform/tast-tests/tools/run_debugger.py --dut=DUT_IP --current-file=${file}", 60 "isBackground": true, 61 "problemMatcher": [ 62 { 63 "owner": "tast", 64 "fileLocation": [ 65 "relative", 66 "${workspaceFolder}/src/platform" 67 ], 68 "pattern": { 69 // 2021/01/20 11:53:25 ../platform/tast-tests/src/go.chromium.org/tast-tests/cros/local/bundlemain/main.go:274:3: unknown field 'BeforeDownload' in struct literal of type "go.chromium.org/tast/core/internal/bundle".LocalDelegate 70 // ../platform/tast-tests/src/go.chromium.org/tast-tests/cros/common/perf/timeline_test.go:217:51: cannot use d1 (type *testTimelineDatasource) as type TimelineDatasource in array or slice literal: 71 "regexp": "(..\/platform\/[^:]+):(\\d+):(\\d+):\\s+(.+)$", 72 "file": 1, 73 "line": 2, 74 "column": 3, 75 // "severity": 2, 76 "message": 4 77 }, 78 "background": { 79 "activeOnStart": true, 80 "beginsPattern": ".*", 81 "endsPattern": ".*Waiting for debugger on port.*", 82 } 83 } 84 ], 85 } 86 ] 87 } 88 ``` 89 90 5) Replace launch.json with the following (or if you already had useful configurations, merge the files). 91 ``` 92 { 93 // Use IntelliSense to learn about possible attributes. 94 // Hover to view descriptions of existing attributes. 95 // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 96 "version": "0.2.0", 97 "configurations": [ 98 { 99 "name": "Debug tast test", 100 "type": "go", 101 "request": "attach", 102 "mode": "remote", 103 "remotePath": "", 104 "port": 2345, 105 "host": "127.0.0.1", 106 "apiVersion": 2, 107 "preLaunchTask": "prep debugger" 108 }, 109 ] 110 } 111 ``` 112 113 ## Step 6: Try it out 114 1) Open a test file 115 116 2) Add a breakpoint at the start of your test 117 118 3) Click on the debug button in vscode 119 120 