|
| 1 | +/* |
| 2 | + * Copyright (C) 2018 Freie Universität Berlin |
| 3 | + * |
| 4 | + * This file is subject to the terms and conditions of the GNU Lesser |
| 5 | + * General Public License v2.1. See the file LICENSE in the top level |
| 6 | + * directory for more details. |
| 7 | + */ |
| 8 | + |
| 9 | +/** |
| 10 | + * @ingroup tests |
| 11 | + * @{ |
| 12 | + * |
| 13 | + * @file |
| 14 | + * @brief Test application for newlib/newlib-nano inclusion |
| 15 | + * |
| 16 | + * @author Gaëtan Harter <gaetan.harter@fu-berlin.de> |
| 17 | + * |
| 18 | + * @} |
| 19 | + */ |
| 20 | + |
| 21 | +/* |
| 22 | + * Make some different functions visible between newlib and newlib-nano |
| 23 | + */ |
| 24 | +#define _DEFAULT_SOURCE 1 |
| 25 | + |
| 26 | +#include <stdio.h> |
| 27 | +#include "embUnit.h" |
| 28 | + |
| 29 | + |
| 30 | +#ifdef MODULE_NEWLIB |
| 31 | +#include <newlib.h> |
| 32 | + |
| 33 | +/* Newlib-nano defines the _NANO_FORMATTED_IO macro |
| 34 | + * |
| 35 | + * Source: |
| 36 | + * |
| 37 | + * https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;a=blob;f=newlib/newlib.hin;h=eadafc8a6a51ef7674c004a14777f6a4619115ee;hb=d34336767e45ee801ebb107e40abe4b1acbd3d14#l83 |
| 38 | + */ |
| 39 | +#ifdef MODULE_NEWLIB_NANO |
| 40 | +#ifndef _NANO_FORMATTED_IO |
| 41 | +#error newlib-nano is enabled but the header is not visible by the build system |
| 42 | +#endif /* _NANO_FORMATTED_IO */ |
| 43 | +#endif /* MODULE_NEWLIB_NANO */ |
| 44 | + |
| 45 | +#endif /* MODULE_NEWLIB */ |
| 46 | + |
| 47 | + |
| 48 | +/* Newlib-nano removed the integer only 'iprintf' functions which are now mapped |
| 49 | + * to printf. |
| 50 | + * |
| 51 | + * Source: |
| 52 | + * |
| 53 | + * https://github.com/32bitmicro/newlib-nano-1.0/blob/f157c994b9a2c4bd8d0cfe9fe8fdd9cd54f8c63b/newlib/README.nano#L32 |
| 54 | + * |
| 55 | + */ |
| 56 | +static void test_newlib(void) |
| 57 | +{ |
| 58 | +#ifdef MODULE_NEWLIB |
| 59 | +#ifdef MODULE_NEWLIB_NANO |
| 60 | + /* Nano maps iprintf to printf */ |
| 61 | + TEST_ASSERT(iprintf == printf); |
| 62 | +#else |
| 63 | + /* Normal newlib does not */ |
| 64 | + TEST_ASSERT(iprintf != printf); |
| 65 | +#endif |
| 66 | +#endif |
| 67 | +} |
| 68 | + |
| 69 | + |
| 70 | +static Test *tests_newlib(void) |
| 71 | +{ |
| 72 | + EMB_UNIT_TESTFIXTURES(fixtures) { |
| 73 | + new_TestFixture(test_newlib), |
| 74 | + }; |
| 75 | + |
| 76 | + EMB_UNIT_TESTCALLER(tests, NULL, NULL, fixtures); |
| 77 | + return (Test *)&tests; |
| 78 | +} |
| 79 | + |
| 80 | +int main(void) |
| 81 | +{ |
| 82 | + puts("Newlib/nano test"); |
| 83 | + TESTS_START(); |
| 84 | + TESTS_RUN(tests_newlib()); |
| 85 | + TESTS_END(); |
| 86 | + |
| 87 | + return 0; |
| 88 | +} |
0 commit comments