Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  * Copyright (c) 2014 embedded brains GmbH & Co. KG
0005  *
0006  * Redistribution and use in source and binary forms, with or without
0007  * modification, are permitted provided that the following conditions
0008  * are met:
0009  * 1. Redistributions of source code must retain the above copyright
0010  *    notice, this list of conditions and the following disclaimer.
0011  * 2. Redistributions in binary form must reproduce the above copyright
0012  *    notice, this list of conditions and the following disclaimer in the
0013  *    documentation and/or other materials provided with the distribution.
0014  *
0015  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0016  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0017  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0018  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0019  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0020  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0021  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0022  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0023  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0024  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0025  * POSSIBILITY OF SUCH DAMAGE.
0026  */
0027 
0028 #ifdef HAVE_CONFIG_H
0029 #include "config.h"
0030 #endif
0031 
0032 #include <rtems/profiling.h>
0033 #include <rtems/bspIo.h>
0034 #include <rtems.h>
0035 
0036 #include <stdio.h>
0037 #include <string.h>
0038 
0039 #include "tmacros.h"
0040 
0041 const char rtems_test_name[] = "SPPROFILING 1";
0042 
0043 typedef struct {
0044   rtems_interrupt_lock a;
0045   rtems_interrupt_lock b;
0046   rtems_interrupt_lock c;
0047   rtems_interrupt_lock d;
0048   enum {
0049     WAIT_FOR_A,
0050     EXPECT_B,
0051     EXPECT_D,
0052     DONE
0053   } state;
0054 } visitor_context;
0055 
0056 static bool is_equal(const rtems_profiling_smp_lock *psl, const char *name)
0057 {
0058   return strcmp(psl->name, name) == 0;
0059 }
0060 
0061 static void visitor(void *arg, const rtems_profiling_data *data)
0062 {
0063   visitor_context *ctx = arg;
0064 
0065   if (data->header.type == RTEMS_PROFILING_SMP_LOCK) {
0066     const rtems_profiling_smp_lock *psl = &data->smp_lock;
0067 
0068     switch (ctx->state) {
0069       case WAIT_FOR_A:
0070         rtems_test_assert(!is_equal(psl, "b"));
0071         rtems_test_assert(!is_equal(psl, "c"));
0072         rtems_test_assert(!is_equal(psl, "d"));
0073 
0074         if (is_equal(psl, "a")) {
0075           ctx->state = EXPECT_B;
0076         }
0077         break;
0078       case EXPECT_B:
0079         rtems_test_assert(is_equal(psl, "b"));
0080         rtems_interrupt_lock_destroy(&ctx->c);
0081         ctx->state = EXPECT_D;
0082         break;
0083       case EXPECT_D:
0084         rtems_test_assert(is_equal(psl, "d"));
0085         ctx->state = DONE;
0086         break;
0087       case DONE:
0088         rtems_test_assert(!is_equal(psl, "a"));
0089         rtems_test_assert(!is_equal(psl, "b"));
0090         rtems_test_assert(!is_equal(psl, "c"));
0091         rtems_test_assert(!is_equal(psl, "d"));
0092         break;
0093     }
0094   }
0095 }
0096 
0097 static void lock_init(rtems_interrupt_lock *lock, const char *name)
0098 {
0099   rtems_interrupt_lock_context lock_context;
0100 
0101   rtems_interrupt_lock_initialize(lock, name);
0102   rtems_interrupt_lock_acquire(lock, &lock_context);
0103   rtems_interrupt_lock_release(lock, &lock_context);
0104 }
0105 
0106 static void test_iterate(void)
0107 {
0108   visitor_context ctx_instance;
0109   visitor_context *ctx = &ctx_instance;
0110 
0111   ctx->state = WAIT_FOR_A;
0112   lock_init(&ctx->a, "a");
0113   lock_init(&ctx->b, "b");
0114   lock_init(&ctx->c, "c");
0115   lock_init(&ctx->d, "d");
0116 
0117   rtems_profiling_iterate(visitor, ctx);
0118 
0119   rtems_interrupt_lock_destroy(&ctx->a);
0120   rtems_interrupt_lock_destroy(&ctx->b);
0121 
0122   if (ctx->state != DONE) {
0123     rtems_interrupt_lock_destroy(&ctx->c);
0124   }
0125 
0126   rtems_interrupt_lock_destroy(&ctx->d);
0127 }
0128 
0129 static void test_report_xml(void)
0130 {
0131   rtems_status_code sc;
0132   int rv;
0133 
0134   sc = rtems_task_wake_after(3);
0135   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0136 
0137   rv = rtems_profiling_report_xml("X", &rtems_test_printer, 1, "  ");
0138   printf("characters produced by rtems_profiling_report_xml(): %i\n", rv);
0139 }
0140 
0141 static void Init(rtems_task_argument arg)
0142 {
0143   TEST_BEGIN();
0144 
0145   test_iterate();
0146   test_report_xml();
0147 
0148   TEST_END();
0149 
0150   rtems_test_exit(0);
0151 }
0152 
0153 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0154 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0155 
0156 #define CONFIGURE_MAXIMUM_TASKS 1
0157 
0158 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0159 
0160 #define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT
0161 
0162 #define CONFIGURE_INIT
0163 
0164 #include <rtems/confdefs.h>