Changeset 47b6fad in rtems


Ignore:
Timestamp:
09/01/13 13:14:07 (9 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, 5, master
Children:
0c47440
Parents:
7136d7f
git-author:
Sebastian Huber <sebastian.huber@…> (09/01/13 13:14:07)
git-committer:
Sebastian Huber <sebastian.huber@…> (09/01/13 13:18:11)
Message:

smptests/smpatomic08: Avoid copy and paste

Location:
testsuites/smptests/smpatomic08
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • testsuites/smptests/smpatomic08/init.c

    r7136d7f r47b6fad  
    105105}
    106106
     107static void test_fini(
     108  test_context *ctx,
     109  const char *test,
     110  bool atomic
     111)
     112{
     113  uint_fast32_t expected_value = 0;
     114  uint_fast32_t actual_value;
     115  size_t worker_index;
     116
     117  printf("=== atomic %s test case ==\n", test);
     118
     119  for (worker_index = 0; worker_index < ctx->worker_count; ++worker_index) {
     120    uint_fast32_t worker_value = ctx->per_worker_value[worker_index];
     121
     122    expected_value += worker_value;
     123
     124    printf(
     125      "worker %zu value: %" PRIuFAST32 "\n",
     126      worker_index,
     127      worker_value
     128    );
     129  }
     130
     131  if (atomic) {
     132    actual_value = _Atomic_Load_uint(&ctx->atomic_value, ATOMIC_ORDER_RELAXED);
     133  } else {
     134    actual_value = ctx->normal_value;
     135  }
     136
     137  printf(
     138    "atomic value: expected = %" PRIuFAST32 ", actual = %" PRIuFAST32 "\n",
     139    expected_value,
     140    actual_value
     141  );
     142
     143  rtems_test_assert(expected_value == actual_value);
     144}
     145
    107146static void test_atomic_add_init(test_context *ctx)
    108147{
     
    124163static void test_atomic_add_fini(test_context *ctx)
    125164{
    126   uint_fast32_t expected_counter = 0;
    127   uint_fast32_t actual_counter;
    128   size_t worker_index;
    129 
    130   printf("=== atomic add test case ==\n");
    131 
    132   for (worker_index = 0; worker_index < ctx->worker_count; ++worker_index) {
    133     uint_fast32_t worker_counter = ctx->per_worker_value[worker_index];
    134 
    135     expected_counter += worker_counter;
    136 
    137     printf(
    138       "atomic add worker %zu counter: %" PRIuFAST32 "\n",
    139       worker_index,
    140       worker_counter
    141     );
    142   }
    143 
    144   actual_counter = _Atomic_Load_uint(&ctx->atomic_value, ATOMIC_ORDER_RELAXED);
    145 
    146   printf(
    147     "global counter: expected = %" PRIuFAST32 ", actual = %" PRIuFAST32 "\n",
    148     expected_counter,
    149     actual_counter
    150   );
    151 
    152   rtems_test_assert(expected_counter == actual_counter);
     165  test_fini(ctx, "add", true);
    153166}
    154167
     
    179192static void test_atomic_flag_fini(test_context *ctx)
    180193{
    181   uint_fast32_t expected_counter = 0;
    182   uint_fast32_t actual_counter;
    183   size_t worker_index;
    184 
    185   printf("=== atomic flag test case ===\n");
    186 
    187   for (worker_index = 0; worker_index < ctx->worker_count; ++worker_index) {
    188     uint_fast32_t worker_counter = ctx->per_worker_value[worker_index];
    189 
    190     expected_counter += worker_counter;
    191 
    192     printf(
    193       "atomic flag worker %zu counter: %" PRIuFAST32 "\n",
    194       worker_index,
    195       worker_counter
    196     );
    197   }
    198 
    199   actual_counter = ctx->normal_value;
    200 
    201   printf(
    202     "global flag counter: expected = %" PRIuFAST32 ", actual = %" PRIuFAST32 "\n",
    203     expected_counter,
    204     actual_counter
    205   );
    206 
    207   rtems_test_assert(expected_counter == actual_counter);
     194  test_fini(ctx, "flag", false);
    208195}
    209196
    210197static void test_atomic_sub_init(test_context *ctx)
    211198{
    212   _Atomic_Init_uint(&ctx->atomic_value, 0xffffffff);
     199  _Atomic_Init_uint(&ctx->atomic_value, 0);
    213200}
    214201
    215202static void test_atomic_sub_body(test_context *ctx, size_t worker_index)
    216203{
    217   uint_fast32_t counter = 0xffffffff;
     204  uint_fast32_t counter = 0;
    218205
    219206  while (!stop(ctx)) {
     
    222209  }
    223210
    224   ctx->per_worker_value[worker_index] = 0xffffffff - counter;
     211  ctx->per_worker_value[worker_index] = counter;
    225212}
    226213
    227214static void test_atomic_sub_fini(test_context *ctx)
    228215{
    229   uint_fast32_t expected_counter = 0;
    230   uint_fast32_t actual_counter;
    231   size_t worker_index;
    232 
    233   printf("=== atomic sub test case ==\n");
    234 
    235   for (worker_index = 0; worker_index < ctx->worker_count; ++worker_index) {
    236     uint_fast32_t worker_counter = ctx->per_worker_value[worker_index];
    237 
    238     expected_counter += worker_counter;
    239 
    240     printf(
    241       "atomic sub worker %zu counter: %" PRIuFAST32 "\n",
    242       worker_index,
    243       worker_counter
    244     );
    245   }
    246 
    247   actual_counter = _Atomic_Load_uint(&ctx->atomic_value, ATOMIC_ORDER_RELAXED);
    248   actual_counter = 0xffffffff - actual_counter;
    249 
    250   printf(
    251     "global counter: expected = %" PRIuFAST32 ", actual = %" PRIuFAST32 "\n",
    252     expected_counter,
    253     actual_counter
    254   );
    255 
    256   rtems_test_assert(expected_counter == actual_counter);
     216  test_fini(ctx, "sub", true);
    257217}
    258218
     
    293253static void test_atomic_compare_exchange_fini(test_context *ctx)
    294254{
    295   uint_fast32_t expected_counter = 0;
    296   uint_fast32_t actual_counter;
    297   size_t worker_index;
    298 
    299   printf("=== atomic compare_exchange test case ==\n");
    300 
    301   for (worker_index = 0; worker_index < ctx->worker_count; ++worker_index) {
    302     uint_fast32_t worker_counter = ctx->per_worker_value[worker_index];
    303 
    304     expected_counter += worker_counter;
    305 
    306     printf(
    307       "atomic compare_exchange worker %zu counter: %" PRIuFAST32 "\n",
    308       worker_index,
    309       worker_counter
    310     );
    311   }
    312 
    313   actual_counter = ctx->normal_value;
    314 
    315   printf(
    316     "global counter: expected = %" PRIuFAST32 ", actual = %" PRIuFAST32 "\n",
    317     expected_counter,
    318     actual_counter
    319   );
    320 
    321   rtems_test_assert(expected_counter == actual_counter);
     255  test_fini(ctx, "compare exchange", false);
    322256}
    323257
     
    359293static void test_atomic_or_and_fini(test_context *ctx)
    360294{
    361   uint_fast32_t expected_counter = 0;
    362   uint_fast32_t actual_counter;
    363   size_t worker_index;
    364 
    365   printf("=== atomic or_and test case ==\n");
    366 
    367   for (worker_index = 0; worker_index < ctx->worker_count; ++worker_index) {
    368     uint_fast32_t worker_counter = ctx->per_worker_value[worker_index];
    369 
    370     expected_counter += worker_counter;
    371 
    372     printf(
    373       "atomic or_and worker %zu counter: %" PRIuFAST32 "\n",
    374       worker_index,
    375       worker_counter
    376     );
    377   }
    378 
    379   actual_counter = _Atomic_Load_uint(&ctx->atomic_value, ATOMIC_ORDER_RELAXED);
    380 
    381   printf(
    382     "global counter: expected = %" PRIuFAST32 ", actual = %" PRIuFAST32 "\n",
    383     expected_counter,
    384     actual_counter
    385   );
    386 
    387   rtems_test_assert(expected_counter == actual_counter);
     295  test_fini(ctx, "or/and", true);
    388296}
    389297
    390298static const test_case test_cases[] = {
    391   { test_atomic_add_init, test_atomic_add_body, test_atomic_add_fini },
    392   { test_atomic_flag_init, test_atomic_flag_body, test_atomic_flag_fini },
    393   { test_atomic_sub_init, test_atomic_sub_body, test_atomic_sub_fini },
    394   { test_atomic_compare_exchange_init, test_atomic_compare_exchange_body,
    395     test_atomic_compare_exchange_fini },
    396   { test_atomic_or_and_init, test_atomic_or_and_body, test_atomic_or_and_fini },
     299  {
     300    test_atomic_add_init,
     301    test_atomic_add_body,
     302    test_atomic_add_fini
     303  }, {
     304    test_atomic_flag_init,
     305    test_atomic_flag_body,
     306    test_atomic_flag_fini
     307  }, {
     308    test_atomic_sub_init,
     309    test_atomic_sub_body,
     310    test_atomic_sub_fini
     311  }, {
     312    test_atomic_compare_exchange_init,
     313    test_atomic_compare_exchange_body,
     314    test_atomic_compare_exchange_fini
     315  }, {
     316    test_atomic_or_and_init,
     317    test_atomic_or_and_body,
     318    test_atomic_or_and_fini
     319  },
    397320};
    398321
  • testsuites/smptests/smpatomic08/smpatomic08.scn

    r7136d7f r47b6fad  
    11*** TEST SMPATOMIC 8 ***
    22=== atomic add test case ==
    3 atomic add worker 0 counter: 18583
    4 atomic add worker 1 counter: 36324
    5 global counter: expected = 54907, actual = 54907
    6 === atomic flag test case ===
    7 atomic flag worker 0 counter: 7388
    8 atomic flag worker 1 counter: 17280
    9 global flag counter: expected = 24668, actual = 24668
     3worker 0 value: 16686
     4worker 1 value: 36405
     5atomic value: expected = 53091, actual = 53091
     6=== atomic flag test case ==
     7worker 0 value: 5588
     8worker 1 value: 16019
     9atomic value: expected = 21607, actual = 21607
    1010=== atomic sub test case ==
    11 atomic sub worker 0 counter: 18583
    12 atomic sub worker 1 counter: 36324
    13 global counter: expected = 54907, actual = 54907
    14 === atomic compare_exchange test case ==
    15 atomic compare_exchange worker 0 counter: 3467
    16 atomic compare_exchange worker 1 counter: 19635
    17 global counter: expected = 23102, actual = 23102
    18 === atomic or_and test case ==
    19 atomic or_and worker 0 counter: 1
    20 atomic or_and worker 1 counter: 1
    21 global counter: expected = 3, actual = 3
     11worker 0 value: 4294950967
     12worker 1 value: 4294930886
     13atomic value: expected = 4294914557, actual = 4294914557
     14=== atomic compare exchange test case ==
     15worker 0 value: 2950
     16worker 1 value: 22456
     17atomic value: expected = 25406, actual = 25406
     18=== atomic or/and test case ==
     19worker 0 value: 1
     20worker 1 value: 0
     21atomic value: expected = 1, actual = 1
    2222*** END OF TEST SMPATOMIC 8 ***
Note: See TracChangeset for help on using the changeset viewer.