zephyr/tests/include/tc_nano_timeout_common.h

69 lines
2.2 KiB
C
Raw Normal View History

/*
* Copyright (c) 2015 Wind River Systems, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _samples_include_tc_nano_timeout_common__h_
#define _samples_include_tc_nano_timeout_common__h_
/*
* SHORT_TIMEOUTS should be the preferred configuration, but they cause a
* problem with the Jenkins auto-builders for the ARM QEMU. Until this is
* fixed, do not use them by default.
*/
#define SHORT_TIMEOUTS 0
#if SHORT_TIMEOUTS
#define TIMEOUT_BASE 10
#define TIMEOUT_INCREMENT 5
#else
#define TIMEOUT_BASE 50
#define TIMEOUT_INCREMENT 25
#endif
#define TIMEOUT(x) (TIMEOUT_BASE + ((x) * TIMEOUT_INCREMENT))
#define TIMEOUT_TWO_INTERVALS TIMEOUT(1)
#define TIMEOUT_TEN_INTERVALS TIMEOUT(9)
/*
* Verify a timeout is in range, either a diff of 0 or 1 to account for tick
* boundaries.
*/
static inline int is_timeout_in_range(int32_t orig_ticks, int32_t expected)
{
int32_t diff = sys_tick_get() - orig_ticks;
#if SHORT_TIMEOUTS
/*
* This should be the real test: however, there is an issue with the
* Jenkins auto-builders and QEMU for ARM, where (it seems) if the
* builder is overloaded, they do not give enough time to a QEMU instance
* so the Zephyr ticker can increment multiple times (so the interrupt
* handling happens) before the regular processing does occur, which gives
* the impression that more ticks have elapsed than expected.
*/
if (diff != expected && diff != expected + 1) {
TC_ERROR(" *** timeout skew: expected %d/%d, got %d\n",
expected, expected + 1, diff);
return 0;
}
/* TC_PRINT("timeout in range (%d vs %d)\n", diff, expected); */
return 1;
#else
return diff >= expected;
#endif
}
#endif /* _samples_include_tc_nano_timeout_common__h_ */