From patchwork Wed Oct 29 21:52:46 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Torvald Riegel X-Patchwork-Id: 3491 Received: (qmail 17894 invoked by alias); 29 Oct 2014 21:52:51 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 17881 invoked by uid 89); 29 Oct 2014 21:52:51 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.4 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Subject: [PATCH 3/4] Add tests for C11-like atomic operations. From: Torvald Riegel To: GLIBC Devel In-Reply-To: <1414617613.10085.23.camel@triegel.csb> References: <1414617613.10085.23.camel@triegel.csb> Date: Wed, 29 Oct 2014 22:52:46 +0100 Message-ID: <1414619566.10085.49.camel@triegel.csb> Mime-Version: 1.0 This adds tests for the new C11 atomics to the existing test case for the old glibc-specific atomics. The old test was single-threaded, so this remains single-threaded. Thus, some of the tests such as for standalone barriers are more or less compilation tests. * csu/tst-atomic.c (do_test): Add tests for C11-like atomics. commit 4f6859b59ed1dff441b2a7e747ad1b59ee7f70a4 Author: Torvald Riegel Date: Mon Oct 20 20:25:40 2014 +0200 Add tests for C11-like atomic operations. diff --git a/csu/tst-atomic.c b/csu/tst-atomic.c index d16c66d..c6e786d 100644 --- a/csu/tst-atomic.c +++ b/csu/tst-atomic.c @@ -28,7 +28,7 @@ static int do_test (void) { - atomic_t mem; + atomic_t mem, expected; int ret = 0; #ifdef atomic_compare_and_exchange_val_acq @@ -489,6 +489,134 @@ do_test (void) ret = 1; } + /* Tests for C11-like atomics. */ + mem = 11; + if (atomic_load_relaxed (&mem) != 11 || atomic_load_acquire (&mem) != 11) + { + puts ("atomic_load_{relaxed,acquire} test failed"); + ret = 1; + } + + atomic_store_relaxed (&mem, 12); + if (mem != 12) + { + puts ("atomic_store_relaxed test failed"); + ret = 1; + } + atomic_store_release (&mem, 13); + if (mem != 13) + { + puts ("atomic_store_release test failed"); + ret = 1; + } + + mem = 14; + expected = 14; + if (!atomic_compare_exchange_weak_relaxed (&mem, &expected, 25) + || mem != 25 || expected != 14) + { + puts ("atomic_compare_exchange_weak_relaxed test 1 failed"); + ret = 1; + } + if (atomic_compare_exchange_weak_relaxed (&mem, &expected, 14) + || mem != 25 || expected != 25) + { + puts ("atomic_compare_exchange_weak_relaxed test 2 failed"); + ret = 1; + } + mem = 14; + expected = 14; + if (!atomic_compare_exchange_weak_acquire (&mem, &expected, 25) + || mem != 25 || expected != 14) + { + puts ("atomic_compare_exchange_weak_acquire test 1 failed"); + ret = 1; + } + if (atomic_compare_exchange_weak_acquire (&mem, &expected, 14) + || mem != 25 || expected != 25) + { + puts ("atomic_compare_exchange_weak_acquire test 2 failed"); + ret = 1; + } + mem = 14; + expected = 14; + if (!atomic_compare_exchange_weak_release (&mem, &expected, 25) + || mem != 25 || expected != 14) + { + puts ("atomic_compare_exchange_weak_release test 1 failed"); + ret = 1; + } + if (atomic_compare_exchange_weak_release (&mem, &expected, 14) + || mem != 25 || expected != 25) + { + puts ("atomic_compare_exchange_weak_release test 2 failed"); + ret = 1; + } + + mem = 23; + if (atomic_exchange_acquire (&mem, 42) != 23 || mem != 42) + { + puts ("atomic_exchange_acquire test failed"); + ret = 1; + } + mem = 23; + if (atomic_exchange_release (&mem, 42) != 23 || mem != 42) + { + puts ("atomic_exchange_release test failed"); + ret = 1; + } + + mem = 23; + if (atomic_fetch_add_relaxed (&mem, 1) != 23 || mem != 24) + { + puts ("atomic_fetch_add_relaxed test failed"); + ret = 1; + } + mem = 23; + if (atomic_fetch_add_acquire (&mem, 1) != 23 || mem != 24) + { + puts ("atomic_fetch_add_acquire test failed"); + ret = 1; + } + mem = 23; + if (atomic_fetch_add_release (&mem, 1) != 23 || mem != 24) + { + puts ("atomic_fetch_add_release test failed"); + ret = 1; + } + mem = 23; + if (atomic_fetch_add_acq_rel (&mem, 1) != 23 || mem != 24) + { + puts ("atomic_fetch_add_acq_rel test failed"); + ret = 1; + } + + mem = 3; + if (atomic_fetch_and_acquire (&mem, 2) != 3 || mem != 2) + { + puts ("atomic_fetch_and_acquire test failed"); + ret = 1; + } + + mem = 4; + if (atomic_fetch_or_relaxed (&mem, 2) != 4 || mem != 6) + { + puts ("atomic_fetch_or_relaxed test failed"); + ret = 1; + } + mem = 4; + if (atomic_fetch_or_acquire (&mem, 2) != 4 || mem != 6) + { + puts ("atomic_fetch_or_acquire test failed"); + ret = 1; + } + + /* This is a single-threaded test, so we can't test the effects of the + fences. */ + atomic_thread_fence_acquire (); + atomic_thread_fence_release (); + atomic_thread_fence_seq_cst (); + return ret; }