Changeset fee154be in rtems


Ignore:
Timestamp:
Sep 28, 2013, 6:54:36 AM (6 years ago)
Author:
WeiY <wei.a.yang@…>
Branches:
4.11, master
Children:
27a034ef
Parents:
382f714
git-author:
WeiY <wei.a.yang@…> (09/28/13 06:54:36)
git-committer:
Sebastian Huber <sebastian.huber@…> (10/08/13 14:06:59)
Message:

add simple atomic test cases into smpatomic08

File:
1 edited

Legend:

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

    r382f714 rfee154be  
    77 *  Germany
    88 *  <rtems@embedded-brains.de>
     9 *
     10 * Copyright (c) 2013 Deng Hengyi.
    911 *
    1012 * The license and distribution terms for this file may be
     
    455457}
    456458
     459typedef void (*simple_test_body)(test_context *ctx);
     460
     461static void test_simple_atomic_add_body(test_context *ctx)
     462{
     463  unsigned long a = 2, b = 1;
     464  unsigned long c;
     465
     466  puts("=== atomic simple add test case ==\n");
     467
     468  _Atomic_Store_ulong(&ctx->atomic_value, a, ATOMIC_ORDER_RELAXED);
     469  _Atomic_Fetch_add_ulong(&ctx->atomic_value, b, ATOMIC_ORDER_RELAXED);
     470  c = _Atomic_Load_ulong(&ctx->atomic_value, ATOMIC_ORDER_RELAXED);
     471  rtems_test_assert(c == (a + b));
     472}
     473
     474static void test_simple_atomic_sub_body(test_context *ctx)
     475{
     476  unsigned long a = 2, b = 1;
     477  unsigned long c;
     478
     479  puts("=== atomic simple sub test case ==\n");
     480
     481  _Atomic_Store_ulong(&ctx->atomic_value, a, ATOMIC_ORDER_RELAXED);
     482  _Atomic_Fetch_sub_ulong(&ctx->atomic_value, b, ATOMIC_ORDER_RELAXED);
     483  c = _Atomic_Load_ulong(&ctx->atomic_value, ATOMIC_ORDER_RELAXED);
     484  rtems_test_assert(c == (a - b));
     485}
     486
     487static void test_simple_atomic_or_body(test_context *ctx)
     488{
     489  unsigned long a = 2, b = 1;
     490  unsigned long c;
     491
     492  puts("=== atomic simple or test case ==\n");
     493
     494  _Atomic_Store_ulong(&ctx->atomic_value, a, ATOMIC_ORDER_RELAXED);
     495  _Atomic_Fetch_or_ulong(&ctx->atomic_value, b, ATOMIC_ORDER_RELAXED);
     496  c = _Atomic_Load_ulong(&ctx->atomic_value, ATOMIC_ORDER_RELAXED);
     497  rtems_test_assert(c == (a | b));
     498}
     499
     500static void test_simple_atomic_and_body(test_context *ctx)
     501{
     502  unsigned long a = 2, b = 1;
     503  unsigned long c;
     504
     505  puts("=== atomic simple and test case ==\n");
     506
     507  _Atomic_Store_ulong(&ctx->atomic_value, a, ATOMIC_ORDER_RELAXED);
     508  _Atomic_Fetch_and_ulong(&ctx->atomic_value, b, ATOMIC_ORDER_RELAXED);
     509  c = _Atomic_Load_ulong(&ctx->atomic_value, ATOMIC_ORDER_RELAXED);
     510  rtems_test_assert(c == (a & b));
     511}
     512
     513static void test_simple_atomic_exchange_body(test_context *ctx)
     514{
     515  unsigned long a = 2, b = 1;
     516  unsigned long c;
     517
     518  puts("=== atomic simple exchange test case ==\n");
     519
     520  _Atomic_Store_ulong(&ctx->atomic_value, a, ATOMIC_ORDER_RELAXED);
     521  _Atomic_Exchange_ulong(&ctx->atomic_value, b, ATOMIC_ORDER_RELAXED);
     522  c = _Atomic_Load_ulong(&ctx->atomic_value, ATOMIC_ORDER_RELAXED);
     523  rtems_test_assert(c == b);
     524}
     525
     526static void test_simple_atomic_compare_exchange_body(test_context *ctx)
     527{
     528  unsigned long a = 2, b = 1;
     529  unsigned long c;
     530
     531  puts("=== atomic simple compare exchange test case ==\n");
     532
     533  _Atomic_Store_ulong(&ctx->atomic_value, a, ATOMIC_ORDER_RELAXED);
     534  _Atomic_Compare_exchange_ulong(&ctx->atomic_value, &a, b,
     535    ATOMIC_ORDER_RELAXED, ATOMIC_ORDER_RELAXED);
     536  c = _Atomic_Load_ulong(&ctx->atomic_value, ATOMIC_ORDER_RELAXED);
     537  rtems_test_assert(c == b);
     538}
     539
     540static const simple_test_body simple_test_bodies[] = {
     541  test_simple_atomic_add_body,
     542  test_simple_atomic_sub_body,
     543  test_simple_atomic_or_body,
     544  test_simple_atomic_and_body,
     545  test_simple_atomic_exchange_body,
     546  test_simple_atomic_compare_exchange_body,
     547};
     548
     549#define SIMPLE_TEST_COUNT RTEMS_ARRAY_SIZE(simple_test_bodies)
     550
     551static void simple_tests(void)
     552{
     553  test_context *ctx = &test_instance;
     554  size_t test;
     555
     556  for (test = 0; test < SIMPLE_TEST_COUNT; ++test) {
     557    const simple_test_body *test_body = &simple_test_bodies[test];
     558
     559    (*test_body)(ctx);
     560  }
     561}
     562
    457563static void Init(rtems_task_argument arg)
    458564{
    459565  puts("\n\n*** TEST SMPATOMIC 8 ***");
     566
     567  simple_tests();
    460568
    461569  test();
Note: See TracChangeset for help on using the changeset viewer.