Skip to content

Commit c212d32

Browse files
authored
Doc structure revision (#1387)
* Interprocess debugging doc added * doc_structure_revision
1 parent fc36ef8 commit c212d32

8 files changed

+356
-35
lines changed

CONTRIBUTING.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ There are so many ways to contribute. Choose yours and find the relevant short g
3232
## Reporting a bug
3333

3434
1. Check if the bug (a true bug!) has already been reported: search through [UnitTestBot issues](https://github.com/UnitTestBot/UTBotJava/issues). Please, don't duplicate.
35-
2. Check with the [Naming and labeling conventions](Conventions.md).
35+
2. Check with the [Naming and labeling conventions](docs/contributing/Conventions.md).
3636
3. Make sure you have all the necessary information as per [template](https://github.com/UnitTestBot/UTBotJava/issues/new?assignees=&labels=&template=bug_report.md&title=) and create the bug reporting issue.
3737

3838
## Requesting a feature
3939

4040
1. Check if the feature has already been requested: search through [UnitTestBot issues](https://github.com/UnitTestBot/UTBotJava/issues).
41-
2. Check with our [Naming and labeling conventions](Conventions.md).
41+
2. Check with our [Naming and labeling conventions](docs/contributing/Conventions.md).
4242
3. Make sure you are able to provide all the necessary information as per [template](https://github.com/UnitTestBot/UTBotJava/issues/new?assignees=&labels=&template=feature_request.md&title=) and create the feature request issue.
4343

4444
## Contributing the code (bug fix or feature implementation)
@@ -66,7 +66,7 @@ Do you need to create an issue if you want to fix a bug?
6666
* Before creating the pull request perform the tests you find necessary for your code changes.
6767
* When implementing something new, it's great to find real users and ask them to try out your feature — to prove
6868
the necessity and quality of your suggestion.
69-
6. Check with the [Naming and labeling conventions](Conventions.md).
69+
6. Check with the [Naming and labeling conventions](docs/contributing/Conventions.md).
7070
7. Create the pull request, and you'll see if the automated tests pass on GitHub. Your reviewer will possibly recommend
7171
you more tests.
7272

@@ -87,7 +87,7 @@ is the same as for the code. If you'd like to improve the existing docs or to ad
8787
2. Create your own fork of the code.
8888
3. Clone the forked repository to your local machine.
8989
4. Implement changes to docs (change the existing doc or create a new one). Usually, we create a new doc for a new feature, not for the small fixes. You are not obliged to write a detailed text about the feature you implement. You have to only describe it properly in both the related issue and the pull request, but it will be great if you still provide some docs.
90-
6. Check with the [Naming and labeling conventions](Conventions.md).
90+
6. Check with the [Naming and labeling conventions](docs/contributing/Conventions.md).
9191
7. Create the pull request, and we'll review it.
9292

9393
* You can request a new doc — create an issue, using the [guide for a feature request](#Requesting-a-feature).

SystemRequirements.md

Lines changed: 0 additions & 31 deletions
This file was deleted.

docs/ci/ci-in-utbot-java.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<!---
2+
name: CI in UTBot Java
3+
route: /docs/java/ci/ci-in-utbot-java
4+
parent: Documentation
5+
menu: CI
6+
description: CI processes description
7+
--->
8+
9+
# CI features
10+
11+
UTBot Java offers contributors bunch of workflows e.g., the workflow _building the project and running tests_, the workflow _archiving plugin and CLI_.
12+
13+
The main CI features in UTBot Java:
14+
* reproducible environment
15+
* available monitoring processes
16+
17+
## Reproducible environment
18+
19+
Depending on the resources where you are intended to build and test software environment will be different. The key goal is to provide the same environment on different resources. To do that we use Docker images with appropriate software, environment variables and OS settings.
20+
21+
Crucial CI workflows run in those docker containers thus you can reproduce the environment locally. The environment can be used for running tests or for debugging ([see detailed information](https://github.com/UnitTestBot/UTBotJava/wiki/docker-for-utbot-java)).
22+
23+
If you have any questions of where images are placed, how many they are, what software versions are used, visit [repository](https://github.com/UnitTestBot/infra-images) please (now is private, will be changed in the future), leave an issue with your questions or ask in DM.
24+
25+
## All stages Monitoring
26+
27+
Since the workflow has started you can check access to the metrics on our monitoring service (ask teammates for url). The server offers developers the following dashboards:
28+
29+
* **Node Exporter Full** - metrics of consuming the RAM, CPU, Network and other resources on the host
30+
* **JVM dashboard** (don't forget to set job to `pushgateway`) - Java metrics
31+
* **Test executor statistics*** - RAM consuming by Java processes
32+
* **cAdvisor: container details*** - system resources consuming by certain container
33+
* **cAdvisor: host summary*** - summarized system resources consuming by all containers
34+
35+
**Note:** * developed by UTBot team
36+
37+
When you open a dashboard you need to choose valid instance. GitHub runs **each job on separate runner** so instance ID (`HOSTNAME` env var) would be different. But all instances have **the same Run ID** (`GITHUB_RUN_ID` env var). Follow this steps:
38+
39+
1. Go to Actions and open your Run;
40+
2. Expand job list and choose any job you need;
41+
3. At the right you'll see a list of steps. You need step `Run monitoring`;
42+
4. Find the string like:
43+
```
44+
Find your Prometheus metrics using label {instance="2911909439-7f83f93ff335"}
45+
```
46+
5. Copy value between double quotes and go to monitoring dashboard. Set `github` service and expand instance list, CTRL+F and paste copied value. Choose your instance
47+
48+
<img width="398" alt="image" src="https://user-images.githubusercontent.com/25527604/186348770-c4d88867-5656-4733-bf8a-84cf2c2a638c.png">
49+
50+
**Note:** label consists of two part - `${GITHUB_RUN_ID}-${HOSTNAME}`. Use only one part to find all jobs of your Run.
51+
52+
# Available workflows
53+
54+
| Workflow name | What it's supposed to do | What it triggers on |
55+
| --- | --- | --- |
56+
| UTBot Java: build and run tests | Builds the project and runs tests for it | **push** or **pull request** to the **main** branch |
57+
| [M] UTBot Java: build and run tests | Builds the project and runs tests for it | **manual** call or call from **another workflow** |
58+
| [M] Run chosen tests | Runs a single test or tests in chosen package/class | **manual** call |
59+
| Plugin and CLI: publish as archives | Archives plugin and CLI and stores them attached to the workflow run report | **push** to the **main** branch |
60+
| [M] Plugin and CLI: publish as archives | Archives plugin and CLI and stores them attached to the workflow run report | **manual** call or call from **another workflow** |
61+
| [M] Publish on GitHub Packages | Publishes artifacts such as _utbot-api_, _utbot-core_, _utbot-framework_, etc., on GitHub Packages | **manual** call |

docs/ci/docker-for-utbot-java.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<!---
2+
name: Docker for UTBot Java
3+
route: /docs/java/ci/docker-for-utbot-java
4+
parent: Documentation
5+
menu: CI
6+
description: Setting up docker for UTBot Java building/debugging
7+
--->
8+
9+
# Reproducible environment
10+
11+
It's available to download docker image with the environment for UTBot. The environment is also used in the crucial CI scripts focused on building project and running tests.
12+
13+
The docker image pre-installed environment includes:
14+
1. *Java 11* + *JDK* package
15+
3. *Gradle 7.4.2*
16+
3. *Kotlin compiler 1.7.10*
17+
18+
It's based on Ubuntu [SOME VERSION].
19+
20+
## How to install Docker
21+
22+
Using reproducible environment requires Docker installed.
23+
24+
The detailed information of how to install Docker can be found on the [official site](https://docs.docker.com/engine/install/).
25+
26+
## How to run tests in docker container
27+
28+
Do the following steps to run tests in docker container:
29+
30+
1. Pull docker image
31+
```
32+
docker pull unittestbot/java-env:java11-zulu-jdk-gradle7.4.2-kotlinc1.7.0
33+
```
34+
2. Run docker container
35+
```bash
36+
# -v <utbot-repository-root>:/usr/utbot-debug - mounts the host directory into the container directory
37+
# -it - make the container look like a terminal connection session
38+
# -w /usr/utbot-tests - sets up working directory inside the container
39+
docker run -it -v <utbot-repository-root>:/usr/utbot-tests --name utbot-tests -w /usr/utbot-tests unittestbot/java-env:java11-zulu-jdk-fx-gradle7.4.2-kotlinc1.7.0
40+
```
41+
3. Do whatever you want
42+
43+
* Build UTBot and run tests:
44+
```
45+
gradle clean build --no-daemon
46+
```
47+
* Build UTBot without running tests:
48+
```
49+
gradle clean build --no-daemon -x test
50+
```
51+
* Run tests for *utbot-framework* project *CustomerExamplesTest* class:
52+
```
53+
gradle :utbot-framework:test --no-daemon --tests "org.utbot.examples.collections.CustomerExamplesTest"
54+
```
55+
4. Exit container
56+
```
57+
exit
58+
```
59+
60+
## How to debug UTBot in docker container
61+
62+
Do the following steps to debug UTBot in docker container:
63+
64+
1. Set up configuration for remote debug in IntelliJ IDEA
65+
66+
**Run/Debug Configurations****Add New Configuration** → Choose **Remote JVM Debug** → Set up **Configuration name****Ok**
67+
68+
2. Pull docker image
69+
```
70+
docker pull unittestbot/java-env:java11-zulu-jdk-fx-gradle7.4.2-kotlinc1.7.0
71+
```
72+
3. Run docker container
73+
```bash
74+
# -v <utbot-repository-root>:/usr/utbot-debug - mounts the host directory into the container directory
75+
# -it - make the container look like a terminal connection session
76+
# -w /usr/utbot-tests - sets up working directory inside the container
77+
# -p 5005:5005 - mounts the host port into the container port (debugging port)
78+
docker run -it -p 5005:5005 -v <utbot-repository-root>:/usr/utbot-debug --name utbot-debug -w /usr/utbot-tests unittestbot/java-env:java11-zulu-jdk-fx-gradle7.4.2-kotlinc1.7.0
79+
```
80+
4. Set up gradle options for remote debug:
81+
```
82+
export GRADLE_OPTS=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005
83+
```
84+
5. Start building and running tests
85+
```
86+
gradle clean build --no-daemon
87+
```
88+
6. Attach in IntelliJ IDEA to the gradle process in the container
89+
90+
Set up **breakpoints** wherever you want → **Run** new **Configuration** in **Debug** mode
91+
92+
7. Exit container
93+
```
94+
exit
95+
```
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!---
2+
name: SSH session with GitHub agent
3+
route: /docs/java/ci/ssh-session-with-github-agent
4+
parent: Documentation
5+
menu: CI
6+
description: How to setup SSH session with GitHub agent
7+
--->
8+
9+
# SSH session with GitHub agent
10+
11+
It's available to use **action** letting set up SSH session with GitHub agent in your **workflows**. The detailed documentation with the examples of use can be found in the [official repository](https://github.com/mxschmitt/action-tmate).
12+
13+
The action setting SSH session can be easily plugged in your workflow with the example below:
14+
```
15+
- name: Setup tmate session
16+
uses: mxschmitt/action-tmate@v3
17+
```
18+
19+
When the action is plugged in the workflow log (the part corresponding to tmate action log) can be found the URL. By the URL you can access the terminal of your host.
20+
21+
There are also some ways to setup action behavior. E.g., the default behavior of the action is to remain SSH session open until the workflow times out. It's available to setup timeout parameter yourself.
File renamed without changes.
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Interprocess debugging of UnitTestBot Java
2+
3+
### Background
4+
5+
We have split the UnitTestBot machinery into three processes. This approach has improved UnitTestBot capabilities, e.g.
6+
provided support for various JVMs and scenarios, but also complicated the debugging flow.
7+
8+
These are UnitTestBot processes (according to the execution order):
9+
10+
* IDE process
11+
* Engine process
12+
* Concrete execution process
13+
14+
Usually, main problems happen in the Engine process, but it is not the process we run first.
15+
The most straightforward way to debug the Engine process is the following.
16+
17+
### Enable debugging for the Engine process
18+
19+
1. Open `org/utbot/framework/UtSettings.kt`.
20+
2. Set `runIdeaProcessWithDebug` property to _true_. This enables `EngineProcess.debugArgument`.
21+
3. Find `EngineProcess.debugArgument` at `org/utbot/intellij/plugin/process/EngineProcess` and check the parameters of the debug run:
22+
23+
`"-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,quiet=y,address=5005"`
24+
25+
* The `suspend` mode is enabled. Modify it in the case of some tricky timeouts in your scenario.
26+
* The port that will be used for debugging (`address`) is set to `5005`. Modify it if the port is already in use on your system.
27+
28+
### Create a new run configuration for debugging the Engine process
29+
30+
In addition to the `runIde` Gradle task that is supposed to run a new IDE instance, we should create another run
31+
configuration.
32+
33+
1. In your IntelliJ IDEA go to **Ru**n > **Edit configurations…**.
34+
2. In the **Run/Debug Configuration** dialog, click **`+`** on the toolbar.
35+
3. In the **Run/Debug Configuration Templates** dialog that opens, select a **Remote JVM Debug** configuration type.
36+
4. Check that **Port** has the same number as the `address` parameter from the `EngineProcess.debugArgument` mentioned above.
37+
5. Give the new run configuration a meaningful name and save the run configuration.
38+
39+
### How to debug
40+
41+
1. In your current IntelliJ IDEA, use breakpoints to define where the program needs to be stopped. For example, set the breakpoints at
42+
43+
`EngineProcess.createTestGenerator()`<br>
44+
`engineModel().createTestGenerator.startSuspending()`
45+
46+
2. Start the debugger session (**Shift+F9**) for the `runIde` Gradle task (wait for the debug IDE instance to open).
47+
3. Generate tests with UnitTestBot in the debug IDE instance. Make sure symbolic execution is turned on.
48+
4. The debug IDE instance will stop generation (if you have not changed the debug parameters). If you take no action, test generation will be cancelled by timeout.
49+
5. When the Engine process started (build processes have finished, and the progress bar says: _"Generate tests: read
50+
classes"_), start the debugger session (**Shift+F9**) for your newly created Remote JVM Debug run configuration.
51+
6. Wait for the program to be suspended upon reaching the first breakpoint.
52+
53+
### Interprocess call mapping
54+
55+
Now you are standing on a breakpoint in the IDE process, for example, the process stopped on:
56+
57+
`EngineProcess.createTestGenerator()`
58+
59+
If you resume the process it reaches the next breakpoint (you are still in the IDE process):
60+
61+
`engineModel().createTestGenerator.startSuspending()`
62+
63+
It seems that the test generation itself should occur in the Engine process and there should be an outbound point of the IDE process. How can we find it? An how can we reach the inbound point of the Engine process?
64+
65+
Standing on the breakpoint` engineModel().createTestGenerator.startSuspending()`, you may **Go to Declaration or
66+
Usage** and navigate to the definition of `RdCall` (which is responsible for cross-process communication) in `EngineProcessModel.createTestGenerator`.
67+
68+
Now **Find Usages** for `EngineProcessModel.createTestGenerator` and see the point where `RdCall` is passed to the next method:
69+
70+
synchronizer.measureExecutionForTermination()
71+
72+
This is the point where `RdCall` is called in the Engine process.
73+
74+
Actually you could have skipped the previous step and used **Find Usages** right away, but it is useful to know where `RdCall` is defined.
75+
76+
If you are interested in the trailing lambda of `synchronizer.measureExecutionForTermination()`, set the breakpoint here.
77+
78+
#### Architectural notice
79+
80+
We must place the outbound point of the IDE process and the inbound point of the Engine process as close as possible.
81+
They may be two lambda-parameters of the same function. In this case we hope that the developer will not spend time on straying around.
82+

0 commit comments

Comments
 (0)