Skip to content

Commit 8016386

Browse files
Merge branch 'master' into littlefs
2 parents a42bc48 + 187f6a5 commit 8016386

File tree

11 files changed

+268
-134
lines changed

11 files changed

+268
-134
lines changed

.travis.yml

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,58 +20,70 @@ stages:
2020
jobs:
2121
include:
2222
# Build stage. To save time, run all kinds of builds and tests in parallel.
23-
- name: "Host tests"
23+
24+
- name: "Platformio (1)"
2425
stage: build
25-
script: $TRAVIS_BUILD_DIR/tests/ci/host_test.sh
26-
install: sudo apt-get install valgrind lcov
26+
script: $TRAVIS_BUILD_DIR/tests/platformio.sh
27+
env:
28+
- BUILD_PARITY=even
29+
- name: "Platformio (2)"
30+
stage: build
31+
script: $TRAVIS_BUILD_DIR/tests/platformio.sh
32+
env:
33+
- BUILD_PARITY=odd
2734

28-
# TODO: since we can now call different script for each job,
29-
# split the do-it-all common.sh into separate scripts responsible
30-
# for different types of jobs below:
3135
- name: "Build (1)"
32-
script: $TRAVIS_BUILD_DIR/tests/common.sh
36+
stage: build
37+
script: $TRAVIS_BUILD_DIR/tests/build.sh
3338
env:
34-
- BUILD_TYPE=build_even
39+
- BUILD_PARITY=even
3540
- name: "Build (2)"
36-
script: $TRAVIS_BUILD_DIR/tests/common.sh
41+
stage: build
42+
script: $TRAVIS_BUILD_DIR/tests/build.sh
3743
env:
38-
- BUILD_TYPE=build_odd
44+
- BUILD_PARITY=odd
45+
3946
- name: "Debug (1)"
40-
script: $TRAVIS_BUILD_DIR/tests/common.sh
47+
stage: build
48+
script: $TRAVIS_BUILD_DIR/tests/debug.sh
4149
env:
42-
- BUILD_TYPE=debug_even
50+
- BUILD_PARITY=even
4351
- name: "Debug (2)"
44-
script: $TRAVIS_BUILD_DIR/tests/common.sh
52+
stage: build
53+
script: $TRAVIS_BUILD_DIR/tests/debug.sh
4554
env:
46-
- BUILD_TYPE=debug_odd
55+
- BUILD_PARITY=odd
56+
4757
- name: "Build IPv6 (1)"
48-
script: $TRAVIS_BUILD_DIR/tests/common.sh
58+
stage: build
59+
script: $TRAVIS_BUILD_DIR/tests/build6.sh
4960
env:
50-
- BUILD_TYPE=build6_even
61+
- BUILD_PARITY=even
5162
- name: "Build IPv6 (2)"
52-
script: $TRAVIS_BUILD_DIR/tests/common.sh
53-
env:
54-
- BUILD_TYPE=build6_odd
55-
- name: "Platformio (1)"
56-
script: $TRAVIS_BUILD_DIR/tests/common.sh
57-
env:
58-
- BUILD_TYPE=platformio_even
59-
- name: "Platformio (2)"
60-
script: $TRAVIS_BUILD_DIR/tests/common.sh
63+
stage: build
64+
script: $TRAVIS_BUILD_DIR/tests/build6.sh
6165
env:
62-
- BUILD_TYPE=platformio_odd
66+
- BUILD_PARITY=odd
67+
68+
- name: "Host tests"
69+
stage: build
70+
script: $TRAVIS_BUILD_DIR/tests/ci/host_test.sh
71+
install: sudo apt-get install valgrind lcov
6372

6473
- name: "Docs"
74+
stage: build
6575
script: $TRAVIS_BUILD_DIR/tests/ci/build_docs.sh
6676
install:
6777
- sudo apt-get install python3-pip
6878
- pip3 install --user -r doc/requirements.txt;
6979

7080
- name: "Style check"
81+
stage: build
7182
script: $TRAVIS_BUILD_DIR/tests/ci/style_check.sh
7283
install: tests/ci/install_astyle.sh
7384

7485
- name: "Boards"
86+
stage: build
7587
script: $TRAVIS_BUILD_DIR/tests/ci/build_boards.sh
7688

7789
# Deploy stage.

cores/esp8266/HardwareSerial.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <stdio.h>
2828
#include <string.h>
2929
#include <inttypes.h>
30+
#include <PolledTimeout.h>
3031
#include "Arduino.h"
3132
#include "HardwareSerial.h"
3233
#include "Esp.h"
@@ -132,6 +133,22 @@ unsigned long HardwareSerial::detectBaudrate(time_t timeoutMillis)
132133
return detectedBaudrate;
133134
}
134135

136+
size_t HardwareSerial::readBytes(char* buffer, size_t size)
137+
{
138+
size_t got = 0;
139+
140+
while (got < size)
141+
{
142+
esp8266::polledTimeout::oneShot timeOut(_timeout);
143+
size_t avail;
144+
while ((avail = available()) == 0 && !timeOut);
145+
if (avail == 0)
146+
break;
147+
got += read(buffer + got, std::min(size - got, avail));
148+
}
149+
return got;
150+
}
151+
135152
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SERIAL)
136153
HardwareSerial Serial(UART0);
137154
#endif

