Skip to content

Rework the Greentea docs #927

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 26, 2019

Conversation

janjongboom
Copy link
Contributor

@iriark01 @ARMmbed/mbed-docs As per our discussion on e-mail.

This PR:

  • Consolidates the two Greentea documents that we had in the tests directory.
  • Updates all commands to use mbed test instead of the mbedgt command.
  • Adds examples on how to run the tests.
  • Adds host test runner documentation.

…amples, move everything into a single document
Copy link
Contributor

@theotherjimmy theotherjimmy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please prefer to use Mbed CLI over the tools shipped with dependent packages.


#### Writing tests
![Exporting to Make](https://s3-us-west-2.amazonaws.com/mbed-os-docs-images/test01.png)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should promote working with Mbed CLI within it's own documentation where possible. Either this is titled incorrectly, or it should be removed (I can't see the image content)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I think I copied something wrong there. The description just shows the tree structure, nothing to do with make. My bad :-)


Where `02400203C3423E603EBEC3D8` and `024002031E031E6AE3FFE3D` are the target IDs of platforms attached to your system.

You can view target IDs using the [`mbed-ls`](https://github.com/ARMmbed/mbed-os-tools/tree/master/packages/mbed-ls) tool (installed with Greentea).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use mbed detect instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated. Copied it from old content but missed this.

Copy link
Contributor

@bridadan bridadan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like the format you've put forward here, I think it's definitely an improvement.

The CLI for mbed test is at best described as "finicky", I'm actively working to make it better. I've commented on some of the commands below and some issues I foresee.


The Greentea tool handles the actual testing process. To read more about this tool, please visit its [GitHub repository](https://github.com/ARMmbed/mbed-os-tools/tree/master/packages/mbed-greentea).
As specified above, there is a convention where all tests live in the `TESTS/` directory. In the `first-greentea-test` folder create a folder `TESTS/tests/simple-test/`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest the following example folder structure since the example kind of looks like a duplication (double "tests" folders):

Suggested change
As specified above, there is a convention where all tests live in the `TESTS/` directory. In the `first-greentea-test` folder create a folder `TESTS/tests/simple-test/`.
As specified above, there is a convention where all tests live in the `TESTS/` directory. In the `first-greentea-test` folder create a folder `TESTS/test-group/simple-test/`.


#### Writing tests
![Tree structure for Greentea tests](https://s3-us-west-2.amazonaws.com/mbed-os-docs-images/test01.png)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we usually host these on s3? Perhaps just using an text representation of the structure would be easier. Ex:

project/
    TESTS/
        test-group/
            simple-test/
                main.cpp

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the image is in this pr, but not uploaded to s3 yet. @bridadan Good suggestion, I'll update it to use that.

void test_success() {
TEST_ASSERT(true);
}
// this is how a test looks
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: differentiate between "test" with "test case"

Suggested change
// this is how a test looks
// this is how a test case looks

GREENTEA_SETUP(40, "default_auto");
return verbose_test_setup_handler(number_of_cases);
utest::v1::status_t greentea_setup(const size_t number_of_cases) {
// here we specify the timeout (60s) and the host runner (the name of our Python file)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: default_auto is currently provided by htrun, not by a python file within mbed-os.

Suggested change
// here we specify the timeout (60s) and the host runner (the name of our Python file)
// here we specify the timeout (60s) and the host test (a built-in host test or the name of our Python file)

return verbose_test_setup_handler(number_of_cases);
utest::v1::status_t greentea_setup(const size_t number_of_cases) {
// here we specify the timeout (60s) and the host runner (the name of our Python file)
GREENTEA_SETUP(1*60, "default_auto");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Ok to drop the multiplication here?

Suggested change
GREENTEA_SETUP(1*60, "default_auto");
GREENTEA_SETUP(60, "default_auto");

$ mbed test -n tests-mbedmicro-rtos-mbed-mail
```

When using the `-n` argument, you can use the `*` character at the end of a test name to match all tests that share a prefix. This command executes all tests that start with `tests-mbedmicro-rtos`:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will now use "globbing" rules, so you can actually sprinkle the * characters any where you like.

You can limit which boards Greentea uses for testing by using the `--use-tids` argument.

```
$ mbed test --use-tids 02400203C3423E603EBEC3D8,024002031E031E6AE3FFE3D2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will currently error unless you add --run.

|K64F |K64F[0] |E: |COM160 |024002031E031E6AE3FFE3D2 |
|K64F |K64F[1] |F: |COM162 |02400203C3423E603EBEC3D8 |
|LPC1768 |LPC1768[0] |G: |COM5 |1010ac87cfc4f23c4c57438d |
+--------------+---------------------+------------+------------+-------------------------+
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If your current working directly is within an Mbed OS project, the output of mbed detect looks like this:

mbed detect
[mbed] Working path "C:\Users\bridan01\onedrive_arm\Documents\dev\mbed-os" (program)

[mbed] Detected K64F, port COM79, mounted F:, interface version 0250:
[mbed] Supported toolchains for K64F
| Target        | mbed OS 2 | mbed OS 5 | uARM |    IAR    |    ARM    |  GCC_ARM  |
|---------------|-----------|-----------|------|-----------|-----------|-----------|
| K64F          | Supported | Supported |  -   | Supported | Supported | Supported |
| RAPIDIOT_K64F | Supported | Supported |  -   | Supported | Supported | Supported |
Supported targets: 2


[mbed] Detected K64F, port COM78, mounted D:, interface version 0251:
[mbed] Supported toolchains for K64F
| Target        | mbed OS 2 | mbed OS 5 | uARM |    IAR    |    ARM    |  GCC_ARM  |
|---------------|-----------|-----------|------|-----------|-----------|-----------|
| K64F          | Supported | Supported |  -   | Supported | Supported | Supported |
| RAPIDIOT_K64F | Supported | Supported |  -   | Supported | Supported | Supported |
Supported targets: 2

Which unfortunately does not list the target id. mbedls will but I know we want to direct folks to use Mbed CLI commands. In this case I don't think we have many options here, any ideas @theotherjimmy?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, huh. Not only does mbed detect omit the information, it also neglects to use unique names. I suppose we'll have to use mbedls until we fix this in mbed detect.

This creates a human-friendly text summary of the test run.

```
mbed test --report-text text_report.text
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of these report commands would need the --run command added first, otherwise it would throw an exception:

$ mbed test -n tests-mbed_functional-callback -v --report-json report.json
[mbed] Working path "C:\Users\bridan01\onedrive_arm\Documents\dev\mbed-os" (program)
[mbed] Exec "c:\python27\python.exe -u C:\Users\bridan01\onedrive_arm\Documents\dev\mbed-os\tools\test.py -t GCC_ARM -m K64F --source . --build .\BUILD\tests\K64F\GCC_ARM --test-spec .\BUILD\tests\K64F\GCC_ARM\test_spec.json --build-data .\BUILD\tests\K64F\GCC_ARM\build_data.json -n tests-mbed_functional-callback -v --greentea --report-json report.json" in "C:\Users\bridan01\onedrive_arm\Documents\dev\mbed-os"
usage: test.py [-h] [-m MCU] [--custom-targets CUSTOM_TARGETS_DIRECTORY]
               [-t TOOLCHAIN] [--color] [--cflags CFLAGS]
               [--asmflags ASMFLAGS] [--ldflags LDFLAGS] [-c]
               [--profile PROFILE] [--app-config APP_CONFIG] [-D MACROS]
               [-j JOBS] [--source SOURCE_DIR] [--build BUILD_DIR] [-l]
               [-p PATHS] [-f FORMAT] [--continue-on-build-fail] [-n NAMES]
               [--test-config TEST_CONFIG] [--test-spec TEST_SPEC]
               [--build-report-junit BUILD_REPORT_JUNIT]
               [--build-data BUILD_DATA] [-v] [--stats-depth STATS_DEPTH]
               [--ignore IGNORE] [--icetea] [--greentea]
test.py: error: unrecognized arguments: --report-json report.json
[mbed] ERROR: "c:\python27\python.exe" returned error.
       Code: 2
       Path: "C:\Users\bridan01\onedrive_arm\Documents\dev\mbed-os"
       Command: "c:\python27\python.exe -u C:\Users\bridan01\onedrive_arm\Documents\dev\mbed-os\tools\test.py -t GCC_ARM -m K64F --source . --build .\BUILD\tests\K64F\GCC_ARM --test-spec .\BUILD\tests\K64F\GCC_ARM\test_spec.json --build-data .\BUILD\tests\K64F\GCC_ARM\build_data.json -n tests-mbed_functional-callback -v --greentea --report-json report.json"
       Tip: You could retry the last command with "-v" flag for verbose output
---

}
```

If you now run `mbed test -l` this will now list only these tests:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You want to use the --run-list option here as well.

Suggested change
If you now run `mbed test -l` this will now list only these tests:
If you now run `mbed test --run-list` this will now list only these tests:


#### Writing tests
![Tree structure for Greentea tests](https://s3-us-west-2.amazonaws.com/mbed-os-docs-images/test01.png)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -1,6 +1,10 @@
## Greentea testing applications

The way tests are run and compiled in Arm Mbed OS 5 is substantially different from previous versions of Mbed.
Greentea is the automated testing tool for Arm Mbed OS development. It's a test runner that automates the process of flashing development boards, starting tests, and accumulating test results into test reports. Developers use it for local development as well as for automation in a Continuous Integration environment.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there some reason to use capital first letters for "Continous Integration"?

}

// Test cases
// list of all cases
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is listing test cases which are contained in this file and there are multiple files. "all" sounds me a bit more than one file tests

@janjongboom
Copy link
Contributor Author

@bridadan @OPpuolitaival @ARMmbed/mbed-docs Updated based on feedback.

Copy link
Contributor

@bridadan bridadan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely looking really good, thanks for making those changes. Just a few more comments below.

This creates a human-friendly text summary of the test run.

```
mbed test --report-text text_report.text --run
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about this more, none of the report arguments are currently part of the help options in Mbed CLI. This only works because Mbed CLI passes along arguments to the underlying scripts when it doesn't recognize it. How do you feel about removing this reporting section altogether?

You can limit which boards Greentea uses for testing by using the `--use-tids` argument.

```
$ mbed test --use-tids 02400203C3423E603EBEC3D8,024002031E031E6AE3FFE3D2 --run
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing that I mentioned below about the reporting section, this isn't in the mbed test --help text. How do you feel about removing this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, isn't it great that our docs are more complete than our CLI?


utest::v1::status_t greentea_setup(const size_t number_of_cases) {
// here we specify the timeout (60s) and the host runner (the name of our Python file)
GREENTEA_SETUP(1*60, "hello_world_tests");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One other 1*60 that can be removed

Copy link
Contributor

@OPpuolitaival OPpuolitaival left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@janjongboom
Copy link
Contributor Author

@bridadan @ARMmbed/mbed-docs Is this good to go now?

@janjongboom
Copy link
Contributor Author

@ARMmbed/mbed-docs Ping.

Edit file, mostly for consistent person and voice across docs.
$ mbed test -t GCC_ARM -m auto -v -n tests-test-group-simple-test
```

This yields (on a K64F):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please use a different board for our examples?

@janjongboom
Copy link
Contributor Author

@AnotherButler Fixed

@AnotherButler
Copy link
Contributor

@theotherjimmy Have your concerns been addressed?

@janjongboom
Copy link
Contributor Author

@theotherjimmy @ARMmbed/mbed-docs ping again.

@janjongboom janjongboom dismissed theotherjimmy’s stale review February 26, 2019 08:45

Addressed in comments.

@janjongboom
Copy link
Contributor Author

@AnotherButler @ARMmbed/mbed-docs Who can merge this?

@AnotherButler
Copy link
Contributor

@theotherjimmy I'm going to merge this today or tomorrow. If you have any further concerns, please create a new PR.

@AnotherButler AnotherButler merged commit 25600c9 into ARMmbed:development Feb 26, 2019
@janjongboom
Copy link
Contributor Author

@AnotherButler @ARMmbed/mbed-docs When will this be available?

@iriark01
Copy link
Contributor

iriark01 commented Mar 7, 2019

5.12 at the end of the month

AnotherButler pushed a commit that referenced this pull request Mar 8, 2019
Apply changes from PR #927 to 5.11.
AnotherButler pushed a commit that referenced this pull request Mar 8, 2019
Apply changes from PR #927 to 5.11.
@AnotherButler
Copy link
Contributor

I just applied your changes to 5.11. Let me know if they haven't built by tomorrow.

@janjongboom
Copy link
Contributor Author

@AnotherButler Awesome, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants