예제 #1
0
파일: init.c 프로젝트: Avanznow/rtems
static void test_blkdev_imfs_errors(void)
{
  static uintptr_t disk_size [] = { sizeof(rtems_disk_device) + sizeof(int) };

  rtems_status_code sc;
  int rv;
  ramdisk *rd;
  void *opaque;
  struct stat st;

  rd = ramdisk_allocate(NULL, BLOCK_SIZE, BLOCK_COUNT, false);
  rtems_test_assert(rd != NULL);

  ramdisk_enable_free_at_delete_request(rd);

  sc = rtems_blkdev_create(
    rda,
    0,
    BLOCK_COUNT,
    ramdisk_ioctl,
    rd
  );
  rtems_test_assert(sc == RTEMS_INVALID_NUMBER);

  sc = rtems_blkdev_create(
    rda,
    BLOCK_SIZE,
    0,
    ramdisk_ioctl,
    rd
  );
  rtems_test_assert(sc == RTEMS_INVALID_NUMBER);

  opaque = rtems_heap_greedy_allocate(NULL, 0);
  sc = rtems_blkdev_create(
    rda,
    BLOCK_SIZE,
    BLOCK_COUNT,
    ramdisk_ioctl,
    rd
  );
  rtems_test_assert(sc == RTEMS_NO_MEMORY);
  rtems_heap_greedy_free(opaque);

  opaque = rtems_heap_greedy_allocate(disk_size, 1);
  sc = rtems_blkdev_create(
    rda,
    BLOCK_SIZE,
    BLOCK_COUNT,
    ramdisk_ioctl,
    rd
  );
  rtems_test_assert(sc == RTEMS_UNSATISFIED);
  rtems_heap_greedy_free(opaque);

  sc = rtems_blkdev_create(
    rda,
    BLOCK_SIZE,
    BLOCK_COUNT,
    ramdisk_ioctl,
    rd
  );
  ASSERT_SC(sc);

  sc = rtems_blkdev_create_partition(
    rda1,
    not_exist,
    0,
    BLOCK_COUNT
  );
  rtems_test_assert(sc == RTEMS_INVALID_ID);

  rv = lstat(&dev_invalid[0], &st);
  rtems_test_assert(rv == 0);

  rv = mknod(not_blkdev, S_IFREG | S_IRWXU | S_IRWXG | S_IRWXO, st.st_rdev);
  rtems_test_assert(rv == 0);

  sc = rtems_blkdev_create_partition(
    rda1,
    not_blkdev,
    0,
    BLOCK_COUNT
  );
  rtems_test_assert(sc == RTEMS_INVALID_NODE);

  rv = mknod(invalid_blkdev, S_IFBLK | S_IRWXU | S_IRWXG | S_IRWXO, st.st_rdev);
  rtems_test_assert(rv == 0);

  sc = rtems_blkdev_create_partition(
    rda1,
    invalid_blkdev,
    0,
    BLOCK_COUNT
  );
  rtems_test_assert(sc == RTEMS_NOT_IMPLEMENTED);

  sc = rtems_blkdev_create_partition(
    rda1,
    rda,
    0,
    0
  );
  rtems_test_assert(sc == RTEMS_INVALID_NUMBER);

  sc = rtems_blkdev_create_partition(
    rda1,
    rda,
    BLOCK_COUNT,
    BLOCK_COUNT
  );
  rtems_test_assert(sc == RTEMS_INVALID_NUMBER);

  sc = rtems_blkdev_create_partition(
    rda1,
    rda,
    0,
    BLOCK_COUNT + 1
  );
  rtems_test_assert(sc == RTEMS_INVALID_NUMBER);

  opaque = rtems_heap_greedy_allocate(NULL, 0);
  sc = rtems_blkdev_create_partition(
    rda1,
    rda,
    0,
    BLOCK_COUNT
  );
  rtems_test_assert(sc == RTEMS_NO_MEMORY);
  rtems_heap_greedy_free(opaque);

  opaque = rtems_heap_greedy_allocate(disk_size, 1);
  sc = rtems_blkdev_create_partition(
    rda1,
    rda,
    0,
    BLOCK_COUNT
  );
  rtems_test_assert(sc == RTEMS_UNSATISFIED);
  rtems_heap_greedy_free(opaque);

  rv = unlink(rda);
  rtems_test_assert(rv == 0);
}
예제 #2
0
static rtems_task Init(rtems_task_argument argument)
{
  rtems_status_code sc = RTEMS_SUCCESSFUL;
  size_t i_w = 0;
  size_t i_ac = 0;
  size_t i_rel = 0;
  size_t i_p = 0;

  printk("\n\n*** TEST BLOCK 10 ***\n");

  task_id_init = rtems_task_self();

  sc = rtems_disk_io_initialize();
  ASSERT_SC(sc);

  sc = disk_register(BLOCK_SIZE, BLOCK_COUNT, &dev);
  ASSERT_SC(sc);

  sc = rtems_task_create(
    rtems_build_name('P', 'U', 'R', 'G'),
    PRIORITY_HIGH,
    0,
    RTEMS_DEFAULT_MODES,
    RTEMS_DEFAULT_ATTRIBUTES,
    &task_id_purger
  );
  ASSERT_SC(sc);

  sc = rtems_task_start(task_id_purger, task_purger, 0);
  ASSERT_SC(sc);

  set_task_prio(task_id_purger, PRIORITY_LOW);

  sc = rtems_task_create(
    rtems_build_name('W', 'A', 'I', 'T'),
    PRIORITY_HIGH,
    0,
    RTEMS_DEFAULT_MODES,
    RTEMS_DEFAULT_ATTRIBUTES,
    &task_id_waiter
  );
  ASSERT_SC(sc);

  sc = rtems_task_start(task_id_waiter, task_waiter, 0);
  ASSERT_SC(sc);

  for (i_ac = 0; i_ac < ACCESS_COUNT; ++i_ac) {
    for (i_rel = 0; i_rel < RELEASE_COUNT; ++i_rel) {
      for (i_w = 0; i_w < WAITER_COUNT; ++i_w) {
        printk("test case [access]: %s and %s %s\n", access_assoc_table [i_ac], release_assoc_table [i_rel], waiter_assoc_table [i_w]);
        check_access(access_table [i_ac], release_table [i_rel], waiter_table [i_w]);
      }
    }
  }

  for (i_rel = 0; i_rel < RELEASE_COUNT; ++i_rel) {
    for (i_w = 0; i_w < WAITER_COUNT; ++i_w) {
      printk("test case [intermediate]: %s %s\n", release_assoc_table [i_rel], waiter_assoc_table [i_w]);
      check_intermediate(release_table [i_rel], waiter_table [i_w]);
    }
  }

  for (i_p = 0; i_p < PURGER_COUNT; ++i_p) {
    for (i_w = 0; i_w < WAITER_COUNT; ++i_w) {
      printk("test case [transfer]: %s %s\n", purger_assoc_table [i_p], waiter_assoc_table [i_w]);
      check_transfer(purger_table [i_p], waiter_table [i_w]);
    }
  }

  printk("*** END OF TEST BLOCK 10 ***\n");

  exit(0);
}
예제 #3
0
파일: init.c 프로젝트: Avanznow/rtems
static void test_blkdev_imfs_parameters(void)
{
  rtems_status_code sc;
  int rv;
  ramdisk *rd;
  int fd;
  rtems_disk_device *dd;
  struct stat st;

  rd = ramdisk_allocate(NULL, BLOCK_SIZE, BLOCK_COUNT, false);
  rtems_test_assert(rd != NULL);

  ramdisk_enable_free_at_delete_request(rd);

  sc = rtems_blkdev_create(
    rda,
    BLOCK_SIZE,
    BLOCK_COUNT,
    ramdisk_ioctl,
    rd
  );
  ASSERT_SC(sc);

  sc = rtems_blkdev_create_partition(
    rda1,
    rda,
    1,
    BLOCK_COUNT - 1
  );
  ASSERT_SC(sc);

  fd = open(rda, O_RDWR);
  rtems_test_assert(fd >= 0);

  rv = fstat(fd, &st);
  rtems_test_assert(rv == 0);

  rv = rtems_disk_fd_get_disk_device(fd, &dd);
  rtems_test_assert(rv == 0);

  rtems_test_assert(rtems_disk_get_driver_data(dd) == rd);
  rtems_test_assert(rtems_disk_get_device_identifier(dd) == st.st_rdev);
  rtems_test_assert(rtems_disk_get_media_block_size(dd) == BLOCK_SIZE);
  rtems_test_assert(rtems_disk_get_block_size(dd) == BLOCK_SIZE);
  rtems_test_assert(rtems_disk_get_block_begin(dd) == 0);
  rtems_test_assert(rtems_disk_get_block_count(dd) == BLOCK_COUNT);

  rv = close(fd);
  rtems_test_assert(rv == 0);

  fd = open(rda1, O_RDWR);
  rtems_test_assert(fd >= 0);

  rv = fstat(fd, &st);
  rtems_test_assert(rv == 0);

  rv = rtems_disk_fd_get_disk_device(fd, &dd);
  rtems_test_assert(rv == 0);

  rtems_test_assert(rtems_disk_get_driver_data(dd) == rd);
  rtems_test_assert(rtems_disk_get_device_identifier(dd) == st.st_rdev);
  rtems_test_assert(rtems_disk_get_media_block_size(dd) == BLOCK_SIZE);
  rtems_test_assert(rtems_disk_get_block_size(dd) == BLOCK_SIZE);
  rtems_test_assert(rtems_disk_get_block_begin(dd) == 1);
  rtems_test_assert(rtems_disk_get_block_count(dd) == BLOCK_COUNT - 1);

  rv = close(fd);
  rtems_test_assert(rv == 0);

  rv = unlink(rda1);
  rtems_test_assert(rv == 0);

  rv = unlink(rda);
  rtems_test_assert(rv == 0);
}
예제 #4
0
파일: init.c 프로젝트: AlexShiLucky/rtems
static rtems_task Init(rtems_task_argument argument)
{
  rtems_status_code sc = RTEMS_SUCCESSFUL;
  rtems_task_priority cur_prio = 0;
  rtems_bdbuf_buffer *bd = NULL;
  dev_t dev = 0;

  rtems_test_begink();

  sc = rtems_disk_io_initialize();
  ASSERT_SC(sc);

  sc = ramdisk_register(BLOCK_SIZE_A, BLOCK_COUNT, false, "/dev/rda", &dev);
  ASSERT_SC(sc);

  dd = rtems_disk_obtain(dev);
  rtems_test_assert(dd != NULL);

  sc = rtems_task_create(
    rtems_build_name(' ', 'L', 'O', 'W'),
    PRIORITY_LOW,
    0,
    RTEMS_DEFAULT_MODES,
    RTEMS_DEFAULT_ATTRIBUTES,
    &task_id_low
  );
  ASSERT_SC(sc);

  sc = rtems_task_start(task_id_low, task_low, 0);
  ASSERT_SC(sc);

  sc = rtems_task_create(
    rtems_build_name(' ', 'M', 'I', 'D'),
    PRIORITY_MID,
    0,
    RTEMS_DEFAULT_MODES,
    RTEMS_DEFAULT_ATTRIBUTES,
    &task_id_mid
  );
  ASSERT_SC(sc);

  sc = rtems_task_start(task_id_mid, task_mid, 0);
  ASSERT_SC(sc);

  sc = rtems_task_create(
    rtems_build_name('H', 'I', 'G', 'H'),
    PRIORITY_HIGH,
    0,
    RTEMS_DEFAULT_MODES,
    RTEMS_DEFAULT_ATTRIBUTES,
    &task_id_high
  );
  ASSERT_SC(sc);

  sc = rtems_task_start(task_id_high, task_high, 0);
  ASSERT_SC(sc);

  sc = rtems_task_suspend(task_id_mid);
  ASSERT_SC(sc);

  sc = rtems_task_suspend(task_id_high);
  ASSERT_SC(sc);

  sc = rtems_bdbuf_get(dd, 1, &bd);
  ASSERT_SC(sc);

  sc = rtems_bdbuf_release(bd);
  ASSERT_SC(sc);

  printk("I: try access: 0\n");

  sc = rtems_bdbuf_get(dd, 0, &bd);
  ASSERT_SC(sc);

  printk("I: access: 0\n");

  sc = rtems_task_set_priority(RTEMS_SELF, PRIORITY_IDLE, &cur_prio);
  ASSERT_SC(sc);

  sc = rtems_task_resume(task_id_high);
  ASSERT_SC(sc);

  sc = rtems_task_resume(task_id_mid);
  ASSERT_SC(sc);

  sc = rtems_task_set_priority(RTEMS_SELF, PRIORITY_INIT, &cur_prio);
  ASSERT_SC(sc);

  printk("I: release: 0\n");

  sc = rtems_bdbuf_release(bd);
  ASSERT_SC(sc);

  printk("I: release done: 0\n");

  rtems_task_delete(RTEMS_SELF);
}
예제 #5
0
파일: init.c 프로젝트: gedare/rtems
static rtems_task Init(rtems_task_argument argument)
{
  rtems_status_code sc = RTEMS_SUCCESSFUL;
  rtems_bdbuf_buffer *bd = NULL;
  dev_t dev_a = 0;
  dev_t dev_b = 0;

  TEST_BEGIN();

  sc = rtems_disk_io_initialize();
  ASSERT_SC(sc);

  sc = ramdisk_register(BLOCK_SIZE_A, BLOCK_COUNT_A, false, "/dev/rda", &dev_a);
  ASSERT_SC(sc);

  sc = ramdisk_register(BLOCK_SIZE_B, BLOCK_COUNT_B, false, "/dev/rdb", &dev_b);
  ASSERT_SC(sc);

  dd_a = rtems_disk_obtain(dev_a);
  rtems_test_assert(dd_a != NULL);

  dd_b = rtems_disk_obtain(dev_b);
  rtems_test_assert(dd_b != NULL);

  sc = rtems_task_create(
    rtems_build_name(' ', 'L', 'O', 'W'),
    PRIORITY_LOW,
    0,
    RTEMS_DEFAULT_MODES,
    RTEMS_DEFAULT_ATTRIBUTES,
    &task_id_low
  );
  ASSERT_SC(sc);

  sc = rtems_task_start(task_id_low, task_low, 0);
  ASSERT_SC(sc);

  sc = rtems_task_create(
    rtems_build_name('H', 'I', 'G', 'H'),
    PRIORITY_HIGH,
    0,
    RTEMS_DEFAULT_MODES,
    RTEMS_DEFAULT_ATTRIBUTES,
    &task_id_high
  );
  ASSERT_SC(sc);

  sc = rtems_task_start(task_id_high, task_high, 0);
  ASSERT_SC(sc);

  sc = rtems_bdbuf_get(dd_a, 0, &bd);
  ASSERT_SC(sc);

  sc = rtems_bdbuf_sync(bd);
  ASSERT_SC(sc);

  printk("I: sync done: A0\n");

  sync_done = true;

  sc = rtems_task_suspend(RTEMS_SELF);
  ASSERT_SC(sc);
}
예제 #6
0
파일: init.c 프로젝트: AlexShiLucky/rtems
static void test_bdpart(void)
{
  rtems_status_code sc = RTEMS_SUCCESSFUL;
  rtems_bdpart_partition created_partitions [PARTITION_COUNT];
  rtems_bdpart_format actual_format;
  rtems_bdpart_partition actual_partitions [PARTITION_COUNT];
  rtems_resource_snapshot before;
  size_t actual_count = PARTITION_COUNT;
  size_t i = 0;

  memset(&created_partitions [0], 0, sizeof(created_partitions));
  memset(&actual_format, 0, sizeof(actual_format));
  memset(&actual_partitions [0], 0, sizeof(actual_partitions));

  rtems_resource_snapshot_take(&before);

  for (i = 0; i < PARTITION_COUNT; ++i) {
    rtems_bdpart_to_partition_type(
      RTEMS_BDPART_MBR_FAT_32,
      created_partitions [i].type
    );
  }

  sc = rtems_bdpart_create(
    rda,
    &format,
    &created_partitions [0],
    &distribution [0],
    PARTITION_COUNT
  );
  ASSERT_SC(sc);

  sc = rtems_bdpart_write(
    rda,
    &format,
    &created_partitions [0],
    PARTITION_COUNT
  );
  ASSERT_SC(sc);

  sc = rtems_bdpart_read(
    rda,
    &actual_format,
    &actual_partitions [0],
    &actual_count
  );
  ASSERT_SC(sc);
  rtems_test_assert(actual_format.mbr.disk_id == format.mbr.disk_id);
  rtems_test_assert(
    memcmp(
      &actual_partitions [0],
      &created_partitions [0],
      PARTITION_COUNT
    ) == 0
  );

  sc = rtems_bdpart_register(
    rda,
    actual_partitions,
    actual_count
  );
  ASSERT_SC(sc);
  test_logical_disks(&bdpart_rdax [0], true);

  sc = rtems_bdpart_unregister(
    rda,
    actual_partitions,
    actual_count
  );
  ASSERT_SC(sc);
  test_logical_disks(&bdpart_rdax [0], false);

  rtems_test_assert(rtems_resource_snapshot_check(&before));

  sc = rtems_bdpart_register_from_disk(rda);
  ASSERT_SC(sc);
  test_logical_disks(&bdpart_rdax [0], true);

  sc = rtems_bdpart_unregister(
    rda,
    actual_partitions,
    actual_count
  );
  ASSERT_SC(sc);
  test_logical_disks(&bdpart_rdax [0], false);

  rtems_test_assert(rtems_resource_snapshot_check(&before));

  rtems_bdpart_dump(&actual_partitions [0], actual_count);
}
예제 #7
0
static void test_diskdevs(void)
{
    rtems_status_code sc = RTEMS_SUCCESSFUL;
    rtems_device_major_number major = 0;
    rtems_device_minor_number minor = 0;
    rtems_disk_device *physical_dd = NULL;
    rtems_disk_device *logical_dd = NULL;
    rtems_disk_device *dd = NULL;
    dev_t physical_dev = 0;
    dev_t logical_dev = 0;
    dev_t logical_2_dev = 0;
    dev_t const big_major_dev = rtems_filesystem_make_dev_t((rtems_device_major_number) -2, 0);
    dev_t const big_minor_dev = rtems_filesystem_make_dev_t(0, (rtems_device_minor_number) -2);
    ramdisk *const rd = ramdisk_allocate(NULL, BLOCK_SIZE, BLOCK_COUNT, false);

    rtems_test_assert(rd != NULL);

    sc = rtems_disk_io_initialize();
    ASSERT_SC(sc);

    sc = rtems_io_register_driver(0, &ramdisk_ops, &major);
    ASSERT_SC(sc);

    physical_dev = rtems_filesystem_make_dev_t(major, minor);
    logical_dev = rtems_filesystem_make_dev_t(major, minor + 1);
    logical_2_dev = rtems_filesystem_make_dev_t(major, minor + 2);

    /* Consistency checks for physical disks creation */

    sc = rtems_disk_create_phys(physical_dev, BLOCK_SIZE, BLOCK_COUNT, NULL, rd, "/dev/rda");
    ASSERT_SC_EQ(sc, RTEMS_INVALID_ADDRESS);

    sc = rtems_disk_create_phys(physical_dev, 0, BLOCK_COUNT, ramdisk_ioctl, rd, "/dev/rda");
    ASSERT_SC_EQ(sc, RTEMS_INVALID_NUMBER);

    sc = rtems_disk_create_phys(big_major_dev, BLOCK_SIZE, BLOCK_COUNT, ramdisk_ioctl, rd, "/dev/rda");
    ASSERT_SC_EQ(sc, RTEMS_NO_MEMORY);

    sc = rtems_disk_create_phys(big_minor_dev, BLOCK_SIZE, BLOCK_COUNT, ramdisk_ioctl, rd, "/dev/rda");
    ASSERT_SC_EQ(sc, RTEMS_NO_MEMORY);

    sc = rtems_disk_create_phys(physical_dev, BLOCK_SIZE, BLOCK_COUNT, ramdisk_ioctl, rd, NULL);
    ASSERT_SC(sc);

    sc = rtems_disk_create_phys(physical_dev, BLOCK_SIZE, BLOCK_COUNT, ramdisk_ioctl, rd, NULL);
    ASSERT_SC_EQ(sc, RTEMS_RESOURCE_IN_USE);

    sc = rtems_disk_delete(physical_dev);
    ASSERT_SC(sc);

    /* Consistency checks for logical disks creation */

    sc = rtems_disk_create_log(logical_dev, physical_dev, 0, 1, "/dev/rda1");
    ASSERT_SC_EQ(sc, RTEMS_INVALID_ID);

    sc = rtems_disk_create_phys(physical_dev, BLOCK_SIZE, BLOCK_COUNT, ramdisk_ioctl, rd, "/dev/rda");
    ASSERT_SC(sc);

    sc = rtems_disk_create_log(big_major_dev, physical_dev, 0, 1, "/dev/rda1");
    ASSERT_SC_EQ(sc, RTEMS_NO_MEMORY);

    sc = rtems_disk_create_log(big_minor_dev, physical_dev, 0, 1, "/dev/rda1");
    ASSERT_SC_EQ(sc, RTEMS_NO_MEMORY);

    sc = rtems_disk_create_log(logical_dev, physical_dev, BLOCK_COUNT, 0, "/dev/rda1");
    ASSERT_SC_EQ(sc, RTEMS_INVALID_NUMBER);

    sc = rtems_disk_create_log(logical_dev, physical_dev, 0, BLOCK_COUNT + 1, "/dev/rda1");
    ASSERT_SC_EQ(sc, RTEMS_INVALID_NUMBER);

    sc = rtems_disk_create_log(logical_dev, physical_dev, 1, BLOCK_COUNT, "/dev/rda1");
    ASSERT_SC_EQ(sc, RTEMS_INVALID_NUMBER);

    sc = rtems_disk_create_log(logical_dev, physical_dev, 0, 1, "/dev/rda1");
    ASSERT_SC(sc);

    sc = rtems_disk_create_log(logical_dev, physical_dev, 0, 1, "/dev/rda1");
    ASSERT_SC_EQ(sc, RTEMS_RESOURCE_IN_USE);

    sc = rtems_disk_create_log(logical_2_dev, logical_dev, 0, 1, "/dev/rda1");
    ASSERT_SC_EQ(sc, RTEMS_INVALID_ID);

    sc = rtems_disk_delete(logical_dev);
    ASSERT_SC(sc);

    /* Consistency checks delete */

    sc = rtems_disk_create_log(logical_dev, physical_dev, 0, 1, "/dev/rda1");
    ASSERT_SC(sc);

    physical_dd = rtems_disk_obtain(physical_dev);
    rtems_test_assert(physical_dd != NULL && physical_dd->uses == 2);

    sc = rtems_disk_release(physical_dd);
    ASSERT_SC(sc);

    logical_dd = rtems_disk_obtain(logical_dev);
    rtems_test_assert(logical_dd != NULL && logical_dd->uses == 1);

    sc = rtems_disk_delete(physical_dev);
    ASSERT_SC(sc);

    sc = rtems_disk_create_phys(physical_dev, BLOCK_SIZE, BLOCK_COUNT, ramdisk_ioctl, rd, "/dev/rda");
    ASSERT_SC_EQ(sc, RTEMS_RESOURCE_IN_USE);

    dd = rtems_disk_obtain(physical_dev);
    rtems_test_assert(dd == NULL);

    dd = rtems_disk_obtain(logical_dev);
    rtems_test_assert(dd == NULL);

    sc = rtems_disk_release(logical_dd);
    ASSERT_SC(sc);

    /* Test block IO control API */

    test_block_io_control_api(physical_dev, rd);

    /* Cleanup */

    sc = rtems_io_unregister_driver(major);
    ASSERT_SC(sc);

    ramdisk_free(rd);

    sc = rtems_disk_io_done();
    ASSERT_SC(sc);
}