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  * Copyright (C) 2018, 2024 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/record.h>
0033 #include <rtems/recordclient.h>
0034 #include <rtems.h>
0035 
0036 #include <string.h>
0037 
0038 #include "tmacros.h"
0039 
0040 const char rtems_test_name[] = "RECORD 2";
0041 
0042 typedef struct {
0043   rtems_record_client_context client;
0044 } test_context;
0045 
0046 static test_context test_instance;
0047 
0048 static rtems_record_client_status client_handler(
0049   uint64_t            bt,
0050   uint32_t            cpu,
0051   rtems_record_event  event,
0052   uint64_t            data,
0053   void               *arg
0054 )
0055 {
0056   uint32_t seconds;
0057   uint32_t nanoseconds;
0058 
0059   (void) arg;
0060 
0061   if (event == RTEMS_RECORD_USER_5) {
0062     return RTEMS_RECORD_CLIENT_SUCCESS;
0063   }
0064 
0065   rtems_record_client_bintime_to_seconds_and_nanoseconds(
0066     bt,
0067     &seconds,
0068     &nanoseconds
0069   );
0070   printf(
0071     "%" PRIu32 ".%09" PRIu32 ":"
0072     "%" PRIu32 ":%s:%" PRIx64 "\n",
0073     seconds,
0074     nanoseconds,
0075     cpu,
0076     rtems_record_event_text( event ),
0077     data
0078   );
0079 
0080   return RTEMS_RECORD_CLIENT_SUCCESS;
0081 }
0082 
0083 static void wait(void)
0084 {
0085   int i;
0086 
0087   for (i = 0; i < 10; ++i) {
0088     rtems_task_wake_after(1);
0089   }
0090 }
0091 
0092 static void generate_events(void)
0093 {
0094   uint32_t level;
0095 
0096   rtems_record_line();
0097   rtems_record_line_2(RTEMS_RECORD_USER_0, 0);
0098   rtems_record_line_3(RTEMS_RECORD_USER_1, 1, RTEMS_RECORD_USER_2, 2);
0099   rtems_record_line_arg(0);
0100   rtems_record_line_arg_2(0, 1);
0101   rtems_record_line_arg_3(0, 1, 2);
0102   rtems_record_line_arg_4(0, 1, 2, 3);
0103   rtems_record_line_arg_5(0, 1, 2, 3, 4);
0104   rtems_record_line_arg_6(0, 1, 2, 3, 4, 5);
0105   rtems_record_line_arg_7(0, 1, 2, 3, 4, 5, 6);
0106   rtems_record_line_arg_8(0, 1, 2, 3, 4, 5, 6, 7);
0107   rtems_record_line_arg_9(0, 1, 2, 3, 4, 5, 6, 7, 8);
0108   rtems_record_line_arg_10(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
0109   rtems_record_caller();
0110   rtems_record_caller_3(RTEMS_RECORD_USER_0, 0);
0111   rtems_record_caller_4(RTEMS_RECORD_USER_1, 1, RTEMS_RECORD_USER_2, 2);
0112   rtems_record_caller_arg(0);
0113   rtems_record_caller_arg_2(0, 1);
0114   rtems_record_caller_arg_3(0, 1, 2);
0115   rtems_record_caller_arg_4(0, 1, 2, 3);
0116   rtems_record_caller_arg_5(0, 1, 2, 3, 4);
0117   rtems_record_caller_arg_6(0, 1, 2, 3, 4, 5);
0118   rtems_record_caller_arg_7(0, 1, 2, 3, 4, 5, 6);
0119   rtems_record_caller_arg_8(0, 1, 2, 3, 4, 5, 6, 7);
0120   rtems_record_caller_arg_9(0, 1, 2, 3, 4, 5, 6, 7, 8);
0121   rtems_record_caller_arg_10(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
0122   rtems_record_entry(RTEMS_RECORD_USER_3);
0123   rtems_record_entry_1(RTEMS_RECORD_USER_3, 0);
0124   rtems_record_entry_2(RTEMS_RECORD_USER_3, 0, 1);
0125   rtems_record_entry_3(RTEMS_RECORD_USER_3, 0, 1, 2);
0126   rtems_record_entry_4(RTEMS_RECORD_USER_3, 0, 1, 2, 3);
0127   rtems_record_entry_5(RTEMS_RECORD_USER_3, 0, 1, 2, 3, 4);
0128   rtems_record_entry_6(RTEMS_RECORD_USER_3, 0, 1, 2, 3, 4, 5);
0129   rtems_record_entry_7(RTEMS_RECORD_USER_3, 0, 1, 2, 3, 4, 5, 6);
0130   rtems_record_entry_8(RTEMS_RECORD_USER_3, 0, 1, 2, 3, 4, 5, 6, 7);
0131   rtems_record_entry_9(RTEMS_RECORD_USER_3, 0, 1, 2, 3, 4, 5, 6, 7, 8);
0132   rtems_record_entry_10(RTEMS_RECORD_USER_3, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
0133   rtems_record_exit(RTEMS_RECORD_USER_4);
0134   rtems_record_exit_1(RTEMS_RECORD_USER_4, 0);
0135   rtems_record_exit_2(RTEMS_RECORD_USER_4, 0, 1);
0136   rtems_record_exit_3(RTEMS_RECORD_USER_4, 0, 1, 2);
0137   rtems_record_exit_4(RTEMS_RECORD_USER_4, 0, 1, 2, 3);
0138   rtems_record_exit_5(RTEMS_RECORD_USER_4, 0, 1, 2, 3, 4);
0139   rtems_record_exit_6(RTEMS_RECORD_USER_4, 0, 1, 2, 3, 4, 5);
0140   rtems_record_exit_7(RTEMS_RECORD_USER_4, 0, 1, 2, 3, 4, 5, 6);
0141   rtems_record_exit_8(RTEMS_RECORD_USER_4, 0, 1, 2, 3, 4, 5, 6, 7);
0142   rtems_record_exit_9(RTEMS_RECORD_USER_4, 0, 1, 2, 3, 4, 5, 6, 7, 8);
0143   rtems_record_exit_10(RTEMS_RECORD_USER_4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
0144   level = rtems_record_interrupt_disable();
0145   rtems_record_interrupt_enable(level);
0146 }
0147 
0148 static void fetch(test_context *ctx)
0149 {
0150   rtems_record_client_status cs;
0151   rtems_record_fetch_control control;
0152   rtems_record_item          items[256];
0153   rtems_record_fetch_status  fs;
0154 
0155   rtems_record_fetch_initialize(
0156     &control,
0157     &items[0],
0158     RTEMS_ARRAY_SIZE( items )
0159   );
0160 
0161   do {
0162     fs = rtems_record_fetch(&control);
0163     cs = rtems_record_client_run(
0164       &ctx->client,
0165       control.fetched_items,
0166       control.fetched_count * sizeof(*control.fetched_items)
0167     );
0168     rtems_test_assert(cs == RTEMS_RECORD_CLIENT_SUCCESS);
0169   } while (fs == RTEMS_RECORD_FETCH_CONTINUE);
0170 }
0171 
0172 static void overflow(void)
0173 {
0174   int i;
0175 
0176   for (i = 0; i < 512; ++i) {
0177     rtems_record_produce(RTEMS_RECORD_USER_5, 0);
0178   }
0179 
0180   rtems_record_produce(RTEMS_RECORD_USER_6, 0);
0181 }
0182 
0183 static void Init(rtems_task_argument arg)
0184 {
0185   test_context *ctx;
0186   Record_Stream_header header;
0187   size_t size;
0188   rtems_record_client_status cs;
0189   rtems_interrupt_level level;
0190 
0191   TEST_BEGIN();
0192   ctx = &test_instance;
0193 
0194   wait();
0195   generate_events();
0196 
0197   cs = rtems_record_client_init(&ctx->client, client_handler, NULL);
0198   rtems_test_assert(cs == RTEMS_RECORD_CLIENT_SUCCESS);
0199   size = _Record_Stream_header_initialize(&header);
0200   cs = rtems_record_client_run(&ctx->client, &header, size);
0201   rtems_test_assert(cs == RTEMS_RECORD_CLIENT_SUCCESS);
0202   fetch(ctx);
0203 
0204   rtems_interrupt_local_disable(level);
0205   overflow();
0206   fetch(ctx);
0207   rtems_interrupt_local_enable(level);
0208 
0209   rtems_record_client_destroy(&ctx->client);
0210 
0211   wait();
0212   generate_events();
0213   rtems_fatal( RTEMS_FATAL_SOURCE_EXIT, 0 );
0214 }
0215 
0216 static void fatal_extension(
0217   rtems_fatal_source source,
0218   bool always_set_to_false,
0219   rtems_fatal_code code
0220 )
0221 {
0222   generate_events();
0223   _Record_Fatal_dump_base64(source, always_set_to_false, code);
0224   TEST_END();
0225 }
0226 
0227 #define INITIAL_EXTENSION \
0228   { NULL, NULL, NULL, NULL, NULL, NULL, NULL, fatal_extension, NULL }
0229 
0230 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0231 
0232 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0233 
0234 #define CONFIGURE_MAXIMUM_TASKS 1
0235 
0236 #define CONFIGURE_INITIAL_EXTENSIONS \
0237   INITIAL_EXTENSION, RTEMS_TEST_INITIAL_EXTENSION
0238 
0239 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0240 
0241 #define CONFIGURE_RECORD_PER_PROCESSOR_ITEMS 512
0242 
0243 #define CONFIGURE_RECORD_EXTENSIONS_ENABLED
0244 
0245 #define CONFIGURE_RECORD_FATAL_DUMP_BASE64_ZLIB
0246 
0247 #define CONFIGURE_INIT
0248 
0249 #include <rtems/confdefs.h>