* Upgrade to GCC 9.1 toolchain * Rebuilt using pure GNU binutils and GCC Remove dependencies on earlier forked GNU utilities (gcc-xtensa, binutils-gdb-xtensa) and just use GCC sources, unmodified (except for patches in the esp-quick-toolchain directories). * Rebuild bearssl using new toolchain * Fix GDBstub linkage options GDB works with pure GNU GCC and pure GNU binutils now. Still warnings galore, but tested with the example sketch in the docs. * Fix digitalRead alias warning * Remove gdb stub warnings w/a pragma * Fix deprecated implicit copy ctors in IP code Fix some warnings present in GCC8/9 in the IPAddress code In AddressListIterator there was a copy constructor which simply copied the structure bit-for-bit. That's the default operation, so remove it to avoid the warning there. IPAddress, add a default copy constructor since the other copy constructors are simply parsing from one format into a native ip_addr_t. @d-a-v, can you give these a look over and see if they're good (since IP stuff is really your domain). * Fix AxTLS alias function defs to match real code * Fix WiFiClientSecure implicit default copy ctor These both use shared-ptrs to handle refcnts to allocated data, so using the default copy constructor is fine (and has been in use for a long time). * Dummy size for heap to avoid GCC 8/9 warnings Make GCC think _heap_start is large enough to avoid the basic (and incorrect) bounds-checking warnings it produces. The size chosen is arbitrary and does not affect the actual size of the heap in any way. * Make heap an undefined extend array Instead of a bogus size, use an indefinite size for the heap to avoid GCC warnings * Trivial tab to space fix * Update SDFat to remove FatFile warnings * Fix ticker function cast warnings in GCC 9 The callback function is defined to take a (void*) as parameter, but our templates let users use anything that fits inside sizeof(void*) to be passed in. Add pragmas to stop GCC warnings about this, since we already check the size of the type will fit in the allocated space. * Remove GCC support fcn that's in ROM Manually delete the divdi3.so from the libgcc.a library by running the updated EQT's 9.1-post script. * Make exceptions work again, get std::regex up Exceptions are broken on all builds (GCC4.8-9.1) due to the removal of the PROGMEM non-32b read exception handler (added in the unstable pre3.0.0). Build the exception code with -mforce-l32 and patch accordingly to avoid LoadStore errors. Apply patches to select portions of the regex lib which use _stype_ (which is now in flash). * Rebuild Bearssl using latest GCC push * Automate building of BearSSL and LWIP w/new toolchain * Workaround g++ template section problem for exception strings G++ seems to throw out the section attributes for templates. This means that the __EXCSTR(a synonym for "PSTR()") is ignored and exception.what strings are stored in RODATA, eating up RAM. Workaround by using the linker to place the strings keying off their name ("*__exception_what__*"). * Rebuild moving exception.what to unique names Exception.whats are now all in __exception_what__ and can be moved by the linker to flash. Works aroung G++ issue with segments being lost in templates. * Rebuild with new LWIP locking * Update to latest libs, save iram Move two GCC FP support routines out of iram since they are in ROM already, saving some add'l IRAM. Same list as gcc 4.8. * Update BearSSL to latest release * Fix umm_perf reference to ROM function * Fix "reinterpret_case is not a constexpr" error In GCC 9 (and 8 from what I read on SO), a cast of a const int to a function pointer (via explicit or implicit reinterpret_cast) is not a constexpr. ```` /home/earle/Arduino/hardware/esp8266com/esp8266/cores/esp8266/umm_malloc/umm_performance.cpp:45:36: error: a reinterpret_cast is not a constant expression 45 | int constexpr (*_rom_putc1)(int) = (int (*)(int))(void*)0x40001dcc; | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ```` Remove the constexpr, potentially increasing heap usage by 4 bytes in debug mode. * Update libc.a to latest rev * Full rebuild of toolchain and libs * Upgrade to GCC 9.2, released in August 2019 Add builds for all 5 cross-compiles to pass CI * Move to --std=gnu++14 (C++14 + GNU extensions) * Fix Ticker merge conflict * Fix json merge conflict * One more merge diff fix * Reapply Ticker.h casting warning fixes for gcc9 * Update with fixes from Sming repo for PSTR and ASM * Upgrade to -gnu4 toolchain * Move to gnu5 build with add'l softFP from ROM * Move add'l softFP from IRAM to flash Per @mikee47, we miss sone add'l soft-FP routined in the linker which makes them end up in IRAM. Move them explicitly into flash, like a couple others we have already done this for. * Move to std=c++17/c17 in platform, remove abs/round Move to C++17 and C17 standards on the compiler options. Remove "register" from core since it is deprecated. Remove the #define abs() and #define round() which a) overwrote the C stdlib definitions, poorly, and b) broke the GCC core code which used "abs" as an internal function name. Now abs() returns an integer, and not whatever was being absoluted. fabs() etc. can be used if users need fload/double suport. round() returns a double now, which is basically what it was returning in the original case since adding/subtracting by a FP. * Use std::abs/round to replace the macro definitions Per discussion w/@devyte, preserve the abs() and round() functionality via the using statement. * Remove using std::abs which conflicted with C lib headers * Add 2nd arg (exception handler) to ets_isr_t Disassembly of the ROM shows there are 2 params to the ets_isr_t callback. The first is the arg passed in, the second is a pointer to an exception frame where you can get info about when the IRQ happened. * Move the gdbstub example to a subdir The Arduino IDE and the build CI don't build it without a subdir, so make one for gdbstub's example so it's visible and tested. * Fix ets_irq_arratch redefinition and core IRQ handlers Remove a duplicated, different declaration for ets_irq_attach from ets_sys.h. It never really even matched the other declaration in the same header. Update the core to IRQ handlers to fix the prototype and include the 2nd, unused frame parameter. * Actually rebuild the libc.a using GCC 9.2 * Fix SPISlave interrupt attach's 2nd parameter * Rebuild eboot.elf with GCC 9 * Update to latest SoftwareSerial for Delegate fix * Upgrade to GCC 9.3 * Rebuild all arch toolchains * Move to GCC 10.1 * Merge master and fix eboot build GCC10 now uses `-fno-common` so the eboot global variables were being placed in IRAM. Adjust the makefile and rebuild to fix. * Built complete toolchain for all archs * Pull in latest PSTR changes and fix GCC10.1 build Somehow the prior GCC build's -mforce32 patch wasn't applying correctly, but I was still able to get a binary. Fixed. Also pulled in latest PSTR changes in progmem.h * Update platform.io to platform C/C++ standards * Use PR's toolchain in platformio build * Fix several asm warnings in PIO build * Optional stack smash protection -fstack-protector Add a menu to enable GCC's built-in stack smash protection. When a subroutine goes past its end of stack, generate a crashdump on function exit like: ```` GCC detected stack overrun Stack corrupted, stack smash detected. >>>stack>>> ctx: cont sp: 3fffff20 end: 3fffffc0 offset: 0000 3fffff20: 40202955 00000001 0000001c 4020287e 3fffff30: feefeffe 000000fd 00000000 00000000 ... <<<stack<<< ```` Disabled by default because there is a small per-function code overhead (and CPU time if the function is called very frequently and is very small). BearSSL and LWIP are not built using stack smash detection, yet. * Fix duplicated stc=gnu99/c17 in build * Dump faulting function PC in stack overflow Report a fake exception to have the exception decoder print the actual faulting function. This won't tell you where in the function the issue happened, but it will tell you the function name first and foremost. * Rebuild with Platform.io JSON tag in release tgzs
Testing Arduino ESP8266 Core
Testing on host
Some features of this project can be tested by compiling and running the code on the PC, rather than running it on the ESP8266. Tests and testing infrastructure for such features is located in tests/host
directory of the project.
Some hardware features, such as Flash memory and HardwareSerial, can be emulated on the PC. Others, such as network, WiFi, and other hardware (SPI, I2C, timers, etc) are not yet emulated. This limits the amount of features which can be tested on the host.
Adding a test case
Tests are written in C++ using Catch framework.
See .cpp files under tests/host/core/ for a few examples how to write test cases.
When adding new test files, update TEST_CPP_FILES
variable in tests/host/Makefile to compile them.
If you want to add emulation of a certain feature, add it into tests/host/common/ directory.
Running test cases
NOTE! The test-on-host environment is dependent on some submodules. Make sure to run git submodule update --init
before running any test.
To run test cases, go to tests/host/ directory and run make
. This will compile and run the tests.
If all tests pass, you will see "All tests passed" message and the exit code will be 0.
Additionally, test coverage info will be generated using gcov
tool. You can use some tool to analyze coverage information, for example lcov
:
lcov -c -d . -d ../../cores/esp8266 -o test.info
genhtml -o html test.info
This will generate an HTML report in html
directory. Open html/index.html in your browser to see the report.
Note to macOS users: you will need to install GCC using Homebrew or MacPorts. Before running make
, set CC
, CXX
, and GCOV
variables to point to GCC tools you have installed. For example, when installing gcc-5 using Homebrew:
export CC=gcc-5
export CXX=g++-5
export GCOV=gcov-5
When running lcov
(which you also need to install), specify gcov
binary using --gcov-tool $(which $GCOV)
(assuming you have already set GCOV
environment variable).
Testing on device
Most features and libraries of this project can not be tested on host. Therefore testing on an ESP8266 device is required. Such tests and the test infrastructure are located in tests/device directory of this project.
Test cases
Tests are written in the form of Arduino sketches, and placed into tests/device/test_xxx directories. These tests are compiled using Arduino IDE, so test file name should match the name of the directory it is located in (e.g. test_foobar/test_foobar.ino). Tests use a very simple BSTest library, which handles test registration and provides TEST_CASE
, CHECK
, REQUIRE
, and FAIL
macros, similar to Catch.
Note: we should migrate to Catch framework with a custom runner.
Here is a simple test case written with BSTest:
#include <BSTest.h>
#include <test_config.h>
BS_ENV_DECLARE();
void setup()
{
Serial.begin(115200);
BS_RUN(Serial);
}
TEST_CASE("this test runs successfully", "[bs]")
{
CHECK(1 + 1 == 2);
REQUIRE(2 * 2 == 4);
}
BSTest is a header-only library, so necessary static data is injected into the sketch using BS_ENV_DECLARE();
macro.
BS_RUN(Serial)
passes control to the test runner, which uses Serial
stream to communicate with the host. If you need to do any preparation before starting tests, for example connect to an AP, do this before calling BS_RUN
.
TEST_CASE
macro defines a test case. First argument is human-readable test name, second contains optional set of tags (identifiers with square brackets). Currently only one tag has special meaning: [.]
can be used to mark the test case as ignored. Such tests will not be skipped by the test runner (see below).
Test execution
Once BS_RUN
is called, BSTest library starts by printing the menu, i.e. the list of tests defined in the sketch. For example:
>>>>>bs_test_menu_begin
>>>>>bs_test_item id=1 name="this test runs successfully" desc="[bs]"
>>>>>bs_test_menu_end
Then it waits for the test index to be sent by the host, followed by newline.
Once the line number is received, the test is executed, and feedback is printed:
>>>>>bs_test_start file="arduino-esp8266/tests/device/test_tests/test_tests.ino" line=13 name="this test runs successfully" desc="[bs]"
>>>>>bs_test_end line=0 result=1 checks=2 failed_checks=0
Or, in case the test fails:
>>>>>bs_test_start file="arduino-esp8266/tests/device/test_tests/test_tests.ino" line=19 name="another test which fails" desc="[bs][fail]"
>>>>>bs_test_check_failure line=22
>>>>>bs_test_check_failure line=24
>>>>>bs_test_end line=0 result=0 checks=4 failed_checks=2
BSTest library also contains a Python script which can "talk" to the ESP8266 board and run the tests, tests/device/libraries/BSTest/runner.py. Normally it is not necessary to use this script directly, as the top level Makefile in tests/device/ directory can call it automatically (see below).
Test configuration
Some tests need to connect to WiFi AP or to the PC running the tests. In the test code, this configuration is read from environment variables (the ones set using C getenv
/setenv
functions). There are two ways environment variables can be set.
-
Environment variables which apply to all or most of the tests can be defined in
tests/device/test_env.cfg
file. This file is not present in Git by default. Make a copy oftests/device/test_env.cfg.template
and change the values to suit your environment. -
Environment variables which apply to a specific test can be set dynamically by the
setup
host side helper (see section below). This is done usingsetenv
function defined inmock_decorators
.
Environment variables can also be used to pass some information from the test code to the host side helper. To do that, test code can set an environment variable using setenv
C function. Then the teardown
host side helper can obtain the value of that variable using request_env
function defined in mock_decorators
.
A SPIFFS filesystem may be generated on the host and uploade before a test by including a file called make_spiffs.py
in the individual test directory.
Building and running the tests
Makefile in tests/device/ directory handles compiling, uploading, and executing test cases.
Here are some of the supported targets:
-
virtualenv
: prepares Python virtual environment inside tests/device/libaries/BSTest/virtualenv/. This has to be run once on each computer where tests are to be run. This target will usepip
to install several Python libraries required by the test runner (see tests/device/libaries/BSTest/requirements.txt). -
test_xxx/test_xxx.ino
: compiles, uploads, and runs the tests defined intest_xxx/test_xxx.ino
sketch. Some extra options are available, these can be passed as additional arguments tomake
:NO_BUILD=1
: don't compile the test.NO_UPLOAD=1
: don't upload the test.NO_RUN=1
: don't run the test.V=1
: enable verbose output from compilation, upload, and test runner.
For example,
make test_newlib/test_newlib.ino V=1
will compile, upload, and run all tests defined intest_newlib/test_newlib.ino
.For each test sketch, test results are stored in
tests/device/.build/test_xxx.ino/test_result.xml
. This file is an xUnit XML file, and can be read by a variety of tools, such as Jenkins. -
test_report
: Generate HTML test report from xUnit XML files produced by test runs. -
all
(or justmake
without a target): Run tests from all the .ino files, and generate HTML test report.
Host-side helpers
Some tests running on the device need a matching part running on the host. For example, HTTP client test might need a web server running on the host to connect to. TCP server test might need to be connected to by TCP client running on the host. To support such use cases, for each test file, an optional Python test file can be provided. This Python file defines setup and teardown functions which have to be run before and after the test is run on the device. setup
and teardown
decorators bind setup/teardown functions to the test with specified name:
from mock_decorators import setup, teardown, setenv, request_env
@setup('WiFiClient test')
def setup_wificlient_test(e):
# create a TCP server
# pass environment variable to the test
setenv(e, 'SERVER_PORT', '10000')
setenv(e, 'SERVER_IP', repr(server_ip))
@teardown('WiFiClient test')
def teardown_wificlient_test(e):
# delete TCP server
# request environment variable from the test, compare to the expected value
read_bytes = request_env(e, 'READ_BYTES')
assert(read_bytes == '4096')
Corresponding test code might look like this:
TEST_CASE("WiFiClient test", "[wificlient]")
{
const char* server_ip = getenv("SERVER_IP");
int server_port = (int) strtol(getenv("SERVER_PORT"), NULL, 0);
WiFiClient client;
REQUIRE(client.connect(server_ip, server_port));
// read data from server
// ...
// Save the result back so that host side helper can read it
setenv("READ_BYTES", String(read_bytes).c_str(), 1);
}