cores/esp8266/HardwareSerial.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,15 @@ class HardwareSerial: public Stream
132132
// return -1 when data is unvailable (arduino api)
133133
return uart_read_char(_uart);
134134
}
135-
size_t readBytes(char* buffer, size_t size) override
135+
// ::read(buffer, size): same as readBytes without timeout
136+
size_t read(char* buffer, size_t size)
136137
{
137138
return uart_read(_uart, buffer, size);
138139
}
140+
size_t readBytes(char* buffer, size_t size) override;
139141
size_t readBytes(uint8_t* buffer, size_t size) override
140142
{
141-
return uart_read(_uart, (char*)buffer, size);
143+
return readBytes((char*)buffer, size);
142144
}
143145
int availableForWrite(void)
144146
{

libraries/esp8266/examples/SerialStress/SerialStress.ino

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@
1616
#define BUFFER_SIZE 4096 // may be useless to use more than 2*SERIAL_SIZE_RX
1717
#define SERIAL_SIZE_RX 1024 // Serial.setRxBufferSize()
1818

19+
#define FAKE_INCREASED_AVAILABLE 100 // test readBytes's timeout
20+
1921
#define TIMEOUT 5000
2022
#define DEBUG(x...) //x
2123

2224
uint8_t buf [BUFFER_SIZE];
2325
uint8_t temp [BUFFER_SIZE];
2426
bool reading = true;
27+
size_t testReadBytesTimeout = 0;
2528

2629
static size_t out_idx = 0, in_idx = 0;
2730
static size_t local_receive_size = 0;
@@ -83,6 +86,7 @@ void setup() {
8386
size_for_1sec = baud / 10; // 8n1=10baudFor8bits
8487
logger->printf("led changes state every %zd bytes (= 1 second)\n", size_for_1sec);
8588
logger->printf("press 's' to stop reading, not writing (induces overrun)\n");
89+
logger->printf("press 't' to toggle timeout testing on readBytes\n");
8690

8791
// prepare send/compare buffer
8892
for (size_t i = 0; i < sizeof buf; i++) {
@@ -136,7 +140,7 @@ void loop() {
136140

137141
if (reading) {
138142
// receive data
139-
maxlen = Serial.available();
143+
maxlen = Serial.available() + testReadBytesTimeout;
140144
if (maxlen > maxavail) {
141145
maxavail = maxlen;
142146
}
@@ -180,8 +184,16 @@ void loop() {
180184
timeout = (last_ms = now_ms) + TIMEOUT;
181185
}
182186

183-
if (logger->read() == 's') {
184-
logger->println("now stopping reading, keeping writing");
185-
reading = false;
186-
}
187+
if (logger->available())
188+
switch (logger->read()) {
189+
case 's':
190+
logger->println("now stopping reading, keeping writing");
191+
reading = false;
192+
break;
193+
case 't':
194+
testReadBytesTimeout ^= FAKE_INCREASED_AVAILABLE;
195+
logger->printf("testing readBytes timeout: %d\n", !!testReadBytesTimeout);
196+
break;
197+
default:;
198+
}
187199
}

tests/build.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
3+
cache_dir=$(mktemp -d)
4+
5+
source "$TRAVIS_BUILD_DIR"/tests/common.sh
6+
7+
if [ -z "$BUILD_PARITY" ]; then
8+
mod=1
9+
rem=0
10+
elif [ "$BUILD_PARITY" = "even" ]; then
11+
mod=2
12+
rem=0
13+
elif [ "$BUILD_PARITY" = "odd" ]; then
14+
mod=2
15+
rem=1
16+
fi
17+
18+
install_arduino nodebug
19+
build_sketches_with_arduino "$mod" "$rem" lm2f
20+
21+
rm -rf "$cache_dir"
22+

tests/build6.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
3+
cache_dir=$(mktemp -d)
4+
5+
source "$TRAVIS_BUILD_DIR"/tests/common.sh
6+
7+
if [ -z "$BUILD_PARITY" ]; then
8+
mod=1
9+
rem=0
10+
elif [ "$BUILD_PARITY" = "even" ]; then
11+
mod=2
12+
rem=0
13+
elif [ "$BUILD_PARITY" = "odd" ]; then
14+
mod=2
15+
rem=1
16+
fi
17+
18+
install_arduino nodebug
19+
build_sketches_with_arduino "$mod" "$rem" lm6f
20+
21+
rm -rf "$cache_dir"
22+

tests/common.sh

Lines changed: 0 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -141,59 +141,6 @@ function install_ide()
141141
export PATH="$ide_path:$core_path/tools/xtensa-lx106-elf/bin:$PATH"
142142
}
143143

144-
function install_platformio()
145-
{
146-
pip install --user -U https://github.com/platformio/platformio/archive/develop.zip
147-
platformio platform install "https://github.com/platformio/platform-espressif8266.git#feature/stage"
148-
sed -i 's/https:\/\/github\.com\/esp8266\/Arduino\.git/*/' ~/.platformio/platforms/espressif8266/platform.json
149-
ln -s $TRAVIS_BUILD_DIR ~/.platformio/packages/framework-arduinoespressif8266
150-
# Install dependencies:
151-
# - esp8266/examples/ConfigFile
152-
pio lib install ArduinoJson
153-
}
154-
155-
function build_sketches_with_platformio()
156-
{
157-
set +e
158-
local srcpath=$1
159-
local build_arg=$2
160-
local build_mod=$3
161-
local build_rem=$4
162-
local sketches=$(find $srcpath -name *.ino | sort)
163-
local testcnt=0
164-
for sketch in $sketches; do
165-
testcnt=$(( ($testcnt + 1) % $build_mod ))
166-
if [ $testcnt -ne $build_rem ]; then
167-
continue # Not ours to do
168-
fi
169-
local sketchdir=$(dirname $sketch)
170-
local sketchdirname=$(basename $sketchdir)
171-
local sketchname=$(basename $sketch)
172-
if [[ "${sketchdirname}.ino" != "$sketchname" ]]; then
173-
echo "Skipping $sketch, beacause it is not the main sketch file";
174-
continue
175-
fi;
176-
if [[ -f "$sketchdir/.test.skip" ]]; then
177-
echo -e "\n ------------ Skipping $sketch ------------ \n";
178-
continue
179-
fi
180-
local build_cmd="pio ci $sketchdir $build_arg"
181-
echo -e "\n ------------ Building $sketch ------------ \n";
182-
echo "$build_cmd"
183-
time ($build_cmd >build.log)
184-
local result=$?
185-
if [ $result -ne 0 ]; then
186-
echo "Build failed ($1)"
187-
echo "Build log:"
188-
cat build.log
189-
set -e
190-
return $result
191-
fi
192-
rm build.log
193-
done
194-
set -e
195-
}
196-
197144
function install_arduino()
198145
{
199146
local debug=$1
@@ -235,48 +182,3 @@ if [ -z "$TRAVIS_BUILD_DIR" ]; then
235182
echo "TRAVIS_BUILD_DIR=$TRAVIS_BUILD_DIR"
236183
fi
237184

238-
cache_dir=$(mktemp -d)
239-
240-
if [ "$BUILD_TYPE" = "build" ]; then
241-
install_arduino nodebug
242-
build_sketches_with_arduino 1 0 lm2f
243-
elif [ "$BUILD_TYPE" = "build6" ]; then
244-
install_arduino nodebug
245-
build_sketches_with_arduino 1 0 lm6f
246-
elif [ "$BUILD_TYPE" = "build_even" ]; then
247-
install_arduino nodebug
248-
build_sketches_with_arduino 2 0 lm2f
249-
elif [ "$BUILD_TYPE" = "build_odd" ]; then
250-
install_arduino nodebug
251-
build_sketches_with_arduino 2 1 lm2f
252-
elif [ "$BUILD_TYPE" = "debug_even" ]; then
253-
install_arduino debug
254-
build_sketches_with_arduino 2 0 lm2f
255-
elif [ "$BUILD_TYPE" = "debug_odd" ]; then
256-
install_arduino debug
257-
build_sketches_with_arduino 2 1 lm2f
258-
elif [ "$BUILD_TYPE" = "build6_even" ]; then
259-
install_arduino nodebug
260-
build_sketches_with_arduino 2 0 lm6f
261-
elif [ "$BUILD_TYPE" = "build6_odd" ]; then
262-
install_arduino nodebug
263-
build_sketches_with_arduino 2 1 lm6f
264-
elif [ "$BUILD_TYPE" = "platformio" ]; then
265-
# PlatformIO
266-
install_platformio
267-
build_sketches_with_platformio $TRAVIS_BUILD_DIR/libraries "--board nodemcuv2 --verbose" 1 0
268-
elif [ "$BUILD_TYPE" = "platformio_even" ]; then
269-
# PlatformIO
270-
install_platformio
271-
build_sketches_with_platformio $TRAVIS_BUILD_DIR/libraries "--board nodemcuv2 --verbose" 2 0
272-
elif [ "$BUILD_TYPE" = "platformio_odd" ]; then
273-
# PlatformIO
274-
install_platformio
275-
build_sketches_with_platformio $TRAVIS_BUILD_DIR/libraries "--board nodemcuv2 --verbose" 2 1
276-
else
277-
echo "BUILD_TYPE not set or invalid"
278-
rm -rf $cache_dir
279-
exit 1
280-
fi
281-
282-
rm -rf $cache_dir

tests/debug.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
3+
cache_dir=$(mktemp -d)
4+
5+
source "$TRAVIS_BUILD_DIR"/tests/common.sh
6+
7+
if [ "$BUILD_PARITY" = "even" ]; then
8+
mod=2
9+
rem=0
10+
elif [ "$BUILD_PARITY" = "odd" ]; then
11+
mod=2
12+
rem=1
13+
fi
14+
15+
install_arduino debug
16+
build_sketches_with_arduino "$mod" "$rem" lm2f
17+
18+
rm -rf "$cache_dir"
19+

0 commit comments

Comments
 (0)