Changeset 7136d7f in rtems


Ignore:
Timestamp:
Sep 1, 2013, 1:01:42 PM (6 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
47b6fad
Parents:
d39ccd69
git-author:
Sebastian Huber <sebastian.huber@…> (09/01/13 13:01:42)
git-committer:
Sebastian Huber <sebastian.huber@…> (09/01/13 13:17:02)
Message:

smptests/smpatomic08: Simplify or/and test case

Renamed and use common integer variables.

File:
1 edited

Legend:

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

    rd39ccd69 r7136d7f  
    7878  size_t worker_count;
    7979  rtems_id stop_worker_timer_id;
    80   Atomic_Uint global_uint;
    81   uint_fast32_t per_worker_uint[CPU_COUNT];
    82   uint32_t flag_counter;
     80  Atomic_Uint atomic_value;
     81  uint_fast32_t per_worker_value[CPU_COUNT];
     82  uint32_t normal_value;
    8383  Atomic_Flag global_flag;
    8484} test_context;
     
    107107static void test_atomic_add_init(test_context *ctx)
    108108{
    109   _Atomic_Init_uint(&ctx->global_uint, 0);
     109  _Atomic_Init_uint(&ctx->atomic_value, 0);
    110110}
    111111
     
    116116  while (!stop(ctx)) {
    117117    ++counter;
    118     _Atomic_Fetch_add_uint(&ctx->global_uint, 1, ATOMIC_ORDER_RELAXED);
    119   }
    120 
    121   ctx->per_worker_uint[worker_index] = counter;
     118    _Atomic_Fetch_add_uint(&ctx->atomic_value, 1, ATOMIC_ORDER_RELAXED);
     119  }
     120
     121  ctx->per_worker_value[worker_index] = counter;
    122122}
    123123
     
    131131
    132132  for (worker_index = 0; worker_index < ctx->worker_count; ++worker_index) {
    133     uint_fast32_t worker_counter = ctx->per_worker_uint[worker_index];
     133    uint_fast32_t worker_counter = ctx->per_worker_value[worker_index];
    134134
    135135    expected_counter += worker_counter;
     
    142142  }
    143143
    144   actual_counter = _Atomic_Load_uint(&ctx->global_uint, ATOMIC_ORDER_RELAXED);
     144  actual_counter = _Atomic_Load_uint(&ctx->atomic_value, ATOMIC_ORDER_RELAXED);
    145145
    146146  printf(
     
    156156{
    157157  _Atomic_Flag_clear(&ctx->global_flag, ATOMIC_ORDER_RELEASE);
    158   ctx->flag_counter = 0;
     158  ctx->normal_value = 0;
    159159}
    160160
     
    169169
    170170    ++counter;
    171     ++ctx->flag_counter;
     171    ++ctx->normal_value;
    172172
    173173    _Atomic_Flag_clear(&ctx->global_flag, ATOMIC_ORDER_RELEASE);
    174174  }
    175175
    176   ctx->per_worker_uint[worker_index] = counter;
     176  ctx->per_worker_value[worker_index] = counter;
    177177}
    178178
     
    186186
    187187  for (worker_index = 0; worker_index < ctx->worker_count; ++worker_index) {
    188     uint_fast32_t worker_counter = ctx->per_worker_uint[worker_index];
     188    uint_fast32_t worker_counter = ctx->per_worker_value[worker_index];
    189189
    190190    expected_counter += worker_counter;
     
    197197  }
    198198
    199   actual_counter = ctx->flag_counter;
     199  actual_counter = ctx->normal_value;
    200200
    201201  printf(
     
    210210static void test_atomic_sub_init(test_context *ctx)
    211211{
    212   _Atomic_Init_uint(&ctx->global_uint, 0xffffffff);
     212  _Atomic_Init_uint(&ctx->atomic_value, 0xffffffff);
    213213}
    214214
     
    219219  while (!stop(ctx)) {
    220220    --counter;
    221     _Atomic_Fetch_sub_uint(&ctx->global_uint, 1, ATOMIC_ORDER_RELAXED);
    222   }
    223 
    224   ctx->per_worker_uint[worker_index] = 0xffffffff - counter;
     221    _Atomic_Fetch_sub_uint(&ctx->atomic_value, 1, ATOMIC_ORDER_RELAXED);
     222  }
     223
     224  ctx->per_worker_value[worker_index] = 0xffffffff - counter;
    225225}
    226226
     
    234234
    235235  for (worker_index = 0; worker_index < ctx->worker_count; ++worker_index) {
    236     uint_fast32_t worker_counter = ctx->per_worker_uint[worker_index];
     236    uint_fast32_t worker_counter = ctx->per_worker_value[worker_index];
    237237
    238238    expected_counter += worker_counter;
     
    245245  }
    246246
    247   actual_counter = _Atomic_Load_uint(&ctx->global_uint, ATOMIC_ORDER_RELAXED);
     247  actual_counter = _Atomic_Load_uint(&ctx->atomic_value, ATOMIC_ORDER_RELAXED);
    248248  actual_counter = 0xffffffff - actual_counter;
    249249
     
    259259static void test_atomic_compare_exchange_init(test_context *ctx)
    260260{
    261   _Atomic_Init_uint(&ctx->global_uint, 0);
    262   ctx->flag_counter = 0;
     261  _Atomic_Init_uint(&ctx->atomic_value, 0);
     262  ctx->normal_value = 0;
    263263}
    264264
     
    274274
    275275      success = _Atomic_Compare_exchange_uint(
    276         &ctx->global_uint,
     276        &ctx->atomic_value,
    277277        &zero,
    278278        1,
     
    283283
    284284    ++counter;
    285     ++ctx->flag_counter;
    286 
    287     _Atomic_Store_uint(&ctx->global_uint, 0, ATOMIC_ORDER_RELEASE);
    288   }
    289 
    290   ctx->per_worker_uint[worker_index] = counter;
     285    ++ctx->normal_value;
     286
     287    _Atomic_Store_uint(&ctx->atomic_value, 0, ATOMIC_ORDER_RELEASE);
     288  }
     289
     290  ctx->per_worker_value[worker_index] = counter;
    291291}
    292292
     
    300300
    301301  for (worker_index = 0; worker_index < ctx->worker_count; ++worker_index) {
    302     uint_fast32_t worker_counter = ctx->per_worker_uint[worker_index];
     302    uint_fast32_t worker_counter = ctx->per_worker_value[worker_index];
    303303
    304304    expected_counter += worker_counter;
     
    311311  }
    312312
    313   actual_counter = ctx->flag_counter;
     313  actual_counter = ctx->normal_value;
    314314
    315315  printf(
     
    324324static void test_atomic_or_and_init(test_context *ctx)
    325325{
    326   _Atomic_Init_uint(&ctx->global_uint, 0);
     326  _Atomic_Init_uint(&ctx->atomic_value, 0);
    327327}
    328328
    329329static void test_atomic_or_and_body(test_context *ctx, size_t worker_index)
    330330{
    331   uint_fast32_t counter = 0;
     331  uint_fast32_t the_bit = 1UL << worker_index;
     332  uint_fast32_t current_bit = 0;
    332333
    333334  while (!stop(ctx)) {
    334     _Atomic_Fetch_or_uint(&ctx->global_uint, (1 << worker_index), ATOMIC_ORDER_RELAXED);
    335     counter = 1;
    336     if (!stop(ctx))
    337       break;
    338     _Atomic_Fetch_and_uint(&ctx->global_uint, ~(1 << worker_index), ATOMIC_ORDER_RELAXED);
    339     counter = 0;
    340   }
    341 
    342   ctx->per_worker_uint[worker_index] = counter;
     335    uint_fast32_t previous;
     336
     337    if (current_bit != 0) {
     338      previous = _Atomic_Fetch_and_uint(
     339        &ctx->atomic_value,
     340        ~the_bit,
     341        ATOMIC_ORDER_RELAXED
     342      );
     343      current_bit = 0;
     344    } else {
     345      previous = _Atomic_Fetch_or_uint(
     346        &ctx->atomic_value,
     347        the_bit,
     348        ATOMIC_ORDER_RELAXED
     349      );
     350      current_bit = the_bit;
     351    }
     352
     353    rtems_test_assert((previous & the_bit) != current_bit);
     354  }
     355
     356  ctx->per_worker_value[worker_index] = current_bit;
    343357}
    344358
     
    352366
    353367  for (worker_index = 0; worker_index < ctx->worker_count; ++worker_index) {
    354     uint_fast32_t worker_counter = ctx->per_worker_uint[worker_index];
    355 
    356     expected_counter |= ( worker_counter << worker_index );
     368    uint_fast32_t worker_counter = ctx->per_worker_value[worker_index];
     369
     370    expected_counter += worker_counter;
    357371
    358372    printf(
     
    363377  }
    364378
    365   actual_counter = _Atomic_Load_uint(&ctx->global_uint, ATOMIC_ORDER_RELAXED);
     379  actual_counter = _Atomic_Load_uint(&ctx->atomic_value, ATOMIC_ORDER_RELAXED);
    366380
    367381  printf(
Note: See TracChangeset for help on using the changeset viewer.