Skip to content

Commit a23078e

Browse files
committed
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.
1 parent d04058b commit a23078e

4 files changed

Lines changed: 136 additions & 0 deletions

File tree

tests/libc_newlib/Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
include ../Makefile.tests_common
2+
3+
TEST_ON_CI_WHITELIST += all
4+
USEMODULE += embunit
5+
6+
include $(RIOTBASE)/Makefile.include
7+
8+
test:
9+
tests/01-run.py

tests/libc_newlib/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
About
2+
=====
3+
4+
Terifies if newlib/newlib-nano is correctly included by the build system
5+
6+
At compile time, it checks that:
7+
8+
* newlib-nano header is used when 'newlib-nano' module is included
9+
* It defines `_NANO_FORMATTED_IO` macro
10+
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;a=blob;f=newlib/newlib.hin;h=eadafc8a6a51ef7674c004a14777f6a4619115ee;hb=d34336767e45ee801ebb107e40abe4b1acbd3d14#l83
11+
12+
At runtime, it checks that:
13+
14+
* newlib or newlib-nano is properly linked
15+
* `iprintf` is the same as `printf` or not as mentionned in:
16+
https://github.com/32bitmicro/newlib-nano-1.0/blob/f157c994b9a2c4bd8d0cfe9fe8fdd9cd54f8c63b/newlib/README.nano#L32
17+
18+
19+
Without newlib, the test does nothing.

tests/libc_newlib/main.c

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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+
}

tests/libc_newlib/tests/01-run.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env python3
2+
3+
# Copyright (C) 2018 Freie Universität Berlin
4+
#
5+
# This file is subject to the terms and conditions of the GNU Lesser
6+
# General Public License v2.1. See the file LICENSE in the top level
7+
# directory for more details.
8+
9+
import os
10+
import sys
11+
12+
13+
def testfunc(child):
14+
child.expect(r"OK \([0-9]+ tests\)")
15+
16+
17+
if __name__ == "__main__":
18+
sys.path.append(os.path.join(os.environ['RIOTTOOLS'], 'testrunner'))
19+
from testrunner import run
20+
sys.exit(run(testfunc))

0 commit comments

Comments
 (0)