Changeset deb3f29 in rtems


Ignore:
Timestamp:
Sep 11, 2015, 8:21:15 AM (4 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11
Children:
edf7732
Parents:
44eb9893
git-author:
Sebastian Huber <sebastian.huber@…> (09/11/15 08:21:15)
git-committer:
Sebastian Huber <sebastian.huber@…> (09/11/15 09:29:06)
Message:

libtests/rbheap01: Simplify

Update #2417.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • testsuites/libtests/rbheap01/init.c

    r44eb9893 rdeb3f29  
    11/*
    2  * Copyright (c) 2012 embedded brains GmbH.  All rights reserved.
     2 * Copyright (c) 2012-2015 embedded brains GmbH.  All rights reserved.
    33 *
    44 *  embedded brains GmbH
    5  *  Obere Lagerstr. 30
     5 *  Dornierstr. 4
    66 *  82178 Puchheim
    77 *  Germany
     
    6868
    6969typedef struct {
    70   const uintptr_t *index_current;
    71   const uintptr_t *index_end;
    72   const bool *free_current;
    73   const bool *free_end;
     70  uintptr_t index;
     71  bool free;
     72} chunk_descriptor;
     73
     74typedef struct {
     75  const chunk_descriptor *chunk_current;
     76  const chunk_descriptor *chunk_end;
    7477} chunk_visitor_context;
    7578
     
    8285  rtems_rbheap_chunk *chunk = rtems_rbheap_chunk_of_node(node);
    8386  chunk_visitor_context *context = visitor_arg;
    84 
    85   rtems_test_assert(context->index_current != context->index_end);
    86   rtems_test_assert(context->free_current != context->free_end);
    87 
    88   rtems_test_assert(idx(chunk) == *context->index_current);
    89   rtems_test_assert(rtems_rbheap_is_chunk_free(chunk) == *context->free_current);
    90 
    91   ++context->index_current;
    92   ++context->free_current;
     87  const chunk_descriptor *current = context->chunk_current;
     88
     89  rtems_test_assert(current != context->chunk_end);
     90
     91  rtems_test_assert(idx(chunk) == current->index);
     92  rtems_test_assert(rtems_rbheap_is_chunk_free(chunk) == current->free);
     93
     94  context->chunk_current = current + 1;
    9395
    9496  return false;
     
    161163static void test_chunk_tree(
    162164  const rtems_rbheap_control *control,
    163   const uintptr_t *index_begin,
    164   const uintptr_t *index_end,
    165   const bool *free_begin,
    166   const bool *free_end
     165  const chunk_descriptor *chunk_begin,
     166  size_t chunk_count
    167167)
    168168{
    169169  chunk_visitor_context context = {
    170     .index_current = index_begin,
    171     .index_end = index_end,
    172     .free_current = free_begin,
    173     .free_end = free_end
     170    .chunk_current = chunk_begin,
     171    .chunk_end = chunk_begin + chunk_count
    174172  };
    175173
     
    182180}
    183181
    184 #define TEST_PAGE_TREE(control, indices, frees) \
     182#define TEST_PAGE_TREE(control, chunks) \
    185183  test_chunk_tree( \
    186184    control, \
    187     indices, \
    188     &indices [sizeof(indices) / sizeof(indices [0])], \
    189     frees, \
    190     &frees [sizeof(frees) / sizeof(frees [0])] \
     185    chunks, \
     186    RTEMS_ARRAY_SIZE(chunks) \
    191187  )
    192188
    193189static void test_init_successful(rtems_rbheap_control *control)
    194190{
    195   static const uintptr_t indices [] = {
    196     0
    197   };
    198   static const bool frees [] = {
    199     true
     191  static const chunk_descriptor chunks [] = {
     192    { 0, true }
    200193  };
    201194
     
    212205  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
    213206
    214   TEST_PAGE_TREE(control, indices, frees);
     207  TEST_PAGE_TREE(control, chunks);
    215208}
    216209
    217210static void test_alloc_and_free_one(void)
    218211{
    219   static const uintptr_t indices_0 [] = {
    220     0,
    221     PAGE_COUNT - 1
    222   };
    223   static const bool frees_0 [] = {
    224     true,
    225     false
    226   };
    227   static const uintptr_t indices_1 [] = {
    228     0
    229   };
    230   static const bool frees_1 [] = {
    231     true,
     212  static const chunk_descriptor chunks_0 [] = {
     213    { 0, true },
     214    { PAGE_COUNT - 1, false }
     215  };
     216  static const chunk_descriptor chunks_1 [] = {
     217    { 0, true }
    232218  };
    233219
     
    241227  rtems_test_assert(ptr != NULL);
    242228
    243   TEST_PAGE_TREE(&control, indices_0, frees_0);
     229  TEST_PAGE_TREE(&control, chunks_0);
    244230
    245231  sc = rtems_rbheap_free(&control, ptr);
    246232  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
    247233
    248   TEST_PAGE_TREE(&control, indices_1, frees_1);
     234  TEST_PAGE_TREE(&control, chunks_1);
    249235}
    250236
    251237static void test_alloc_zero(void)
    252238{
    253   static const uintptr_t indices [] = {
    254     0
    255   };
    256   static const bool frees [] = {
    257     true
     239  static const chunk_descriptor chunks [] = {
     240    { 0, true }
    258241  };
    259242
     
    266249  rtems_test_assert(ptr == NULL);
    267250
    268   TEST_PAGE_TREE(&control, indices, frees);
     251  TEST_PAGE_TREE(&control, chunks);
    269252}
    270253
    271254static void test_alloc_huge_chunk(void)
    272255{
    273   static const uintptr_t indices [] = {
    274     0
    275   };
    276   static const bool frees [] = {
    277     true
     256  static const chunk_descriptor chunks [] = {
     257    { 0, true }
    278258  };
    279259
     
    286266  rtems_test_assert(ptr == NULL);
    287267
    288   TEST_PAGE_TREE(&control, indices, frees);
     268  TEST_PAGE_TREE(&control, chunks);
    289269}
    290270
    291271static void test_alloc_one_chunk(void)
    292272{
    293   static const uintptr_t indices_0 [] = {
    294     0
    295   };
    296   static const bool frees_0 [] = {
    297     false
    298   };
    299   static const uintptr_t indices_1 [] = {
    300     0
    301   };
    302   static const bool frees_1 [] = {
    303     true,
     273  static const chunk_descriptor chunks_0 [] = {
     274    { 0, false }
     275  };
     276  static const chunk_descriptor chunks_1 [] = {
     277    { 0, true },
    304278  };
    305279
     
    313287  rtems_test_assert(ptr != NULL);
    314288
    315   TEST_PAGE_TREE(&control, indices_0, frees_0);
     289  TEST_PAGE_TREE(&control, chunks_0);
    316290
    317291  sc = rtems_rbheap_free(&control, ptr);
    318292  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
    319293
    320   TEST_PAGE_TREE(&control, indices_1, frees_1);
     294  TEST_PAGE_TREE(&control, chunks_1);
    321295}
    322296
    323297static void test_alloc_many_chunks(void)
    324298{
    325   static const uintptr_t indices_0 [] = {
    326     0,
    327     1,
    328     2,
    329     3,
    330     4,
    331     5,
    332     6,
    333     7
    334   };
    335   static const bool frees_0 [] = {
    336     false,
    337     false,
    338     false,
    339     false,
    340     false,
    341     false,
    342     false,
    343     false
    344   };
    345   static const uintptr_t indices_1 [] = {
    346     0
    347   };
    348   static const bool frees_1 [] = {
    349     true,
     299  static const chunk_descriptor chunks_0 [] = {
     300    { 0, false },
     301    { 1, false },
     302    { 2, false },
     303    { 3, false },
     304    { 4, false },
     305    { 5, false },
     306    { 6, false },
     307    { 7, false }
     308  };
     309  static const chunk_descriptor chunks_1 [] = {
     310    { 0, true }
    350311  };
    351312
     
    363324  }
    364325
    365   TEST_PAGE_TREE(&control, indices_0, frees_0);
     326  TEST_PAGE_TREE(&control, chunks_0);
    366327
    367328  null = rtems_rbheap_allocate(&control, PAGE_SIZE);
    368329  rtems_test_assert(null == NULL);
    369330
    370   TEST_PAGE_TREE(&control, indices_0, frees_0);
     331  TEST_PAGE_TREE(&control, chunks_0);
    371332
    372333  for (i = 0; i < PAGE_COUNT; ++i) {
     
    375336  }
    376337
    377   TEST_PAGE_TREE(&control, indices_1, frees_1);
     338  TEST_PAGE_TREE(&control, chunks_1);
    378339}
    379340
     
    467428static void test_free_merge_left_or_right(bool left)
    468429{
    469   static const uintptr_t indices_0 [] = {
    470     0,
    471     3,
    472     4,
    473     5,
    474     6,
    475     7
    476   };
    477   static const bool frees_0 [] = {
    478     true,
    479     false,
    480     false,
    481     false,
    482     false,
    483     false
    484   };
    485   static const uintptr_t indices_1_left [] = {
    486     0,
    487     3,
    488     4,
    489     5,
    490     6,
    491     7
    492   };
    493   static const bool frees_1_left [] = {
    494     true,
    495     false,
    496     true,
    497     false,
    498     false,
    499     false
    500   };
    501   static const uintptr_t indices_1_right [] = {
    502     0,
    503     3,
    504     4,
    505     5,
    506     6,
    507     7
    508   };
    509   static const bool frees_1_right [] = {
    510     true,
    511     false,
    512     false,
    513     false,
    514     true,
    515     false
    516   };
    517   static const uintptr_t indices_2_left [] = {
    518     0,
    519     3,
    520     4,
    521     6,
    522     7
    523   };
    524   static const bool frees_2_left [] = {
    525     true,
    526     false,
    527     true,
    528     false,
    529     false
    530   };
    531   static const uintptr_t indices_2_right [] = {
    532     0,
    533     3,
    534     4,
    535     5,
    536     7
    537   };
    538   static const bool frees_2_right [] = {
    539     true,
    540     false,
    541     false,
    542     true,
    543     false
     430  static const chunk_descriptor chunks_0 [] = {
     431    { 0, true },
     432    { 3, false },
     433    { 4, false },
     434    { 5, false },
     435    { 6, false },
     436    { 7, false }
     437  };
     438  static const chunk_descriptor chunks_1_left [] = {
     439    { 0, true },
     440    { 3, false },
     441    { 4, true },
     442    { 5, false },
     443    { 6, false },
     444    { 7, false }
     445  };
     446  static const chunk_descriptor chunks_1_right [] = {
     447    { 0, true },
     448    { 3, false },
     449    { 4, false },
     450    { 5, false },
     451    { 6, true },
     452    { 7, false }
     453  };
     454  static const chunk_descriptor chunks_2_left [] = {
     455    { 0, true },
     456    { 3, false },
     457    { 4, true },
     458    { 6, false },
     459    { 7, false }
     460  };
     461  static const chunk_descriptor chunks_2_right [] = {
     462    { 0, true },
     463    { 3, false },
     464    { 4, false },
     465    { 5, true },
     466    { 7, false }
    544467  };
    545468
     
    557480  }
    558481
    559   TEST_PAGE_TREE(&control, indices_0, frees_0);
     482  TEST_PAGE_TREE(&control, chunks_0);
    560483
    561484  sc = rtems_rbheap_free(&control, ptr [dir]);
     
    563486
    564487  if (left) {
    565     TEST_PAGE_TREE(&control, indices_1_left, frees_1_left);
     488    TEST_PAGE_TREE(&control, chunks_1_left);
    566489  } else {
    567     TEST_PAGE_TREE(&control, indices_1_right, frees_1_right);
     490    TEST_PAGE_TREE(&control, chunks_1_right);
    568491  }
    569492
     
    572495
    573496  if (left) {
    574     TEST_PAGE_TREE(&control, indices_2_left, frees_2_left);
     497    TEST_PAGE_TREE(&control, chunks_2_left);
    575498  } else {
    576     TEST_PAGE_TREE(&control, indices_2_right, frees_2_right);
     499    TEST_PAGE_TREE(&control, chunks_2_right);
    577500  }
    578501}
Note: See TracChangeset for help on using the changeset viewer.