2 * Copyright 2010-2016 Nest Labs Inc. All Rights Reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 * This file defines macros and interfaces for performing both
21 * compile- and run-time assertion checking and run-time
24 * Where exception-handing is concerned, the format of the macros
25 * are inspired by those found in Mac OS Classic and, later, Mac
26 * OS X. These, in turn, were inspired by "Living In an
27 * Exceptional World" by Sean Parent (develop, The Apple
28 * Technical Journal, Issue 11, August/September 1992)
29 * <http://www.mactech.com/articles/develop/issue_11/Parent_final.html>
30 * for the methodology behind these error handling and assertion
38 * @section introduction Introduction
40 * This package defines macros and interfaces for performing both
41 * compile- and run-time assertion checking and run-time exception
44 * Where exception-handing is concerned, the format of the macros are
45 * inspired by those found in Mac OS Classic and, later, Mac OS
46 * X. These, in turn, were inspired by "Living In an Exceptional
47 * World" by Sean Parent (develop, The Apple Technical Journal, Issue
48 * 11, August/September 1992). See:
50 * http://www.mactech.com/articles/develop/issue_11/Parent_final.html
52 * for the methodology behind these error handling and assertion
55 * @section overview Overview
57 * The interfaces in this package come in two interface modalities:
60 * <dt>[Run-time](@ref run-time)</dt>
61 * <dd>Interfaces that dynamically check a logical assertion and
62 * alter run-time execution on assertion firing.</dd>
63 * <dt>[Compile-time](@ref compile-time)</dt>
64 * <dd>Interfaces that statically check a logical assertion and
65 * terminate compile-time execution on assertion firing.</dd>
68 * @subsection run-time Run-time
70 * The [run-time modality interfaces](@ref run-time-interfaces) in
71 * this package come in three families:
74 * <dt>[Assertion](@ref run-time-assertions)</dt>
75 * <dd>Similar to the traditional C Standard Library
76 * [assert()](http://pubs.opengroup.org/onlinepubs/009695399/functions/assert.html).</dd>
78 * <dt>[Precondition](@ref preconditions)</dt>
79 * <dd>Designed to be placed at the head of an interface or
80 * method to check incoming parameters and return on
81 * assertion failure.</dd>
83 * <dt>[Exception](@ref exceptions)</dt>
84 * <dd>Designed to jump to a local label on assertion failure
85 * to support the method of error and exception handling that
86 * advocates a single function or method return site and, by
87 * extension, consolidated points of exception and error
88 * handling as well as resource clean-up.</dd>
91 * There are several styles of interfaces within each family and
92 * several potential variants within each style, all of which are
93 * summarized below and are described in detail in the following
96 * @subsection compile-time Compile-time
98 * The [compile-time modality interfaces](@ref compile-time-interfaces)
99 * in this package are simpler and come in a single family with a
100 * couple of variants.
102 * @section run-time-interfaces Run-time Interfaces
104 * @subsection triggers Behavior Triggers
106 * Unlike the traditional C Standard Library
107 * [assert()](http://pubs.opengroup.org/onlinepubs/009695399/functions/assert.html)
108 * or other assertion checking packages, this package offers the
109 * ability to enable and customize one or more of a few triggers that
110 * run when an assertion fires, including:
112 * * [Abort](@ref abort-behavior)
113 * * [Backtrace](@ref backtrace-behavior)
114 * * [Log](@ref log-behavior)
115 * * [Trap](@ref trap-behavior)
117 * @subsubsection abort-behavior Abort
119 * The abort behavior trigger allows, on an assertion firing, to
120 * execute a trigger that terminates overall program or system
123 * Note, however, the abort behavior trigger is only available in
124 * some styles of the [assertion-family](@ref run-time-assertions) of
127 * Please see #NL_ASSERT_ABORT() and @ref customization for more
128 * information about this behavior trigger.
130 * @subsubsection backtrace-behavior Backtrace
132 * The backtrace behavior trigger allows, on an assertion firing, to
133 * execute a trigger that generates a stack backtrace.
135 * This style of assertion is available, when configured, on all
136 * interface families.
138 * Please see #NL_ASSERT_BACKTRACE() and @ref customization for more
139 * information about this behavior trigger.
141 * @subsubsection log-behavior Log
143 * The log behavior trigger allows, on an assertion firing, to
144 * execute a trigger that logs a message summarizing the assertion
147 * This style of assertion is available, when configured, on all
148 * interface families.
150 * Please see #NL_ASSERT_LOG() and @ref customization for more
151 * information about this behavior trigger.
153 * @subsubsection trap-behavior Trap
155 * The log behavior trigger allows, on an assertion firing, to
156 * execute a trigger that generates a debugger trap or exception.
158 * This style of assertion is available, when configured, on all
159 * interface families.
161 * Please see #NL_ASSERT_TRAP() and @ref customization for more
162 * information about this behavior trigger.
164 * @subsection run-time-assertions Assertion Interfaces
166 * The assertion interfaces are similar to the traditional C
168 * [assert()](http://pubs.opengroup.org/onlinepubs/009695399/functions/assert.html).
170 * These interfaces include the following styles:
172 * * [Assert](@ref run-time-assert)
173 * * [Abort](@ref run-time-abort)
174 * * [Check](@ref run-time-check)
175 * * [Verify](@ref run-time-verify)
177 * The following table summarizes the relationship and features among
182 * <th rowspan="2">Style</th>
183 * <th colspan="4">Behaviors</th>
184 * <th colspan="2">Availability</th>
191 * <th>Non-production</th>
192 * <th>Production</th>
196 * <td align="center">Non-production</td>
197 * <td align="center">Non-production</td>
198 * <td align="center">Non-production</td>
199 * <td align="center"></td>
200 * <td align="center">X</td>
201 * <td align="center"></td>
205 * <td align="center">X</td>
206 * <td align="center">X</td>
207 * <td align="center">X</td>
208 * <td align="center"></td>
209 * <td align="center">X</td>
210 * <td align="center">X</td>
214 * <td align="center"></td>
215 * <td align="center">Non-production</td>
216 * <td align="center">Non-production</td>
217 * <td align="center">Non-production</td>
218 * <td align="center">X</td>
219 * <td align="center"></td>
223 * <td align="center"></td>
224 * <td align="center">X</td>
225 * <td align="center">X</td>
226 * <td align="center">Non-production</td>
227 * <td align="center">X</td>
228 * <td align="center">X</td>
232 * @note The above described behaviors are only in effect when
233 * #NL_ASSERT_USE_FLAGS_DEFAULT to 1. See @ref customization
234 * for more information on configuring and customizing the
237 * @subsubsection run-time-assert Assert
239 * These assertions are identical to the traditional C Standard
240 * Library-style assertion (see
241 * [assert()](http://pubs.opengroup.org/onlinepubs/009695399/functions/assert.html))
242 * except that side-effects, if any, in the asserted expression will be
243 * produced even when the assertion is made inactive, as in production build
244 * configurations, by setting #NL_ASSERT_PRODUCTION to true.
246 * Like the C Standard Library assertion, a trigger of this style of
247 * assertion interface will invoke #NL_ASSERT_ABORT().
249 * @subsubsection run-time-abort Abort
251 * These assertions are identical to the @ref run-time-assert style
252 * assertions; however, they are active in __both__ non-production
253 * __and__ production build configurations.
255 * A trigger of this style of assertion interface will invoke #NL_ASSERT_ABORT().
257 * @subsubsection run-time-check Check
259 * These assertions are similar to the @ref run-time-assert style; however,
260 * this style __does not__ abort. Normal program flow and execution
261 * will continue past this assertion.
263 * Side-effects, if any, in the asserted expression will be produced even when
264 * the assertion is made inactive, as in production build configurations, by
265 * setting #NL_ASSERT_PRODUCTION to true.
267 * @subsubsection run-time-verify Verify
269 * These assertions are similar to the @ref run-time-abort style; however,
270 * this style __does not__ abort. Normal program flow and execution
271 * will continue past this assertion.
273 * These are active in __both__ non-production __and__ production
274 * build configurations.
276 * @subsection preconditions Precondition Interfaces
278 * These assertions are designed to be placed at the head of an
279 * interface or method to check incoming parameters.
281 * These assertions implicitly return, either void or a specified
282 * value for non-void interfaces or methods.
284 * @note This family of interfaces may be in violation of your site's
285 * or project's coding style and best practices by virtue of its
286 * implicit return. If so, please consider using the
287 * [exception-style](@ref exceptions) interfaces instead.
289 * The following table summarizes the features for this family of interfaces:
293 * <th rowspan="2">Style</th>
294 * <th colspan="4">Behaviors</th>
295 * <th colspan="2">Availability</th>
302 * <th>Non-production</th>
303 * <th>Production</th>
306 * <td>Precondition</td>
307 * <td align="center"></td>
308 * <td align="center">X</td>
309 * <td align="center">X</td>
310 * <td align="center"></td>
311 * <td align="center">X</td>
312 * <td align="center">X</td>
316 * @note The above described behaviors are only in effect when
317 * #NL_ASSERT_USE_FLAGS_DEFAULT to 1. See @ref customization
318 * for more information on configuring and customizing the
321 * @subsection exceptions Exception Interfaces
323 * This family of interfaces is designed to support the method of
324 * error and exception handling that advocates a single function or
325 * method return site and, by extension, consolidated points of
326 * exception and error handling as well as resource clean-up.
328 * A general example usage of this family of interfaces is:
331 * int Bar(uint8_t **aBuffer, const Foo *aParameter)
333 * const size_t size = 1024;
336 * nlREQUIRE(aBuffer != NULL, exit, retval = -EINVAL);
338 * *aBuffer = (uint8_t *)malloc(size);
339 * nlREQUIRE(*aBuffer != NULL, exit, retval = -ENOMEM);
341 * memset(*aBuffer, 0, size);
348 * As shown in the example, this family checks for the specified
349 * condition, which is expected to commonly be true, and branches to
350 * the specified label if the condition is false.
352 * * [Expect](@ref expect)
353 * * [Desire](@ref desire)
354 * * [Require](@ref require)
356 * This family of interfaces are all identical across the styles and
357 * all styles support an identical set of variants. The only
358 * difference among them is the default configured trigger action
359 * behavior, as summarized in the table below:
363 * <th rowspan="2">Style</th>
364 * <th colspan="3">Behaviors</th>
365 * <th colspan="2">Availability</th>
371 * <th>Non-production</th>
372 * <th>Production</th>
379 * <td align="center">X</td>
380 * <td align="center">X</td>
385 * <td align="center">Non-production</td>
387 * <td align="center">X</td>
388 * <td align="center">X</td>
392 * <td align="center">X</td>
393 * <td align="center">X</td>
394 * <td align="center">Non-production</td>
395 * <td align="center">X</td>
396 * <td align="center">X</td>
400 * @note The above described behaviors are only in effect when
401 * #NL_ASSERT_USE_FLAGS_DEFAULT to 1. See @ref customization
402 * for more information on configuring and customizing the
405 * @subsubsection expect Expect
407 * These assertions are designed to be placed anywhere an exceptional
408 * condition might occur where handling needs to locally jump to
409 * error-handling code.
411 * These checks are always present and do nothing beyond branching to
412 * the named exception label. Consequently, they are simply mnemonics
413 * or syntactic sugar.
415 * This style of check should be used where either true or false
416 * evaluation of the assertion expression are equally likely since
417 * there is no default configured trigger behavior.
419 * __Anticipated Assertion Firing Frequency:__ Frequent
421 * @subsubsection desire Desire
423 * These are identical to the @ref expect style checks; except for
424 * their non-production and production configured behavior.
426 * This style of check should be used where false evaluation of the
427 * assertion expression is expected to be occasional.
429 * __Anticipated Assertion Firing Frequency:__ Occasional
431 * @subsubsection require Require
433 * These are identical to the @ref expect style checks; except for
434 * their non-production and production configured behavior.
436 * This style of check should be used where false evaluation of the
437 * assertion expression is expected to be rare.
439 * __Anticipated Assertion Firing Frequency:__ Rare
441 * @subsection variants Variants
443 * The three families of run-time interface are available in one of several
444 * variants, as summarized below. <em><STYLE></em> may be replaced with one of (see [Run-time Availability](@ref run-time-availability) for details):
455 * to form an actual interface name.
457 * | Interface Variant | Description |
458 * |:---------------------------------------------- |:------------------------------------------------------------------------------------------------------------ |
459 * | nl<em><STYLE></em> | Base variant; execute the check. |
460 * | nl<em><STYLE></em>\_ACTION | Execute the base check and execute the action if the check fails. |
461 * | nl<em><STYLE></em>\_PRINT | Execute the base check and print the descriptive string if the check fails. |
462 * | nl<em><STYLE></em>\_ACTION_PRINT | Execute the base check and both execute the action and print the descriptive string if the check fails. |
463 * | nl<em><STYLE></em>\_SUCCESS | Adds a check against zero (0) as the logical condition to assert. |
464 * | nl<em><STYLE></em>\_SUCCESS_ACTION | Execute the success check and execute the action if the check fails. |
465 * | nl<em><STYLE></em>\_SUCCESS_PRINT | Execute the success check and print the descriptive string if the check fails. |
466 * | nl<em><STYLE></em>\_SUCCESS_ACTION_PRINT | Execute the success check and both execute the action and print the descriptive string if the check fails. |
467 * | nlN<em><STYLE></em> | Inverts the logical sense of the base check; execute the check. |
468 * | nlN<em><STYLE></em>\_ACTION | Execute the inversion check and execute the action if the check fails. |
469 * | nlN<em><STYLE></em>\_PRINT | Execute the inversion check and print the descriptive string if the check fails. |
470 * | nlN<em><STYLE></em>\_ACTION_PRINT | Execute the inversion check and both execute the action and print the descriptive string if the check fails. |
472 * @section run-time-availability Run-time Availability
474 * The following table indicates the availability of the run-time interface
475 * variants for each style.
479 * <th rowspan="2">Interface Variant</th>
480 * <th colspan="8">Style</th>
487 * <th>Precondition</th>
493 * <td>nl<em><STYLE></em></td>
494 * <td align="center">X</td>
495 * <td align="center">X</td>
496 * <td align="center">X</td>
497 * <td align="center">X</td>
498 * <td align="center">X</td>
499 * <td align="center">X</td>
500 * <td align="center">X</td>
501 * <td align="center">X</td>
504 * <td>nl<em><STYLE></em>\_ACTION</td>
505 * <td align="center">X</td>
506 * <td align="center">X</td>
507 * <td align="center">X</td>
508 * <td align="center">X</td>
509 * <td align="center">X</td>
510 * <td align="center">X</td>
511 * <td align="center">X</td>
512 * <td align="center">X</td>
515 * <td>nl<em><STYLE></em>\_PRINT</td>
516 * <td align="center"></td>
517 * <td align="center"></td>
518 * <td align="center">X</td>
519 * <td align="center">X</td>
520 * <td align="center">X</td>
521 * <td align="center">X</td>
522 * <td align="center">X</td>
523 * <td align="center">X</td>
526 * <td>nl<em><STYLE></em>\_ACTION_PRINT</td>
527 * <td align="center"></td>
528 * <td align="center"></td>
529 * <td align="center"></td>
530 * <td align="center"></td>
531 * <td align="center"></td>
532 * <td align="center">X</td>
533 * <td align="center">X</td>
534 * <td align="center">X</td>
537 * <td>nl<em><STYLE></em>\_SUCCESS</td>
538 * <td align="center"></td>
539 * <td align="center"></td>
540 * <td align="center">X</td>
541 * <td align="center">X</td>
542 * <td align="center">X</td>
543 * <td align="center">X</td>
544 * <td align="center">X</td>
545 * <td align="center">X</td>
548 * <td>nl<em><STYLE></em>\_SUCCESS_ACTION</td>
549 * <td align="center"></td>
550 * <td align="center"></td>
551 * <td align="center">X</td>
552 * <td align="center">X</td>
553 * <td align="center">X</td>
554 * <td align="center">X</td>
555 * <td align="center">X</td>
556 * <td align="center">X</td>
559 * <td>nl<em><STYLE></em>\_SUCCESS_PRINT</td>
560 * <td align="center"></td>
561 * <td align="center"></td>
562 * <td align="center">X</td>
563 * <td align="center">X</td>
564 * <td align="center">X</td>
565 * <td align="center">X</td>
566 * <td align="center">X</td>
567 * <td align="center">X</td>
570 * <td>nl<em><STYLE></em>\_SUCCESS_ACTION_PRINT</td>
571 * <td align="center"></td>
572 * <td align="center"></td>
573 * <td align="center"></td>
574 * <td align="center"></td>
575 * <td align="center"></td>
576 * <td align="center">X</td>
577 * <td align="center">X</td>
578 * <td align="center">X</td>
581 * <td>nlN<em><STYLE></em></td>
582 * <td align="center"></td>
583 * <td align="center"></td>
584 * <td align="center">X</td>
585 * <td align="center">X</td>
586 * <td align="center">X</td>
587 * <td align="center">X</td>
588 * <td align="center">X</td>
589 * <td align="center">X</td>
592 * <td>nlN<em><STYLE></em>\_ACTION</td>
593 * <td align="center"></td>
594 * <td align="center"></td>
595 * <td align="center">X</td>
596 * <td align="center">X</td>
597 * <td align="center">X</td>
598 * <td align="center">X</td>
599 * <td align="center">X</td>
600 * <td align="center">X</td>
603 * <td>nlN<em><STYLE></em>\_PRINT</td>
604 * <td align="center"></td>
605 * <td align="center"></td>
606 * <td align="center">X</td>
607 * <td align="center">X</td>
608 * <td align="center">X</td>
609 * <td align="center">X</td>
610 * <td align="center">X</td>
611 * <td align="center">X</td>
614 * <td>nlN<em><STYLE></em>\_ACTION_PRINT</td>
615 * <td align="center"></td>
616 * <td align="center"></td>
617 * <td align="center"></td>
618 * <td align="center"></td>
619 * <td align="center"></td>
620 * <td align="center">X</td>
621 * <td align="center">X</td>
622 * <td align="center">X</td>
626 * @section customization Customization
628 * The Nest Labs Assertion library is designed "out of the box" to
629 * provide a high degree of utility. However, there are a number of
630 * aspects that can be tuned on a per-module, -project, or -site basis
631 * to customize the appearance and behavior through user-definable
632 * attributes via the C preprocessor.
634 * @subsection userattrs User-definable Attributes
636 * The following attributes may be defined by the user before
637 * the nlassert.h header is included by the preprocessor, overriding
638 * the default behavior:
640 * * #NL_ASSERT_PRODUCTION
641 * * #NL_ASSERT_PREFIX_STRING
642 * * #NL_ASSERT_COMPONENT_STRING
645 * * #NL_ASSERT_BACKTRACE
649 * Without any customization, all of the interface styles are set to
650 * use __no__ trigger behaviors (i.e. #NL_ASSERT_FLAG_NONE). However, a
651 * set of default trigger behaviors (as documented in the tables
652 * above) may be enabled by setting #NL_ASSERT_USE_FLAGS_DEFAULT to 1
653 * before nlassert.h is included by the preprocessor.
655 * Otherwise, the following attributes may be overridden, customizing
656 * the trigger behavior of each assertion interface family for both
657 * non-production and production configurations:
659 * * #NL_ASSERT_EXPECT_FLAGS
661 * * #NL_ASSERT_CHECK_NONPRODUCTION_FLAGS
662 * * #NL_ASSERT_VERIFY_NONPRODUCTION_FLAGS
663 * * #NL_ASSERT_ASSERT_NONPRODUCTION_FLAGS
664 * * #NL_ASSERT_ABORT_NONPRODUCTION_FLAGS
665 * * #NL_ASSERT_DESIRE_NONPRODUCTION_FLAGS
666 * * #NL_ASSERT_REQUIRE_NONPRODUCTION_FLAGS
667 * * #NL_ASSERT_PRECONDITION_NONPRODUCTION_FLAGS
669 * * #NL_ASSERT_VERIFY_PRODUCTION_FLAGS
670 * * #NL_ASSERT_ABORT_PRODUCTION_FLAGS
671 * * #NL_ASSERT_DESIRE_PRODUCTION_FLAGS
672 * * #NL_ASSERT_REQUIRE_PRODUCTION_FLAGS
673 * * #NL_ASSERT_PRECONDITION_PRODUCTION_FLAGS
675 * @section compile-time-interfaces Compile-time Interfaces
677 * The compile-time interfaces are a limited subset of their run-time
678 * counterparts. Rather than altering run-time execution on assertion
679 * firing against a dynamically-checked run-time condition, these
680 * interfaces terminate compilation against a statically-checked
681 * compile-time condition.
683 * @subsection compile-time-assertions Assertion Interfaces
685 * These interfaces have only one style:
687 * * [Assert](@ref compile-time-assert)
691 * <th rowspan="2">Style</th>
692 * <th colspan="2">Availability</th>
695 * <th>Non-production</th>
696 * <th>Production</th>
700 * <td align="center">X</td>
701 * <td align="center">X</td>
705 * @subsubsection compile-time-assert Assert
707 * These assertions are active in __both__ non-production
708 * __and__ production build configurations. This behavior
709 * is unconventional with respect to the [run-time assert-style assertions](@ref run-time-assert)
710 * but very conventional with respect to the similar
711 * C11/C++11 static-assertion standards.
713 * @subsection compile-time-variants Variants
715 * The compile-time interfaces are available in two variants:
717 * | Interface Variant | Description |
718 * |:---------------------------------------------- |:------------------------------------------------------------------------------------------------------------ |
719 * | nlSTATIC\_ASSERT | Base variant; execute the check. |
720 * | nlSTATIC\_ASSERT\_PRINT | Execute the base check with a descriptive string. Note, this string is not actually emitted in any meaningful way. It serves to simply comment or annotate the assertion and to provide interface parallelism with the run-time assertion interfaces. |
722 * @section compile-time-availability Compile-time Availability
724 * The following table indicates the availability of the compile-time interface
729 * <th rowspan="2">Interface Variant</th>
730 * <th colspan="2">Availability</th>
733 * <th>Non-Production</th>
734 * <th>Production</th>
737 * <td>nlSTATIC\_ASSERT</td>
738 * <td align="center">X</td>
739 * <td align="center">X</td>
742 * <td>nlSTATIC\_ASSERT\_PRINT</td>
743 * <td align="center">X</td>
744 * <td align="center">X</td>
748 * @section compatibility Standard C Library Compatibility
750 * This package also provides an ISO/IEC 9899:1999-, C89-, and
751 * C99-compatible Standard C Library header (via assert.h) and
752 * assertion interface definition (assert()), implemented atop Nest
753 * Labs assertion checking and runtime exception interfaces such that
754 * consistent platform and system capabilities, behavior, and output
755 * may be implemented and enforced across the two interfaces.
757 * Systems wishing to use this compatibility header and interface in
758 * lieu of their Standard C Library header of the same name should
759 * ensure that their toolchain is configured to either ignore or
760 * deprioritize standard search paths while placing the directory this
761 * header is contained in among the preferred header search paths.
765 #ifndef NLCORE_NLASSERT_H
766 #define NLCORE_NLASSERT_H
773 * @name Behavioral Control Flags
776 * These flags are used to influence the behavior of the various
777 * classes and styles of assertion macros.
784 * @def NL_ASSERT_FLAG_NONE
787 * Perform no actions when an assertion expression evaluates to
790 * @sa #NL_ASSERT_FLAG_BACKTRACE
791 * @sa #NL_ASSERT_FLAG_LOG
792 * @sa #NL_ASSERT_FLAG_TRAP
795 #define NL_ASSERT_FLAG_NONE 0x00000000
798 * @def NL_ASSERT_FLAG_BACKTRACE
801 * Invoke #NL_ASSERT_BACKTRACE() when an assertion expression
802 * evaluates to false.
804 * @note For the *_ACTION*-style assertion variants,
805 * #NL_ASSERT_BACKTRACE() is a pre-action trigger and will run
806 * before the specified action.
808 * @sa #NL_ASSERT_FLAG_NONE
809 * @sa #NL_ASSERT_FLAG_LOG
810 * @sa #NL_ASSERT_FLAG_TRAP
812 * @sa #NL_ASSERT_BACKTRACE
815 #define NL_ASSERT_FLAG_BACKTRACE 0x00000001
818 * @def NL_ASSERT_FLAG_LOG
821 * Invoke #NL_ASSERT_LOG() when an assertion expression evaluates
824 * @note For the *_ACTION*-style assertion variants,
825 * #NL_ASSERT_LOG() is a pre-action trigger and will run
826 * before the specified action.
828 * @sa #NL_ASSERT_FLAG_NONE
829 * @sa #NL_ASSERT_FLAG_BACKTRACE
830 * @sa #NL_ASSERT_FLAG_TRAP
835 #define NL_ASSERT_FLAG_LOG 0x00000002
838 * @def NL_ASSERT_FLAG_TRAP
841 * Invoke #NL_ASSERT_TRAP() when an assertion expression evaluates
844 * @note For the *_ACTION*-style assertion variants,
845 * #NL_ASSERT_TRAP() is a post-action trigger and will run
846 * after the specified action.
848 * @sa #NL_ASSERT_FLAG_NONE
849 * @sa #NL_ASSERT_FLAG_BACKTRACE
850 * @sa #NL_ASSERT_FLAG_LOG
852 * @sa #NL_ASSERT_TRAP
855 #define NL_ASSERT_FLAG_TRAP 0x00000004
863 * @def NL_ASSERT_USE_FLAGS_DEFAULT
866 * Enable (1) or disable (0) use of the default trigger behavior flags.
868 * This enables or disables the use of the default trigger behavior
869 * flags as specified by:
871 * * #NL_ASSERT_EXPECT_FLAGS_DEFAULT
873 * * #NL_ASSERT_CHECK_NONPRODUCTION_FLAGS_DEFAULT
874 * * #NL_ASSERT_VERIFY_NONPRODUCTION_FLAGS_DEFAULT
875 * * #NL_ASSERT_ASSERT_NONPRODUCTION_FLAGS_DEFAULT
876 * * #NL_ASSERT_ABORT_NONPRODUCTION_FLAGS_DEFAULT
877 * * #NL_ASSERT_DESIRE_NONPRODUCTION_FLAGS_DEFAULT
878 * * #NL_ASSERT_REQUIRE_NONPRODUCTION_FLAGS_DEFAULT
879 * * #NL_ASSERT_PRECONDITION_NONPRODUCTION_FLAGS_DEFAULT
881 * * #NL_ASSERT_VERIFY_PRODUCTION_FLAGS_DEFAULT
882 * * #NL_ASSERT_ABORT_PRODUCTION_FLAGS_DEFAULT
883 * * #NL_ASSERT_DESIRE_PRODUCTION_FLAGS_DEFAULT
884 * * #NL_ASSERT_REQUIRE_PRODUCTION_FLAGS_DEFAULT
885 * * #NL_ASSERT_PRECONDITION_PRODUCTION_FLAGS_DEFAULT
887 * Setting this to 1, effectively does the following:
890 * #define NL_ASSERT_<STYLE>_<CONFIGURATION>_FLAGS NL_ASSERT_<STYLE>_<CONFIGURATION>_FLAGS_DEFAULT
893 * for each assertion interface <em><STYLE></em> for both
894 * non-production and production (see #NL_ASSERT_PRODUCTION) <em><CONFIGURATION></em> .
897 #if !defined(NL_ASSERT_USE_FLAGS_DEFAULT)
898 #define NL_ASSERT_USE_FLAGS_DEFAULT 0
899 #endif /* !defined(NL_ASSERT_USE_FLAGS_DEFAULT) */
902 * @def NL_ASSERT_PRODUCTION
905 * Enable (1) or disable (0) when production (or non-production)
906 * assertion behavior is desired.
908 * When production behavior is asserted, a number of interface
909 * families are elided entirely and for others, the default behavior
910 * changes (default: ((defined(NDEBUG) && NDEBUG) || (defined(DEBUG)
914 #if !defined(NL_ASSERT_PRODUCTION)
916 #define NL_ASSERT_PRODUCTION NDEBUG
918 #define NL_ASSERT_PRODUCTION !DEBUG
920 #define NL_ASSERT_PRODUCTION 1
921 #endif /* defined(NDEBUG) */
922 #endif /* !defined(NL_ASSERT_PRODUCTION) */
925 * @name Log Output Definitions
928 * These definitions control how the output of assertion log
929 * messages appear, when so configured, on assertion expression
930 * failure evaluation.
937 * @def NL_ASSERT_PREFIX_STRING
940 * This is the string printed at the beginning of the assertion
941 * printed (default: 'ASSERT: ').
943 * Developers may, but are generally not encouraged to, override
944 * this by defining #NL_ASSERT_PREFIX_STRING before nlassert.h is
945 * included by the preprocessor, as shown in the following example:
948 * #define NL_ASSERT_PREFIX_STRING "assertion: "
950 * #include <nlassert.h>
953 * @sa #NL_ASSERT_PREFIX_STRING
955 #if !defined(NL_ASSERT_PREFIX_STRING)
956 #define NL_ASSERT_PREFIX_STRING "ASSERT: "
957 #endif /* !defined(NL_ASSERT_PREFIX_STRING) */
960 * @def NL_ASSERT_COMPONENT_STRING
963 * This is the string printed following the prefix string (see
964 * #NL_ASSERT_PREFIX_STRING) that indicates what module, program,
965 * application or subsystem the assertion occurred in (default:
968 * Developers may override this by defining
969 * #NL_ASSERT_COMPONENT_STRING before nlassert.h is included by the
970 * preprocessor, as shown in the following example:
973 * #define NL_ASSERT_COMPONENT_STRING "nlbar"
975 * #include <nlassert.h>
978 * @sa #NL_ASSERT_PREFIX_STRING
981 #if !defined(NL_ASSERT_COMPONENT_STRING)
982 #define NL_ASSERT_COMPONENT_STRING ""
983 #endif /* !defined(NL_ASSERT_COMPONENT_STRING) */
991 * @def NL_ASSERT_ABORT()
994 * This macro is invoked when an nlASSERT- or nlABORT-style
995 * assertion expression evaluates to false.
997 * By default, this is defined to the C Standard Library
998 * [abort()](http://pubs.opengroup.org/onlinepubs/009695399/functions/abort.html). When
999 * overridden, this should generally provide similar functionality,
1000 * terminating the overall process or system execution.
1002 * Developers may override and customize this by defining
1003 * #NL_ASSERT_ABORT() before nlassert.h is included by the
1007 #if !defined(NL_ASSERT_ABORT)
1008 #define NL_ASSERT_ABORT() abort()
1009 #endif /* !defined(NL_ASSERT_ABORT) */
1012 * @def NL_ASSERT_BACKTRACE()
1015 * This macro is invoked when an assertion expression evaluates to
1016 * false when the macro has been configured with / passed
1017 * #NL_ASSERT_FLAG_BACKTRACE.
1019 * By default, this is defined to do nothing. However, when defined,
1020 * this should generally generate a stack back trace when invoked.
1022 * Developers may override and customize this by defining
1023 * #NL_ASSERT_BACKTRACE() before nlassert.h is included by the
1026 * @note For the *_ACTION*-style assertion variants,
1027 * #NL_ASSERT_BACKTRACE() is a pre-action trigger and will run
1028 * before the specified action.
1030 * @sa #NL_ASSERT_FLAG_BACKTRACE
1033 #if !defined(NL_ASSERT_BACKTRACE)
1034 #define NL_ASSERT_BACKTRACE()
1035 #endif /* !defined(NL_ASSERT_BACKTRACE) */
1038 * @def NL_ASSERT_TRAP()
1041 * This macro is invoked when an assertion expression evaluates to
1042 * false when the macro has been configured with / passed
1043 * #NL_ASSERT_FLAG_TRAP.
1045 * By default, this is defined to do nothing. However, when defined,
1046 * this should generally generate a debug trap or breakpoint such that
1047 * when the assertion expression evaluates to false an attached
1048 * debugger will stop at the assertion point.
1050 * Developers may override and customize this by defining
1051 * #NL_ASSERT_TRAP() before nlassert.h is included by the
1052 * preprocessor, as shown in the following example:
1055 * #if defined(__i386__) || defined(__x86_64__)
1056 * #define DEBUGGER_TRAP __asm__ __volatile__("int3")
1057 * #elif defined(__arm__)
1058 * #define DEBUGGER_TRAP __asm__ __volatile__("bkpt")
1061 * #define NL_ASSERT_TRAP() \
1064 * if (IsDebuggerAttached()) \
1070 * #include <nlassert.h>
1073 * @note For the *_ACTION*-style assertion variants,
1074 * #NL_ASSERT_TRAP() is a post-action trigger and will run
1075 * after the specified action.
1077 * @sa #NL_ASSERT_FLAG_TRAP
1080 #if !defined(NL_ASSERT_TRAP)
1081 #define NL_ASSERT_TRAP()
1082 #endif /* !defined(NL_ASSERT_TRAP) */
1085 * @def NL_ASSERT_LOG_FORMAT_DEFAULT
1088 * This is the NULL-terminated C string literal with C Standard
1089 * Library-style format specifiers used by #NL_ASSERT_LOG_DEFAULT.
1091 * This may be used by overrides to #NL_ASSERT_LOG that want to use a
1092 * consistent output formatting.
1094 * @sa #NL_ASSERT_LOG_DEFAULT
1097 #define NL_ASSERT_LOG_FORMAT_DEFAULT "%s%s%s%s, %s%sfile: %s, line: %d\n"
1100 * @def NL_ASSERT_LOG_DEFAULT(aPrefix, aName, aCondition, aLabel, aFile, aLine, aMessage)
1103 * This macro conforms to #NL_ASSERT_LOG and may be assigned to
1104 * #NL_ASSERT_LOG, as shown in the following example, to display an
1105 * assertion message when the assertion triggers, via the C
1106 * Standard I/O Library error stream.
1109 * #define NL_ASSERT_LOG(aPrefix, aName, aCondition, aLabel, aFile, aLine, aMessage) \
1110 * NL_ASSERT_LOG_DEFAULT(aPrefix, aName, aCondition, aLabel, aFile, aLine, aMessage)
1112 * #include <nlassert.h>
1115 * @param[in] aPrefix A pointer to a NULL-terminated C string printed
1116 * at the beginning of the logged assertion
1117 * message. Typically this is and should be
1118 * #NL_ASSERT_PREFIX_STRING.
1119 * @param[in] aName A pointer to a NULL-terminated C string printed
1120 * following @p aPrefix that indicates what
1121 * module, program, application or subsystem
1122 * the assertion occurred in Typically this
1124 * #NL_ASSERT_COMPONENT_STRING.
1125 * @param[in] aCondition A pointer to a NULL-terminated C string indicating
1126 * the expression that evaluated to false in
1127 * the assertion. Typically this is a
1128 * stringified version of the actual
1129 * assertion expression.
1130 * @param[in] aLabel An optional pointer to a NULL-terminated C string
1131 * indicating, for exception-style
1132 * assertions, the label that will be
1133 * branched to when the assertion expression
1134 * evaluates to false.
1135 * @param[in] aFile A pointer to a NULL-terminated C string indicating
1136 * the file in which the exception
1137 * occurred. Typically this is and should be
1138 * \_\_FILE\_\_ from the C preprocessor or
1140 * @param[in] aLine The line number in @p aFile on which the assertion
1141 * expression evaluated to false. Typically
1142 * this is and should be \_\_LINE\_\_ from the C
1144 * @param[in] aMessage An optional pointer to a NULL-terminated C string
1145 * containing a caller-specified message
1146 * further describing the assertion failure.
1148 * @sa #NL_ASSERT_LOG
1150 * @sa #NL_ASSERT_FLAG_LOG
1152 * @sa #NL_ASSERT_PREFIX_STRING
1153 * @sa #NL_ASSERT_COMPONENT_STRING
1154 * @sa #NL_ASSERT_LOG_FORMAT_DEFAULT
1156 * @sa #NL_ASSERT_FILE
1159 #define NL_ASSERT_LOG_DEFAULT(aPrefix, aName, aCondition, aLabel, aFile, aLine, aMessage) \
1163 NL_ASSERT_LOG_FORMAT_DEFAULT, \
1165 (((aName) == 0) || (*(aName) == '\0')) ? "" : aName, \
1166 (((aName) == 0) || (*(aName) == '\0')) ? "" : ": ", \
1168 ((aMessage == 0) ? "" : aMessage), \
1169 ((aMessage == 0) ? "" : ", "), \
1175 * @def NL_ASSERT_LOG(aPrefix, aName, aCondition, aLabel, aFile, aLine, aMessage)
1178 * This macro is invoked when an assertion expression evaluates to
1179 * false when the macro has been configured with / passed
1180 * #NL_ASSERT_FLAG_LOG.
1182 * This is intended to display a message, to an appropriate log stream, informing the developer where the assertion was and what expression failed, similar to:
1184 * "ASSERT: MyComponent: aPointer != NULL, bad pointer, file: foo.c, line: 453"
1186 * Developers may override and customize this by defining
1187 * #NL_ASSERT_LOG() before nlassert.h is included by the
1190 * @note For the *_ACTION*-style assertion variants, #NL_ASSERT_LOG()
1191 * is a pre-action trigger and will run before the specified action.
1193 * @param[in] aPrefix A pointer to a NULL-terminated C string printed
1194 * at the beginning of the logged assertion
1195 * message. Typically this is and should be
1196 * #NL_ASSERT_PREFIX_STRING.
1197 * @param[in] aName A pointer to a NULL-terminated C string printed
1198 * following @p aPrefix that indicates what
1199 * module, program, application or subsystem
1200 * the assertion occurred in Typically this
1202 * #NL_ASSERT_COMPONENT_STRING.
1203 * @param[in] aCondition A pointer to a NULL-terminated C string indicating
1204 * the expression that evaluated to false in
1205 * the assertion. Typically this is a
1206 * stringified version of the actual
1207 * assertion expression.
1208 * @param[in] aLabel An optional pointer to a NULL-terminated C string
1209 * indicating, for exception-style
1210 * assertions, the label that will be
1211 * branched to when the assertion expression
1212 * evaluates to false.
1213 * @param[in] aFile A pointer to a NULL-terminated C string indicating
1214 * the file in which the exception
1215 * occurred. Typically this is and should be
1216 * \_\_FILE\_\_ from the C preprocessor or
1218 * @param[in] aLine The line number in @p aFile on which the assertion
1219 * expression evaluated to false. Typically
1220 * this is and should be \_\_LINE\_\_ from the C
1222 * @param[in] aMessage An optional pointer to a NULL-terminated C string
1223 * containing a caller-specified message
1224 * further describing the assertion failure.
1226 * @sa #NL_ASSERT_LOG_DEFAULT
1228 * @sa #NL_ASSERT_FLAG_LOG
1230 * @sa #NL_ASSERT_PREFIX_STRING
1231 * @sa #NL_ASSERT_COMPONENT_STRING
1233 * @sa #NL_ASSERT_FILE
1236 #if !defined(NL_ASSERT_LOG)
1237 #define NL_ASSERT_LOG(aPrefix, aName, aCondition, aLabel, aFile, aLine, aMessage)
1238 #endif /* !defined(NL_ASSERT_LOG) */
1241 * @def NL_ASSERT_FILE
1244 * This is the NULL-terminated C string literal with the fully-,
1245 * partially-, or non-qualified path of the file name in which an
1246 * assertion occurred (default \_\_FILE\_\_).
1248 * This may be used by developers to override the C preprocessor default,
1249 * potentially shortening the size of string literals used for
1250 * assertion file names and, consequently, decreasing the size of a
1251 * particular target image.
1254 #if !defined(NL_ASSERT_FILE)
1255 #define NL_ASSERT_FILE __FILE__
1256 #endif /* !defined(NL_ASSERT_FILE) */
1259 * @defgroup static-modality Static
1260 * @defgroup assert-style Assert
1261 * @defgroup abort-style Abort
1262 * @defgroup check-style Check
1263 * @defgroup verify-style Verify
1264 * @defgroup precondition-style Precondition
1265 * @defgroup expect-style Expect
1266 * @defgroup desire-style Desire
1267 * @defgroup require-style Require
1272 * @ingroup static-modality
1279 * @def nlSTATIC_ASSERT(aCondition)
1282 * This checks, at compile-time, for the specified condition, which
1283 * is expected to commonly be true, and terminates compilation if
1284 * the condition is false.
1286 * @note Unlike the runtime assert macros, this compile-time macro is active
1287 * regardless of the state of #NL_ASSERT_PRODUCTION.
1289 * @param[in] aCondition A Boolean expression to be evaluated.
1291 * @sa #nlSTATIC_ASSERT_PRINT
1294 #define nlSTATIC_ASSERT(aCondition) _nlSTATIC_ASSERT(aCondition, #aCondition)
1297 * @def nlSTATIC_ASSERT_PRINT(aCondition, aMessage)
1300 * This checks, at compile-time, for the specified condition, which
1301 * is expected to commonly be true, and terminates compilation if
1302 * the condition is false.
1304 * @note Unlike the runtime assert macros, this compile-time macro is active
1305 * regardless of the state of #NL_ASSERT_PRODUCTION.
1307 * @param[in] aCondition A Boolean expression to be evaluated.
1308 * @param[in] aMessage A pointer to a NULL-terminated C string
1309 * containing a caller-specified message
1310 * further describing the assertion
1311 * failure. Note, this message is not
1312 * actually emitted in any meaningful way for
1313 * non-C11 or -C++11 code. It serves to
1314 * simply comment or annotate the assertion
1315 * and to provide interface parallelism with
1316 * the run-time assertion interfaces.
1318 * @sa #nlSTATIC_ASSERT
1321 #define nlSTATIC_ASSERT_PRINT(aCondition, aMessage) _nlSTATIC_ASSERT(aCondition, aMessage)
1329 * @ingroup expect-style
1336 * @def NL_ASSERT_EXPECT_FLAGS_DEFAULT
1339 * This defines the default behavioral flags for expect-style
1340 * exception family assertions.
1342 * This may be used to override #NL_ASSERT_EXPECT_FLAGS as follows:
1345 * #define NL_ASSERT_EXPECT_FLAGS NL_ASSERT_EXPECT_FLAGS_DEFAULT
1347 * #include <nlassert.h>
1350 * @sa #NL_ASSERT_EXPECT_FLAGS
1352 * @sa #NL_ASSERT_FLAG_BACKTRACE
1353 * @sa #NL_ASSERT_FLAG_LOG
1354 * @sa #NL_ASSERT_FLAG_TRAP
1357 #define NL_ASSERT_EXPECT_FLAGS_DEFAULT (NL_ASSERT_FLAG_NONE)
1360 * @def NL_ASSERT_EXPECT_FLAGS
1363 * This defines the behavioral flags that govern the behavior for
1364 * expect-style exception family assertions when the assertion
1365 * expression evaluates to false.
1367 * @sa #NL_ASSERT_EXPECT_FLAGS_DEFAULT
1369 * @sa #NL_ASSERT_FLAG_BACKTRACE
1370 * @sa #NL_ASSERT_FLAG_LOG
1371 * @sa #NL_ASSERT_FLAG_TRAP
1373 #if NL_ASSERT_USE_FLAGS_DEFAULT
1374 #define NL_ASSERT_EXPECT_FLAGS NL_ASSERT_EXPECT_FLAGS_DEFAULT
1375 #elif !defined(NL_ASSERT_EXPECT_FLAGS)
1376 #define NL_ASSERT_EXPECT_FLAGS (NL_ASSERT_FLAG_NONE)
1380 * @def nlEXPECT(aCondition, aLabel)
1383 * This checks for the specified condition, which is expected to
1384 * commonly be true, and branches to @p aLabel if the condition is
1387 * __Anticipated Assertion Firing Frequency:__ Frequent
1389 * @param[in] aCondition A Boolean expression to be evaluated.
1390 * @param[in] aLabel The local label to which execution branches
1391 * when @p aCondition evaluates to false (i.e.
1392 * compares equal to zero).
1394 * @sa #NL_ASSERT_EXPECT_FLAGS
1400 #define nlEXPECT(aCondition, aLabel) __nlEXPECT(NL_ASSERT_EXPECT_FLAGS, aCondition, aLabel)
1403 * @def nlEXPECT_PRINT(aCondition, aLabel, aMessage)
1406 * This checks for the specified condition, which is expected to
1407 * commonly be true, and both prints @p aMessage and then branches
1408 * to @p aLabel if the condition is false.
1410 * __Anticipated Assertion Firing Frequency:__ Frequent
1412 * @param[in] aCondition A Boolean expression to be evaluated.
1413 * @param[in] aLabel The local label to which execution branches
1414 * when @p aCondition evaluates to false (i.e.
1415 * compares equal to zero).
1416 * @param[in] aMessage A pointer to a NULL-terminated C string
1417 * containing a caller-specified message
1418 * further describing the assertion failure.
1420 * @sa #NL_ASSERT_EXPECT_FLAGS
1422 * @sa #nlDESIRE_PRINT
1423 * @sa #nlREQUIRE_PRINT
1426 #define nlEXPECT_PRINT(aCondition, aLabel, aMessage) __nlEXPECT_PRINT(NL_ASSERT_EXPECT_FLAGS, aCondition, aLabel, aMessage)
1429 * @def nlEXPECT_ACTION(aCondition, aLabel, anAction)
1432 * This checks for the specified condition, which is expected to
1433 * commonly be true, and both executes @p anAction and branches to
1434 * @p aLabel if the condition is false.
1436 * __Anticipated Assertion Firing Frequency:__ Frequent
1438 * @param[in] aCondition A Boolean expression to be evaluated.
1439 * @param[in] aLabel The local label to which execution branches
1440 * when @p aCondition evaluates to false (i.e.
1441 * compares equal to zero).
1442 * @param[in] anAction An expression or block to execute when the
1443 * assertion fails. This will be executed
1444 * after #NL_ASSERT_LOG() and
1445 * #NL_ASSERT_BACKTRACE() but before
1446 * #NL_ASSERT_TRAP().
1448 * @sa #NL_ASSERT_EXPECT_FLAGS
1450 * @sa #nlDESIRE_ACTION
1451 * @sa #nlREQUIRE_ACTION
1454 #define nlEXPECT_ACTION(aCondition, aLabel, anAction) __nlEXPECT_ACTION(NL_ASSERT_EXPECT_FLAGS, aCondition, aLabel, anAction)
1457 * @def nlEXPECT_ACTION_PRINT(aCondition, aLabel, anAction, aMessage)
1460 * This checks for the specified condition, which is expected to
1461 * commonly be true, prints @p aMessage, executes @p anAction, and
1462 * branches to @p aLabel if the condition is false.
1464 * __Anticipated Assertion Firing Frequency:__ Frequent
1466 * @param[in] aCondition A Boolean expression to be evaluated.
1467 * @param[in] aLabel The local label to which execution branches
1468 * when @p aCondition evaluates to false (i.e.
1469 * compares equal to zero).
1470 * @param[in] anAction An expression or block to execute when the
1471 * assertion fails. This will be executed
1472 * after #NL_ASSERT_LOG() and
1473 * #NL_ASSERT_BACKTRACE() but before
1474 * #NL_ASSERT_TRAP().
1475 * @param[in] aMessage A pointer to a NULL-terminated C string
1476 * containing a caller-specified message
1477 * further describing the assertion failure.
1479 * @sa #NL_ASSERT_EXPECT_FLAGS
1481 * @sa #nlDESIRE_ACTION_PRINT
1482 * @sa #nlREQUIRE_ACTION_PRINT
1485 #define nlEXPECT_ACTION_PRINT(aCondition, aLabel, anAction, aMessage) __nlEXPECT_ACTION_PRINT(NL_ASSERT_EXPECT_FLAGS, aCondition, aLabel, anAction, aMessage)
1488 * @def nlEXPECT_SUCCESS(aStatus, aLabel)
1491 * This checks for the specified status, which is expected to
1492 * commonly be successful (i.e. zero (0)), and branches to @p
1493 * aLabel if the status is unsuccessful.
1495 * __Anticipated Assertion Firing Frequency:__ Frequent
1497 * @param[in] aStatus A scalar status to be evaluated against zero (0).
1498 * @param[in] aLabel The local label to which execution branches
1499 * when @p aStatus does not evaluate to zero
1502 * @sa #NL_ASSERT_EXPECT_FLAGS
1504 * @sa #nlDESIRE_SUCCESS
1505 * @sa #nlREQUIRE_SUCCESS
1508 #define nlEXPECT_SUCCESS(aStatus, aLabel) __nlEXPECT_SUCCESS(NL_ASSERT_EXPECT_FLAGS, aStatus, aLabel)
1511 * @def nlEXPECT_SUCCESS_PRINT(aStatus, aLabel, aMessage)
1514 * This checks for the specified status, which is expected to
1515 * commonly be successful (i.e. zero (0)), and both prints @p
1516 * aMessage and then branches to @p aLabel if the status is
1519 * __Anticipated Assertion Firing Frequency:__ Frequent
1521 * @param[in] aStatus A scalar status to be evaluated against zero (0).
1522 * @param[in] aLabel The local label to which execution branches
1523 * when @p aStatus does not evaluate to zero
1525 * @param[in] aMessage A pointer to a NULL-terminated C string
1526 * containing a caller-specified message
1527 * further describing the assertion failure.
1529 * @sa #NL_ASSERT_EXPECT_FLAGS
1531 * @sa #nlDESIRE_SUCCESS_PRINT
1532 * @sa #nlREQUIRE_SUCCESS_PRINT
1535 #define nlEXPECT_SUCCESS_PRINT(aStatus, aLabel, aMessage) __nlEXPECT_SUCCESS_PRINT(NL_ASSERT_EXPECT_FLAGS, aStatus, aLabel, aMessage)
1538 * @def nlEXPECT_SUCCESS_ACTION(aStatus, aLabel, anAction)
1541 * This checks for the specified status, which is expected to
1542 * commonly be successful (i.e. zero (0)), and both executes @p
1543 * anAction and branches to @p aLabel if the status is unsuccessful.
1545 * __Anticipated Assertion Firing Frequency:__ Frequent
1547 * @param[in] aStatus A scalar status to be evaluated against zero (0).
1548 * @param[in] aLabel The local label to which execution branches
1549 * when @p aStatus does not evaluate to zero
1551 * @param[in] anAction An expression or block to execute when the
1552 * assertion fails. This will be executed
1553 * after #NL_ASSERT_LOG() and
1554 * #NL_ASSERT_BACKTRACE() but before
1555 * #NL_ASSERT_TRAP().
1557 * @sa #NL_ASSERT_EXPECT_FLAGS
1559 * @sa #nlDESIRE_SUCCESS_ACTION
1560 * @sa #nlREQUIRE_SUCCESS_ACTION
1563 #define nlEXPECT_SUCCESS_ACTION(aStatus, aLabel, anAction) __nlEXPECT_SUCCESS_ACTION(NL_ASSERT_EXPECT_FLAGS, aStatus, aLabel, anAction)
1566 * @def nlEXPECT_SUCCESS_ACTION_PRINT(aStatus, aLabel, anAction, aMessage)
1569 * This checks for the specified status, which is expected to
1570 * commonly be successful (i.e. zero (0)), prints @p aMessage,
1571 * executes @p anAction, and branches to @p aLabel if the status is
1574 * __Anticipated Assertion Firing Frequency:__ Frequent
1576 * @param[in] aStatus A scalar status to be evaluated against zero (0).
1577 * @param[in] aLabel The local label to which execution branches
1578 * when @p aStatus does not evaluate to zero
1580 * @param[in] anAction An expression or block to execute when the
1581 * assertion fails. This will be executed
1582 * after #NL_ASSERT_LOG() and
1583 * #NL_ASSERT_BACKTRACE() but before
1584 * #NL_ASSERT_TRAP().
1585 * @param[in] aMessage A pointer to a NULL-terminated C string
1586 * containing a caller-specified message
1587 * further describing the assertion failure.
1589 * @sa #NL_ASSERT_EXPECT_FLAGS
1591 * @sa #nlDESIRE_SUCCESS_ACTION_PRINT
1592 * @sa #nlREQUIRE_SUCCESS_ACTION_PRINT
1595 #define nlEXPECT_SUCCESS_ACTION_PRINT(aStatus, aLabel, anAction, aMessage) __nlEXPECT_SUCCESS_ACTION_PRINT(NL_ASSERT_EXPECT_FLAGS, aStatus, aLabel, anAction, aMessage)
1598 * @def nlNEXPECT(aCondition, aLabel)
1601 * This checks for the specified condition, which is expected to
1602 * commonly be false, and branches to @p aLabel if the condition is
1605 * @note This is the logical inverse of #nlEXPECT.
1607 * __Anticipated Assertion Firing Frequency:__ Frequent
1609 * @param[in] aCondition A Boolean expression to be evaluated.
1610 * @param[in] aLabel The local label to which execution branches
1611 * when @p aCondition evaluates to false (i.e.
1612 * compares equal to zero).
1614 * @sa #NL_ASSERT_EXPECT_FLAGS
1621 #define nlNEXPECT(aCondition, aLabel) __nlNEXPECT(NL_ASSERT_EXPECT_FLAGS, aCondition, aLabel)
1624 * @def nlNEXPECT_PRINT(aCondition, aLabel, aMessage)
1627 * This checks for the specified condition, which is expected to
1628 * commonly be false, and both prints @p aMessage and then branches
1629 * to @p aLabel if the condition is true.
1631 * @note This is the logical inverse of #nlEXPECT_PRINT.
1633 * __Anticipated Assertion Firing Frequency:__ Frequent
1635 * @param[in] aCondition A Boolean expression to be evaluated.
1636 * @param[in] aLabel The local label to which execution branches
1637 * when @p aCondition evaluates to false (i.e.
1638 * compares equal to zero).
1639 * @param[in] aMessage A pointer to a NULL-terminated C string
1640 * containing a caller-specified message
1641 * further describing the assertion failure.
1643 * @sa #NL_ASSERT_EXPECT_FLAGS
1645 * @sa #nlEXPECT_PRINT
1646 * @sa #nlNDESIRE_PRINT
1647 * @sa #nlNREQUIRE_PRINT
1650 #define nlNEXPECT_PRINT(aCondition, aLabel, aMessage) __nlNEXPECT_PRINT(NL_ASSERT_EXPECT_FLAGS, aCondition, aLabel, aMessage)
1653 * @def nlNEXPECT_ACTION(aCondition, aLabel, anAction)
1656 * This checks for the specified condition, which is expected to
1657 * commonly be false, and both executes @p anAction and branches to
1658 * @p aLabel if the condition is true.
1660 * @note This is the logical inverse of #nlEXPECT_ACTION.
1662 * __Anticipated Assertion Firing Frequency:__ Frequent
1664 * @param[in] aCondition A Boolean expression to be evaluated.
1665 * @param[in] aLabel The local label to which execution branches
1666 * when @p aCondition evaluates to false (i.e.
1667 * compares equal to zero).
1668 * @param[in] anAction An expression or block to execute when the
1669 * assertion fails. This will be executed
1670 * after #NL_ASSERT_LOG() and
1671 * #NL_ASSERT_BACKTRACE() but before
1672 * #NL_ASSERT_TRAP().
1674 * @sa #NL_ASSERT_EXPECT_FLAGS
1676 * @sa #nlEXPECT_ACTION
1677 * @sa #nlNDESIRE_ACTION
1678 * @sa #nlNREQUIRE_ACTION
1681 #define nlNEXPECT_ACTION(aCondition, aLabel, anAction) __nlNEXPECT_ACTION(NL_ASSERT_EXPECT_FLAGS, aCondition, aLabel, anAction)
1684 * @def nlNEXPECT_ACTION_PRINT(aCondition, aLabel, anAction, aMessage)
1687 * This checks for the specified condition, which is expected to
1688 * commonly be false, prints @p aMessage, executes @p anAction, and
1689 * branches to @p aLabel if the condition is true.
1691 * @note This is the logical inverse of #nlEXPECT_ACTION_PRINT.
1693 * __Anticipated Assertion Firing Frequency:__ Frequent
1695 * @param[in] aCondition A Boolean expression to be evaluated.
1696 * @param[in] aLabel The local label to which execution branches
1697 * when @p aCondition evaluates to false (i.e.
1698 * compares equal to zero).
1699 * @param[in] anAction An expression or block to execute when the
1700 * assertion fails. This will be executed
1701 * after #NL_ASSERT_LOG() and
1702 * #NL_ASSERT_BACKTRACE() but before
1703 * #NL_ASSERT_TRAP().
1704 * @param[in] aMessage A pointer to a NULL-terminated C string
1705 * containing a caller-specified message
1706 * further describing the assertion failure.
1708 * @sa #NL_ASSERT_EXPECT_FLAGS
1710 * @sa #nlEXPECT_ACTION_PRINT
1711 * @sa #nlNDESIRE_ACTION_PRINT
1712 * @sa #nlNREQUIRE_ACTION_PRINT
1715 #define nlNEXPECT_ACTION_PRINT(aCondition, aLabel, anAction, aMessage) __nlNEXPECT_ACTION_PRINT(NL_ASSERT_EXPECT_FLAGS, aCondition, aLabel, anAction, aMessage)
1722 #if !NL_ASSERT_PRODUCTION
1723 #include "nlassert-nonproduction.h"
1725 #include "nlassert-production.h"
1726 #endif /* !NL_ASSERT_PRODUCTION */
1728 #endif /* NLCORE_NLASSERT_H */