Home | History | Annotate | Line # | Download | only in atomic
t___sync_and.c revision 1.3.2.2
      1  1.3.2.2  christos /*	$NetBSD: t___sync_and.c,v 1.3.2.2 2019/06/10 22:10:03 christos Exp $	*/
      2  1.3.2.2  christos 
      3  1.3.2.2  christos /*
      4  1.3.2.2  christos  * Copyright (C) 2019 Tetsuya Isaki. All rights reserved.
      5  1.3.2.2  christos  *
      6  1.3.2.2  christos  * Redistribution and use in source and binary forms, with or without
      7  1.3.2.2  christos  * modification, are permitted provided that the following conditions
      8  1.3.2.2  christos  * are met:
      9  1.3.2.2  christos  * 1. Redistributions of source code must retain the above copyright
     10  1.3.2.2  christos  *    notice, this list of conditions and the following disclaimer.
     11  1.3.2.2  christos  * 2. Redistributions in binary form must reproduce the above copyright
     12  1.3.2.2  christos  *    notice, this list of conditions and the following disclaimer in the
     13  1.3.2.2  christos  *    documentation and/or other materials provided with the distribution.
     14  1.3.2.2  christos  *
     15  1.3.2.2  christos  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     16  1.3.2.2  christos  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     17  1.3.2.2  christos  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     18  1.3.2.2  christos  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     19  1.3.2.2  christos  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     20  1.3.2.2  christos  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     21  1.3.2.2  christos  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     22  1.3.2.2  christos  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     23  1.3.2.2  christos  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     24  1.3.2.2  christos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     25  1.3.2.2  christos  * SUCH DAMAGE.
     26  1.3.2.2  christos  */
     27  1.3.2.2  christos 
     28  1.3.2.2  christos #include <sys/cdefs.h>
     29  1.3.2.2  christos __RCSID("$NetBSD: t___sync_and.c,v 1.3.2.2 2019/06/10 22:10:03 christos Exp $");
     30  1.3.2.2  christos 
     31  1.3.2.2  christos #include <atf-c.h>
     32  1.3.2.2  christos #include <inttypes.h>
     33  1.3.2.2  christos #include <machine/types.h>	// for __HAVE_ATOMIC64_OPS
     34  1.3.2.2  christos 
     35  1.3.2.2  christos /*
     36  1.3.2.2  christos  * These tests don't examine the atomicity.
     37  1.3.2.2  christos  */
     38  1.3.2.2  christos 
     39  1.3.2.2  christos /* XXX
     40  1.3.2.2  christos  * Depending on a combination of arch and compiler, __sync_* is
     41  1.3.2.2  christos  * implemented as compiler's builtin function.  In that case, even
     42  1.3.2.2  christos  * if libc exports the function symbol, it is not used.  As a result
     43  1.3.2.2  christos  * this tests will examine compiler's builtin functions.
     44  1.3.2.2  christos  * It's better to run only when target is actually in libc.
     45  1.3.2.2  christos  */
     46  1.3.2.2  christos 
     47  1.3.2.2  christos #define DST    (0x1122334455667788UL)
     48  1.3.2.2  christos #define SRC    (0xf0f0f0f0f0f0f0f0UL)
     49  1.3.2.2  christos #define EXPECT (0x1020304050607080UL)
     50  1.3.2.2  christos 
     51  1.3.2.2  christos #define atf_sync_prefetch(NAME, TYPE, FMT) \
     52  1.3.2.2  christos ATF_TC(NAME); \
     53  1.3.2.2  christos ATF_TC_HEAD(NAME, tc) \
     54  1.3.2.2  christos { \
     55  1.3.2.2  christos 	atf_tc_set_md_var(tc, "descr", #NAME); \
     56  1.3.2.2  christos } \
     57  1.3.2.2  christos ATF_TC_BODY(NAME, tc) \
     58  1.3.2.2  christos { \
     59  1.3.2.2  christos 	volatile TYPE val; \
     60  1.3.2.2  christos 	TYPE src; \
     61  1.3.2.2  christos 	TYPE res; \
     62  1.3.2.2  christos 	TYPE expval; \
     63  1.3.2.2  christos 	TYPE expres; \
     64  1.3.2.2  christos 	val = (TYPE)DST; \
     65  1.3.2.2  christos 	src = (TYPE)SRC; \
     66  1.3.2.2  christos 	expval = (TYPE)EXPECT; \
     67  1.3.2.2  christos 	expres = (TYPE)DST; \
     68  1.3.2.2  christos 	res = NAME(&val, src); \
     69  1.3.2.2  christos 	ATF_REQUIRE_MSG(val == expval, \
     70  1.3.2.2  christos 	    "val expects 0x%" FMT " but 0x%" FMT, expval, val); \
     71  1.3.2.2  christos 	ATF_REQUIRE_MSG(res == expres, \
     72  1.3.2.2  christos 	    "res expects 0x%" FMT " but 0x%" FMT, expres, res); \
     73  1.3.2.2  christos }
     74  1.3.2.2  christos 
     75  1.3.2.2  christos atf_sync_prefetch(__sync_fetch_and_and_1, uint8_t,  PRIx8);
     76  1.3.2.2  christos atf_sync_prefetch(__sync_fetch_and_and_2, uint16_t, PRIx16);
     77  1.3.2.2  christos atf_sync_prefetch(__sync_fetch_and_and_4, uint32_t, PRIx32);
     78  1.3.2.2  christos #if defined(__HAVE_ATOMIC64_OPS)
     79  1.3.2.2  christos atf_sync_prefetch(__sync_fetch_and_and_8, uint64_t, PRIx64);
     80  1.3.2.2  christos #endif
     81  1.3.2.2  christos 
     82  1.3.2.2  christos #define atf_sync_postfetch(NAME, TYPE, FMT) \
     83  1.3.2.2  christos ATF_TC(NAME); \
     84  1.3.2.2  christos ATF_TC_HEAD(NAME, tc) \
     85  1.3.2.2  christos { \
     86  1.3.2.2  christos 	atf_tc_set_md_var(tc, "descr", #NAME); \
     87  1.3.2.2  christos } \
     88  1.3.2.2  christos ATF_TC_BODY(NAME, tc) \
     89  1.3.2.2  christos { \
     90  1.3.2.2  christos 	volatile TYPE val; \
     91  1.3.2.2  christos 	TYPE src; \
     92  1.3.2.2  christos 	TYPE res; \
     93  1.3.2.2  christos 	TYPE exp; \
     94  1.3.2.2  christos 	val = (TYPE)DST; \
     95  1.3.2.2  christos 	src = (TYPE)SRC; \
     96  1.3.2.2  christos 	exp = (TYPE)EXPECT; \
     97  1.3.2.2  christos 	res = NAME(&val, src); \
     98  1.3.2.2  christos 	ATF_REQUIRE_MSG(val == exp, \
     99  1.3.2.2  christos 	    "val expects 0x%" FMT " but 0x%" FMT, exp, val); \
    100  1.3.2.2  christos 	ATF_REQUIRE_MSG(res == exp, \
    101  1.3.2.2  christos 	    "res expects 0x%" FMT " but 0x%" FMT, exp, res); \
    102  1.3.2.2  christos }
    103  1.3.2.2  christos 
    104  1.3.2.2  christos atf_sync_postfetch(__sync_and_and_fetch_1, uint8_t,  PRIx8);
    105  1.3.2.2  christos atf_sync_postfetch(__sync_and_and_fetch_2, uint16_t, PRIx16);
    106  1.3.2.2  christos atf_sync_postfetch(__sync_and_and_fetch_4, uint32_t, PRIx32);
    107  1.3.2.2  christos #ifdef __HAVE_ATOMIC64_OPS
    108  1.3.2.2  christos atf_sync_postfetch(__sync_and_and_fetch_8, uint64_t, PRIx64);
    109  1.3.2.2  christos #endif
    110  1.3.2.2  christos 
    111  1.3.2.2  christos ATF_TP_ADD_TCS(tp)
    112  1.3.2.2  christos {
    113  1.3.2.2  christos 	ATF_TP_ADD_TC(tp, __sync_fetch_and_and_1);
    114  1.3.2.2  christos 	ATF_TP_ADD_TC(tp, __sync_fetch_and_and_2);
    115  1.3.2.2  christos 	ATF_TP_ADD_TC(tp, __sync_fetch_and_and_4);
    116  1.3.2.2  christos #ifdef __HAVE_ATOMIC64_OPS
    117  1.3.2.2  christos 	ATF_TP_ADD_TC(tp, __sync_fetch_and_and_8);
    118  1.3.2.2  christos #endif
    119  1.3.2.2  christos 
    120  1.3.2.2  christos 	ATF_TP_ADD_TC(tp, __sync_and_and_fetch_1);
    121  1.3.2.2  christos 	ATF_TP_ADD_TC(tp, __sync_and_and_fetch_2);
    122  1.3.2.2  christos 	ATF_TP_ADD_TC(tp, __sync_and_and_fetch_4);
    123  1.3.2.2  christos #ifdef __HAVE_ATOMIC64_OPS
    124  1.3.2.2  christos 	ATF_TP_ADD_TC(tp, __sync_and_and_fetch_8);
    125  1.3.2.2  christos #endif
    126  1.3.2.2  christos 
    127  1.3.2.2  christos 	return atf_no_error();
    128  1.3.2.2  christos }
    129