[posix-app] fix alarm issue (#3035)

This commit is contained in:
Yakun Xu
2018-09-05 23:16:33 -10:00
committed by Jonathan Hui
parent e34b0f3437
commit f227bbe7f2
4 changed files with 59 additions and 5 deletions
+3
View File
@@ -53,6 +53,9 @@ matrix:
- env: BUILD_TARGET="posix-app-ncp" VERBOSE=1 VIRTUAL_TIME=1
os: linux
compiler: gcc
- env: BUILD_TARGET="posix-app-pty" VERBOSE=1
os: linux
compiler: gcc
- env: BUILD_TARGET="android-build" VERBOSE=1
language: android
android:
+4
View File
@@ -57,6 +57,10 @@ cd /tmp || die
clang-format --version || die
}
[ $BUILD_TARGET != posix-app-pty ] || {
sudo apt-get install socat expect || die
}
[ $BUILD_TARGET != scan-build ] || {
sudo apt-get install clang || die
}
+46
View File
@@ -547,6 +547,52 @@ set -x
PYTHONUNBUFFERED=1 OT_CLI_PATH="$(pwd)/$(ls output/posix/*/bin/ot-cli)" RADIO_DEVICE="$(pwd)/$(ls output/*/bin/ot-ncp-radio)" COVERAGE=1 make -f src/posix/Makefile-posix check || die
}
[ $BUILD_TARGET != posix-app-pty ] || {
./bootstrap
make -f examples/Makefile-posix
make -f src/posix/Makefile-posix
SOCAT_OUTPUT=/tmp/ot-socat
socat -d -d pty,raw,echo=0 pty,raw,echo=0 > /dev/null 2> $SOCAT_OUTPUT &
while true; do
if test $(head -n2 $SOCAT_OUTPUT | wc -l) = 2; then
RADIO_PTY=$(head -n1 $SOCAT_OUTPUT | grep -o '/dev/.\+')
CORE_PTY=$(head -n2 $SOCAT_OUTPUT | tail -n1 | grep -o '/dev/.\+')
break
fi
echo 'Waiting for socat ready...'
sleep 1
done
echo 'RADIO_PTY' $DEVICE_PTY
echo 'CORE_PTY' $CORE_PTY
RADIO_NCP_PATH="$(pwd)/$(ls output/*linux*/bin/ot-ncp-radio)"
$RADIO_NCP_PATH 1 > $RADIO_PTY < $RADIO_PTY &
OT_CLI_PATH="$(pwd)/$(ls output/posix/*linux*/bin/ot-cli)"
expect <<EOF || die
spawn $OT_CLI_PATH $CORE_PTY -echo
set timeout 2
send "panid 0xface\r\n"
expect "Done"
send "ifconfig up\r\n"
expect "Done"
send "thread start\r\n"
expect "Done"
sleep 5
send "state\r\n"
expect {
"leader" {
send "exit\r\n"
expect eof
}
timeout abort
}
send_user "Success"
EOF
killall socat
}
[ $BUILD_TARGET != posix-mtd ] || {
./bootstrap || die
COVERAGE=1 CFLAGS=-m32 CXXFLAGS=-m32 LDFLAGS=-m32 USE_MTD=1 make -f examples/Makefile-posix check || die
+6 -5
View File
@@ -106,17 +106,14 @@ void otPlatAlarmMicroStop(otInstance *aInstance)
void platformAlarmUpdateTimeout(struct timeval *aTimeout)
{
int32_t usRemaining = INT32_MAX;
int32_t msRemaining = INT32_MAX;
struct timeval now;
int32_t usRemaining = INT32_MAX;
int32_t msRemaining = INT32_MAX;
if (aTimeout == NULL)
{
return;
}
otSysGetTime(&now);
if (sIsUsRunning)
{
usRemaining = (int64_t)(sUsAlarm - otPlatAlarmMicroGetNow());
@@ -124,6 +121,10 @@ void platformAlarmUpdateTimeout(struct timeval *aTimeout)
if (sIsMsRunning)
{
struct timeval now;
otSysGetTime(&now);
timersub(&now, &sStart, &now);
msRemaining = (int64_t)sMsAlarm * US_PER_MS - now.tv_sec * US_PER_S - now.tv_usec;
}