|
| 1 | +/* mbed Microcontroller Library |
| 2 | + * Copyright (c) 2017-2017 ARM Limited |
| 3 | + * |
| 4 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 | + * of this software and associated documentation files (the "Software"), to deal |
| 6 | + * in the Software without restriction, including without limitation the rights |
| 7 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 8 | + * copies of the Software, and to permit persons to whom the Software is |
| 9 | + * furnished to do so, subject to the following conditions: |
| 10 | + * |
| 11 | + * The above copyright notice and this permission notice shall be included in |
| 12 | + * all copies or substantial portions of the Software. |
| 13 | + * |
| 14 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 20 | + * SOFTWARE. |
| 21 | + */ |
| 22 | + |
| 23 | +#include "mbed.h" |
| 24 | +#include "unity.h" |
| 25 | +#include "utest.h" |
| 26 | +#include "test_env.h" |
| 27 | + |
| 28 | +#include "atomic_usage.h" |
| 29 | +#include "ObservingBlockDevice.h" |
| 30 | +#include "LittleFileSystem.h" |
| 31 | + |
| 32 | +#include <string.h> |
| 33 | + |
| 34 | + |
| 35 | +using namespace utest::v1; |
| 36 | + |
| 37 | +#ifndef MBED_TEST_BLOCKDEVICE |
| 38 | +#define MBED_TEST_BLOCKDEVICE SPIFBlockDevice |
| 39 | +#define MBED_TEST_BLOCKDEVICE_DECL SPIFBlockDevice bd(PTE2, PTE4, PTE1, PTE5) |
| 40 | +#endif |
| 41 | + |
| 42 | +#ifndef MBED_TEST_BLOCKDEVICE_DECL |
| 43 | +#define MBED_TEST_BLOCKDEVICE_DECL MBED_TEST_BLOCKDEVICE bd |
| 44 | +#endif |
| 45 | + |
| 46 | +// declarations |
| 47 | +#define STRINGIZE(x) STRINGIZE2(x) |
| 48 | +#define STRINGIZE2(x) #x |
| 49 | +#define INCLUDE(x) STRINGIZE(x.h) |
| 50 | + |
| 51 | +#include INCLUDE(MBED_TEST_BLOCKDEVICE) |
| 52 | + |
| 53 | +MBED_TEST_BLOCKDEVICE_DECL; |
| 54 | + |
| 55 | +typedef enum { |
| 56 | + CMD_STATUS_PASS, |
| 57 | + CMD_STATUS_FAIL, |
| 58 | + CMD_STATUS_CONTINUE, |
| 59 | + CMD_STATUS_ERROR |
| 60 | +} cmd_status_t; |
| 61 | + |
| 62 | +void use_filesystem() |
| 63 | +{ |
| 64 | + // Perform operations |
| 65 | + while (true) { |
| 66 | + int64_t ret = perform_atomic_operations(&bd); |
| 67 | + TEST_ASSERT(ret > 0); |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +static cmd_status_t handle_command(const char *key, const char *value) |
| 72 | +{ |
| 73 | + if (strcmp(key, "format") == 0) { |
| 74 | + setup_atomic_operations(&bd, true); |
| 75 | + greentea_send_kv("format_done", 1); |
| 76 | + return CMD_STATUS_CONTINUE; |
| 77 | + |
| 78 | + } else if (strcmp(key, "run") == 0) { |
| 79 | + use_filesystem(); |
| 80 | + return CMD_STATUS_CONTINUE; |
| 81 | + |
| 82 | + } else if (strcmp(key, "exit") == 0) { |
| 83 | + if (strcmp(value, "pass") != 0) { |
| 84 | + return CMD_STATUS_FAIL; |
| 85 | + } |
| 86 | + check_atomic_operations(&bd); |
| 87 | + return CMD_STATUS_PASS; |
| 88 | + |
| 89 | + } else { |
| 90 | + return CMD_STATUS_ERROR; |
| 91 | + |
| 92 | + } |
| 93 | +} |
| 94 | + |
| 95 | +int main() |
| 96 | +{ |
| 97 | + GREENTEA_SETUP(60, "unexpected_reset"); |
| 98 | + |
| 99 | + static char _key[10 + 1] = {}; |
| 100 | + static char _value[128 + 1] = {}; |
| 101 | + |
| 102 | + greentea_send_kv("start", 1); |
| 103 | + |
| 104 | + // Handshake with host |
| 105 | + cmd_status_t cmd_status = CMD_STATUS_CONTINUE; |
| 106 | + while (CMD_STATUS_CONTINUE == cmd_status) { |
| 107 | + memset(_key, 0, sizeof(_key)); |
| 108 | + memset(_value, 0, sizeof(_value)); |
| 109 | + greentea_parse_kv(_key, _value, sizeof(_key) - 1, sizeof(_value) - 1); |
| 110 | + cmd_status = handle_command(_key, _value); |
| 111 | + } |
| 112 | + |
| 113 | + GREENTEA_TESTSUITE_RESULT(CMD_STATUS_PASS == cmd_status); |
| 114 | +} |
0 commit comments