From 000ee90bfe9a7eb82fd4eddf317e4be994b63f49 Mon Sep 17 00:00:00 2001 From: Russ Butler Date: Mon, 9 Oct 2017 14:26:42 -0500 Subject: [PATCH] Add a minimum requirements HAL test Add a test to ensure that devices have at least 2K free ram and 2K free heap. This test should be the first test that fails due to running out of ram or heap. --- TESTS/mbed_hal/minimum_requirements/main.cpp | 71 ++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 TESTS/mbed_hal/minimum_requirements/main.cpp diff --git a/TESTS/mbed_hal/minimum_requirements/main.cpp b/TESTS/mbed_hal/minimum_requirements/main.cpp new file mode 100644 index 0000000000..88f742c3ff --- /dev/null +++ b/TESTS/mbed_hal/minimum_requirements/main.cpp @@ -0,0 +1,71 @@ +/* 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. + */ + +#include "utest/utest.h" +#include "unity/unity.h" +#include "greentea-client/test_env.h" + +#include "mbed.h" + +using namespace utest::v1; + +/** + * This test is intended to gate devices that do not have enough RAM to run + * Mbed os. Devices passing this test should have enough RAM to run all + * other Mbed OS tests. + * + * If your device does not pass this test, then you should determine the + * cause of high memory usage and fix it. If you cannot free enough memory, + * then you should turn off Mbed OS support for this device. + */ + +#define MIN_HEAP_SIZE 2048 +#define MIN_DATA_SIZE 2048 + +volatile uint8_t test_buffer[MIN_DATA_SIZE]; + +static void minimum_heap_test() +{ + void *mem = malloc(MIN_HEAP_SIZE); + TEST_ASSERT_NOT_EQUAL(NULL, mem); + free(mem); +} + +static void minimum_data_test() +{ + // Use test buffer so it is not optimized away + for (int i = 0; i < MIN_DATA_SIZE; i++) { + test_buffer[i] = i & 0xFF; + } +} + + +utest::v1::status_t greentea_test_setup(const size_t number_of_cases) +{ + GREENTEA_SETUP(30, "default_auto"); + return greentea_test_setup_handler(number_of_cases); +} + +Case cases[] = { + Case("Minimum heap test", minimum_heap_test), + Case("Minimum data test", minimum_data_test), +}; + +Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler); + +int main() { + Harness::run(specification); +}