mbed-os / features / frameworks / greentea-client /
@Jamie Smith Jamie Smith authored on 29 May 2022
Jay Sridharan committed on 14 Sep 2022
..
greentea-client greentea: Add missing license header 2 years ago
source CMake: greentea: Fix io issue with greentea-client 2 years ago
CMakeLists.txt Only support GCC ARM compiler, but reap the benefits of static libraries instead of objects 1 year ago
README.md Use standalone greentea-client 3 years ago
mbed_lib.json Add placeholder libraries for things we probably refer to as libraries 5 years ago
README.md

Table of contents

greentea-client

Note: This copy of greentea-client is used only with Mbed CLI 1. Mbed CLI 2 will use the standalone greentea-client, automatically fetched by CMake in the extern/ directory.

greentea-client is a client library for the Greentea test tool when used in an Mbed OS project.

This package implements the client side of the key-value protocol used for communication between the device under test (DUT) and the host. The Greentea tool implements the protocol's host behavior. We use utest as our test harness.

      DUT  <--- serial port connection --->  host
    (client)         .                       (host)
                    .
[greentea-client]   .       [conn_process]               [htrun]
     =====          .      ================             =========
       |            .             |                         |
       |            .             |                         |
       |    {{ key ; value }}     |                         |
       |------------------------->| (key, value, timestamp) |
       |            .             |------------------------>|
       |            .             |                         |
       |            .             |                         |
       |            .             |                         |
       |            .             |                         |
       |            .             |                         |
       |            .             | (key, value, timestamp) |
       |    {{ key ; value }}     |<------------------------|
       |<-------------------------|                         |
       |            .             |                         |
                    .

Concepts

Test suite

A test suite is a binary containing test cases we execute on hardware. The test suite has a beginning and an end (like the main() function would. The test suite may pass, fail or be in an error state (for example, if the test suite times out or there was a serial port connection problem).

Test case

A test case is contained within a test suite. You can have multiple test cases within a test suite. unity assert macros are used to run the checks during the test case. Your test cases may pass, fail or be in an error state.

Key-value protocol

The key-value protocol is a protocol specific to the Greentea test tool. It is used to send messages (events) between the DUT and the host. Each message consists of a key and value pair. A message is surrounded by double curly braces. The key and value are separated by a semicolon (;).

For example, the {{timeout;120}}} string is a key-value message where the key timeout has the value 120. Both greentea-client and Greentea understand this format and can detect key-value messages in a data stream.

Test example

#include "mbed.h"
#include "greentea-client/test_env.h"
#include "utest/utest.h"
#include "unity/unity.h"

void test_case_1_func() {
    // Test case #1 body
    // Here you can run your test cases and assertions
    TEST_ASSERT_TRUE(true);
    TEST_ASSERT_FALSE(false);
}

void test_case_2_func() {
    // Test case #2 body
    // Here you can run your test cases and assertions
    TEST_ASSERT_TRUE(true);
    TEST_ASSERT_FALSE(false);
}

const Case cases[] = {
    Case("Test case #1 name", test_case_1_func),
    Case("Test case #1 name", test_case_2_func)
};

status_t greentea_setup(const size_t number_of_cases) {
    GREENTEA_SETUP(5, "default_auto");
    return greentea_test_setup_handler(number_of_cases);
}

void main(int, char*[]) {
    Harness::run(specification);
}