|
| 1 | +/* mbed Microcontroller Library |
| 2 | + * Copyright (c) 2017 ARM Limited |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +#include "utest/utest.h" |
| 18 | +#include "unity/unity.h" |
| 19 | +#include "greentea-client/test_env.h" |
| 20 | + |
| 21 | +#include "mbed.h" |
| 22 | + |
| 23 | +using namespace utest::v1; |
| 24 | + |
| 25 | +/** |
| 26 | + * This test is intended to gate devices that do not have enough RAM to run |
| 27 | + * Mbed os. Devices passing this test should have enough RAM to run all |
| 28 | + * other Mbed OS tests. |
| 29 | + * |
| 30 | + * If your device does not pass this test, then you should determine the |
| 31 | + * cause of high memory usage and fix it. If you cannot free enough memory, |
| 32 | + * then you should turn off Mbed OS support for this device. |
| 33 | + */ |
| 34 | + |
| 35 | +#define MIN_HEAP_SIZE 2048 |
| 36 | +#define MIN_DATA_SIZE 2048 |
| 37 | + |
| 38 | +volatile uint8_t test_buffer[MIN_DATA_SIZE]; |
| 39 | + |
| 40 | +static void minimum_heap_test() |
| 41 | +{ |
| 42 | + void *mem = malloc(MIN_HEAP_SIZE); |
| 43 | + TEST_ASSERT_NOT_EQUAL(NULL, mem); |
| 44 | + free(mem); |
| 45 | +} |
| 46 | + |
| 47 | +static void minimum_data_test() |
| 48 | +{ |
| 49 | + // Use test buffer so it is not optimized away |
| 50 | + for (int i = 0; i < MIN_DATA_SIZE; i++) { |
| 51 | + test_buffer[i] = i & 0xFF; |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | + |
| 56 | +utest::v1::status_t greentea_test_setup(const size_t number_of_cases) |
| 57 | +{ |
| 58 | + GREENTEA_SETUP(30, "default_auto"); |
| 59 | + return greentea_test_setup_handler(number_of_cases); |
| 60 | +} |
| 61 | + |
| 62 | +Case cases[] = { |
| 63 | + Case("Minimum heap test", minimum_heap_test), |
| 64 | + Case("Minimum data test", minimum_data_test), |
| 65 | +}; |
| 66 | + |
| 67 | +Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler); |
| 68 | + |
| 69 | +int main() { |
| 70 | + Harness::run(specification); |
| 71 | +} |
0 commit comments