mbed-os/TESTS/mbedmicro-mbed/cpp/main.cpp

106 lines
2.2 KiB
C++
Raw Normal View History

2017-08-07 17:02:33 +00:00
/* mbed Microcontroller Library
* Copyright (c) 2017 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Adding test frameworks and test sources This commit adds the following test frameworks: - `greentea-client` (https://github.com/ARMmbed/greentea-client) - This framework provides a key-value api for communicating with the greentea test tool (https://github.com/ARMmbed/greentea) - `unity` (https://github.com/ARMmbed/unity) - This framework provides test assert macros that can be used when writing test cases - `utest` (https://github.com/ARMmbed/utest) - This framework allows you to execute a series of test cases with reporting that works with the greentea test tool (https://github.com/ARMmbed/greentea) The following changes were made when bringing these frameworks into the tree: - References to `mbed_drivers/mbed.h` within utest's tests were migrated to `mbed.h` - The yotta file `module.json` was removed from `greentea-client` and `unity` - `coverage.json` was also removed from `greentea-client` - `.gitignore` and `.gitattributes` were removed from `greentea-client` - Apache 2.0 license files were removed from `greentea-client` This also brings in a number of tests that have been newly written or ported from various sources: - `TESTS/integration` - Very basic tests, used to check if testing frameworks are working correctly - `TESTS/mbed_drivers` (Thanks @PrzemekWirkus!) - TESTS ported from mbed OS 3.0 (https://github.com/ARMmbed/mbed-drivers) - `TESTS/mbedmicro-mbed` (Thanks @PrzemekWirkus!) - Tests that weren't covered by `TESTS/mbed_drivers` that currently live in `libraries/tests/mbed` - `TESTS/mbedmicro-rtos-mbed` (Thanks @PrzemekWirkus!) - Ported tests that currently live in `libraries/tests/rtos/mbed` - `TESTS/storage_abstraction` (Thanks @rgrover!) - Tests for the storage_abstraction hal
2016-07-19 18:39:53 +00:00
#include "greentea-client/test_env.h"
#define PATTERN_CHECK_VALUE 0xF0F0ADAD
class Test {
private:
const char *name;
Adding test frameworks and test sources This commit adds the following test frameworks: - `greentea-client` (https://github.com/ARMmbed/greentea-client) - This framework provides a key-value api for communicating with the greentea test tool (https://github.com/ARMmbed/greentea) - `unity` (https://github.com/ARMmbed/unity) - This framework provides test assert macros that can be used when writing test cases - `utest` (https://github.com/ARMmbed/utest) - This framework allows you to execute a series of test cases with reporting that works with the greentea test tool (https://github.com/ARMmbed/greentea) The following changes were made when bringing these frameworks into the tree: - References to `mbed_drivers/mbed.h` within utest's tests were migrated to `mbed.h` - The yotta file `module.json` was removed from `greentea-client` and `unity` - `coverage.json` was also removed from `greentea-client` - `.gitignore` and `.gitattributes` were removed from `greentea-client` - Apache 2.0 license files were removed from `greentea-client` This also brings in a number of tests that have been newly written or ported from various sources: - `TESTS/integration` - Very basic tests, used to check if testing frameworks are working correctly - `TESTS/mbed_drivers` (Thanks @PrzemekWirkus!) - TESTS ported from mbed OS 3.0 (https://github.com/ARMmbed/mbed-drivers) - `TESTS/mbedmicro-mbed` (Thanks @PrzemekWirkus!) - Tests that weren't covered by `TESTS/mbed_drivers` that currently live in `libraries/tests/mbed` - `TESTS/mbedmicro-rtos-mbed` (Thanks @PrzemekWirkus!) - Ported tests that currently live in `libraries/tests/rtos/mbed` - `TESTS/storage_abstraction` (Thanks @rgrover!) - Tests for the storage_abstraction hal
2016-07-19 18:39:53 +00:00
const int pattern;
public:
Test(const char *_name, bool print_message = true) : name(_name), pattern(PATTERN_CHECK_VALUE)
{
if (print_message) {
print("init");
}
Adding test frameworks and test sources This commit adds the following test frameworks: - `greentea-client` (https://github.com/ARMmbed/greentea-client) - This framework provides a key-value api for communicating with the greentea test tool (https://github.com/ARMmbed/greentea) - `unity` (https://github.com/ARMmbed/unity) - This framework provides test assert macros that can be used when writing test cases - `utest` (https://github.com/ARMmbed/utest) - This framework allows you to execute a series of test cases with reporting that works with the greentea test tool (https://github.com/ARMmbed/greentea) The following changes were made when bringing these frameworks into the tree: - References to `mbed_drivers/mbed.h` within utest's tests were migrated to `mbed.h` - The yotta file `module.json` was removed from `greentea-client` and `unity` - `coverage.json` was also removed from `greentea-client` - `.gitignore` and `.gitattributes` were removed from `greentea-client` - Apache 2.0 license files were removed from `greentea-client` This also brings in a number of tests that have been newly written or ported from various sources: - `TESTS/integration` - Very basic tests, used to check if testing frameworks are working correctly - `TESTS/mbed_drivers` (Thanks @PrzemekWirkus!) - TESTS ported from mbed OS 3.0 (https://github.com/ARMmbed/mbed-drivers) - `TESTS/mbedmicro-mbed` (Thanks @PrzemekWirkus!) - Tests that weren't covered by `TESTS/mbed_drivers` that currently live in `libraries/tests/mbed` - `TESTS/mbedmicro-rtos-mbed` (Thanks @PrzemekWirkus!) - Ported tests that currently live in `libraries/tests/rtos/mbed` - `TESTS/storage_abstraction` (Thanks @rgrover!) - Tests for the storage_abstraction hal
2016-07-19 18:39:53 +00:00
}
void print(const char *message)
{
Adding test frameworks and test sources This commit adds the following test frameworks: - `greentea-client` (https://github.com/ARMmbed/greentea-client) - This framework provides a key-value api for communicating with the greentea test tool (https://github.com/ARMmbed/greentea) - `unity` (https://github.com/ARMmbed/unity) - This framework provides test assert macros that can be used when writing test cases - `utest` (https://github.com/ARMmbed/utest) - This framework allows you to execute a series of test cases with reporting that works with the greentea test tool (https://github.com/ARMmbed/greentea) The following changes were made when bringing these frameworks into the tree: - References to `mbed_drivers/mbed.h` within utest's tests were migrated to `mbed.h` - The yotta file `module.json` was removed from `greentea-client` and `unity` - `coverage.json` was also removed from `greentea-client` - `.gitignore` and `.gitattributes` were removed from `greentea-client` - Apache 2.0 license files were removed from `greentea-client` This also brings in a number of tests that have been newly written or ported from various sources: - `TESTS/integration` - Very basic tests, used to check if testing frameworks are working correctly - `TESTS/mbed_drivers` (Thanks @PrzemekWirkus!) - TESTS ported from mbed OS 3.0 (https://github.com/ARMmbed/mbed-drivers) - `TESTS/mbedmicro-mbed` (Thanks @PrzemekWirkus!) - Tests that weren't covered by `TESTS/mbed_drivers` that currently live in `libraries/tests/mbed` - `TESTS/mbedmicro-rtos-mbed` (Thanks @PrzemekWirkus!) - Ported tests that currently live in `libraries/tests/rtos/mbed` - `TESTS/storage_abstraction` (Thanks @rgrover!) - Tests for the storage_abstraction hal
2016-07-19 18:39:53 +00:00
printf("%s::%s\n", name, message);
}
bool check_init(void)
{
Adding test frameworks and test sources This commit adds the following test frameworks: - `greentea-client` (https://github.com/ARMmbed/greentea-client) - This framework provides a key-value api for communicating with the greentea test tool (https://github.com/ARMmbed/greentea) - `unity` (https://github.com/ARMmbed/unity) - This framework provides test assert macros that can be used when writing test cases - `utest` (https://github.com/ARMmbed/utest) - This framework allows you to execute a series of test cases with reporting that works with the greentea test tool (https://github.com/ARMmbed/greentea) The following changes were made when bringing these frameworks into the tree: - References to `mbed_drivers/mbed.h` within utest's tests were migrated to `mbed.h` - The yotta file `module.json` was removed from `greentea-client` and `unity` - `coverage.json` was also removed from `greentea-client` - `.gitignore` and `.gitattributes` were removed from `greentea-client` - Apache 2.0 license files were removed from `greentea-client` This also brings in a number of tests that have been newly written or ported from various sources: - `TESTS/integration` - Very basic tests, used to check if testing frameworks are working correctly - `TESTS/mbed_drivers` (Thanks @PrzemekWirkus!) - TESTS ported from mbed OS 3.0 (https://github.com/ARMmbed/mbed-drivers) - `TESTS/mbedmicro-mbed` (Thanks @PrzemekWirkus!) - Tests that weren't covered by `TESTS/mbed_drivers` that currently live in `libraries/tests/mbed` - `TESTS/mbedmicro-rtos-mbed` (Thanks @PrzemekWirkus!) - Ported tests that currently live in `libraries/tests/rtos/mbed` - `TESTS/storage_abstraction` (Thanks @rgrover!) - Tests for the storage_abstraction hal
2016-07-19 18:39:53 +00:00
bool result = (pattern == PATTERN_CHECK_VALUE);
print(result ? "check_init: OK" : "check_init: ERROR");
return result;
}
void stack_test(void)
{
Adding test frameworks and test sources This commit adds the following test frameworks: - `greentea-client` (https://github.com/ARMmbed/greentea-client) - This framework provides a key-value api for communicating with the greentea test tool (https://github.com/ARMmbed/greentea) - `unity` (https://github.com/ARMmbed/unity) - This framework provides test assert macros that can be used when writing test cases - `utest` (https://github.com/ARMmbed/utest) - This framework allows you to execute a series of test cases with reporting that works with the greentea test tool (https://github.com/ARMmbed/greentea) The following changes were made when bringing these frameworks into the tree: - References to `mbed_drivers/mbed.h` within utest's tests were migrated to `mbed.h` - The yotta file `module.json` was removed from `greentea-client` and `unity` - `coverage.json` was also removed from `greentea-client` - `.gitignore` and `.gitattributes` were removed from `greentea-client` - Apache 2.0 license files were removed from `greentea-client` This also brings in a number of tests that have been newly written or ported from various sources: - `TESTS/integration` - Very basic tests, used to check if testing frameworks are working correctly - `TESTS/mbed_drivers` (Thanks @PrzemekWirkus!) - TESTS ported from mbed OS 3.0 (https://github.com/ARMmbed/mbed-drivers) - `TESTS/mbedmicro-mbed` (Thanks @PrzemekWirkus!) - Tests that weren't covered by `TESTS/mbed_drivers` that currently live in `libraries/tests/mbed` - `TESTS/mbedmicro-rtos-mbed` (Thanks @PrzemekWirkus!) - Ported tests that currently live in `libraries/tests/rtos/mbed` - `TESTS/storage_abstraction` (Thanks @rgrover!) - Tests for the storage_abstraction hal
2016-07-19 18:39:53 +00:00
print("stack_test");
Test t("Stack");
t.hello();
}
void hello(void)
{
Adding test frameworks and test sources This commit adds the following test frameworks: - `greentea-client` (https://github.com/ARMmbed/greentea-client) - This framework provides a key-value api for communicating with the greentea test tool (https://github.com/ARMmbed/greentea) - `unity` (https://github.com/ARMmbed/unity) - This framework provides test assert macros that can be used when writing test cases - `utest` (https://github.com/ARMmbed/utest) - This framework allows you to execute a series of test cases with reporting that works with the greentea test tool (https://github.com/ARMmbed/greentea) The following changes were made when bringing these frameworks into the tree: - References to `mbed_drivers/mbed.h` within utest's tests were migrated to `mbed.h` - The yotta file `module.json` was removed from `greentea-client` and `unity` - `coverage.json` was also removed from `greentea-client` - `.gitignore` and `.gitattributes` were removed from `greentea-client` - Apache 2.0 license files were removed from `greentea-client` This also brings in a number of tests that have been newly written or ported from various sources: - `TESTS/integration` - Very basic tests, used to check if testing frameworks are working correctly - `TESTS/mbed_drivers` (Thanks @PrzemekWirkus!) - TESTS ported from mbed OS 3.0 (https://github.com/ARMmbed/mbed-drivers) - `TESTS/mbedmicro-mbed` (Thanks @PrzemekWirkus!) - Tests that weren't covered by `TESTS/mbed_drivers` that currently live in `libraries/tests/mbed` - `TESTS/mbedmicro-rtos-mbed` (Thanks @PrzemekWirkus!) - Ported tests that currently live in `libraries/tests/rtos/mbed` - `TESTS/storage_abstraction` (Thanks @rgrover!) - Tests for the storage_abstraction hal
2016-07-19 18:39:53 +00:00
print("hello");
}
~Test()
{
Adding test frameworks and test sources This commit adds the following test frameworks: - `greentea-client` (https://github.com/ARMmbed/greentea-client) - This framework provides a key-value api for communicating with the greentea test tool (https://github.com/ARMmbed/greentea) - `unity` (https://github.com/ARMmbed/unity) - This framework provides test assert macros that can be used when writing test cases - `utest` (https://github.com/ARMmbed/utest) - This framework allows you to execute a series of test cases with reporting that works with the greentea test tool (https://github.com/ARMmbed/greentea) The following changes were made when bringing these frameworks into the tree: - References to `mbed_drivers/mbed.h` within utest's tests were migrated to `mbed.h` - The yotta file `module.json` was removed from `greentea-client` and `unity` - `coverage.json` was also removed from `greentea-client` - `.gitignore` and `.gitattributes` were removed from `greentea-client` - Apache 2.0 license files were removed from `greentea-client` This also brings in a number of tests that have been newly written or ported from various sources: - `TESTS/integration` - Very basic tests, used to check if testing frameworks are working correctly - `TESTS/mbed_drivers` (Thanks @PrzemekWirkus!) - TESTS ported from mbed OS 3.0 (https://github.com/ARMmbed/mbed-drivers) - `TESTS/mbedmicro-mbed` (Thanks @PrzemekWirkus!) - Tests that weren't covered by `TESTS/mbed_drivers` that currently live in `libraries/tests/mbed` - `TESTS/mbedmicro-rtos-mbed` (Thanks @PrzemekWirkus!) - Ported tests that currently live in `libraries/tests/rtos/mbed` - `TESTS/storage_abstraction` (Thanks @rgrover!) - Tests for the storage_abstraction hal
2016-07-19 18:39:53 +00:00
print("destroy");
}
};
/* Check C++ startup initialisation */
Test s("Static", false);
Adding test frameworks and test sources This commit adds the following test frameworks: - `greentea-client` (https://github.com/ARMmbed/greentea-client) - This framework provides a key-value api for communicating with the greentea test tool (https://github.com/ARMmbed/greentea) - `unity` (https://github.com/ARMmbed/unity) - This framework provides test assert macros that can be used when writing test cases - `utest` (https://github.com/ARMmbed/utest) - This framework allows you to execute a series of test cases with reporting that works with the greentea test tool (https://github.com/ARMmbed/greentea) The following changes were made when bringing these frameworks into the tree: - References to `mbed_drivers/mbed.h` within utest's tests were migrated to `mbed.h` - The yotta file `module.json` was removed from `greentea-client` and `unity` - `coverage.json` was also removed from `greentea-client` - `.gitignore` and `.gitattributes` were removed from `greentea-client` - Apache 2.0 license files were removed from `greentea-client` This also brings in a number of tests that have been newly written or ported from various sources: - `TESTS/integration` - Very basic tests, used to check if testing frameworks are working correctly - `TESTS/mbed_drivers` (Thanks @PrzemekWirkus!) - TESTS ported from mbed OS 3.0 (https://github.com/ARMmbed/mbed-drivers) - `TESTS/mbedmicro-mbed` (Thanks @PrzemekWirkus!) - Tests that weren't covered by `TESTS/mbed_drivers` that currently live in `libraries/tests/mbed` - `TESTS/mbedmicro-rtos-mbed` (Thanks @PrzemekWirkus!) - Ported tests that currently live in `libraries/tests/rtos/mbed` - `TESTS/storage_abstraction` (Thanks @rgrover!) - Tests for the storage_abstraction hal
2016-07-19 18:39:53 +00:00
/* EXPECTED OUTPUT:
*******************
Static::init
Static::stack_test
Stack::init
Stack::hello
Stack::destroy
Static::check_init: OK
Heap::init
Heap::hello
Heap::destroy
*******************/
int main(void)
{
Adding test frameworks and test sources This commit adds the following test frameworks: - `greentea-client` (https://github.com/ARMmbed/greentea-client) - This framework provides a key-value api for communicating with the greentea test tool (https://github.com/ARMmbed/greentea) - `unity` (https://github.com/ARMmbed/unity) - This framework provides test assert macros that can be used when writing test cases - `utest` (https://github.com/ARMmbed/utest) - This framework allows you to execute a series of test cases with reporting that works with the greentea test tool (https://github.com/ARMmbed/greentea) The following changes were made when bringing these frameworks into the tree: - References to `mbed_drivers/mbed.h` within utest's tests were migrated to `mbed.h` - The yotta file `module.json` was removed from `greentea-client` and `unity` - `coverage.json` was also removed from `greentea-client` - `.gitignore` and `.gitattributes` were removed from `greentea-client` - Apache 2.0 license files were removed from `greentea-client` This also brings in a number of tests that have been newly written or ported from various sources: - `TESTS/integration` - Very basic tests, used to check if testing frameworks are working correctly - `TESTS/mbed_drivers` (Thanks @PrzemekWirkus!) - TESTS ported from mbed OS 3.0 (https://github.com/ARMmbed/mbed-drivers) - `TESTS/mbedmicro-mbed` (Thanks @PrzemekWirkus!) - Tests that weren't covered by `TESTS/mbed_drivers` that currently live in `libraries/tests/mbed` - `TESTS/mbedmicro-rtos-mbed` (Thanks @PrzemekWirkus!) - Ported tests that currently live in `libraries/tests/rtos/mbed` - `TESTS/storage_abstraction` (Thanks @rgrover!) - Tests for the storage_abstraction hal
2016-07-19 18:39:53 +00:00
GREENTEA_SETUP(10, "default_auto");
bool result = true;
for (;;) {
s.print("init");
Adding test frameworks and test sources This commit adds the following test frameworks: - `greentea-client` (https://github.com/ARMmbed/greentea-client) - This framework provides a key-value api for communicating with the greentea test tool (https://github.com/ARMmbed/greentea) - `unity` (https://github.com/ARMmbed/unity) - This framework provides test assert macros that can be used when writing test cases - `utest` (https://github.com/ARMmbed/utest) - This framework allows you to execute a series of test cases with reporting that works with the greentea test tool (https://github.com/ARMmbed/greentea) The following changes were made when bringing these frameworks into the tree: - References to `mbed_drivers/mbed.h` within utest's tests were migrated to `mbed.h` - The yotta file `module.json` was removed from `greentea-client` and `unity` - `coverage.json` was also removed from `greentea-client` - `.gitignore` and `.gitattributes` were removed from `greentea-client` - Apache 2.0 license files were removed from `greentea-client` This also brings in a number of tests that have been newly written or ported from various sources: - `TESTS/integration` - Very basic tests, used to check if testing frameworks are working correctly - `TESTS/mbed_drivers` (Thanks @PrzemekWirkus!) - TESTS ported from mbed OS 3.0 (https://github.com/ARMmbed/mbed-drivers) - `TESTS/mbedmicro-mbed` (Thanks @PrzemekWirkus!) - Tests that weren't covered by `TESTS/mbed_drivers` that currently live in `libraries/tests/mbed` - `TESTS/mbedmicro-rtos-mbed` (Thanks @PrzemekWirkus!) - Ported tests that currently live in `libraries/tests/rtos/mbed` - `TESTS/storage_abstraction` (Thanks @rgrover!) - Tests for the storage_abstraction hal
2016-07-19 18:39:53 +00:00
// Global stack object simple test
s.stack_test();
if (s.check_init() == false) {
Adding test frameworks and test sources This commit adds the following test frameworks: - `greentea-client` (https://github.com/ARMmbed/greentea-client) - This framework provides a key-value api for communicating with the greentea test tool (https://github.com/ARMmbed/greentea) - `unity` (https://github.com/ARMmbed/unity) - This framework provides test assert macros that can be used when writing test cases - `utest` (https://github.com/ARMmbed/utest) - This framework allows you to execute a series of test cases with reporting that works with the greentea test tool (https://github.com/ARMmbed/greentea) The following changes were made when bringing these frameworks into the tree: - References to `mbed_drivers/mbed.h` within utest's tests were migrated to `mbed.h` - The yotta file `module.json` was removed from `greentea-client` and `unity` - `coverage.json` was also removed from `greentea-client` - `.gitignore` and `.gitattributes` were removed from `greentea-client` - Apache 2.0 license files were removed from `greentea-client` This also brings in a number of tests that have been newly written or ported from various sources: - `TESTS/integration` - Very basic tests, used to check if testing frameworks are working correctly - `TESTS/mbed_drivers` (Thanks @PrzemekWirkus!) - TESTS ported from mbed OS 3.0 (https://github.com/ARMmbed/mbed-drivers) - `TESTS/mbedmicro-mbed` (Thanks @PrzemekWirkus!) - Tests that weren't covered by `TESTS/mbed_drivers` that currently live in `libraries/tests/mbed` - `TESTS/mbedmicro-rtos-mbed` (Thanks @PrzemekWirkus!) - Ported tests that currently live in `libraries/tests/rtos/mbed` - `TESTS/storage_abstraction` (Thanks @rgrover!) - Tests for the storage_abstraction hal
2016-07-19 18:39:53 +00:00
result = false;
break;
}
// Heap test object simple test
Test *m = new Test("Heap");
m->hello();
if (m->check_init() == false) {
Adding test frameworks and test sources This commit adds the following test frameworks: - `greentea-client` (https://github.com/ARMmbed/greentea-client) - This framework provides a key-value api for communicating with the greentea test tool (https://github.com/ARMmbed/greentea) - `unity` (https://github.com/ARMmbed/unity) - This framework provides test assert macros that can be used when writing test cases - `utest` (https://github.com/ARMmbed/utest) - This framework allows you to execute a series of test cases with reporting that works with the greentea test tool (https://github.com/ARMmbed/greentea) The following changes were made when bringing these frameworks into the tree: - References to `mbed_drivers/mbed.h` within utest's tests were migrated to `mbed.h` - The yotta file `module.json` was removed from `greentea-client` and `unity` - `coverage.json` was also removed from `greentea-client` - `.gitignore` and `.gitattributes` were removed from `greentea-client` - Apache 2.0 license files were removed from `greentea-client` This also brings in a number of tests that have been newly written or ported from various sources: - `TESTS/integration` - Very basic tests, used to check if testing frameworks are working correctly - `TESTS/mbed_drivers` (Thanks @PrzemekWirkus!) - TESTS ported from mbed OS 3.0 (https://github.com/ARMmbed/mbed-drivers) - `TESTS/mbedmicro-mbed` (Thanks @PrzemekWirkus!) - Tests that weren't covered by `TESTS/mbed_drivers` that currently live in `libraries/tests/mbed` - `TESTS/mbedmicro-rtos-mbed` (Thanks @PrzemekWirkus!) - Ported tests that currently live in `libraries/tests/rtos/mbed` - `TESTS/storage_abstraction` (Thanks @rgrover!) - Tests for the storage_abstraction hal
2016-07-19 18:39:53 +00:00
result = false;
}
delete m;
break;
}
GREENTEA_TESTSUITE_RESULT(result);
}