t_atomic_dec.c revision 1.1.2.2 1 1.1.2.2 christos /* $NetBSD: t_atomic_dec.c,v 1.1.2.2 2019/06/10 22:10:03 christos Exp $ */
2 1.1.2.2 christos
3 1.1.2.2 christos /*
4 1.1.2.2 christos * Copyright (C) 2019 Tetsuya Isaki. All rights reserved.
5 1.1.2.2 christos *
6 1.1.2.2 christos * Redistribution and use in source and binary forms, with or without
7 1.1.2.2 christos * modification, are permitted provided that the following conditions
8 1.1.2.2 christos * are met:
9 1.1.2.2 christos * 1. Redistributions of source code must retain the above copyright
10 1.1.2.2 christos * notice, this list of conditions and the following disclaimer.
11 1.1.2.2 christos * 2. Redistributions in binary form must reproduce the above copyright
12 1.1.2.2 christos * notice, this list of conditions and the following disclaimer in the
13 1.1.2.2 christos * documentation and/or other materials provided with the distribution.
14 1.1.2.2 christos *
15 1.1.2.2 christos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 1.1.2.2 christos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 1.1.2.2 christos * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 1.1.2.2 christos * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 1.1.2.2 christos * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
20 1.1.2.2 christos * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 1.1.2.2 christos * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
22 1.1.2.2 christos * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23 1.1.2.2 christos * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 1.1.2.2 christos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 1.1.2.2 christos * SUCH DAMAGE.
26 1.1.2.2 christos */
27 1.1.2.2 christos
28 1.1.2.2 christos #include <sys/cdefs.h>
29 1.1.2.2 christos __RCSID("$NetBSD: t_atomic_dec.c,v 1.1.2.2 2019/06/10 22:10:03 christos Exp $");
30 1.1.2.2 christos
31 1.1.2.2 christos #include <atf-c.h>
32 1.1.2.2 christos #include <inttypes.h>
33 1.1.2.2 christos #include <sys/atomic.h>
34 1.1.2.2 christos
35 1.1.2.2 christos /*
36 1.1.2.2 christos * These tests don't examine the atomicity.
37 1.1.2.2 christos */
38 1.1.2.2 christos
39 1.1.2.2 christos #define VAL (0x1122334455667788UL)
40 1.1.2.2 christos #define EXPECT (0x1122334455667787UL)
41 1.1.2.2 christos
42 1.1.2.2 christos /*
43 1.1.2.2 christos * atomic_dec_*()
44 1.1.2.2 christos */
45 1.1.2.2 christos #define atf_dec(NAME, TYPE, FMT) \
46 1.1.2.2 christos ATF_TC(NAME); \
47 1.1.2.2 christos ATF_TC_HEAD(NAME, tc) \
48 1.1.2.2 christos { \
49 1.1.2.2 christos atf_tc_set_md_var(tc, "descr", #NAME); \
50 1.1.2.2 christos } \
51 1.1.2.2 christos ATF_TC_BODY(NAME, tc) \
52 1.1.2.2 christos { \
53 1.1.2.2 christos volatile TYPE val; \
54 1.1.2.2 christos TYPE exp; \
55 1.1.2.2 christos val = (TYPE)VAL; \
56 1.1.2.2 christos exp = (TYPE)EXPECT; \
57 1.1.2.2 christos NAME(&val); \
58 1.1.2.2 christos ATF_REQUIRE_MSG(val == exp, \
59 1.1.2.2 christos "val expects " FMT " but " FMT, exp, val); \
60 1.1.2.2 christos }
61 1.1.2.2 christos
62 1.1.2.2 christos atf_dec(atomic_dec_32, uint32_t, "0x%" PRIx32);
63 1.1.2.2 christos atf_dec(atomic_dec_uint, unsigned int, "0x%x");
64 1.1.2.2 christos atf_dec(atomic_dec_ulong, unsigned long, "0x%lx");
65 1.1.2.2 christos atf_dec(atomic_dec_ptr, void *, "%p");
66 1.1.2.2 christos #if defined(__HAVE_ATOMIC64_OPS)
67 1.1.2.2 christos atf_dec(atomic_dec_64, uint64_t, "0x%" PRIx64);
68 1.1.2.2 christos #endif
69 1.1.2.2 christos
70 1.1.2.2 christos /*
71 1.1.2.2 christos * atomic_dec_*_nv()
72 1.1.2.2 christos */
73 1.1.2.2 christos #define atf_dec_nv(NAME, TYPE, FMT) \
74 1.1.2.2 christos ATF_TC(NAME); \
75 1.1.2.2 christos ATF_TC_HEAD(NAME, tc) \
76 1.1.2.2 christos { \
77 1.1.2.2 christos atf_tc_set_md_var(tc, "descr", #NAME); \
78 1.1.2.2 christos } \
79 1.1.2.2 christos ATF_TC_BODY(NAME, tc) \
80 1.1.2.2 christos { \
81 1.1.2.2 christos volatile TYPE val; \
82 1.1.2.2 christos TYPE res; \
83 1.1.2.2 christos TYPE exp; \
84 1.1.2.2 christos val = (TYPE)VAL; \
85 1.1.2.2 christos exp = (TYPE)EXPECT; \
86 1.1.2.2 christos res = NAME(&val); \
87 1.1.2.2 christos ATF_REQUIRE_MSG(val == exp, \
88 1.1.2.2 christos "val expects " FMT " but " FMT, exp, val); \
89 1.1.2.2 christos ATF_REQUIRE_MSG(res == exp, \
90 1.1.2.2 christos "res expects " FMT " but " FMT, exp, res); \
91 1.1.2.2 christos }
92 1.1.2.2 christos
93 1.1.2.2 christos atf_dec_nv(atomic_dec_32_nv, uint32_t, "0x%" PRIx32);
94 1.1.2.2 christos atf_dec_nv(atomic_dec_uint_nv, unsigned int, "0x%x");
95 1.1.2.2 christos atf_dec_nv(atomic_dec_ulong_nv, unsigned long, "0x%lx");
96 1.1.2.2 christos atf_dec_nv(atomic_dec_ptr_nv, void *, "%p");
97 1.1.2.2 christos #if defined(__HAVE_ATOMIC64_OPS)
98 1.1.2.2 christos atf_dec_nv(atomic_dec_64_nv, uint64_t, "0x%" PRIx64);
99 1.1.2.2 christos #endif
100 1.1.2.2 christos
101 1.1.2.2 christos ATF_TP_ADD_TCS(tp)
102 1.1.2.2 christos {
103 1.1.2.2 christos ATF_TP_ADD_TC(tp, atomic_dec_32);
104 1.1.2.2 christos ATF_TP_ADD_TC(tp, atomic_dec_uint);
105 1.1.2.2 christos ATF_TP_ADD_TC(tp, atomic_dec_ulong);
106 1.1.2.2 christos ATF_TP_ADD_TC(tp, atomic_dec_ptr);
107 1.1.2.2 christos #if defined(__HAVE_ATOMIC64_OPS)
108 1.1.2.2 christos ATF_TP_ADD_TC(tp, atomic_dec_64);
109 1.1.2.2 christos #endif
110 1.1.2.2 christos
111 1.1.2.2 christos ATF_TP_ADD_TC(tp, atomic_dec_32_nv);
112 1.1.2.2 christos ATF_TP_ADD_TC(tp, atomic_dec_uint_nv);
113 1.1.2.2 christos ATF_TP_ADD_TC(tp, atomic_dec_ulong_nv);
114 1.1.2.2 christos ATF_TP_ADD_TC(tp, atomic_dec_ptr_nv);
115 1.1.2.2 christos #if defined(__HAVE_ATOMIC64_OPS)
116 1.1.2.2 christos ATF_TP_ADD_TC(tp, atomic_dec_64_nv);
117 1.1.2.2 christos #endif
118 1.1.2.2 christos
119 1.1.2.2 christos return atf_no_error();
120 1.1.2.2 christos }
121