Changeset f9126f6 in rtems


Ignore:
Timestamp:
06/22/16 15:09:23 (7 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.10
Children:
95d5a0a9
Parents:
fc027be
git-author:
Sebastian Huber <sebastian.huber@…> (06/22/16 15:09:23)
git-committer:
Gedare Bloom <gedare@…> (03/23/18 15:33:59)
Message:

sptests/spmutex01: add tests for lock nesting

File:
1 edited

Legend:

Unmodified
Added
Removed
  • testsuites/sptests/spmutex01/init.c

    rfc027be rf9126f6  
    4242  REQ_MTX_0_RELEASE = RTEMS_EVENT_3,
    4343  REQ_MTX_1_OBTAIN = RTEMS_EVENT_4,
    44   REQ_MTX_1_RELEASE = RTEMS_EVENT_5,
    45   REQ_MTX_2_OBTAIN = RTEMS_EVENT_6,
    46   REQ_MTX_2_RELEASE = RTEMS_EVENT_7,
    47   REQ_MTX_C11_OBTAIN = RTEMS_EVENT_8,
    48   REQ_MTX_C11_RELEASE = RTEMS_EVENT_9,
    49   REQ_MTX_POSIX_OBTAIN = RTEMS_EVENT_10,
    50   REQ_MTX_POSIX_RELEASE = RTEMS_EVENT_11
     44  REQ_MTX_1_OBTAIN_TIMEOUT = RTEMS_EVENT_5,
     45  REQ_MTX_1_RELEASE = RTEMS_EVENT_6,
     46  REQ_MTX_2_OBTAIN = RTEMS_EVENT_7,
     47  REQ_MTX_2_RELEASE = RTEMS_EVENT_8,
     48  REQ_MTX_C11_OBTAIN = RTEMS_EVENT_9,
     49  REQ_MTX_C11_RELEASE = RTEMS_EVENT_10,
     50  REQ_MTX_POSIX_OBTAIN = RTEMS_EVENT_11,
     51  REQ_MTX_POSIX_RELEASE = RTEMS_EVENT_12
    5152} request_id;
    5253
     
    111112}
    112113
     114static void wait(void)
     115{
     116  rtems_status_code sc;
     117
     118  sc = rtems_task_wake_after(4);
     119  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
     120}
     121
    113122static rtems_event_set wait_for_events(void)
    114123{
     
    142151}
    143152
     153static void obtain_timeout(test_context *ctx, mutex_id id)
     154{
     155  rtems_status_code sc;
     156
     157  sc = rtems_semaphore_obtain(ctx->mtx[id], RTEMS_WAIT, 2);
     158  rtems_test_assert(sc == RTEMS_TIMEOUT);
     159}
     160
    144161static void obtain(test_context *ctx, mutex_id id)
    145162{
     
    250267}
    251268
     269static void change_prio(
     270  test_context *ctx,
     271  task_id id,
     272  rtems_task_priority prio
     273)
     274{
     275  rtems_status_code sc;
     276
     277  sc = rtems_task_set_priority(
     278    ctx->tasks[id],
     279    prio,
     280    &prio
     281  );
     282  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
     283}
     284
    252285static void helper(rtems_task_argument arg)
    253286{
     
    281314    if ((events & REQ_MTX_1_OBTAIN) != 0) {
    282315      obtain(ctx, MTX_1);
     316      ++ctx->generation[id];
     317    }
     318
     319    if ((events & REQ_MTX_1_OBTAIN_TIMEOUT) != 0) {
     320      obtain_timeout(ctx, MTX_1);
    283321      ++ctx->generation[id];
    284322    }
     
    371409static void test_inherit(test_context *ctx)
    372410{
     411  assert_prio(ctx, M, 3);
    373412  obtain(ctx, MTX_0);
    374413  request(ctx, A_1, REQ_MTX_0_OBTAIN);
    375414  check_generations(ctx, NONE, NONE);
    376415  assert_prio(ctx, M, 1);
     416  change_prio(ctx, A_1, 2);
     417  assert_prio(ctx, M, 2);
     418  change_prio(ctx, A_1, 3);
     419  assert_prio(ctx, M, 3);
     420  change_prio(ctx, A_1, 4);
     421  assert_prio(ctx, M, 3);
     422  change_prio(ctx, A_1, 1);
     423  assert_prio(ctx, M, 1);
    377424  release(ctx, MTX_0);
    378425  check_generations(ctx, A_1, NONE);
     
    384431static void test_inherit_fifo_for_equal_priority(test_context *ctx)
    385432{
     433  assert_prio(ctx, M, 3);
    386434  obtain(ctx, MTX_0);
    387435  request(ctx, A_2_0, REQ_MTX_0_OBTAIN);
     
    402450}
    403451
     452static void test_inherit_nested_vertical(test_context *ctx)
     453{
     454  assert_prio(ctx, M, 3);
     455  obtain(ctx, MTX_0);
     456  obtain(ctx, MTX_1);
     457  request(ctx, A_1, REQ_MTX_1_OBTAIN);
     458  check_generations(ctx, NONE, NONE);
     459  assert_prio(ctx, M, 1);
     460  release(ctx, MTX_1);
     461  check_generations(ctx, A_1, NONE);
     462  assert_prio(ctx, M, 3);
     463  request(ctx, A_1, REQ_MTX_1_RELEASE);
     464  check_generations(ctx, A_1, NONE);
     465  release(ctx, MTX_0);
     466}
     467
     468static void test_inherit_nested_vertical_timeout(test_context *ctx)
     469{
     470  assert_prio(ctx, M, 3);
     471  obtain(ctx, MTX_0);
     472  obtain(ctx, MTX_1);
     473  request(ctx, A_1, REQ_MTX_1_OBTAIN_TIMEOUT);
     474  check_generations(ctx, NONE, NONE);
     475  assert_prio(ctx, M, 1);
     476  wait();
     477  check_generations(ctx, A_1, NONE);
     478  assert_prio(ctx, M, 3);
     479  release(ctx, MTX_1);
     480  release(ctx, MTX_0);
     481}
     482
     483static void test_inherit_nested_horizontal(test_context *ctx)
     484{
     485  assert_prio(ctx, M, 3);
     486  obtain(ctx, MTX_0);
     487  request(ctx, A_2_0, REQ_MTX_1_OBTAIN);
     488  check_generations(ctx, A_2_0, NONE);
     489  request(ctx, A_2_0, REQ_MTX_0_OBTAIN);
     490  check_generations(ctx, NONE, NONE);
     491  assert_prio(ctx, M, 2);
     492  request(ctx, A_1, REQ_MTX_1_OBTAIN_TIMEOUT);
     493  check_generations(ctx, NONE, NONE);
     494  assert_prio(ctx, A_2_0, 1);
     495  assert_prio(ctx, M, 1);
     496  wait();
     497  check_generations(ctx, A_1, NONE);
     498  assert_prio(ctx, A_2_0, 2);
     499  assert_prio(ctx, M, 2);
     500  request(ctx, A_1, REQ_MTX_1_OBTAIN);
     501  check_generations(ctx, NONE, NONE);
     502  assert_prio(ctx, A_2_0, 1);
     503  assert_prio(ctx, M, 1);
     504  change_prio(ctx, A_1, 2);
     505  assert_prio(ctx, M, 2);
     506  change_prio(ctx, A_1, 3);
     507  assert_prio(ctx, M, 2);
     508  change_prio(ctx, A_2_0, 3);
     509  assert_prio(ctx, M, 3);
     510  change_prio(ctx, A_2_0, 2);
     511  assert_prio(ctx, M, 2);
     512  change_prio(ctx, A_1, 1);
     513  assert_prio(ctx, M, 1);
     514  release(ctx, MTX_0);
     515  check_generations(ctx, A_2_0, NONE);
     516  assert_prio(ctx, A_2_0, 1);
     517  assert_prio(ctx, M, 3);
     518  request(ctx, A_2_0, REQ_MTX_0_RELEASE);
     519  check_generations(ctx, A_2_0, NONE);
     520  assert_prio(ctx, A_2_0, 1);
     521  request(ctx, A_2_0, REQ_MTX_1_RELEASE);
     522  check_generations(ctx, A_1, A_2_0);
     523  assert_prio(ctx, A_2_0, 2);
     524  request(ctx, A_1, REQ_MTX_1_RELEASE);
     525  check_generations(ctx, A_1, NONE);
     526}
     527
    404528static void test_deadlock_two_classic(test_context *ctx)
    405529{
     
    548672  test_inherit(ctx);
    549673  test_inherit_fifo_for_equal_priority(ctx);
     674  test_inherit_nested_vertical(ctx);
     675  test_inherit_nested_vertical_timeout(ctx);
     676  test_inherit_nested_horizontal(ctx);
    550677  test_deadlock_two_classic(ctx);
    551678  test_deadlock_three_classic(ctx);
Note: See TracChangeset for help on using the changeset viewer.