1 #define ASSERT_BUFSIZE 256 2 3 #define verify_cmp(may_abort, t, a, b, cmp, neg_cmp, pri, ...) do { \ 4 const t a_ = (a); \ 5 const t b_ = (b); \ 6 if (!(a_ cmp b_)) { \ 7 char prefix[ASSERT_BUFSIZE]; \ 8 char message[ASSERT_BUFSIZE]; \ 9 malloc_snprintf(prefix, sizeof(prefix), \ 10 "%s:%s:%d: Failed assertion: " \ 11 "(%s) " #cmp " (%s) --> " \ 12 "%" pri " " #neg_cmp " %" pri ": ", \ 13 __func__, __FILE__, __LINE__, \ 14 #a, #b, a_, b_); \ 15 malloc_snprintf(message, sizeof(message), __VA_ARGS__); \ 16 if (may_abort) { \ 17 abort(); \ 18 } else { \ 19 p_test_fail(prefix, message); \ 20 } \ 21 } \ 22 } while (0) 23 24 #define expect_cmp(t, a, b, cmp, neg_cmp, pri, ...) verify_cmp(false, \ 25 t, a, b, cmp, neg_cmp, pri, __VA_ARGS__) 26 27 #define expect_ptr_eq(a, b, ...) expect_cmp(void *, a, b, ==, \ 28 !=, "p", __VA_ARGS__) 29 #define expect_ptr_ne(a, b, ...) expect_cmp(void *, a, b, !=, \ 30 ==, "p", __VA_ARGS__) 31 #define expect_ptr_null(a, ...) expect_cmp(void *, a, NULL, ==, \ 32 !=, "p", __VA_ARGS__) 33 #define expect_ptr_not_null(a, ...) expect_cmp(void *, a, NULL, !=, \ 34 ==, "p", __VA_ARGS__) 35 36 #define expect_c_eq(a, b, ...) expect_cmp(char, a, b, ==, !=, "c", __VA_ARGS__) 37 #define expect_c_ne(a, b, ...) expect_cmp(char, a, b, !=, ==, "c", __VA_ARGS__) 38 #define expect_c_lt(a, b, ...) expect_cmp(char, a, b, <, >=, "c", __VA_ARGS__) 39 #define expect_c_le(a, b, ...) expect_cmp(char, a, b, <=, >, "c", __VA_ARGS__) 40 #define expect_c_ge(a, b, ...) expect_cmp(char, a, b, >=, <, "c", __VA_ARGS__) 41 #define expect_c_gt(a, b, ...) expect_cmp(char, a, b, >, <=, "c", __VA_ARGS__) 42 43 #define expect_x_eq(a, b, ...) expect_cmp(int, a, b, ==, !=, "#x", __VA_ARGS__) 44 #define expect_x_ne(a, b, ...) expect_cmp(int, a, b, !=, ==, "#x", __VA_ARGS__) 45 #define expect_x_lt(a, b, ...) expect_cmp(int, a, b, <, >=, "#x", __VA_ARGS__) 46 #define expect_x_le(a, b, ...) expect_cmp(int, a, b, <=, >, "#x", __VA_ARGS__) 47 #define expect_x_ge(a, b, ...) expect_cmp(int, a, b, >=, <, "#x", __VA_ARGS__) 48 #define expect_x_gt(a, b, ...) expect_cmp(int, a, b, >, <=, "#x", __VA_ARGS__) 49 50 #define expect_d_eq(a, b, ...) expect_cmp(int, a, b, ==, !=, "d", __VA_ARGS__) 51 #define expect_d_ne(a, b, ...) expect_cmp(int, a, b, !=, ==, "d", __VA_ARGS__) 52 #define expect_d_lt(a, b, ...) expect_cmp(int, a, b, <, >=, "d", __VA_ARGS__) 53 #define expect_d_le(a, b, ...) expect_cmp(int, a, b, <=, >, "d", __VA_ARGS__) 54 #define expect_d_ge(a, b, ...) expect_cmp(int, a, b, >=, <, "d", __VA_ARGS__) 55 #define expect_d_gt(a, b, ...) expect_cmp(int, a, b, >, <=, "d", __VA_ARGS__) 56 57 #define expect_u_eq(a, b, ...) expect_cmp(int, a, b, ==, !=, "u", __VA_ARGS__) 58 #define expect_u_ne(a, b, ...) expect_cmp(int, a, b, !=, ==, "u", __VA_ARGS__) 59 #define expect_u_lt(a, b, ...) expect_cmp(int, a, b, <, >=, "u", __VA_ARGS__) 60 #define expect_u_le(a, b, ...) expect_cmp(int, a, b, <=, >, "u", __VA_ARGS__) 61 #define expect_u_ge(a, b, ...) expect_cmp(int, a, b, >=, <, "u", __VA_ARGS__) 62 #define expect_u_gt(a, b, ...) expect_cmp(int, a, b, >, <=, "u", __VA_ARGS__) 63 64 #define expect_ld_eq(a, b, ...) expect_cmp(long, a, b, ==, \ 65 !=, "ld", __VA_ARGS__) 66 #define expect_ld_ne(a, b, ...) expect_cmp(long, a, b, !=, \ 67 ==, "ld", __VA_ARGS__) 68 #define expect_ld_lt(a, b, ...) expect_cmp(long, a, b, <, \ 69 >=, "ld", __VA_ARGS__) 70 #define expect_ld_le(a, b, ...) expect_cmp(long, a, b, <=, \ 71 >, "ld", __VA_ARGS__) 72 #define expect_ld_ge(a, b, ...) expect_cmp(long, a, b, >=, \ 73 <, "ld", __VA_ARGS__) 74 #define expect_ld_gt(a, b, ...) expect_cmp(long, a, b, >, \ 75 <=, "ld", __VA_ARGS__) 76 77 #define expect_lu_eq(a, b, ...) expect_cmp(unsigned long, \ 78 a, b, ==, !=, "lu", __VA_ARGS__) 79 #define expect_lu_ne(a, b, ...) expect_cmp(unsigned long, \ 80 a, b, !=, ==, "lu", __VA_ARGS__) 81 #define expect_lu_lt(a, b, ...) expect_cmp(unsigned long, \ 82 a, b, <, >=, "lu", __VA_ARGS__) 83 #define expect_lu_le(a, b, ...) expect_cmp(unsigned long, \ 84 a, b, <=, >, "lu", __VA_ARGS__) 85 #define expect_lu_ge(a, b, ...) expect_cmp(unsigned long, \ 86 a, b, >=, <, "lu", __VA_ARGS__) 87 #define expect_lu_gt(a, b, ...) expect_cmp(unsigned long, \ 88 a, b, >, <=, "lu", __VA_ARGS__) 89 90 #define expect_qd_eq(a, b, ...) expect_cmp(long long, a, b, ==, \ 91 !=, "qd", __VA_ARGS__) 92 #define expect_qd_ne(a, b, ...) expect_cmp(long long, a, b, !=, \ 93 ==, "qd", __VA_ARGS__) 94 #define expect_qd_lt(a, b, ...) expect_cmp(long long, a, b, <, \ 95 >=, "qd", __VA_ARGS__) 96 #define expect_qd_le(a, b, ...) expect_cmp(long long, a, b, <=, \ 97 >, "qd", __VA_ARGS__) 98 #define expect_qd_ge(a, b, ...) expect_cmp(long long, a, b, >=, \ 99 <, "qd", __VA_ARGS__) 100 #define expect_qd_gt(a, b, ...) expect_cmp(long long, a, b, >, \ 101 <=, "qd", __VA_ARGS__) 102 103 #define expect_qu_eq(a, b, ...) expect_cmp(unsigned long long, \ 104 a, b, ==, !=, "qu", __VA_ARGS__) 105 #define expect_qu_ne(a, b, ...) expect_cmp(unsigned long long, \ 106 a, b, !=, ==, "qu", __VA_ARGS__) 107 #define expect_qu_lt(a, b, ...) expect_cmp(unsigned long long, \ 108 a, b, <, >=, "qu", __VA_ARGS__) 109 #define expect_qu_le(a, b, ...) expect_cmp(unsigned long long, \ 110 a, b, <=, >, "qu", __VA_ARGS__) 111 #define expect_qu_ge(a, b, ...) expect_cmp(unsigned long long, \ 112 a, b, >=, <, "qu", __VA_ARGS__) 113 #define expect_qu_gt(a, b, ...) expect_cmp(unsigned long long, \ 114 a, b, >, <=, "qu", __VA_ARGS__) 115 116 #define expect_jd_eq(a, b, ...) expect_cmp(intmax_t, a, b, ==, \ 117 !=, "jd", __VA_ARGS__) 118 #define expect_jd_ne(a, b, ...) expect_cmp(intmax_t, a, b, !=, \ 119 ==, "jd", __VA_ARGS__) 120 #define expect_jd_lt(a, b, ...) expect_cmp(intmax_t, a, b, <, \ 121 >=, "jd", __VA_ARGS__) 122 #define expect_jd_le(a, b, ...) expect_cmp(intmax_t, a, b, <=, \ 123 >, "jd", __VA_ARGS__) 124 #define expect_jd_ge(a, b, ...) expect_cmp(intmax_t, a, b, >=, \ 125 <, "jd", __VA_ARGS__) 126 #define expect_jd_gt(a, b, ...) expect_cmp(intmax_t, a, b, >, \ 127 <=, "jd", __VA_ARGS__) 128 129 #define expect_ju_eq(a, b, ...) expect_cmp(uintmax_t, a, b, ==, \ 130 !=, "ju", __VA_ARGS__) 131 #define expect_ju_ne(a, b, ...) expect_cmp(uintmax_t, a, b, !=, \ 132 ==, "ju", __VA_ARGS__) 133 #define expect_ju_lt(a, b, ...) expect_cmp(uintmax_t, a, b, <, \ 134 >=, "ju", __VA_ARGS__) 135 #define expect_ju_le(a, b, ...) expect_cmp(uintmax_t, a, b, <=, \ 136 >, "ju", __VA_ARGS__) 137 #define expect_ju_ge(a, b, ...) expect_cmp(uintmax_t, a, b, >=, \ 138 <, "ju", __VA_ARGS__) 139 #define expect_ju_gt(a, b, ...) expect_cmp(uintmax_t, a, b, >, \ 140 <=, "ju", __VA_ARGS__) 141 142 #define expect_zd_eq(a, b, ...) expect_cmp(ssize_t, a, b, ==, \ 143 !=, "zd", __VA_ARGS__) 144 #define expect_zd_ne(a, b, ...) expect_cmp(ssize_t, a, b, !=, \ 145 ==, "zd", __VA_ARGS__) 146 #define expect_zd_lt(a, b, ...) expect_cmp(ssize_t, a, b, <, \ 147 >=, "zd", __VA_ARGS__) 148 #define expect_zd_le(a, b, ...) expect_cmp(ssize_t, a, b, <=, \ 149 >, "zd", __VA_ARGS__) 150 #define expect_zd_ge(a, b, ...) expect_cmp(ssize_t, a, b, >=, \ 151 <, "zd", __VA_ARGS__) 152 #define expect_zd_gt(a, b, ...) expect_cmp(ssize_t, a, b, >, \ 153 <=, "zd", __VA_ARGS__) 154 155 #define expect_zu_eq(a, b, ...) expect_cmp(size_t, a, b, ==, \ 156 !=, "zu", __VA_ARGS__) 157 #define expect_zu_ne(a, b, ...) expect_cmp(size_t, a, b, !=, \ 158 ==, "zu", __VA_ARGS__) 159 #define expect_zu_lt(a, b, ...) expect_cmp(size_t, a, b, <, \ 160 >=, "zu", __VA_ARGS__) 161 #define expect_zu_le(a, b, ...) expect_cmp(size_t, a, b, <=, \ 162 >, "zu", __VA_ARGS__) 163 #define expect_zu_ge(a, b, ...) expect_cmp(size_t, a, b, >=, \ 164 <, "zu", __VA_ARGS__) 165 #define expect_zu_gt(a, b, ...) expect_cmp(size_t, a, b, >, \ 166 <=, "zu", __VA_ARGS__) 167 168 #define expect_d32_eq(a, b, ...) expect_cmp(int32_t, a, b, ==, \ 169 !=, FMTd32, __VA_ARGS__) 170 #define expect_d32_ne(a, b, ...) expect_cmp(int32_t, a, b, !=, \ 171 ==, FMTd32, __VA_ARGS__) 172 #define expect_d32_lt(a, b, ...) expect_cmp(int32_t, a, b, <, \ 173 >=, FMTd32, __VA_ARGS__) 174 #define expect_d32_le(a, b, ...) expect_cmp(int32_t, a, b, <=, \ 175 >, FMTd32, __VA_ARGS__) 176 #define expect_d32_ge(a, b, ...) expect_cmp(int32_t, a, b, >=, \ 177 <, FMTd32, __VA_ARGS__) 178 #define expect_d32_gt(a, b, ...) expect_cmp(int32_t, a, b, >, \ 179 <=, FMTd32, __VA_ARGS__) 180 181 #define expect_u32_eq(a, b, ...) expect_cmp(uint32_t, a, b, ==, \ 182 !=, FMTu32, __VA_ARGS__) 183 #define expect_u32_ne(a, b, ...) expect_cmp(uint32_t, a, b, !=, \ 184 ==, FMTu32, __VA_ARGS__) 185 #define expect_u32_lt(a, b, ...) expect_cmp(uint32_t, a, b, <, \ 186 >=, FMTu32, __VA_ARGS__) 187 #define expect_u32_le(a, b, ...) expect_cmp(uint32_t, a, b, <=, \ 188 >, FMTu32, __VA_ARGS__) 189 #define expect_u32_ge(a, b, ...) expect_cmp(uint32_t, a, b, >=, \ 190 <, FMTu32, __VA_ARGS__) 191 #define expect_u32_gt(a, b, ...) expect_cmp(uint32_t, a, b, >, \ 192 <=, FMTu32, __VA_ARGS__) 193 194 #define expect_d64_eq(a, b, ...) expect_cmp(int64_t, a, b, ==, \ 195 !=, FMTd64, __VA_ARGS__) 196 #define expect_d64_ne(a, b, ...) expect_cmp(int64_t, a, b, !=, \ 197 ==, FMTd64, __VA_ARGS__) 198 #define expect_d64_lt(a, b, ...) expect_cmp(int64_t, a, b, <, \ 199 >=, FMTd64, __VA_ARGS__) 200 #define expect_d64_le(a, b, ...) expect_cmp(int64_t, a, b, <=, \ 201 >, FMTd64, __VA_ARGS__) 202 #define expect_d64_ge(a, b, ...) expect_cmp(int64_t, a, b, >=, \ 203 <, FMTd64, __VA_ARGS__) 204 #define expect_d64_gt(a, b, ...) expect_cmp(int64_t, a, b, >, \ 205 <=, FMTd64, __VA_ARGS__) 206 207 #define expect_u64_eq(a, b, ...) expect_cmp(uint64_t, a, b, ==, \ 208 !=, FMTu64, __VA_ARGS__) 209 #define expect_u64_ne(a, b, ...) expect_cmp(uint64_t, a, b, !=, \ 210 ==, FMTu64, __VA_ARGS__) 211 #define expect_u64_lt(a, b, ...) expect_cmp(uint64_t, a, b, <, \ 212 >=, FMTu64, __VA_ARGS__) 213 #define expect_u64_le(a, b, ...) expect_cmp(uint64_t, a, b, <=, \ 214 >, FMTu64, __VA_ARGS__) 215 #define expect_u64_ge(a, b, ...) expect_cmp(uint64_t, a, b, >=, \ 216 <, FMTu64, __VA_ARGS__) 217 #define expect_u64_gt(a, b, ...) expect_cmp(uint64_t, a, b, >, \ 218 <=, FMTu64, __VA_ARGS__) 219 220 #define verify_b_eq(may_abort, a, b, ...) do { \ 221 bool a_ = (a); \ 222 bool b_ = (b); \ 223 if (!(a_ == b_)) { \ 224 char prefix[ASSERT_BUFSIZE]; \ 225 char message[ASSERT_BUFSIZE]; \ 226 malloc_snprintf(prefix, sizeof(prefix), \ 227 "%s:%s:%d: Failed assertion: " \ 228 "(%s) == (%s) --> %s != %s: ", \ 229 __func__, __FILE__, __LINE__, \ 230 #a, #b, a_ ? "true" : "false", \ 231 b_ ? "true" : "false"); \ 232 malloc_snprintf(message, sizeof(message), __VA_ARGS__); \ 233 if (may_abort) { \ 234 abort(); \ 235 } else { \ 236 p_test_fail(prefix, message); \ 237 } \ 238 } \ 239 } while (0) 240 241 #define verify_b_ne(may_abort, a, b, ...) do { \ 242 bool a_ = (a); \ 243 bool b_ = (b); \ 244 if (!(a_ != b_)) { \ 245 char prefix[ASSERT_BUFSIZE]; \ 246 char message[ASSERT_BUFSIZE]; \ 247 malloc_snprintf(prefix, sizeof(prefix), \ 248 "%s:%s:%d: Failed assertion: " \ 249 "(%s) != (%s) --> %s == %s: ", \ 250 __func__, __FILE__, __LINE__, \ 251 #a, #b, a_ ? "true" : "false", \ 252 b_ ? "true" : "false"); \ 253 malloc_snprintf(message, sizeof(message), __VA_ARGS__); \ 254 if (may_abort) { \ 255 abort(); \ 256 } else { \ 257 p_test_fail(prefix, message); \ 258 } \ 259 } \ 260 } while (0) 261 262 #define expect_b_eq(a, b, ...) verify_b_eq(false, a, b, __VA_ARGS__) 263 #define expect_b_ne(a, b, ...) verify_b_ne(false, a, b, __VA_ARGS__) 264 265 #define expect_true(a, ...) expect_b_eq(a, true, __VA_ARGS__) 266 #define expect_false(a, ...) expect_b_eq(a, false, __VA_ARGS__) 267 268 #define verify_str_eq(may_abort, a, b, ...) do { \ 269 if (strcmp((a), (b))) { \ 270 char prefix[ASSERT_BUFSIZE]; \ 271 char message[ASSERT_BUFSIZE]; \ 272 malloc_snprintf(prefix, sizeof(prefix), \ 273 "%s:%s:%d: Failed assertion: " \ 274 "(%s) same as (%s) --> " \ 275 "\"%s\" differs from \"%s\": ", \ 276 __func__, __FILE__, __LINE__, #a, #b, a, b); \ 277 malloc_snprintf(message, sizeof(message), __VA_ARGS__); \ 278 if (may_abort) { \ 279 abort(); \ 280 } else { \ 281 p_test_fail(prefix, message); \ 282 } \ 283 } \ 284 } while (0) 285 286 #define verify_str_ne(may_abort, a, b, ...) do { \ 287 if (!strcmp((a), (b))) { \ 288 char prefix[ASSERT_BUFSIZE]; \ 289 char message[ASSERT_BUFSIZE]; \ 290 malloc_snprintf(prefix, sizeof(prefix), \ 291 "%s:%s:%d: Failed assertion: " \ 292 "(%s) differs from (%s) --> " \ 293 "\"%s\" same as \"%s\": ", \ 294 __func__, __FILE__, __LINE__, #a, #b, a, b); \ 295 malloc_snprintf(message, sizeof(message), __VA_ARGS__); \ 296 if (may_abort) { \ 297 abort(); \ 298 } else { \ 299 p_test_fail(prefix, message); \ 300 } \ 301 } \ 302 } while (0) 303 304 #define expect_str_eq(a, b, ...) verify_str_eq(false, a, b, __VA_ARGS__) 305 #define expect_str_ne(a, b, ...) verify_str_ne(false, a, b, __VA_ARGS__) 306 307 #define verify_not_reached(may_abort, ...) do { \ 308 char prefix[ASSERT_BUFSIZE]; \ 309 char message[ASSERT_BUFSIZE]; \ 310 malloc_snprintf(prefix, sizeof(prefix), \ 311 "%s:%s:%d: Unreachable code reached: ", \ 312 __func__, __FILE__, __LINE__); \ 313 malloc_snprintf(message, sizeof(message), __VA_ARGS__); \ 314 if (may_abort) { \ 315 abort(); \ 316 } else { \ 317 p_test_fail(prefix, message); \ 318 } \ 319 } while (0) 320 321 #define expect_not_reached(...) verify_not_reached(false, __VA_ARGS__) 322 323 #define assert_cmp(t, a, b, cmp, neg_cmp, pri, ...) verify_cmp(true, \ 324 t, a, b, cmp, neg_cmp, pri, __VA_ARGS__) 325 326 #define assert_ptr_eq(a, b, ...) assert_cmp(void *, a, b, ==, \ 327 !=, "p", __VA_ARGS__) 328 #define assert_ptr_ne(a, b, ...) assert_cmp(void *, a, b, !=, \ 329 ==, "p", __VA_ARGS__) 330 #define assert_ptr_null(a, ...) assert_cmp(void *, a, NULL, ==, \ 331 !=, "p", __VA_ARGS__) 332 #define assert_ptr_not_null(a, ...) assert_cmp(void *, a, NULL, !=, \ 333 ==, "p", __VA_ARGS__) 334 335 #define assert_c_eq(a, b, ...) assert_cmp(char, a, b, ==, !=, "c", __VA_ARGS__) 336 #define assert_c_ne(a, b, ...) assert_cmp(char, a, b, !=, ==, "c", __VA_ARGS__) 337 #define assert_c_lt(a, b, ...) assert_cmp(char, a, b, <, >=, "c", __VA_ARGS__) 338 #define assert_c_le(a, b, ...) assert_cmp(char, a, b, <=, >, "c", __VA_ARGS__) 339 #define assert_c_ge(a, b, ...) assert_cmp(char, a, b, >=, <, "c", __VA_ARGS__) 340 #define assert_c_gt(a, b, ...) assert_cmp(char, a, b, >, <=, "c", __VA_ARGS__) 341 342 #define assert_x_eq(a, b, ...) assert_cmp(int, a, b, ==, !=, "#x", __VA_ARGS__) 343 #define assert_x_ne(a, b, ...) assert_cmp(int, a, b, !=, ==, "#x", __VA_ARGS__) 344 #define assert_x_lt(a, b, ...) assert_cmp(int, a, b, <, >=, "#x", __VA_ARGS__) 345 #define assert_x_le(a, b, ...) assert_cmp(int, a, b, <=, >, "#x", __VA_ARGS__) 346 #define assert_x_ge(a, b, ...) assert_cmp(int, a, b, >=, <, "#x", __VA_ARGS__) 347 #define assert_x_gt(a, b, ...) assert_cmp(int, a, b, >, <=, "#x", __VA_ARGS__) 348 349 #define assert_d_eq(a, b, ...) assert_cmp(int, a, b, ==, !=, "d", __VA_ARGS__) 350 #define assert_d_ne(a, b, ...) assert_cmp(int, a, b, !=, ==, "d", __VA_ARGS__) 351 #define assert_d_lt(a, b, ...) assert_cmp(int, a, b, <, >=, "d", __VA_ARGS__) 352 #define assert_d_le(a, b, ...) assert_cmp(int, a, b, <=, >, "d", __VA_ARGS__) 353 #define assert_d_ge(a, b, ...) assert_cmp(int, a, b, >=, <, "d", __VA_ARGS__) 354 #define assert_d_gt(a, b, ...) assert_cmp(int, a, b, >, <=, "d", __VA_ARGS__) 355 356 #define assert_u_eq(a, b, ...) assert_cmp(int, a, b, ==, !=, "u", __VA_ARGS__) 357 #define assert_u_ne(a, b, ...) assert_cmp(int, a, b, !=, ==, "u", __VA_ARGS__) 358 #define assert_u_lt(a, b, ...) assert_cmp(int, a, b, <, >=, "u", __VA_ARGS__) 359 #define assert_u_le(a, b, ...) assert_cmp(int, a, b, <=, >, "u", __VA_ARGS__) 360 #define assert_u_ge(a, b, ...) assert_cmp(int, a, b, >=, <, "u", __VA_ARGS__) 361 #define assert_u_gt(a, b, ...) assert_cmp(int, a, b, >, <=, "u", __VA_ARGS__) 362 363 #define assert_ld_eq(a, b, ...) assert_cmp(long, a, b, ==, \ 364 !=, "ld", __VA_ARGS__) 365 #define assert_ld_ne(a, b, ...) assert_cmp(long, a, b, !=, \ 366 ==, "ld", __VA_ARGS__) 367 #define assert_ld_lt(a, b, ...) assert_cmp(long, a, b, <, \ 368 >=, "ld", __VA_ARGS__) 369 #define assert_ld_le(a, b, ...) assert_cmp(long, a, b, <=, \ 370 >, "ld", __VA_ARGS__) 371 #define assert_ld_ge(a, b, ...) assert_cmp(long, a, b, >=, \ 372 <, "ld", __VA_ARGS__) 373 #define assert_ld_gt(a, b, ...) assert_cmp(long, a, b, >, \ 374 <=, "ld", __VA_ARGS__) 375 376 #define assert_lu_eq(a, b, ...) assert_cmp(unsigned long, \ 377 a, b, ==, !=, "lu", __VA_ARGS__) 378 #define assert_lu_ne(a, b, ...) assert_cmp(unsigned long, \ 379 a, b, !=, ==, "lu", __VA_ARGS__) 380 #define assert_lu_lt(a, b, ...) assert_cmp(unsigned long, \ 381 a, b, <, >=, "lu", __VA_ARGS__) 382 #define assert_lu_le(a, b, ...) assert_cmp(unsigned long, \ 383 a, b, <=, >, "lu", __VA_ARGS__) 384 #define assert_lu_ge(a, b, ...) assert_cmp(unsigned long, \ 385 a, b, >=, <, "lu", __VA_ARGS__) 386 #define assert_lu_gt(a, b, ...) assert_cmp(unsigned long, \ 387 a, b, >, <=, "lu", __VA_ARGS__) 388 389 #define assert_qd_eq(a, b, ...) assert_cmp(long long, a, b, ==, \ 390 !=, "qd", __VA_ARGS__) 391 #define assert_qd_ne(a, b, ...) assert_cmp(long long, a, b, !=, \ 392 ==, "qd", __VA_ARGS__) 393 #define assert_qd_lt(a, b, ...) assert_cmp(long long, a, b, <, \ 394 >=, "qd", __VA_ARGS__) 395 #define assert_qd_le(a, b, ...) assert_cmp(long long, a, b, <=, \ 396 >, "qd", __VA_ARGS__) 397 #define assert_qd_ge(a, b, ...) assert_cmp(long long, a, b, >=, \ 398 <, "qd", __VA_ARGS__) 399 #define assert_qd_gt(a, b, ...) assert_cmp(long long, a, b, >, \ 400 <=, "qd", __VA_ARGS__) 401 402 #define assert_qu_eq(a, b, ...) assert_cmp(unsigned long long, \ 403 a, b, ==, !=, "qu", __VA_ARGS__) 404 #define assert_qu_ne(a, b, ...) assert_cmp(unsigned long long, \ 405 a, b, !=, ==, "qu", __VA_ARGS__) 406 #define assert_qu_lt(a, b, ...) assert_cmp(unsigned long long, \ 407 a, b, <, >=, "qu", __VA_ARGS__) 408 #define assert_qu_le(a, b, ...) assert_cmp(unsigned long long, \ 409 a, b, <=, >, "qu", __VA_ARGS__) 410 #define assert_qu_ge(a, b, ...) assert_cmp(unsigned long long, \ 411 a, b, >=, <, "qu", __VA_ARGS__) 412 #define assert_qu_gt(a, b, ...) assert_cmp(unsigned long long, \ 413 a, b, >, <=, "qu", __VA_ARGS__) 414 415 #define assert_jd_eq(a, b, ...) assert_cmp(intmax_t, a, b, ==, \ 416 !=, "jd", __VA_ARGS__) 417 #define assert_jd_ne(a, b, ...) assert_cmp(intmax_t, a, b, !=, \ 418 ==, "jd", __VA_ARGS__) 419 #define assert_jd_lt(a, b, ...) assert_cmp(intmax_t, a, b, <, \ 420 >=, "jd", __VA_ARGS__) 421 #define assert_jd_le(a, b, ...) assert_cmp(intmax_t, a, b, <=, \ 422 >, "jd", __VA_ARGS__) 423 #define assert_jd_ge(a, b, ...) assert_cmp(intmax_t, a, b, >=, \ 424 <, "jd", __VA_ARGS__) 425 #define assert_jd_gt(a, b, ...) assert_cmp(intmax_t, a, b, >, \ 426 <=, "jd", __VA_ARGS__) 427 428 #define assert_ju_eq(a, b, ...) assert_cmp(uintmax_t, a, b, ==, \ 429 !=, "ju", __VA_ARGS__) 430 #define assert_ju_ne(a, b, ...) assert_cmp(uintmax_t, a, b, !=, \ 431 ==, "ju", __VA_ARGS__) 432 #define assert_ju_lt(a, b, ...) assert_cmp(uintmax_t, a, b, <, \ 433 >=, "ju", __VA_ARGS__) 434 #define assert_ju_le(a, b, ...) assert_cmp(uintmax_t, a, b, <=, \ 435 >, "ju", __VA_ARGS__) 436 #define assert_ju_ge(a, b, ...) assert_cmp(uintmax_t, a, b, >=, \ 437 <, "ju", __VA_ARGS__) 438 #define assert_ju_gt(a, b, ...) assert_cmp(uintmax_t, a, b, >, \ 439 <=, "ju", __VA_ARGS__) 440 441 #define assert_zd_eq(a, b, ...) assert_cmp(ssize_t, a, b, ==, \ 442 !=, "zd", __VA_ARGS__) 443 #define assert_zd_ne(a, b, ...) assert_cmp(ssize_t, a, b, !=, \ 444 ==, "zd", __VA_ARGS__) 445 #define assert_zd_lt(a, b, ...) assert_cmp(ssize_t, a, b, <, \ 446 >=, "zd", __VA_ARGS__) 447 #define assert_zd_le(a, b, ...) assert_cmp(ssize_t, a, b, <=, \ 448 >, "zd", __VA_ARGS__) 449 #define assert_zd_ge(a, b, ...) assert_cmp(ssize_t, a, b, >=, \ 450 <, "zd", __VA_ARGS__) 451 #define assert_zd_gt(a, b, ...) assert_cmp(ssize_t, a, b, >, \ 452 <=, "zd", __VA_ARGS__) 453 454 #define assert_zu_eq(a, b, ...) assert_cmp(size_t, a, b, ==, \ 455 !=, "zu", __VA_ARGS__) 456 #define assert_zu_ne(a, b, ...) assert_cmp(size_t, a, b, !=, \ 457 ==, "zu", __VA_ARGS__) 458 #define assert_zu_lt(a, b, ...) assert_cmp(size_t, a, b, <, \ 459 >=, "zu", __VA_ARGS__) 460 #define assert_zu_le(a, b, ...) assert_cmp(size_t, a, b, <=, \ 461 >, "zu", __VA_ARGS__) 462 #define assert_zu_ge(a, b, ...) assert_cmp(size_t, a, b, >=, \ 463 <, "zu", __VA_ARGS__) 464 #define assert_zu_gt(a, b, ...) assert_cmp(size_t, a, b, >, \ 465 <=, "zu", __VA_ARGS__) 466 467 #define assert_d32_eq(a, b, ...) assert_cmp(int32_t, a, b, ==, \ 468 !=, FMTd32, __VA_ARGS__) 469 #define assert_d32_ne(a, b, ...) assert_cmp(int32_t, a, b, !=, \ 470 ==, FMTd32, __VA_ARGS__) 471 #define assert_d32_lt(a, b, ...) assert_cmp(int32_t, a, b, <, \ 472 >=, FMTd32, __VA_ARGS__) 473 #define assert_d32_le(a, b, ...) assert_cmp(int32_t, a, b, <=, \ 474 >, FMTd32, __VA_ARGS__) 475 #define assert_d32_ge(a, b, ...) assert_cmp(int32_t, a, b, >=, \ 476 <, FMTd32, __VA_ARGS__) 477 #define assert_d32_gt(a, b, ...) assert_cmp(int32_t, a, b, >, \ 478 <=, FMTd32, __VA_ARGS__) 479 480 #define assert_u32_eq(a, b, ...) assert_cmp(uint32_t, a, b, ==, \ 481 !=, FMTu32, __VA_ARGS__) 482 #define assert_u32_ne(a, b, ...) assert_cmp(uint32_t, a, b, !=, \ 483 ==, FMTu32, __VA_ARGS__) 484 #define assert_u32_lt(a, b, ...) assert_cmp(uint32_t, a, b, <, \ 485 >=, FMTu32, __VA_ARGS__) 486 #define assert_u32_le(a, b, ...) assert_cmp(uint32_t, a, b, <=, \ 487 >, FMTu32, __VA_ARGS__) 488 #define assert_u32_ge(a, b, ...) assert_cmp(uint32_t, a, b, >=, \ 489 <, FMTu32, __VA_ARGS__) 490 #define assert_u32_gt(a, b, ...) assert_cmp(uint32_t, a, b, >, \ 491 <=, FMTu32, __VA_ARGS__) 492 493 #define assert_d64_eq(a, b, ...) assert_cmp(int64_t, a, b, ==, \ 494 !=, FMTd64, __VA_ARGS__) 495 #define assert_d64_ne(a, b, ...) assert_cmp(int64_t, a, b, !=, \ 496 ==, FMTd64, __VA_ARGS__) 497 #define assert_d64_lt(a, b, ...) assert_cmp(int64_t, a, b, <, \ 498 >=, FMTd64, __VA_ARGS__) 499 #define assert_d64_le(a, b, ...) assert_cmp(int64_t, a, b, <=, \ 500 >, FMTd64, __VA_ARGS__) 501 #define assert_d64_ge(a, b, ...) assert_cmp(int64_t, a, b, >=, \ 502 <, FMTd64, __VA_ARGS__) 503 #define assert_d64_gt(a, b, ...) assert_cmp(int64_t, a, b, >, \ 504 <=, FMTd64, __VA_ARGS__) 505 506 #define assert_u64_eq(a, b, ...) assert_cmp(uint64_t, a, b, ==, \ 507 !=, FMTu64, __VA_ARGS__) 508 #define assert_u64_ne(a, b, ...) assert_cmp(uint64_t, a, b, !=, \ 509 ==, FMTu64, __VA_ARGS__) 510 #define assert_u64_lt(a, b, ...) assert_cmp(uint64_t, a, b, <, \ 511 >=, FMTu64, __VA_ARGS__) 512 #define assert_u64_le(a, b, ...) assert_cmp(uint64_t, a, b, <=, \ 513 >, FMTu64, __VA_ARGS__) 514 #define assert_u64_ge(a, b, ...) assert_cmp(uint64_t, a, b, >=, \ 515 <, FMTu64, __VA_ARGS__) 516 #define assert_u64_gt(a, b, ...) assert_cmp(uint64_t, a, b, >, \ 517 <=, FMTu64, __VA_ARGS__) 518 519 #define assert_b_eq(a, b, ...) verify_b_eq(true, a, b, __VA_ARGS__) 520 #define assert_b_ne(a, b, ...) verify_b_ne(true, a, b, __VA_ARGS__) 521 522 #define assert_true(a, ...) assert_b_eq(a, true, __VA_ARGS__) 523 #define assert_false(a, ...) assert_b_eq(a, false, __VA_ARGS__) 524 525 #define assert_str_eq(a, b, ...) verify_str_eq(true, a, b, __VA_ARGS__) 526 #define assert_str_ne(a, b, ...) verify_str_ne(true, a, b, __VA_ARGS__) 527 528 #define assert_not_reached(...) verify_not_reached(true, __VA_ARGS__) 529 530 /* 531 * If this enum changes, corresponding changes in test/test.sh.in are also 532 * necessary. 533 */ 534 typedef enum { 535 test_status_pass = 0, 536 test_status_skip = 1, 537 test_status_fail = 2, 538 539 test_status_count = 3 540 } test_status_t; 541 542 typedef void (test_t)(void); 543 544 #define TEST_BEGIN(f) \ 545 static void \ 546 f(void) { \ 547 p_test_init(#f); 548 549 #define TEST_END \ 550 goto label_test_end; \ 551 label_test_end: \ 552 p_test_fini(); \ 553 } 554 555 #define test(...) \ 556 p_test(__VA_ARGS__, NULL) 557 558 #define test_no_reentrancy(...) \ 559 p_test_no_reentrancy(__VA_ARGS__, NULL) 560 561 #define test_no_malloc_init(...) \ 562 p_test_no_malloc_init(__VA_ARGS__, NULL) 563 564 #define test_skip_if(e) do { \ 565 if (e) { \ 566 test_skip("%s:%s:%d: Test skipped: (%s)", \ 567 __func__, __FILE__, __LINE__, #e); \ 568 goto label_test_end; \ 569 } \ 570 } while (0) 571 572 bool test_is_reentrant(); 573 574 void test_skip(const char *format, ...) JEMALLOC_FORMAT_PRINTF(1, 2); 575 void test_fail(const char *format, ...) JEMALLOC_FORMAT_PRINTF(1, 2); 576 577 /* For private use by macros. */ 578 test_status_t p_test(test_t *t, ...); 579 test_status_t p_test_no_reentrancy(test_t *t, ...); 580 test_status_t p_test_no_malloc_init(test_t *t, ...); 581 void p_test_init(const char *name); 582 void p_test_fini(void); 583 void p_test_fail(const char *prefix, const char *message); 584