Commit Graph

34 Commits

Author SHA1 Message Date
Zhanglong Xia f64b7cc73c [test] add code spell check and correct wrong spelling (#9066) 2023-05-22 18:04:09 -07:00
Abtin Keshavarzian 99a615bec2 [clang-format] use AllowShortFunctionsOnASingleLine: All (#8502)
This commit updates `AllowShortFunctionsOnASingleLine` to `All`
from `InlineOnly`.
2022-12-08 09:34:05 -08:00
Jonathan Hui 9c467a23ae [clang-format] apply v14 changes (#8490) 2022-12-07 16:23:20 -08:00
Abtin Keshavarzian 7ec658e47a [common] add GetArrayLength() and GetArrayEnd() (#7413)
This commit adds two inline template functions to get the length of an
array and a pointer to the end of the array. These functions replace
similar macros that were used with OT core modules. The template
functions are safer to use since they would perform type checking at
compile time. The functions validate that the input variable is
indeed an array and unlike the macros they will not work with a
pointer variable.
2022-02-14 14:03:23 -08:00
Abtin Keshavarzian 57ade714a6 [test] simplify unit test platform implementation (#6966)
This commit simplifies `test_platform` module which defines the
platform APIs used by unit tests. It removes the unused global
variables and the function pointer mechanism to override platform
APIs. Instead the platform APIs in `test_platform` are defined as
`OT_TOOL_WEAK` allowing individual tests to override any of the
default implementation with their own version (e.g. `test_timer`
provides its own alarm platform APIs).
2021-08-30 12:07:17 -07:00
Abtin Keshavarzian f7fd2b0813 [timer] add RemoveAll() method for use by unit test (#6814)
This commit adds a new static method `Timer::RemoveAll()` which
removes all running timers from the `Scheduler`. This method is only
intended for use by by `test_timer` unit test, allowing it to remove
any timers that may be started from constructors of different objects
in an OT instance before starting the unit test. With this change, we
can have timers started from constructors.

To ensure that the `RemoveAll()` is only used by the unit test, it is
defined as a `protected` method which can still be used in the test
which defines and uses `TestTimer` as a sub-class of `Timer`.
2021-07-14 12:10:21 -07:00
Abtin Keshavarzian 57d072d352 [test] enhance {Verify/Success}OrQuit() and their use in unit test (#6764)
This commit updates `VerifyOrQuit()` and `SuccessOrQuit()` macros to
include the failed condition in the error message that is printed on
a failure (in addition to function name and line number where the
error happened). This commit also changes the second parameter
(`aMessage`) to in these macros to be optional.

This commit also updates unit tests to remove the second `aMessage`
string in cases where the failure can be inferred from the condition
itself.
2021-06-28 11:38:10 -07:00
Simon Lin 9fb778089b [locator] remove OwnerLocator class (#6138)
This commit removes the OwnerLocator class since it's actually
useless.

Timer and Tasklet inherited from OwnerLocator to so that they can use
GetOwner<Type>() to find the owner object. However, these two classes
already inherited from InstanceLocator, thus can use Get<Type>() to
get any component of the OT instance.
2021-02-04 21:29:43 -08:00
Jonathan Hui 4ac6e5509c [clang-tidy] google-explicit-constructor (#5734) 2020-10-29 08:37:31 -07:00
Simon Lin 5e9b2818eb [style] convert to C++11 for loops (#5263) 2020-07-21 09:41:40 -07:00
Jonathan Hui 1326d64a64 [style] replace NULL with nullptr (#5109) 2020-06-17 22:44:54 -07:00
Yakun Xu 2b9e8facba [test] cover micro timer in unittest (#5030) 2020-06-01 22:05:42 -07:00
Abtin Keshavarzian f10c6c36fd [unit-test] remove (unnecessary) ENABLE_TEST_MAIN definition (#4367) 2019-12-11 09:16:48 -08:00
Abtin Keshavarzian ab27fcd9e6 [unit-test] remove extra \n at end of error message (#4367)
This commit removes the extra `\n` at the end of error message strings
used in `VerifyOrQuit()` or `SuccessOrQuit()` macros in different unit
test modules. This help make the style (usage of macros) consistent
across all unit tests.
2019-12-11 09:16:48 -08:00
Abtin Keshavarzian aab693f9c3 [timer] add helper methods for common timer use patterns and simplify code (#4243)
This commit adds helper methods in `Timer` class which cover commonly
repeated use patterns by other modules.

Method `FireAt()` allows a timer to be started with a given fire time.
`FireAtIfEarlier()` (re-)schedules the timer with a given a fire time
only if the timer is not running or if the new given fire time is
earlier than the current fire time.

Modules mle, coap, ip6-mpl, joiner-router, dns-clinet, and sntp-client
are updated to use the new methods.
2019-11-07 04:45:34 -08:00
Abtin Keshavarzian 4feadec950 [time] adding Time class (#4195)
This commit adds `Time` class which represents an instance of time
(it is a simple wrapper over a `uint32_t` corresponding to a
numerical time value). The `Time` class provides helpful operator
overloads:
- Operators `+` and `-` with a `Time` instance and a `Duration` to
  get a `Time` instance after or before.
- Operator `-` with two `Time` instances to calculate the `Duration`
  duration between two time instances.
- Operators `<`, `<=`, `>`,'>=', '==' and `!=` to compare two `Time`
  instances. They correctly handle the wrapping of numeric time value.

The core modules are updated to use the new `Time` and `Duration`
types which help make the code simpler. This commit also updates the
 unit test `test_timer` to add test cases for newly added types.
2019-10-04 15:35:53 -07:00
Abtin Keshavarzian 2abd7a2822 [code-utils] adding helper macro OT_ARRAY_LENGTH() (#2743)
This commit adds helper macro `OT_ARRAY_LENGTH()` to get the number
of elements in an array.
2018-05-29 15:53:53 -07:00
Jonathan Hui 69d98d4a53 [code-style] apply clang-format 2018-02-09 21:43:42 +00:00
Abtin Keshavarzian 02c876ef62 [instance] define ot::Instance class (#2307)
This commit makes the following changes: It defines the public
`otInstance` as an empty opaque structure which is used by all public
C OpenThread APIs. It defines a new class `ot::Instance` (inheriting
from `otInstance) which is then used in core source files. The
functionality related to the instance is also moved/added into the
newly added `Instance` class (as class/static or member methods).
2017-11-13 08:27:57 -08:00
Abtin Keshavarzian fc72e4e719 [instance-locator] use instance reference instead of pointer (#2007)
This commit changes the `InstanceLocator` class to keep track of a
reference to `otInstance` (instead of a pointer) to make it behave
similar to other `ObjectLocator` classes. The method `GetInstance()`
in all locator objects is updated to provide a reference (instead
of a pointer) to `otInstance`.

The logging macros are updated such that a reference to `otInstance`
is passed as the first argument (with the exception of
`otLog<Level>Plat()` macros which are used by platform code in C
domain). The documentation for log macros are also updated.
2017-07-25 15:06:14 -07:00
Buke Po e14598c680 [scheduler] move schedulers into otInstance (#1997) 2017-07-14 16:23:22 -07:00
Shu Chen 129c419107 [timer] multiple microseconds timer support (#1962)
* [timer] multiple microseconds timer support

* Remove TimerSchedulerLocator, Timer inherit from Ip6Locator instead to get TimerScheduler.

* Add separate UsecTimer and UsecTimerScheduler for multiple microseconds timer support.

* [timer] refine Timer names

* Rename alarm header files to alarm-milli.h and alarm-micro.h

* Rename alarm APIs to start with otPlatAlarmMilli and otPlatAlarmMicro

* Rename Timer classes to TimerMilli/TimerMilliScheduler and TimerMicro/TimerMicroScheduler

* [Timer] Refactor Timer code structure

* Create TimerBase and TimerSchedulerBase class for common functions;

* Use TimerMilli/TimerMicro and TimerMilliScheduler/TimerMicroScheduler for different functions;

* Define AlarmApi, so then TimerMilliScheduler/TimerMicroScheduler could use different AlarmApi.
2017-07-10 16:01:27 -07:00
Abtin Keshavarzian bbab3074ed [instance] single OpenThread instance optimizations (#1926)
This commit new configuration option `enable-multiple-instances` and
its corresponding option `OPENTHREAD_ENABLE_MULTIPLE_INSTANCES`. When
enabled OpenThread supports handling of multiple instances. By default
this is disabled.

This commit also adds two optimizations for single instance case to
simplify the code and also help reduce memory/RAM usage:

(1) OpenThread objects/classes typically keep a reference to a higher
level object (e.g., many classes keep track of owning `ThreadNetif`)
to be able to access other objects/methods within OpenThread class
hierarchy. In single instance mode, the reference member variables are
removed and instead global functions are used to access the singleton
objects from one class to the other. To implement this, a group of
`<Object>Locator` classes are defined (e.g., `ThreadNetifLocator`,
etc.) which are then used as base class of other OpenThread classes.

(2) OpenThread objects which provide a callback/handler (e.g.,
`Timer`, `Tasklet`, etc.) have `void *mContext` member variable which
is used to keep track of the owner of the object. In single instance
mode the `mConext` member variables are removed since the owner is
expected to be a singleton and can be uniquely determined from the
callback function.

To implement this, two changes are made: First the handler methods are
modified to provide a reference to the object (e.g., `Timer` handler
will provide a `Timer &aTimer` as a parameter of its handler
callback). Second, a new base class `Context` is introduced which
hides the implementation providing an arbitrary context information. A
new static method `GetOwner(aContext)` is added to classes which own a
callback providing objects. This method help convert a `Context` to
the reference of the owner class object.
2017-06-30 11:48:26 -07:00
Abtin Keshavarzian c99b4fb921 Timer: Make Timer implementation robust against late firing platform alarm (#1917)
This commit changes the timer code to make the implementation robust
against late firing platform alarm case. In particular, it addresses
the (rare corner-case) scenario where alarm fire is late and the head
timer in the linked-list is already expired and then a new timer is
started with maximum interval. This can possibly violate the
requirement for `TimerScheduler::IsStringlyBefore()` method that the
two times being compared should not differ more than the maximum
interval `Timer::kMaxDt`. To address this, a new method
`Timer::DoesFireBefore()` is added to compare fire time of two timers
which checks for expired timers.

This commit also updates the timer unit test to add test cases related
to the late firing alarm.
2017-06-21 00:14:33 -07:00
Abtin Keshavarzian f067d68f38 Timer: Modify timer implementation to store fire time (#1904)
This commit changes the `Timer` class to store the fire time instead
of start time and duration. This simplifies the `Timer` implementation
and reduces the size of a `Timer` instance. The `test_timer` unit test
is also updated to add new test cases to verify correct timer behavior
during 32-bit timer wrap.

This commit also simplifies the key rotation implementation in
`KeyManager` class. Since the key rotation time and guard time are
provided in hours unit and can span multiple days, the code tracks
number of hours since last key rotation in `mHoursSinceKeyRotation`
(using a one hour interval timer). This is then used to decide when/if
to change the key sequence.
2017-06-16 09:28:52 -07:00
Jonathan Hui fbfd76a990 Apply #include code style. (#1723) 2017-05-05 11:28:29 -07:00
Jonathan Hui 1eabda6a08 Change top-level namespace from 'Thread' to 'ot'. (#1664) 2017-04-27 22:29:05 -07:00
Nick Banks 82e85a7300 Some Very Simple Fuzz Testing (#901)
* Add initial 'dump' fuzzing for radio receive.
2016-11-04 14:53:07 -07:00
Nick Banks 79d99e7a91 Refactor OpenThread Global Variables into a Single Context Structure (#357)
* Refactor OpenThread to contain all global/static variables in a single context structure.
2016-10-04 15:23:25 -07:00
Nick Banks 25cea9414b Windows Unit Test Support (#629)
Window Unit Test Support
2016-09-20 18:11:19 -07:00
Jonathan Hui 44350178ad Change copyright to The OpenThread Authors. (#583)
- Add a top-level file named AUTHORS which identifies the copyright
holders of the project.
2016-09-13 15:57:11 -07:00
Nick Banks ffbe65c6dd otInstance Declarations (#473)
* Add otInstance type declaration and update ot APIs to take it as input.
2016-09-12 14:29:43 -07:00
Jonathan Hui 32b6d343c4 Remove globals from timer.cpp. 2016-09-07 13:30:22 -07:00
pvanhorn ba0955a030 Timer logic improvements. (#96)
* Change timer logic to always fire the earliest timer first. Add unit tests for OT timers.

* Fix formatting error.

* Fix format errors.
2016-06-01 12:17:59 -07:00