mbed-os/features/frameworks/greentea-client
Dustin Crossman c70baa9289 Fix kv parsing bug in greentea client.
Mbed greentea sends all KV pairs in the following format:
"{{key,value}}\n"
Previously the greentea client code was not reading the final '\n' from
the UART as part of the HandleKV() call. This did not cause an
error when multiple KV pairs were being parsed because any whitespace
proceeding a message was ignored. Once the final KV pair was sent,
however, HandleKV() would only read up to the "}}" leaving the final
'\n' in the UART buffer.
2020-07-01 10:38:49 -07:00
..
greentea-client Replace RawSerial instances as it has been deprecated 2020-01-06 15:48:49 +00:00
source Fix kv parsing bug in greentea client. 2020-07-01 10:38:49 -07:00
README.md Correct example given in greentea-client readme 2019-01-28 16:35:34 -06:00
mbed_lib.json Add placeholder libraries for things we probably refer to as libraries 2019-01-16 14:58:58 -06:00

README.md

Table of contents

greentea-client

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);
}