Changeset 4238aff in rtems


Ignore:
Timestamp:
Sep 1, 2013, 10:28:35 AM (6 years ago)
Author:
WeiY <wei.a.yang@…>
Branches:
4.11, master
Children:
d39ccd69
Parents:
bf30999
git-author:
WeiY <wei.a.yang@…> (09/01/13 10:28:35)
git-committer:
Sebastian Huber <sebastian.huber@…> (09/01/13 13:17:01)
Message:

add atomic sub, and, or, compare_exchange test cases into smpatomic08

Location:
testsuites/smptests/smpatomic08
Files:
2 edited

Legend:

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

    rbf30999 r4238aff  
    7979  rtems_id stop_worker_timer_id;
    8080  Atomic_Uint global_uint;
     81  Atomic_Uint global_swap;
     82  uint_fast32_t global_swap_t;
    8183  uint_fast32_t per_worker_uint[CPU_COUNT];
    8284  uint32_t flag_counter;
     
    208210}
    209211
     212static void test_atomic_sub_init(test_context *ctx)
     213{
     214  _Atomic_Init_uint(&ctx->global_uint, 0xffffffff);
     215}
     216
     217static void test_atomic_sub_body(test_context *ctx, size_t worker_index)
     218{
     219  uint_fast32_t counter = 0xffffffff;
     220
     221  while (!stop(ctx)) {
     222    --counter;
     223    _Atomic_Fetch_sub_uint(&ctx->global_uint, 1, ATOMIC_ORDER_RELAXED);
     224  }
     225
     226  ctx->per_worker_uint[worker_index] = 0xffffffff - counter;
     227}
     228
     229static void test_atomic_sub_fini(test_context *ctx)
     230{
     231  uint_fast32_t expected_counter = 0;
     232  uint_fast32_t actual_counter;
     233  size_t worker_index;
     234
     235  printf("=== atomic sub test case ==\n");
     236
     237  for (worker_index = 0; worker_index < ctx->worker_count; ++worker_index) {
     238    uint_fast32_t worker_counter = ctx->per_worker_uint[worker_index];
     239
     240    expected_counter += worker_counter;
     241
     242    printf(
     243      "atomic sub worker %zu counter: %" PRIuFAST32 "\n",
     244      worker_index,
     245      worker_counter
     246    );
     247  }
     248
     249  actual_counter = _Atomic_Load_uint(&ctx->global_uint, ATOMIC_ORDER_RELAXED);
     250  actual_counter = 0xffffffff - actual_counter;
     251
     252  printf(
     253    "global counter: expected = %" PRIuFAST32 ", actual = %" PRIuFAST32 "\n",
     254    expected_counter,
     255    actual_counter
     256  );
     257
     258  rtems_test_assert(expected_counter == actual_counter);
     259}
     260
     261static void test_atomic_compare_exchange_init(test_context *ctx)
     262{
     263  _Atomic_Init_uint(&ctx->global_swap, 0xffffffff);
     264  ctx->global_swap_t = 0xffffffff;
     265  ctx->flag_counter = 0;
     266}
     267
     268static void test_atomic_compare_exchange_body(test_context *ctx, size_t worker_index)
     269{
     270  uint_fast32_t counter = 0;
     271
     272  while (!stop(ctx)) {
     273    while (_Atomic_Compare_exchange_uint(&ctx->global_swap, &ctx->global_swap_t,
     274      worker_index, ATOMIC_ORDER_ACQUIRE, ATOMIC_ORDER_RELAXED)) {
     275      /* Wait */
     276    }
     277    ++counter;
     278    ++ctx->flag_counter;
     279    _Atomic_Store_uint(&ctx->global_swap, 0, ATOMIC_ORDER_RELEASE);
     280  }
     281
     282  ctx->per_worker_uint[worker_index] = counter;
     283}
     284
     285static void test_atomic_compare_exchange_fini(test_context *ctx)
     286{
     287  uint_fast32_t expected_counter = 0;
     288  uint_fast32_t actual_counter;
     289  size_t worker_index;
     290
     291  printf("=== atomic compare_exchange test case ==\n");
     292
     293  for (worker_index = 0; worker_index < ctx->worker_count; ++worker_index) {
     294    uint_fast32_t worker_counter = ctx->per_worker_uint[worker_index];
     295
     296    expected_counter += worker_counter;
     297
     298    printf(
     299      "atomic compare_exchange worker %zu counter: %" PRIuFAST32 "\n",
     300      worker_index,
     301      worker_counter
     302    );
     303  }
     304
     305  actual_counter = ctx->flag_counter;
     306
     307  printf(
     308    "global counter: expected = %" PRIuFAST32 ", actual = %" PRIuFAST32 "\n",
     309    expected_counter,
     310    actual_counter
     311  );
     312
     313  rtems_test_assert(expected_counter == actual_counter);
     314}
     315
     316static void test_atomic_or_and_init(test_context *ctx)
     317{
     318  _Atomic_Init_uint(&ctx->global_uint, 0);
     319}
     320
     321static void test_atomic_or_and_body(test_context *ctx, size_t worker_index)
     322{
     323  uint_fast32_t counter = 0;
     324
     325  while (!stop(ctx)) {
     326    _Atomic_Fetch_or_uint(&ctx->global_uint, (1 << worker_index), ATOMIC_ORDER_RELAXED);
     327    counter = 1;
     328    if (!stop(ctx))
     329      break;
     330    _Atomic_Fetch_and_uint(&ctx->global_uint, ~(1 << worker_index), ATOMIC_ORDER_RELAXED);
     331    counter = 0;
     332  }
     333
     334  ctx->per_worker_uint[worker_index] = counter;
     335}
     336
     337static void test_atomic_or_and_fini(test_context *ctx)
     338{
     339  uint_fast32_t expected_counter = 0;
     340  uint_fast32_t actual_counter;
     341  size_t worker_index;
     342
     343  printf("=== atomic or_and test case ==\n");
     344
     345  for (worker_index = 0; worker_index < ctx->worker_count; ++worker_index) {
     346    uint_fast32_t worker_counter = ctx->per_worker_uint[worker_index];
     347
     348    expected_counter |= ( worker_counter << worker_index );
     349
     350    printf(
     351      "atomic or_and worker %zu counter: %" PRIuFAST32 "\n",
     352      worker_index,
     353      worker_counter
     354    );
     355  }
     356
     357  actual_counter = _Atomic_Load_uint(&ctx->global_uint, ATOMIC_ORDER_RELAXED);
     358
     359  printf(
     360    "global counter: expected = %" PRIuFAST32 ", actual = %" PRIuFAST32 "\n",
     361    expected_counter,
     362    actual_counter
     363  );
     364
     365  rtems_test_assert(expected_counter == actual_counter);
     366}
     367
    210368static const test_case test_cases[] = {
    211369  { test_atomic_add_init, test_atomic_add_body, test_atomic_add_fini },
    212   { test_atomic_flag_init, test_atomic_flag_body, test_atomic_flag_fini }
     370  { test_atomic_flag_init, test_atomic_flag_body, test_atomic_flag_fini },
     371  { test_atomic_sub_init, test_atomic_sub_body, test_atomic_sub_fini },
     372  { test_atomic_compare_exchange_init, test_atomic_compare_exchange_body,
     373    test_atomic_compare_exchange_fini },
     374  { test_atomic_or_and_init, test_atomic_or_and_body, test_atomic_or_and_fini },
    213375};
    214376
  • testsuites/smptests/smpatomic08/smpatomic08.scn

    rbf30999 r4238aff  
    88atomic flag worker 1 counter: 17280
    99global flag counter: expected = 24668, actual = 24668
     10=== atomic sub test case ==
     11atomic sub worker 0 counter: 18583
     12atomic sub worker 1 counter: 36324
     13global counter: expected = 54907, actual = 54907
     14=== atomic compare_exchange test case ==
     15atomic compare_exchange worker 0 counter: 3467
     16atomic compare_exchange worker 1 counter: 19635
     17global counter: expected = 23102, actual = 23102
     18=== atomic or_and test case ==
     19atomic or_and worker 0 counter: 1
     20atomic or_and worker 1 counter: 1
     21global counter: expected = 3, actual = 3
    1022*** END OF TEST SMPATOMIC 8 ***
Note: See TracChangeset for help on using the changeset viewer.