-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests/libc_newlib: add test for newlib-nano inclusion
This test verifies that when used, newlib-nano is correctly included, both header and also linked.
- Loading branch information
Showing
4 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
include ../Makefile.tests_common | ||
|
||
TEST_ON_CI_WHITELIST += all | ||
USEMODULE += embunit | ||
|
||
include $(RIOTBASE)/Makefile.include | ||
|
||
test: | ||
tests/01-run.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
About | ||
===== | ||
|
||
Terifies if newlib/newlib-nano is correctly included by the build system | ||
|
||
At compile time, it checks that: | ||
|
||
* newlib-nano header is used when 'newlib-nano' module is included | ||
* It defines `_NANO_FORMATTED_IO` macro | ||
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;a=blob;f=newlib/newlib.hin;h=eadafc8a6a51ef7674c004a14777f6a4619115ee;hb=d34336767e45ee801ebb107e40abe4b1acbd3d14#l83 | ||
|
||
At runtime, it checks that: | ||
|
||
* newlib or newlib-nano is properly linked | ||
* `iprintf` is the same as `printf` or not as mentionned in: | ||
https://github.com/32bitmicro/newlib-nano-1.0/blob/f157c994b9a2c4bd8d0cfe9fe8fdd9cd54f8c63b/newlib/README.nano#L32 | ||
|
||
|
||
Without newlib, the test does nothing. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright (C) 2018 Freie Universität Berlin | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser | ||
* General Public License v2.1. See the file LICENSE in the top level | ||
* directory for more details. | ||
*/ | ||
|
||
/** | ||
* @ingroup tests | ||
* @{ | ||
* | ||
* @file | ||
* @brief Test application for newlib/newlib-nano inclusion | ||
* | ||
* @author Gaëtan Harter <gaetan.harter@fu-berlin.de> | ||
* | ||
* @} | ||
*/ | ||
|
||
/* | ||
* Make some different functions visible between newlib and newlib-nano | ||
*/ | ||
#define _DEFAULT_SOURCE 1 | ||
|
||
#include <stdio.h> | ||
#include "embUnit.h" | ||
|
||
|
||
#ifdef MODULE_NEWLIB | ||
#include <newlib.h> | ||
|
||
/* Newlib-nano defines the _NANO_FORMATTED_IO macro | ||
* | ||
* Source: | ||
* | ||
* https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;a=blob;f=newlib/newlib.hin;h=eadafc8a6a51ef7674c004a14777f6a4619115ee;hb=d34336767e45ee801ebb107e40abe4b1acbd3d14#l83 | ||
*/ | ||
#ifdef MODULE_NEWLIB_NANO | ||
#ifndef _NANO_FORMATTED_IO | ||
#error newlib-nano is enabled but the header is not visible by the build system | ||
#endif /* _NANO_FORMATTED_IO */ | ||
#endif /* MODULE_NEWLIB_NANO */ | ||
|
||
#endif /* MODULE_NEWLIB */ | ||
|
||
|
||
/* Newlib-nano removed the integer only 'iprintf' functions which are now mapped | ||
* to printf. | ||
* | ||
* Source: | ||
* | ||
* https://github.com/32bitmicro/newlib-nano-1.0/blob/f157c994b9a2c4bd8d0cfe9fe8fdd9cd54f8c63b/newlib/README.nano#L32 | ||
* | ||
*/ | ||
static void test_newlib(void) | ||
{ | ||
#ifdef MODULE_NEWLIB | ||
#ifdef MODULE_NEWLIB_NANO | ||
/* Nano maps iprintf to printf */ | ||
TEST_ASSERT(iprintf == printf); | ||
#else | ||
/* Normal newlib does not */ | ||
TEST_ASSERT(iprintf != printf); | ||
#endif | ||
#endif | ||
} | ||
|
||
|
||
static Test *tests_newlib(void) | ||
{ | ||
EMB_UNIT_TESTFIXTURES(fixtures) { | ||
new_TestFixture(test_newlib), | ||
}; | ||
|
||
EMB_UNIT_TESTCALLER(tests, NULL, NULL, fixtures); | ||
return (Test *)&tests; | ||
} | ||
|
||
int main(void) | ||
{ | ||
puts("Newlib/nano test"); | ||
TESTS_START(); | ||
TESTS_RUN(tests_newlib()); | ||
TESTS_END(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Copyright (C) 2018 Freie Universität Berlin | ||
# | ||
# This file is subject to the terms and conditions of the GNU Lesser | ||
# General Public License v2.1. See the file LICENSE in the top level | ||
# directory for more details. | ||
|
||
import os | ||
import sys | ||
|
||
|
||
def testfunc(child): | ||
child.expect(r"OK \([0-9]+ tests\)") | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.path.append(os.path.join(os.environ['RIOTTOOLS'], 'testrunner')) | ||
from testrunner import run | ||
sys.exit(run(testfunc)) |