Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup test_bdbuf
0007  *
0008  * @brief Bdbuf test.
0009  */
0010 
0011 /*
0012  * Copyright (C) 2009, 2018 embedded brains GmbH & Co. KG
0013  *
0014  * Redistribution and use in source and binary forms, with or without
0015  * modification, are permitted provided that the following conditions
0016  * are met:
0017  * 1. Redistributions of source code must retain the above copyright
0018  *    notice, this list of conditions and the following disclaimer.
0019  * 2. Redistributions in binary form must reproduce the above copyright
0020  *    notice, this list of conditions and the following disclaimer in the
0021  *    documentation and/or other materials provided with the distribution.
0022  *
0023  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0024  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0025  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0026  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0027  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0028  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0029  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0030  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0031  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0032  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0033  * POSSIBILITY OF SUCH DAMAGE.
0034  */
0035 
0036 #ifdef HAVE_CONFIG_H
0037 #include "config.h"
0038 #endif
0039 
0040 #include "tmacros.h"
0041 
0042 #include <rtems.h>
0043 #include <rtems/bspIo.h>
0044 #include <rtems/ramdisk.h>
0045 #include <rtems/bdbuf.h>
0046 
0047 #include <sys/stat.h>
0048 #include <fcntl.h>
0049 #include <unistd.h>
0050 
0051 const char rtems_test_name[] = "BLOCK 4";
0052 
0053 #define ASSERT_SC(sc) rtems_test_assert((sc) == RTEMS_SUCCESSFUL)
0054 
0055 #define PRIORITY_INIT 10
0056 
0057 #define PRIORITY_SWAPOUT 50
0058 
0059 #define PRIORITY_HIGH 30
0060 
0061 #define PRIORITY_LOW 40
0062 
0063 #define BLOCK_SIZE 512
0064 
0065 #define BLOCK_COUNT 1
0066 
0067 static rtems_disk_device *dd;
0068 
0069 static rtems_id task_id_low;
0070 
0071 static rtems_id task_id_high;
0072 
0073 static void task_low(rtems_task_argument arg)
0074 {
0075   rtems_status_code sc = RTEMS_SUCCESSFUL;
0076   rtems_bdbuf_buffer *bd = NULL;
0077 
0078   printk("L: try access: 0\n");
0079 
0080   sc = rtems_bdbuf_get(dd, 0, &bd);
0081   ASSERT_SC(sc);
0082 
0083   printk("L: access: 0\n");
0084 
0085   sc = rtems_task_resume(task_id_high);
0086   ASSERT_SC(sc);
0087 
0088   sc = rtems_bdbuf_sync(bd);
0089   ASSERT_SC(sc);
0090 
0091   printk("L: sync done: 0\n");
0092 
0093   rtems_test_assert(false);
0094 }
0095 
0096 static void task_high(rtems_task_argument arg)
0097 {
0098   rtems_status_code sc = RTEMS_SUCCESSFUL;
0099   rtems_bdbuf_buffer *bd = NULL;
0100 
0101   sc = rtems_task_suspend(RTEMS_SELF);
0102   ASSERT_SC(sc);
0103 
0104   printk("H: try access: 0\n");
0105 
0106   sc = rtems_bdbuf_get(dd, 0, &bd);
0107   ASSERT_SC(sc);
0108 
0109   printk("H: access: 0\n");
0110 
0111   printk("H: release: 0\n");
0112 
0113   sc = rtems_bdbuf_release(bd);
0114   ASSERT_SC(sc);
0115 
0116   printk("H: release done: 0\n");
0117 
0118   TEST_END();
0119 
0120   exit(0);
0121 }
0122 
0123 static void do_ramdisk_register(
0124   uint32_t media_block_size,
0125   rtems_blkdev_bnum media_block_count,
0126   const char *disk,
0127   rtems_disk_device **dd
0128 )
0129 {
0130   rtems_status_code sc;
0131   int fd;
0132   int rv;
0133 
0134   sc = ramdisk_register(media_block_size, media_block_count, false, disk);
0135   ASSERT_SC(sc);
0136 
0137   fd = open(disk, O_RDWR);
0138   rtems_test_assert(fd >= 0);
0139 
0140   rv = rtems_disk_fd_get_disk_device(fd, dd);
0141   rtems_test_assert(rv == 0);
0142 
0143   rv = close(fd);
0144   rtems_test_assert(rv == 0);
0145 }
0146 
0147 static rtems_task Init(rtems_task_argument argument)
0148 {
0149   rtems_status_code sc = RTEMS_SUCCESSFUL;
0150 
0151   TEST_BEGIN();
0152 
0153   do_ramdisk_register(BLOCK_SIZE, BLOCK_COUNT, "/dev/rda", &dd);
0154 
0155   sc = rtems_task_create(
0156     rtems_build_name(' ', 'L', 'O', 'W'),
0157     PRIORITY_LOW,
0158     0,
0159     RTEMS_DEFAULT_MODES,
0160     RTEMS_DEFAULT_ATTRIBUTES,
0161     &task_id_low
0162   );
0163   ASSERT_SC(sc);
0164 
0165   sc = rtems_task_start(task_id_low, task_low, 0);
0166   ASSERT_SC(sc);
0167 
0168   sc = rtems_task_create(
0169     rtems_build_name('H', 'I', 'G', 'H'),
0170     PRIORITY_HIGH,
0171     0,
0172     RTEMS_DEFAULT_MODES,
0173     RTEMS_DEFAULT_ATTRIBUTES,
0174     &task_id_high
0175   );
0176   ASSERT_SC(sc);
0177 
0178   sc = rtems_task_start(task_id_high, task_high, 0);
0179   ASSERT_SC(sc);
0180 
0181   sc = rtems_task_suspend(RTEMS_SELF);
0182   ASSERT_SC(sc);
0183 }
0184 
0185 #define CONFIGURE_INIT
0186 
0187 #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
0188 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0189 #define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
0190 
0191 #define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 4
0192 
0193 #define CONFIGURE_MAXIMUM_TASKS 3
0194 
0195 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0196 
0197 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0198 
0199 #define CONFIGURE_INIT_TASK_PRIORITY PRIORITY_INIT
0200 #define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_DEFAULT_ATTRIBUTES
0201 #define CONFIGURE_INIT_TASK_INITIAL_MODES RTEMS_DEFAULT_MODES
0202 
0203 #define CONFIGURE_SWAPOUT_TASK_PRIORITY PRIORITY_SWAPOUT
0204 
0205 #define CONFIGURE_BDBUF_BUFFER_MIN_SIZE BLOCK_SIZE
0206 #define CONFIGURE_BDBUF_BUFFER_MAX_SIZE BLOCK_SIZE
0207 #define CONFIGURE_BDBUF_CACHE_MEMORY_SIZE BLOCK_SIZE
0208 
0209 #include <rtems/confdefs.h>