Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:34

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @defgroup RegulatorTests Regulator Test Cases
0005  *
0006  * @brief Unit test cases for the Regulator
0007  *
0008  * This is a set of unit test cases for the regulator.
0009  */
0010 
0011 /**
0012  * @ingroup RegulatorTests
0013  *
0014  * @file
0015  *
0016  * @brief Test 01 for Regulator Library
0017  */
0018 
0019 /*
0020  * Copyright (C) 2022 On-Line Applications Research Corporation (OAR)
0021  *
0022  * Redistribution and use in source and binary forms, with or without
0023  * modification, are permitted provided that the following conditions
0024  * are met:
0025  * 1. Redistributions of source code must retain the above copyright
0026  *    notice, this list of conditions and the following disclaimer.
0027  * 2. Redistributions in binary form must reproduce the above copyright
0028  *    notice, this list of conditions and the following disclaimer in the
0029  *    documentation and/or other materials provided with the distribution.
0030  *
0031  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0032  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0033  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0034  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0035  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0036  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0037  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0038  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0039  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0040  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0041  * POSSIBILITY OF SUCH DAMAGE.
0042  */
0043 
0044 #include <stdio.h>
0045 #include <string.h>
0046 #include <unistd.h>
0047 
0048 #include <rtems.h>
0049 #include <rtems/test-info.h>
0050 #include <tmacros.h>
0051 
0052 #include <rtems/regulator.h>
0053 
0054 /**
0055  * @brief Regulator Test Name
0056  */
0057 const char rtems_test_name[] = "Regulator 1";
0058 
0059 /*
0060  * Prototypes for wrapped functions
0061  */
0062 void *__wrap_malloc(size_t size);
0063 void *__real_malloc(size_t size);
0064 
0065 /**
0066  * @ingroup RegulatorTests
0067  * @brief Calloc Wrapper Trigger Count
0068  */
0069 static int malloc_trigger_count;
0070 
0071 /**
0072  * @ingroup RegulatorTests
0073  * @brief Calloc Wrapper Call Count
0074  */
0075 static int malloc_call_count;
0076 
0077 /**
0078  * @ingroup RegulatorTests
0079  * @brief Calloc Wrapper Trigger enable
0080  */
0081 static bool malloc_trigger_enabled;
0082 
0083 /**
0084  * @ingroup RegulatorTests
0085  * @brief Enable Calloc Wrapper Trigger
0086  */
0087 static void malloc_trigger_enable(
0088   int trigger_count
0089 )
0090 {
0091   malloc_trigger_enabled = true;
0092   malloc_trigger_count = trigger_count;
0093   malloc_call_count = 0;
0094 }
0095 /**
0096  * @ingroup RegulatorTests
0097  * @brief Reset Calloc Wrapper Trigger and Count
0098  */
0099 static void malloc_trigger_reset(void)
0100 {
0101   malloc_trigger_enabled = 0;
0102   malloc_trigger_count = 0;
0103   malloc_call_count = 0;
0104 }
0105 /**
0106  * @ingroup RegulatorTests
0107  * @brief Calloc Wrapper to Trigger Allocation Errors
0108  */
0109 void *__wrap_malloc(size_t size)
0110 {
0111   if (malloc_trigger_enabled) {
0112     malloc_call_count++;
0113     if (malloc_call_count == malloc_trigger_count) {
0114       return NULL;
0115     }
0116   }
0117 
0118   return __real_malloc(size);
0119 }
0120 
0121 /**
0122  * @brief Constant to simpify code
0123  */
0124 #define FIVE_SECONDS (5 * rtems_clock_get_ticks_per_second())
0125 
0126 /**
0127  * @ingroup RegulatorTests
0128  * @brief Empty Deliver Method for Testing
0129  */
0130 static bool test_regulator_deliverer(
0131   void     *context,
0132   void     *message,
0133   size_t    length
0134 )
0135 {
0136   (void) context;
0137   (void) message;
0138   (void) length;
0139 
0140   return true;
0141 }
0142 
0143 /**
0144  * @ingroup RegulatorTests
0145  * @brief Maximum length of a test message that is delivered
0146  */
0147 #define MAXIMUM_MESSAGE_LENGTH 32
0148 
0149 /**
0150  * @ingroup RegulatorTests
0151  * @brief Maximum number of test messages to buffer
0152  */
0153 #define MAXIMUM_MESSAGES_TO_BUFFER 10
0154 
0155 /**
0156  * @ingroup RegulatorTests
0157  * @brief Structure for capturing messages as delivered
0158  */
0159 typedef struct {
0160   rtems_interval processed;
0161   char           message[MAXIMUM_MESSAGE_LENGTH];
0162 } message_log_t;
0163 
0164 /**
0165  * @ingroup RegulatorTests
0166  * @brief Set of Delivered messages
0167  */
0168 message_log_t delivered_messages[MAXIMUM_MESSAGES_TO_BUFFER];
0169 
0170 /**
0171  * @ingroup RegulatorTests
0172  * @brief Count of Delivered messages
0173  */
0174 int delivered_message_count;
0175 
0176 /**
0177  * @ingroup RegulatorTests
0178  * @brief Reset Delivered Message Set
0179  *
0180  * This is used at the beginning of a test case which is going to
0181  * check that message contents and delivery times were as expected.
0182  */
0183 static void delivered_messages_reset(void)
0184 {
0185   delivered_message_count = 0;
0186   memset(delivered_messages, 0xc5, sizeof(delivered_messages));
0187 }
0188 
0189 /**
0190  * @brief Context for Logger Delivery Function
0191  */
0192 typedef struct {
0193   /** Regulator instance being operated on */
0194   rtems_regulator_instance   *regulator;
0195 } deliverer_logger_context_t;
0196 
0197 /**
0198  * @brief Context Instance for Logger Delivery Function
0199  */
0200 static deliverer_logger_context_t deliverer_logger_context;
0201 
0202 /**
0203  * @ingroup RegulatorTests
0204  * @brief Empty Deliver Method for Testing
0205  *
0206  * This deliverer method implementation logs the messages along with
0207  * their time of arrival. This is used by the test cases to verify
0208  * proper delivery.
0209  */
0210 static bool test_regulator_deliverer_logger(
0211   void     *context,
0212   void     *message,
0213   size_t    length
0214 )
0215 {
0216   deliverer_logger_context_t *the_context;
0217 
0218   the_context = (deliverer_logger_context_t *)context;
0219 
0220   static bool caller_releases_buffer = true;
0221 
0222   size_t             len;
0223   rtems_interval     ticks;
0224   rtems_status_code  sc;
0225 
0226   len = strnlen(message, MAXIMUM_MESSAGE_LENGTH) + 1;
0227   rtems_test_assert(len = length);
0228 
0229   ticks = rtems_clock_get_ticks_since_boot();
0230 
0231   delivered_messages[delivered_message_count].processed = ticks;
0232 
0233   strcpy(delivered_messages[delivered_message_count].message, message);
0234 
0235   delivered_message_count++;
0236 
0237   /*
0238    * Alternate releasing the buffer here and allowing the calling Delivery
0239    * Thread to do it. This increases coverage of that logic.
0240    */
0241   if (caller_releases_buffer == true) {
0242     caller_releases_buffer = false;
0243     return true;
0244   }
0245 
0246   sc = rtems_regulator_release_buffer(the_context->regulator, message);
0247   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0248 
0249   return false;
0250 }
0251 
0252 
0253 /**
0254  * @ingroup RegulatorTests
0255  * @brief Helper to create a Regulator instance
0256  *
0257  * This helper creates a regulator instance with some arbitrary attributes.
0258  * This is used in multiple test cases to have a valie regulator instance to
0259  * trigger error cases.
0260  */
0261 static rtems_regulator_instance *test_regulator_create_regulator_OK(void)
0262 {
0263   rtems_status_code     sc;
0264   rtems_regulator_attributes  attributes = {
0265     .deliverer = test_regulator_deliverer,
0266     .deliverer_context = NULL,
0267     .maximum_message_size = 16,
0268     .maximum_messages = 10,
0269     .delivery_thread_priority = 16,
0270     .delivery_thread_stack_size = 0,
0271     .delivery_thread_period = RTEMS_MILLISECONDS_TO_TICKS(1000),
0272     .maximum_to_dequeue_per_period = 3
0273   };
0274   rtems_regulator_instance   *regulator;
0275 
0276   regulator = NULL;
0277 
0278   sc = rtems_regulator_create(&attributes, &regulator);
0279   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0280   rtems_test_assert(regulator != NULL);
0281 
0282   return regulator;
0283 }
0284 
0285 /**
0286  * @ingroup RegulatorTests
0287  * @brief Verify rtems_regulator_create() maximum_to_dequeue_per_period
0288  * attributes error
0289  *
0290  * This unit test verifies that rtems_regulator_create() returns an error when
0291  * the maximum_to_dequeue_per_period attribute is zero.
0292  */
0293 static void test_regulator_create_max_dequeue_zero(void)
0294 {
0295   rtems_status_code     sc;
0296   rtems_regulator_attributes  attributes = {
0297     .deliverer = test_regulator_deliverer,
0298     .deliverer_context = NULL,
0299     .maximum_message_size = 16,
0300     .maximum_messages = 10,
0301     .delivery_thread_priority = 16,
0302     .delivery_thread_stack_size = 0,
0303     .delivery_thread_period = RTEMS_MILLISECONDS_TO_TICKS(1000),
0304     .maximum_to_dequeue_per_period = 0
0305   };
0306   rtems_regulator_instance   *regulator;
0307 
0308   regulator = NULL;
0309 
0310   sc = rtems_regulator_create(&attributes, &regulator);
0311   rtems_test_assert(sc == RTEMS_INVALID_NUMBER);
0312 }
0313 
0314 /**
0315  * @ingroup RegulatorTests
0316  * @brief Verify rtems_regulator_create() NULL attributes error
0317  *
0318  * This unit test verifies that rtems_regulator_create() returns an error when
0319  * the attributes argument is NULL.
0320  */
0321 static void test_regulator_create_null_attributes(void)
0322 {
0323   rtems_status_code          sc;
0324   rtems_regulator_instance  *regulator;
0325 
0326   sc = rtems_regulator_create(NULL, &regulator);
0327   rtems_test_assert(sc == RTEMS_INVALID_ADDRESS);
0328 }
0329 
0330 /**
0331  * @ingroup RegulatorTests
0332  * @brief Verify rtems_regulator_create NULL regulator error
0333  *
0334  * This unit test verifies that rtems_regulator_create() returns an error when
0335  * the regulator argument is NULL.
0336  */
0337 static void test_regulator_create_null_regulator(void)
0338 {
0339   rtems_status_code           sc;
0340   rtems_regulator_attributes  attributes;
0341 
0342   sc = rtems_regulator_create(&attributes, NULL);
0343   rtems_test_assert(sc == RTEMS_INVALID_ADDRESS);
0344 }
0345 
0346 /**
0347  * @ingroup RegulatorTests
0348  * @brief Verify rtems_regulator_create deliverer is NULL
0349  *
0350  * This unit test verifies that rtems_regulator_create() returns an error when
0351  * the the attributes deliverer field is NULL.
0352  */
0353 static void test_regulator_create_deliverer_is_null(void)
0354 {
0355   rtems_status_code           sc;
0356   rtems_regulator_attributes  attributes;
0357   rtems_regulator_instance   *regulator;
0358 
0359   (void) memset(&attributes, 0, sizeof(rtems_regulator_attributes));
0360 
0361   attributes.deliverer                     = NULL;
0362   attributes.maximum_messages              = 0;
0363   attributes.maximum_message_size          = 16;
0364   attributes.maximum_to_dequeue_per_period = 1;
0365 
0366   sc = rtems_regulator_create(&attributes, &regulator);
0367   rtems_test_assert(sc == RTEMS_INVALID_ADDRESS);
0368 }
0369 
0370 /**
0371  * @ingroup RegulatorTests
0372  * @brief Verify rtems_regulator_create maximum_messages is 0 error
0373  *
0374  * This unit test verifies that rtems_regulator_create() returns an error when
0375  * the the attributes maximum_messages field is 0.
0376  */
0377 static void test_regulator_create_maximum_messages_is_zero(void)
0378 {
0379   rtems_status_code           sc;
0380   rtems_regulator_attributes  attributes;
0381   rtems_regulator_instance   *regulator;
0382 
0383   (void) memset(&attributes, 0, sizeof(rtems_regulator_attributes));
0384 
0385   attributes.deliverer                     = test_regulator_deliverer;
0386   attributes.maximum_messages              = 0;
0387   attributes.maximum_message_size          = 16;
0388   attributes.maximum_to_dequeue_per_period = 1;
0389 
0390   sc = rtems_regulator_create(&attributes, &regulator);
0391   rtems_test_assert(sc == RTEMS_INVALID_NUMBER);
0392 }
0393 
0394 /**
0395  * @ingroup RegulatorTests
0396  * @brief Verify rtems_regulator_create maximum_message_size is 0 error
0397  *
0398  * This unit test verifies that rtems_regulator_create() returns an error when
0399  * the the attributes maximum_message_size field is 0.
0400  */
0401 static void test_regulator_create_maximum_message_size_is_zero(void)
0402 {
0403   rtems_status_code           sc;
0404   rtems_regulator_attributes  attributes;
0405   rtems_regulator_instance   *regulator;
0406 
0407   (void) memset(&attributes, 0, sizeof(rtems_regulator_attributes));
0408 
0409   attributes.deliverer                     = test_regulator_deliverer;
0410   attributes.maximum_messages              = 10;
0411   attributes.maximum_message_size          = 0;
0412   attributes.maximum_to_dequeue_per_period = 1;
0413 
0414   sc = rtems_regulator_create(&attributes, &regulator);
0415   rtems_test_assert(sc == RTEMS_INVALID_SIZE);
0416 }
0417 
0418 /**
0419  * @ingroup RegulatorTests
0420  * @brief Verify rtems_regulator_create maximum_to_dequeue_per_period is 0 error
0421  *
0422  * This unit test verifies that rtems_regulator_create() returns an error when
0423  * the the attributes maximum_to_dequeue_per_period field is 0.
0424  */
0425 static void test_regulator_create_maximum_to_dequeue_per_period_is_zero(void)
0426 {
0427   rtems_status_code           sc;
0428   rtems_regulator_attributes  attributes;
0429   rtems_regulator_instance   *regulator;
0430 
0431   (void) memset(&attributes, 0, sizeof(rtems_regulator_attributes));
0432 
0433   attributes.deliverer            = test_regulator_deliverer;
0434   attributes.maximum_messages     = 10;
0435   attributes.maximum_message_size = 0;
0436 
0437   sc = rtems_regulator_create(&attributes, &regulator);
0438   rtems_test_assert(sc == RTEMS_INVALID_SIZE);
0439 }
0440 
0441 /**
0442  * @ingroup RegulatorTests
0443  * @brief Verify rtems_regulator_create returns error on failure to allocate regulator
0444  *
0445  * This unit test verifies that rtems_regulator_create() returns an error when
0446  * it is unable to allocate the mmemory for the regulator instance.
0447  */
0448 static void test_regulator_create_malloc_regulator_fails(void)
0449 {
0450   rtems_status_code           sc;
0451   rtems_regulator_attributes  attributes;
0452   rtems_regulator_instance         *regulator;
0453 
0454   (void) memset(&attributes, 0, sizeof(rtems_regulator_attributes));
0455 
0456   attributes.deliverer                     = test_regulator_deliverer;
0457   attributes.maximum_messages              = 10;
0458   attributes.maximum_message_size          = 16;
0459   attributes.delivery_thread_priority      = 32;
0460   attributes.maximum_to_dequeue_per_period = 1;
0461   attributes.delivery_thread_period        = RTEMS_MILLISECONDS_TO_TICKS(1000);
0462 
0463   malloc_trigger_enable(1);
0464 
0465   sc = rtems_regulator_create(&attributes, &regulator);
0466   rtems_test_assert(sc == RTEMS_NO_MEMORY);
0467 
0468   malloc_trigger_reset();
0469 }
0470 
0471 /**
0472  * @ingroup RegulatorTests
0473  * @brief Verify rtems_regulator_create returns error on failure to allocate buffers
0474  *
0475  * This unit test verifies that rtems_regulator_create() returns an error when
0476  * it is unable to allocate the mmemory for the regulator buffers.
0477  */
0478 static void test_regulator_create_malloc_buffers_fails(void)
0479 {
0480   rtems_status_code           sc;
0481   rtems_regulator_attributes  attributes;
0482   rtems_regulator_instance         *regulator;
0483 
0484   (void) memset(&attributes, 0, sizeof(rtems_regulator_attributes));
0485 
0486   attributes.deliverer                     = test_regulator_deliverer;
0487   attributes.maximum_messages              = 10;
0488   attributes.maximum_message_size          = 16;
0489   attributes.delivery_thread_priority      = 32;
0490   attributes.maximum_to_dequeue_per_period = 1;
0491   attributes.delivery_thread_period        = RTEMS_MILLISECONDS_TO_TICKS(1000);
0492 
0493   malloc_trigger_enable(2);
0494 
0495   sc = rtems_regulator_create(&attributes, &regulator);
0496   rtems_test_assert(sc == RTEMS_NO_MEMORY);
0497 
0498   malloc_trigger_reset();
0499 }
0500 
0501 /**
0502  * @ingroup RegulatorTests
0503  * @brief Verify rtems_regulator_create and delete work
0504  *
0505  * This unit test verifies that rtems_regulator_create() can successfully create
0506  * the the attributes delivery_thread_priority field is 0.
0507  */
0508 static void test_regulator_create_delivery_thread_priority_is_zero(void)
0509 {
0510   rtems_status_code           sc;
0511   rtems_regulator_attributes  attributes;
0512   rtems_regulator_instance         *regulator;
0513 
0514   (void) memset(&attributes, 0, sizeof(rtems_regulator_attributes));
0515 
0516   attributes.deliverer                     = test_regulator_deliverer;
0517   attributes.maximum_messages              = 10;
0518   attributes.maximum_message_size          = 16;
0519   attributes.delivery_thread_priority      = 0;
0520   attributes.maximum_to_dequeue_per_period = 1;
0521   attributes.delivery_thread_period        = RTEMS_MILLISECONDS_TO_TICKS(1000);
0522 
0523   sc = rtems_regulator_create(&attributes, &regulator);
0524   rtems_test_assert(sc == RTEMS_INVALID_PRIORITY);
0525 }
0526 
0527 /**
0528  * @ingroup RegulatorTests
0529  * @brief Verify rtems_regulator_create rtems_partition_create error
0530  *
0531  * This unit test verifies that rtems_regulator_create() correctly returns an
0532  * error when the call to rtems_partition_create() fails.
0533  */
0534 static void test_regulator_create_partition_create_fails(void)
0535 {
0536   rtems_status_code           sc;
0537   rtems_id                    partition_id;
0538   unsigned long               partition_area[16];
0539   rtems_regulator_attributes  attributes;
0540   rtems_regulator_instance   *regulator;
0541 
0542   sc = rtems_partition_create(
0543     rtems_build_name('T', 'P', 'T', 'P'),
0544     partition_area,
0545     16 * sizeof(unsigned long),
0546     2 * sizeof(unsigned long),
0547     RTEMS_DEFAULT_ATTRIBUTES,
0548     &partition_id
0549   );
0550   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0551 
0552   (void) memset(&attributes, 0, sizeof(rtems_regulator_attributes));
0553 
0554   attributes.deliverer                     = test_regulator_deliverer;
0555   attributes.maximum_messages              = 10;
0556   attributes.maximum_message_size          = 16;
0557   attributes.delivery_thread_priority      = 8;
0558   attributes.maximum_to_dequeue_per_period = 1;
0559   attributes.delivery_thread_period        = RTEMS_MILLISECONDS_TO_TICKS(1000);
0560 
0561   sc = rtems_regulator_create(&attributes, &regulator);
0562   rtems_test_assert(sc == RTEMS_TOO_MANY);
0563 
0564   sc = rtems_partition_delete(partition_id);
0565   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0566 }
0567 
0568 /**
0569  * @ingroup RegulatorTests
0570  * @brief Verify rtems_regulator_create rtems_message_queue_create error
0571  *
0572  * This unit test verifies that rtems_regulator_create() correctly returns an
0573  * error when the call to rtems_message_queue_create() fails.
0574  */
0575 static void test_regulator_create_message_queue_create_fails(void)
0576 {
0577   rtems_status_code           sc;
0578   rtems_id                    queue_id;
0579   rtems_regulator_attributes  attributes;
0580   rtems_regulator_instance   *regulator;
0581 
0582   sc = rtems_message_queue_create(
0583     rtems_build_name('T', 'Q', 'T', 'Q'),
0584     4,
0585     sizeof(unsigned long),
0586     RTEMS_DEFAULT_ATTRIBUTES,
0587     &queue_id
0588   );
0589   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0590 
0591   (void) memset(&attributes, 0, sizeof(rtems_regulator_attributes));
0592 
0593   attributes.deliverer                     = test_regulator_deliverer;
0594   attributes.maximum_messages              = 10;
0595   attributes.maximum_message_size          = 16;
0596   attributes.delivery_thread_priority      = 8;
0597   attributes.maximum_to_dequeue_per_period = 1;
0598   attributes.delivery_thread_period        = RTEMS_MILLISECONDS_TO_TICKS(1000);
0599 
0600   sc = rtems_regulator_create(&attributes, &regulator);
0601   rtems_test_assert(sc == RTEMS_TOO_MANY);
0602 
0603   sc = rtems_message_queue_delete(queue_id);
0604   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0605 }
0606 
0607 /**
0608  * @ingroup RegulatorTests
0609  * @brief Verify rtems_regulator_create rtems_task_create error
0610  *
0611  * This unit test verifies that rtems_regulator_create() correctly returns an
0612  * error when the call to rtems_task_create() fails.
0613  */
0614 static void test_regulator_create_task_create_fails(void)
0615 {
0616   rtems_status_code           sc;
0617   rtems_id                    task_id;
0618   rtems_regulator_attributes  attributes;
0619   rtems_regulator_instance   *regulator;
0620 
0621   sc = rtems_task_create(
0622     rtems_build_name('T', 'T', 'T', 'T'),
0623     80,
0624     0,
0625     RTEMS_DEFAULT_MODES,
0626     RTEMS_DEFAULT_ATTRIBUTES,
0627     &task_id
0628   );
0629   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0630 
0631   (void) memset(&attributes, 0, sizeof(rtems_regulator_attributes));
0632 
0633   attributes.deliverer                     = test_regulator_deliverer;
0634   attributes.maximum_messages              = 10;
0635   attributes.maximum_message_size          = 16;
0636   attributes.delivery_thread_priority      = 8;
0637   attributes.maximum_to_dequeue_per_period = 1;
0638   attributes.delivery_thread_period        = RTEMS_MILLISECONDS_TO_TICKS(1000);
0639 
0640   sc = rtems_regulator_create(&attributes, &regulator);
0641   rtems_test_assert(sc == RTEMS_TOO_MANY);
0642 
0643   sc = rtems_task_delete(task_id);
0644   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0645 }
0646 
0647 /**
0648  * @ingroup RegulatorTests
0649  * @brief Verify Regulator Output Thread Handles Error on Period Create
0650  *
0651  * This unit test verifies that regulator output thread correctly exits
0652  * when the call to rtems_rate_monotonic_create() fails.
0653  *
0654  * This error condition/path cannot be directly detected via a return code,
0655  * It is verified via a debugger or code coverage reports.
0656  */
0657 static void test_regulator_create_rate_monotonic_create_fails(void)
0658 {
0659   rtems_status_code           sc;
0660   rtems_id                    period_id;
0661   rtems_regulator_attributes  attributes;
0662   rtems_regulator_instance   *regulator;
0663 
0664   sc = rtems_rate_monotonic_create(
0665     rtems_build_name('T', 'S', 'T', 'P'),
0666     &period_id
0667   );
0668   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0669 
0670   (void) memset(&attributes, 0, sizeof(rtems_regulator_attributes));
0671 
0672   attributes.deliverer                     = test_regulator_deliverer;
0673   attributes.maximum_messages              = 10;
0674   attributes.maximum_message_size          = 16;
0675   attributes.delivery_thread_priority      = 8;
0676   attributes.maximum_to_dequeue_per_period = 1;
0677   attributes.delivery_thread_period        = RTEMS_MILLISECONDS_TO_TICKS(1000);
0678 
0679   sc = rtems_regulator_create(&attributes, &regulator);
0680   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0681 
0682   /*
0683    * Let the output thread execute and encounter the create error.
0684    */
0685 
0686   sleep(1);
0687 
0688   /*
0689    * Now deallocate the resources allocated earlier
0690    */
0691   sc = rtems_regulator_delete(regulator, FIVE_SECONDS);
0692   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0693 
0694   sc = rtems_rate_monotonic_delete(period_id);
0695   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0696 }
0697 
0698 /**
0699  * @ingroup RegulatorTests
0700  * @brief Verify rtems_regulator_delete NULL regulator error
0701  *
0702  * This unit test verifies that rtems_regulator_delete() returns an error when
0703  * the regulator argument is NULL.
0704  */
0705 static void test_regulator_delete_null_regulator(void)
0706 {
0707   rtems_status_code     sc;
0708 
0709   sc = rtems_regulator_delete(NULL, FIVE_SECONDS);
0710   rtems_test_assert(sc == RTEMS_INVALID_ADDRESS);
0711 }
0712 
0713 /**
0714  * @ingroup RegulatorTests
0715  * @brief Verify rtems_regulator_delete uninitialized regulator error
0716  *
0717  * This unit test verifies that rtems_regulator_delete() returns an error when
0718  * the regulator argument is uninitialized.
0719  */
0720 static void test_regulator_delete_uninitialized_regulator(void)
0721 {
0722   rtems_status_code         sc;
0723   rtems_regulator_instance  regulator;
0724 
0725   (void) memset(&regulator, 0, sizeof(regulator));
0726 
0727   sc = rtems_regulator_delete(&regulator, 0);
0728   rtems_test_assert(sc == RTEMS_INCORRECT_STATE);
0729 }
0730 
0731 /**
0732  * @ingroup RegulatorTests
0733  * @brief Verify rtems_regulator_delete successful case
0734  *
0735  * This unit test verifies that rtems_regulator_delete() can be successfully
0736  * deleted.
0737  */
0738 static void test_regulator_delete_OK(void)
0739 {
0740   rtems_status_code         sc;
0741   rtems_regulator_instance *regulator;
0742 
0743   regulator = test_regulator_create_regulator_OK();
0744   rtems_test_assert(regulator != NULL);
0745 
0746   sc = rtems_regulator_delete(regulator, FIVE_SECONDS);
0747   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0748 }
0749 
0750 /**
0751  * @ingroup RegulatorTests
0752  * @brief Verify rtems_regulator_obtain_buffer NULL regulator error
0753  *
0754  * This unit test verifies that rtems_regulator_obtain_buffer() returns an error when
0755  * the regulator argument is NULL.
0756  */
0757 static void test_regulator_obtain_buffer_null_regulator(void)
0758 {
0759   rtems_status_code   sc;
0760   void               *buffer;
0761 
0762   sc = rtems_regulator_obtain_buffer(NULL, &buffer);
0763   rtems_test_assert(sc == RTEMS_INVALID_ADDRESS);
0764 }
0765 
0766 /**
0767  * @ingroup RegulatorTests
0768  * @brief Verify rtems_regulator_obtain_buffer uninitialized regulator error
0769  *
0770  * This unit test verifies that rtems_regulator_obtain_buffer() returns an error when
0771  * the regulator argument is uninitialized.
0772  */
0773 static void test_regulator_obtain_buffer_uninitialized_regulator(void)
0774 {
0775   rtems_status_code         sc;
0776   rtems_regulator_instance  regulator;
0777   void                     *buffer;
0778 
0779   (void) memset(&regulator, 0, sizeof(regulator));
0780 
0781   sc = rtems_regulator_obtain_buffer(&regulator, &buffer);
0782   rtems_test_assert(sc == RTEMS_INCORRECT_STATE);
0783 }
0784 
0785 /**
0786  * @ingroup RegulatorTests
0787  * @brief Verify rtems_regulator_obtain_buffer successful case
0788  *
0789  * This unit test verifies that rtems_regulator_obtain_buffer() can be successfully
0790  * obtained from an initialized regulator.
0791  */
0792 static void test_regulator_obtain_buffer_OK(void)
0793 {
0794   rtems_status_code         sc;
0795   rtems_regulator_instance *regulator;
0796   void                     *buffer;
0797 
0798   regulator = test_regulator_create_regulator_OK();
0799   rtems_test_assert(regulator != NULL);
0800 
0801   sc = rtems_regulator_obtain_buffer(regulator, &buffer);
0802   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0803   rtems_test_assert(buffer != NULL);
0804 
0805   /*
0806    * Not really testing this here but cannot delete underlying partition
0807    * if there are buffers outstanding.
0808    */
0809   sc = rtems_regulator_release_buffer(regulator, buffer);
0810   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0811   rtems_test_assert(buffer != NULL);
0812 
0813   sc = rtems_regulator_delete(regulator, FIVE_SECONDS);
0814   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0815 }
0816 
0817 /**
0818  * @ingroup RegulatorTests
0819  * @brief Verify rtems_regulator_release_buffer NULL regulator error
0820  *
0821  * This unit test verifies that rtems_regulator_release_buffer() returns an error when
0822  * the regulator argument is NULL.
0823  */
0824 static void test_regulator_release_buffer_null_regulator(void)
0825 {
0826   rtems_status_code   sc;
0827   void               *buffer;
0828 
0829   sc = rtems_regulator_release_buffer(NULL, &buffer);
0830   rtems_test_assert(sc == RTEMS_INVALID_ADDRESS);
0831 }
0832 
0833 /**
0834  * @ingroup RegulatorTests
0835  * @brief Verify rtems_regulator_release_buffer uninitialized regulator error
0836  *
0837  * This unit test verifies that rtems_regulator_release_buffer() returns an
0838  * error when the regulator argument is uninitialized.
0839  */
0840 static void test_regulator_release_buffer_uninitialized_regulator(void)
0841 {
0842   rtems_status_code         sc;
0843   rtems_regulator_instance  regulator;
0844   void                     *buffer;
0845 
0846   (void) memset(&regulator, 0, sizeof(regulator));
0847 
0848   sc = rtems_regulator_release_buffer(&regulator, &buffer);
0849   rtems_test_assert(sc == RTEMS_INCORRECT_STATE);
0850 }
0851 
0852 /**
0853  * @ingroup RegulatorTests
0854  * @brief Verify rtems_regulator_release_buffer successful case
0855  *
0856  * This unit test verifies that rtems_regulator_release_buffer() can be successfully
0857  * invoked with a buffer previously allocated by rtems_regulator_obtain_buffer().
0858  */
0859 static void test_regulator_release_buffer_OK(void)
0860 {
0861   rtems_status_code         sc;
0862   rtems_regulator_instance *regulator;
0863   void                     *buffer;
0864 
0865   regulator = test_regulator_create_regulator_OK();
0866   rtems_test_assert(regulator != NULL);
0867 
0868   sc = rtems_regulator_obtain_buffer(regulator, &buffer);
0869   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0870   rtems_test_assert(buffer != NULL);
0871 
0872   sc = rtems_regulator_release_buffer(regulator, buffer);
0873   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0874 
0875   sc = rtems_regulator_delete(regulator, FIVE_SECONDS);
0876   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0877 }
0878 
0879 /**
0880  * @ingroup RegulatorTests
0881  * @brief Verify rtems_regulator_send NULL regulator error
0882  *
0883  * This unit test verifies that rtems_regulator_send() returns an error when
0884  * the regulator argument is NULL.
0885  */
0886 static void test_regulator_send_null_regulator(void)
0887 {
0888   rtems_status_code   sc;
0889   void               *buffer;
0890   size_t              length;
0891 
0892   buffer = &length;
0893   length = sizeof(size_t);
0894 
0895   sc = rtems_regulator_send(NULL, buffer, length);
0896   rtems_test_assert(sc == RTEMS_INVALID_ADDRESS);
0897 }
0898 
0899 /**
0900  * @ingroup RegulatorTests
0901  * @brief Verify rtems_regulator_send NULL message error
0902  *
0903  * This unit test verifies that rtems_regulator_send() returns an error when
0904  * the message argument is NULL.
0905  */
0906 static void test_regulator_send_null_message(void)
0907 {
0908   rtems_status_code         sc;
0909   size_t                    length;
0910   rtems_regulator_instance  regulator;
0911 
0912   length = sizeof(size_t);
0913 
0914   sc = rtems_regulator_send(&regulator, NULL, length);
0915   rtems_test_assert(sc == RTEMS_INVALID_ADDRESS);
0916 }
0917 
0918 /**
0919  * @ingroup RegulatorTests
0920  * @brief Verify rtems_regulator_send zero length message error
0921  *
0922  * This unit test verifies that rtems_regulator_send() returns an
0923  * error when the message length is 0.
0924  */
0925 static void test_regulator_send_length_is_zero(void)
0926 {
0927   rtems_status_code         sc;
0928   rtems_regulator_instance  regulator;
0929   void                     *buffer;
0930   size_t                    length;
0931 
0932   buffer = &length;
0933   length = 0;
0934 
0935   sc = rtems_regulator_send(&regulator, buffer, length);
0936   rtems_test_assert(sc == RTEMS_INVALID_NUMBER);
0937 }
0938 
0939 /**
0940  * @ingroup RegulatorTests
0941  * @brief Verify rtems_regulator_send uninitialized regulator error
0942  *
0943  * This unit test verifies that rtems_regulator_send() returns an
0944  * error when the regulator argument is uninitialized.
0945  */
0946 static void test_regulator_send_uninitialized_regulator(void)
0947 {
0948   rtems_status_code         sc;
0949   rtems_regulator_instance  regulator;
0950   void                     *buffer;
0951   size_t                    length;
0952 
0953   buffer = &length;
0954   length = sizeof(size_t);
0955 
0956   (void) memset(&regulator, 0, sizeof(regulator));
0957 
0958   sc = rtems_regulator_send(&regulator, buffer, length);
0959   rtems_test_assert(sc == RTEMS_INCORRECT_STATE);
0960 }
0961 
0962 /**
0963  * @ingroup RegulatorTests
0964  * @brief Verify Cannot Delete with Message Outstanding
0965  *
0966  * This unit test verifies that when the regulator is successfully
0967  * initialized, that it cannot be deleted with an undelivered message.
0968  * It also verifies some basic statistics are working.
0969  */
0970 static void test_regulator_cannot_delete_with_outstanding(void)
0971 {
0972   rtems_status_code         sc;
0973   rtems_regulator_instance *regulator;
0974   char                      message[MAXIMUM_MESSAGE_LENGTH];
0975   void                     *buffer;
0976   size_t                    length;
0977   int                       match;
0978   rtems_regulator_attributes  attributes = {
0979     .deliverer = test_regulator_deliverer_logger,
0980     .deliverer_context = &deliverer_logger_context,
0981     .maximum_message_size = 16,
0982     .maximum_messages = 10,
0983     .delivery_thread_priority = 16,
0984     .delivery_thread_stack_size = 0,
0985     .delivery_thread_period = RTEMS_MILLISECONDS_TO_TICKS(250),
0986     .maximum_to_dequeue_per_period = 3
0987   };
0988   rtems_regulator_statistics stats;
0989 
0990   sc = rtems_regulator_create(&attributes, &regulator);
0991   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0992   rtems_test_assert(regulator != NULL);
0993 
0994   deliverer_logger_context.regulator = regulator;
0995 
0996   delivered_messages_reset();
0997 
0998   // Ensure statistics show no buffers obtained or processed
0999   sc = rtems_regulator_get_statistics(regulator, &stats);
1000   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
1001   rtems_test_assert(stats.obtained == 0);
1002   rtems_test_assert(stats.released == 0);
1003   rtems_test_assert(stats.delivered == 0);
1004   rtems_test_assert(stats.period_statistics.count == 0);
1005   rtems_test_assert(stats.period_statistics.missed_count == 0);
1006 
1007   // Obtain a buffer which should change the statistics
1008   sc = rtems_regulator_obtain_buffer(regulator, &buffer);
1009   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
1010   rtems_test_assert(buffer != NULL);
1011 
1012   // Ensure statistics show one buffer obtained
1013   sc = rtems_regulator_get_statistics(regulator, &stats);
1014   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
1015   rtems_test_assert(stats.obtained == 1);
1016   rtems_test_assert(stats.released == 0);
1017   rtems_test_assert(stats.delivered == 0);
1018   rtems_test_assert(stats.period_statistics.count == 0);
1019   rtems_test_assert(stats.period_statistics.missed_count == 0);
1020 
1021 
1022   // Format and send the message -- statistics do not change
1023   length = snprintf(message, MAXIMUM_MESSAGE_LENGTH, "message %d", 1024) + 1;
1024   strcpy(buffer, message);
1025 
1026   sc = rtems_regulator_send(regulator, buffer, length);
1027   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
1028 
1029   // Ensure statistics show one buffer obtained
1030   sc = rtems_regulator_get_statistics(regulator, &stats);
1031   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
1032   rtems_test_assert(stats.obtained == 1);
1033   rtems_test_assert(stats.released == 0);
1034   rtems_test_assert(stats.delivered == 0);
1035   rtems_test_assert(stats.period_statistics.count == 0);
1036   rtems_test_assert(stats.period_statistics.missed_count == 0);
1037 
1038   // This is the actual failing case -- cannot delete w/outstanding
1039   sc = rtems_regulator_delete(regulator, FIVE_SECONDS);
1040   rtems_test_assert(sc == RTEMS_RESOURCE_IN_USE);
1041 
1042   // Now let the deliveries happen
1043   sleep(1);
1044 
1045   // Ensure statistics show all buffers released
1046   sc = rtems_regulator_get_statistics(regulator, &stats);
1047   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
1048   rtems_test_assert(stats.obtained == 1);
1049   rtems_test_assert(stats.released == 1);
1050   rtems_test_assert(stats.delivered == 1);
1051   rtems_test_assert(stats.period_statistics.count != 0);
1052   rtems_test_assert(stats.period_statistics.missed_count == 0);
1053 
1054   rtems_test_assert(delivered_message_count == 1);
1055   match = strncmp(
1056     delivered_messages[0].message,
1057     message,
1058     MAXIMUM_MESSAGE_LENGTH
1059   );
1060   rtems_test_assert(match == 0);
1061 
1062   sc = rtems_regulator_delete(regulator, FIVE_SECONDS);
1063   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
1064 
1065   deliverer_logger_context.regulator = NULL;
1066 }
1067 
1068 /**
1069  * @ingroup RegulatorTests
1070  * @brief Verify rtems_regulator_send and output thread delivers message
1071  *
1072  * This unit test verifies that when the regulator is
1073  * successfully initialized and used as expected, a message sent via
1074  * rtems_regulator_send() is delivered as expected.
1075  */
1076 static void test_regulator_send_one_message_OK(void)
1077 {
1078   rtems_status_code         sc;
1079   rtems_regulator_instance *regulator;
1080   char                      message[MAXIMUM_MESSAGE_LENGTH];
1081   void                     *buffer;
1082   size_t                    length;
1083   int                       match;
1084   rtems_regulator_attributes  attributes = {
1085     .deliverer = test_regulator_deliverer_logger,
1086     .deliverer_context = &deliverer_logger_context,
1087     .maximum_message_size = 16,
1088     .maximum_messages = 10,
1089     .delivery_thread_priority = 16,
1090     .delivery_thread_stack_size = 0,
1091     .delivery_thread_period = RTEMS_MILLISECONDS_TO_TICKS(250),
1092     .maximum_to_dequeue_per_period = 3
1093   };
1094 
1095   sc = rtems_regulator_create(&attributes, &regulator);
1096   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
1097   rtems_test_assert(regulator != NULL);
1098 
1099   deliverer_logger_context.regulator = regulator;
1100 
1101   delivered_messages_reset();
1102 
1103   sc = rtems_regulator_obtain_buffer(regulator, &buffer);
1104   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
1105   rtems_test_assert(buffer != NULL);
1106 
1107   length = snprintf(message, MAXIMUM_MESSAGE_LENGTH, "message %d", 1024) + 1;
1108   strcpy(buffer, message);
1109 
1110   sc = rtems_regulator_send(regulator, buffer, length);
1111   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
1112 
1113   sleep(1);
1114 
1115   rtems_test_assert(delivered_message_count == 1);
1116   match = strncmp(
1117     delivered_messages[0].message,
1118     message,
1119     MAXIMUM_MESSAGE_LENGTH
1120   );
1121   rtems_test_assert(match == 0);
1122 
1123   sc = rtems_regulator_delete(regulator, FIVE_SECONDS);
1124   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
1125 
1126   deliverer_logger_context.regulator = NULL;
1127 }
1128 
1129 /**
1130  * @ingroup RegulatorTests
1131  * @brief Verify rtems_regulator_send and output thread delivers messages
1132  *
1133  * This unit test verifies that when the regulator is successfully initialized
1134  * and used as expected, and multiple messages are sent via rtems_regulator_send()
1135  * that they are delivered as expected.
1136  */
1137 #include <stdio.h>
1138 static void test_regulator_send_multiple_messages_OK(void)
1139 {
1140   rtems_status_code         sc;
1141   rtems_regulator_instance *regulator;
1142   char                      message[MAXIMUM_MESSAGE_LENGTH];
1143   void                     *buffer;
1144   size_t                    length;
1145   int                       match;
1146   int                       i;
1147   time_t                    base_time;
1148   time_t                    tmp_time;
1149   rtems_interval            base_ticks;
1150   rtems_interval            ticks;
1151   rtems_interval            ticks_per_second;
1152 
1153   rtems_regulator_attributes  attributes = {
1154     .deliverer = test_regulator_deliverer_logger,
1155     .deliverer_context = &deliverer_logger_context,
1156     .maximum_message_size = MAXIMUM_MESSAGE_LENGTH,
1157     .maximum_messages = 10,
1158     .delivery_thread_priority = 16,
1159     .delivery_thread_stack_size = 0,
1160     .delivery_thread_period = RTEMS_MILLISECONDS_TO_TICKS(1000),
1161     .maximum_to_dequeue_per_period = 2
1162   };
1163 
1164   delivered_messages_reset();
1165 
1166   sc = rtems_regulator_create(&attributes, &regulator);
1167   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
1168   rtems_test_assert(regulator != NULL);
1169 
1170   deliverer_logger_context.regulator = regulator;
1171 
1172   /*
1173    * Ensure the messages are sent on a second boundary to ensure the
1174    * output thread will process them as expected.
1175    */
1176   tmp_time = time(NULL);
1177   do {
1178     base_time = time(NULL);
1179   } while (tmp_time == base_time);
1180 
1181   /**
1182    * Send five messages as a burst which will need to be smoothly sent at
1183    * the configured rate.
1184    */
1185   for (i=1 ; i <= 5 ; i++) {
1186     sc = rtems_regulator_obtain_buffer(regulator, &buffer);
1187     rtems_test_assert(sc == RTEMS_SUCCESSFUL);
1188     rtems_test_assert(buffer != NULL);
1189 
1190     length = snprintf(message, MAXIMUM_MESSAGE_LENGTH, "message %d", i);
1191     strcpy(buffer, message);
1192 
1193     sc = rtems_regulator_send(regulator, buffer, length);
1194     rtems_test_assert(sc == RTEMS_SUCCESSFUL);
1195   }
1196 
1197   /*
1198    * Let the output thread executed and deliver the messages.
1199    */
1200   sleep(5);
1201 
1202   /**
1203    * Ensure the five messages were delivered as follows:
1204    *
1205    *   - deliver all 5
1206    *   - contents are "message N" where N is 1 to 5
1207    *   - message 1 and 2 delivered during the first second
1208    *   - message 3 and 4 delivered during the second second
1209    *   - message 5 delivered during the third second
1210    *   - no further messages delivered
1211    */
1212 
1213   rtems_test_assert(delivered_message_count == 5);
1214 
1215   for (i=0 ; i < 5 ; i++) {
1216     (void) snprintf(message, MAXIMUM_MESSAGE_LENGTH, "message %d", i+1);
1217 // printf("%d %s\n", i, delivered_messages[i].message);
1218     match = strncmp(
1219       delivered_messages[i].message,
1220       message,
1221       MAXIMUM_MESSAGE_LENGTH
1222     );
1223     rtems_test_assert(match == 0);
1224   }
1225 
1226   /**
1227    * Verify that messages were delivered in the proper groups. Check that
1228    * the delivery time matches expectations.
1229    */
1230   rtems_test_assert(delivered_messages[0].processed == delivered_messages[1].processed);
1231   rtems_test_assert(delivered_messages[1].processed != delivered_messages[2].processed);
1232   rtems_test_assert(delivered_messages[2].processed == delivered_messages[3].processed);
1233   rtems_test_assert(delivered_messages[3].processed != delivered_messages[4].processed);
1234 
1235   /**
1236    * Verify that the message groups were properly spaced temporally. They
1237    * should be one second apart.
1238    */
1239   ticks_per_second = rtems_clock_get_ticks_per_second();
1240 
1241   base_ticks = delivered_messages[1].processed;
1242   ticks      = delivered_messages[2].processed;
1243   rtems_test_assert(ticks_per_second == ticks - base_ticks);
1244 
1245   base_ticks = delivered_messages[3].processed;
1246   ticks      = delivered_messages[4].processed;
1247   rtems_test_assert(ticks_per_second == ticks - base_ticks);
1248 
1249   sc = rtems_regulator_delete(regulator, FIVE_SECONDS);
1250   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
1251 
1252   deliverer_logger_context.regulator = NULL;
1253 }
1254 
1255 /* Necessary prototype */
1256 rtems_task test_regulator(rtems_task_argument);
1257 
1258 /**
1259  * @ingroup RegulatorTests
1260  * @brief Test entry task which invokes test cases
1261  */
1262 rtems_task test_regulator(rtems_task_argument arg)
1263 {
1264   (void) arg;
1265 
1266   TEST_BEGIN();
1267 
1268   malloc_trigger_reset();
1269 
1270   test_regulator_create_max_dequeue_zero();
1271   test_regulator_create_null_attributes();
1272   test_regulator_create_null_regulator();
1273   test_regulator_create_deliverer_is_null();
1274   test_regulator_create_maximum_messages_is_zero();
1275   test_regulator_create_maximum_message_size_is_zero();
1276   test_regulator_create_maximum_to_dequeue_per_period_is_zero();
1277   test_regulator_create_malloc_regulator_fails();
1278   test_regulator_create_malloc_buffers_fails();
1279   test_regulator_create_delivery_thread_priority_is_zero();
1280   test_regulator_create_partition_create_fails();
1281   test_regulator_create_message_queue_create_fails();
1282   test_regulator_create_task_create_fails();
1283   test_regulator_create_rate_monotonic_create_fails();
1284 
1285   test_regulator_delete_null_regulator();
1286   test_regulator_delete_uninitialized_regulator();
1287   test_regulator_delete_OK();
1288 
1289   test_regulator_obtain_buffer_null_regulator();
1290   test_regulator_obtain_buffer_uninitialized_regulator();
1291   test_regulator_obtain_buffer_OK();
1292 
1293   test_regulator_release_buffer_null_regulator();
1294   test_regulator_release_buffer_uninitialized_regulator();
1295   test_regulator_release_buffer_OK();
1296 
1297   test_regulator_send_null_regulator();
1298   test_regulator_send_null_message();
1299   test_regulator_send_length_is_zero();
1300   test_regulator_send_uninitialized_regulator();
1301 
1302   test_regulator_send_one_message_OK();
1303   test_regulator_cannot_delete_with_outstanding();
1304 
1305   test_regulator_send_multiple_messages_OK();
1306 
1307   TEST_END();
1308 
1309   rtems_test_exit(0);
1310 }