|
| 1 | +/* |
| 2 | + * Copyright (c) 2020 Arm Limited and affiliates. |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +#include "greentea-client/test_env.h" |
| 7 | +#include "unity.h" |
| 8 | +#include "utest.h" |
| 9 | + |
| 10 | +using namespace utest::v1; |
| 11 | + |
| 12 | +void test_simple() |
| 13 | +{ |
| 14 | + TEST_ASSERT_EQUAL(0, 0); |
| 15 | + printf("Simple test called\n"); |
| 16 | +} |
| 17 | + |
| 18 | +utest::v1::status_t test_repeats_setup(const Case *const source, const size_t index_of_case) |
| 19 | +{ |
| 20 | + // Call the default handler for proper reporting |
| 21 | + utest::v1::status_t status = greentea_case_setup_handler(source, index_of_case); |
| 22 | + printf("Setting up for '%s'\n", source->get_description()); |
| 23 | + return status; |
| 24 | +} |
| 25 | +control_t test_repeats(const size_t call_count) |
| 26 | +{ |
| 27 | + printf("Called for the %u. time\n", call_count); |
| 28 | + TEST_ASSERT_NOT_EQUAL(3, call_count); |
| 29 | + // Specify how often this test is repeated i.e. n total calls |
| 30 | + return (call_count < 2) ? CaseRepeatAll : CaseNext; |
| 31 | +} |
| 32 | + |
| 33 | +void test_callback_validate() |
| 34 | +{ |
| 35 | + // You may also use assertions here |
| 36 | + TEST_ASSERT_EQUAL_PTR(0, 0); |
| 37 | + // Validate the callback |
| 38 | + Harness::validate_callback(); |
| 39 | +} |
| 40 | + |
| 41 | +// Specify all your test cases here |
| 42 | +Case cases[] = { |
| 43 | + Case("Simple Test", test_simple), |
| 44 | + Case("Repeating Test", test_repeats_setup, test_repeats) |
| 45 | +}; |
| 46 | + |
| 47 | +// Custom setup handler required for proper Greentea support |
| 48 | +utest::v1::status_t greentea_setup(const size_t number_of_cases) |
| 49 | +{ |
| 50 | + GREENTEA_SETUP(20, "default_auto"); |
| 51 | + // Call the default reporting function |
| 52 | + return greentea_test_setup_handler(number_of_cases); |
| 53 | +} |
| 54 | + |
| 55 | +// Declare your test specification with a custom setup handler |
| 56 | +Specification specification(greentea_setup, cases); |
| 57 | + |
| 58 | +int main() |
| 59 | +{ |
| 60 | + // Run the test specification |
| 61 | + Harness::run(specification); |
| 62 | +} |
0 commit comments