Change assert_* to expect_* in tests

```
grep -Irl assert_ test/ | xargs sed -i \
    's/witness_assert/witness_do_not_replace/g';
grep -Irl assert_ test/ | xargs sed -i \
    's/malloc_mutex_assert_owner/malloc_mutex_do_not_replace_owner/g';

grep -Ir assert_ test/ | grep -o "[_a-zA-Z]*assert_[_a-zA-Z]*" | \
    grep -v "^assert_"; # confirm no output
grep -Irl assert_ test/ | xargs sed -i 's/assert_/expect_/g';

grep -Irl witness_do_not_replace test/ | xargs sed -i \
    's/witness_do_not_replace/witness_assert/g';
grep -Irl malloc_mutex_do_not_replace_owner test/ | xargs sed -i \
    's/malloc_mutex_do_not_replace_owner/malloc_mutex_assert_owner/g';
```
This commit is contained in:
Yinan Zhang
2020-02-18 14:39:06 -08:00
parent 162c2bcf31
commit 21dfa4300d
85 changed files with 1854 additions and 1854 deletions

View File

@@ -8,14 +8,14 @@
/* Invariant before and after every test (when config_prof is on) */
static void confirm_prof_setup(tsd_t *tsd) {
/* Options */
assert_true(opt_prof, "opt_prof not on");
assert_true(opt_prof_active, "opt_prof_active not on");
assert_zd_eq(opt_prof_recent_alloc_max, OPT_ALLOC_MAX,
expect_true(opt_prof, "opt_prof not on");
expect_true(opt_prof_active, "opt_prof_active not on");
expect_zd_eq(opt_prof_recent_alloc_max, OPT_ALLOC_MAX,
"opt_prof_recent_alloc_max not set correctly");
/* Dynamics */
assert_true(prof_active, "prof_active not on");
assert_zd_eq(prof_recent_alloc_max_ctl_read(tsd), OPT_ALLOC_MAX,
expect_true(prof_active, "prof_active not on");
expect_zd_eq(prof_recent_alloc_max_ctl_read(tsd), OPT_ALLOC_MAX,
"prof_recent_alloc_max not set correctly");
}
@@ -35,11 +35,11 @@ TEST_BEGIN(test_prof_recent_off) {
size_t len = len_ref;
#define ASSERT_SHOULD_FAIL(opt, a, b, c, d) do { \
assert_d_eq(mallctl("experimental.prof_recent." opt, a, b, c, \
expect_d_eq(mallctl("experimental.prof_recent." opt, a, b, c, \
d), ENOENT, "Should return ENOENT when config_prof is off");\
assert_zd_eq(past, past_ref, "output was touched"); \
assert_zu_eq(len, len_ref, "output length was touched"); \
assert_zd_eq(future, future_ref, "input was touched"); \
expect_zd_eq(past, past_ref, "output was touched"); \
expect_zu_eq(len, len_ref, "output length was touched"); \
expect_zd_eq(future, future_ref, "input was touched"); \
} while (0)
ASSERT_SHOULD_FAIL("alloc_max", NULL, NULL, NULL, 0);
@@ -61,35 +61,35 @@ TEST_BEGIN(test_prof_recent_on) {
confirm_prof_setup(tsd);
assert_d_eq(mallctl("experimental.prof_recent.alloc_max",
expect_d_eq(mallctl("experimental.prof_recent.alloc_max",
NULL, NULL, NULL, 0), 0, "no-op mallctl should be allowed");
confirm_prof_setup(tsd);
assert_d_eq(mallctl("experimental.prof_recent.alloc_max",
expect_d_eq(mallctl("experimental.prof_recent.alloc_max",
&past, &len, NULL, 0), 0, "Read error");
assert_zd_eq(past, OPT_ALLOC_MAX, "Wrong read result");
expect_zd_eq(past, OPT_ALLOC_MAX, "Wrong read result");
future = OPT_ALLOC_MAX + 1;
assert_d_eq(mallctl("experimental.prof_recent.alloc_max",
expect_d_eq(mallctl("experimental.prof_recent.alloc_max",
NULL, NULL, &future, len), 0, "Write error");
future = -1;
assert_d_eq(mallctl("experimental.prof_recent.alloc_max",
expect_d_eq(mallctl("experimental.prof_recent.alloc_max",
&past, &len, &future, len), 0, "Read/write error");
assert_zd_eq(past, OPT_ALLOC_MAX + 1, "Wrong read result");
expect_zd_eq(past, OPT_ALLOC_MAX + 1, "Wrong read result");
future = -2;
assert_d_eq(mallctl("experimental.prof_recent.alloc_max",
expect_d_eq(mallctl("experimental.prof_recent.alloc_max",
&past, &len, &future, len), EINVAL,
"Invalid write should return EINVAL");
assert_zd_eq(past, OPT_ALLOC_MAX + 1,
expect_zd_eq(past, OPT_ALLOC_MAX + 1,
"Output should not be touched given invalid write");
future = OPT_ALLOC_MAX;
assert_d_eq(mallctl("experimental.prof_recent.alloc_max",
expect_d_eq(mallctl("experimental.prof_recent.alloc_max",
&past, &len, &future, len), 0, "Read/write error");
assert_zd_eq(past, -1, "Wrong read result");
expect_zd_eq(past, -1, "Wrong read result");
future = OPT_ALLOC_MAX + 2;
assert_d_eq(mallctl("experimental.prof_recent.alloc_max",
expect_d_eq(mallctl("experimental.prof_recent.alloc_max",
&past, &len, &future, len * 2), EINVAL,
"Invalid write should return EINVAL");
assert_zd_eq(past, -1,
expect_zd_eq(past, -1,
"Output should not be touched given invalid write");
confirm_prof_setup(tsd);
@@ -100,44 +100,44 @@ TEST_END
#define NTH_REQ_SIZE(n) ((n) * 97 + 101)
static void confirm_malloc(tsd_t *tsd, void *p) {
assert_ptr_not_null(p, "malloc failed unexpectedly");
expect_ptr_not_null(p, "malloc failed unexpectedly");
edata_t *e = emap_edata_lookup(TSDN_NULL, &emap_global, p);
assert_ptr_not_null(e, "NULL edata for living pointer");
expect_ptr_not_null(e, "NULL edata for living pointer");
malloc_mutex_lock(tsd_tsdn(tsd), &prof_recent_alloc_mtx);
prof_recent_t *n = edata_prof_recent_alloc_get(tsd, e);
assert_ptr_not_null(n, "Record in edata should not be NULL");
assert_ptr_not_null(n->alloc_tctx,
expect_ptr_not_null(n, "Record in edata should not be NULL");
expect_ptr_not_null(n->alloc_tctx,
"alloc_tctx in record should not be NULL");
assert_ptr_eq(e, n->alloc_edata,
expect_ptr_eq(e, n->alloc_edata,
"edata pointer in record is not correct");
assert_ptr_null(n->dalloc_tctx, "dalloc_tctx in record should be NULL");
expect_ptr_null(n->dalloc_tctx, "dalloc_tctx in record should be NULL");
malloc_mutex_unlock(tsd_tsdn(tsd), &prof_recent_alloc_mtx);
}
static void confirm_record_size(tsd_t *tsd, prof_recent_t *n, unsigned kth) {
malloc_mutex_assert_owner(tsd_tsdn(tsd), &prof_recent_alloc_mtx);
assert_zu_eq(n->size, NTH_REQ_SIZE(kth),
expect_zu_eq(n->size, NTH_REQ_SIZE(kth),
"Recorded allocation size is wrong");
}
static void confirm_record_living(tsd_t *tsd, prof_recent_t *n) {
malloc_mutex_assert_owner(tsd_tsdn(tsd), &prof_recent_alloc_mtx);
assert_ptr_not_null(n->alloc_tctx,
expect_ptr_not_null(n->alloc_tctx,
"alloc_tctx in record should not be NULL");
assert_ptr_not_null(n->alloc_edata,
expect_ptr_not_null(n->alloc_edata,
"Recorded edata should not be NULL for living pointer");
assert_ptr_eq(n, edata_prof_recent_alloc_get(tsd, n->alloc_edata),
expect_ptr_eq(n, edata_prof_recent_alloc_get(tsd, n->alloc_edata),
"Record in edata is not correct");
assert_ptr_null(n->dalloc_tctx, "dalloc_tctx in record should be NULL");
expect_ptr_null(n->dalloc_tctx, "dalloc_tctx in record should be NULL");
}
static void confirm_record_released(tsd_t *tsd, prof_recent_t *n) {
malloc_mutex_assert_owner(tsd_tsdn(tsd), &prof_recent_alloc_mtx);
assert_ptr_not_null(n->alloc_tctx,
expect_ptr_not_null(n->alloc_tctx,
"alloc_tctx in record should not be NULL");
assert_ptr_null(n->alloc_edata,
expect_ptr_null(n->alloc_edata,
"Recorded edata should be NULL for released pointer");
assert_ptr_not_null(n->dalloc_tctx,
expect_ptr_not_null(n->dalloc_tctx,
"dalloc_tctx in record should not be NULL for released pointer");
}
@@ -167,7 +167,7 @@ TEST_BEGIN(test_prof_recent_alloc) {
if (i < OPT_ALLOC_MAX - 1) {
malloc_mutex_lock(tsd_tsdn(tsd),
&prof_recent_alloc_mtx);
assert_ptr_ne(prof_recent_alloc_begin(tsd),
expect_ptr_ne(prof_recent_alloc_begin(tsd),
prof_recent_alloc_end(tsd),
"Empty recent allocation");
malloc_mutex_unlock(tsd_tsdn(tsd),
@@ -194,7 +194,7 @@ TEST_BEGIN(test_prof_recent_alloc) {
}
}
malloc_mutex_unlock(tsd_tsdn(tsd), &prof_recent_alloc_mtx);
assert_u_eq(c, OPT_ALLOC_MAX,
expect_u_eq(c, OPT_ALLOC_MAX,
"Incorrect total number of allocations");
free(p);
}
@@ -202,7 +202,7 @@ TEST_BEGIN(test_prof_recent_alloc) {
confirm_prof_setup(tsd);
b = false;
assert_d_eq(mallctl("prof.active", NULL, NULL, &b, sizeof(bool)), 0,
expect_d_eq(mallctl("prof.active", NULL, NULL, &b, sizeof(bool)), 0,
"mallctl for turning off prof_active failed");
/*
@@ -212,7 +212,7 @@ TEST_BEGIN(test_prof_recent_alloc) {
for (; i < 3 * OPT_ALLOC_MAX; ++i) {
req_size = NTH_REQ_SIZE(i);
p = malloc(req_size);
assert_ptr_not_null(p, "malloc failed unexpectedly");
expect_ptr_not_null(p, "malloc failed unexpectedly");
c = 0;
malloc_mutex_lock(tsd_tsdn(tsd), &prof_recent_alloc_mtx);
for (n = prof_recent_alloc_begin(tsd);
@@ -223,13 +223,13 @@ TEST_BEGIN(test_prof_recent_alloc) {
++c;
}
malloc_mutex_unlock(tsd_tsdn(tsd), &prof_recent_alloc_mtx);
assert_u_eq(c, OPT_ALLOC_MAX,
expect_u_eq(c, OPT_ALLOC_MAX,
"Incorrect total number of allocations");
free(p);
}
b = true;
assert_d_eq(mallctl("prof.active", NULL, NULL, &b, sizeof(bool)), 0,
expect_d_eq(mallctl("prof.active", NULL, NULL, &b, sizeof(bool)), 0,
"mallctl for turning on prof_active failed");
confirm_prof_setup(tsd);
@@ -267,14 +267,14 @@ TEST_BEGIN(test_prof_recent_alloc) {
}
}
malloc_mutex_unlock(tsd_tsdn(tsd), &prof_recent_alloc_mtx);
assert_u_eq(c, OPT_ALLOC_MAX,
expect_u_eq(c, OPT_ALLOC_MAX,
"Incorrect total number of allocations");
free(p);
}
/* Increasing the limit shouldn't alter the list of records. */
future = OPT_ALLOC_MAX + 1;
assert_d_eq(mallctl("experimental.prof_recent.alloc_max",
expect_d_eq(mallctl("experimental.prof_recent.alloc_max",
NULL, NULL, &future, sizeof(ssize_t)), 0, "Write error");
c = 0;
malloc_mutex_lock(tsd_tsdn(tsd), &prof_recent_alloc_mtx);
@@ -286,7 +286,7 @@ TEST_BEGIN(test_prof_recent_alloc) {
++c;
}
malloc_mutex_unlock(tsd_tsdn(tsd), &prof_recent_alloc_mtx);
assert_u_eq(c, OPT_ALLOC_MAX,
expect_u_eq(c, OPT_ALLOC_MAX,
"Incorrect total number of allocations");
/*
@@ -294,7 +294,7 @@ TEST_BEGIN(test_prof_recent_alloc) {
* the new limit is still no less than the length of the list.
*/
future = OPT_ALLOC_MAX;
assert_d_eq(mallctl("experimental.prof_recent.alloc_max",
expect_d_eq(mallctl("experimental.prof_recent.alloc_max",
NULL, NULL, &future, sizeof(ssize_t)), 0, "Write error");
c = 0;
malloc_mutex_lock(tsd_tsdn(tsd), &prof_recent_alloc_mtx);
@@ -306,7 +306,7 @@ TEST_BEGIN(test_prof_recent_alloc) {
++c;
}
malloc_mutex_unlock(tsd_tsdn(tsd), &prof_recent_alloc_mtx);
assert_u_eq(c, OPT_ALLOC_MAX,
expect_u_eq(c, OPT_ALLOC_MAX,
"Incorrect total number of allocations");
/*
@@ -314,7 +314,7 @@ TEST_BEGIN(test_prof_recent_alloc) {
* limit is less than the length of the list.
*/
future = OPT_ALLOC_MAX - 1;
assert_d_eq(mallctl("experimental.prof_recent.alloc_max",
expect_d_eq(mallctl("experimental.prof_recent.alloc_max",
NULL, NULL, &future, sizeof(ssize_t)), 0, "Write error");
c = 0;
malloc_mutex_lock(tsd_tsdn(tsd), &prof_recent_alloc_mtx);
@@ -326,12 +326,12 @@ TEST_BEGIN(test_prof_recent_alloc) {
confirm_record_released(tsd, n);
}
malloc_mutex_unlock(tsd_tsdn(tsd), &prof_recent_alloc_mtx);
assert_u_eq(c, OPT_ALLOC_MAX - 1,
expect_u_eq(c, OPT_ALLOC_MAX - 1,
"Incorrect total number of allocations");
/* Setting to unlimited shouldn't alter the list of records. */
future = -1;
assert_d_eq(mallctl("experimental.prof_recent.alloc_max",
expect_d_eq(mallctl("experimental.prof_recent.alloc_max",
NULL, NULL, &future, sizeof(ssize_t)), 0, "Write error");
c = 0;
malloc_mutex_lock(tsd_tsdn(tsd), &prof_recent_alloc_mtx);
@@ -343,12 +343,12 @@ TEST_BEGIN(test_prof_recent_alloc) {
confirm_record_released(tsd, n);
}
malloc_mutex_unlock(tsd_tsdn(tsd), &prof_recent_alloc_mtx);
assert_u_eq(c, OPT_ALLOC_MAX - 1,
expect_u_eq(c, OPT_ALLOC_MAX - 1,
"Incorrect total number of allocations");
/* Downshift to only one record. */
future = 1;
assert_d_eq(mallctl("experimental.prof_recent.alloc_max",
expect_d_eq(mallctl("experimental.prof_recent.alloc_max",
NULL, NULL, &future, sizeof(ssize_t)), 0, "Write error");
malloc_mutex_lock(tsd_tsdn(tsd), &prof_recent_alloc_mtx);
n = prof_recent_alloc_begin(tsd);
@@ -361,7 +361,7 @@ TEST_BEGIN(test_prof_recent_alloc) {
/* Completely turn off. */
future = 0;
assert_d_eq(mallctl("experimental.prof_recent.alloc_max",
expect_d_eq(mallctl("experimental.prof_recent.alloc_max",
NULL, NULL, &future, sizeof(ssize_t)), 0, "Write error");
malloc_mutex_lock(tsd_tsdn(tsd), &prof_recent_alloc_mtx);
assert(prof_recent_alloc_begin(tsd) == prof_recent_alloc_end(tsd));
@@ -369,7 +369,7 @@ TEST_BEGIN(test_prof_recent_alloc) {
/* Restore the settings. */
future = OPT_ALLOC_MAX;
assert_d_eq(mallctl("experimental.prof_recent.alloc_max",
expect_d_eq(mallctl("experimental.prof_recent.alloc_max",
NULL, NULL, &future, sizeof(ssize_t)), 0, "Write error");
malloc_mutex_lock(tsd_tsdn(tsd), &prof_recent_alloc_mtx);
assert(prof_recent_alloc_begin(tsd) == prof_recent_alloc_end(tsd));
@@ -395,7 +395,7 @@ static void test_dump_write_cb(void *not_used, const char *str) {
static void call_dump() {
static void *in[2] = {test_dump_write_cb, NULL};
dump_out_len = 0;
assert_d_eq(mallctl("experimental.prof_recent.alloc_dump",
expect_d_eq(mallctl("experimental.prof_recent.alloc_dump",
NULL, NULL, in, sizeof(in)), 0, "Dump mallctl raised error");
}
@@ -418,9 +418,9 @@ static void confirm_record(const char *template,
* "{\"recent_alloc_max\":XYZ,\"recent_alloc\":[...]}".
* Using "- 2" serves to cut right before the ending "]}".
*/
assert_d_eq(memcmp(dump_out, template, strlen(template) - 2), 0,
expect_d_eq(memcmp(dump_out, template, strlen(template) - 2), 0,
DUMP_ERROR);
assert_d_eq(memcmp(dump_out + strlen(dump_out) - 2,
expect_d_eq(memcmp(dump_out + strlen(dump_out) - 2,
template + strlen(template) - 2, 2), 0, DUMP_ERROR);
const char *start = dump_out + strlen(template) - 2;
@@ -429,14 +429,14 @@ static void confirm_record(const char *template,
for (record = records; record < records + n_records; ++record) {
#define ASSERT_CHAR(c) do { \
assert_true(start < end, DUMP_ERROR); \
assert_c_eq(*start++, c, DUMP_ERROR); \
expect_true(start < end, DUMP_ERROR); \
expect_c_eq(*start++, c, DUMP_ERROR); \
} while (0)
#define ASSERT_STR(s) do { \
const size_t len = strlen(s); \
assert_true(start + len <= end, DUMP_ERROR); \
assert_d_eq(memcmp(start, s, len), 0, DUMP_ERROR); \
expect_true(start + len <= end, DUMP_ERROR); \
expect_d_eq(memcmp(start, s, len), 0, DUMP_ERROR); \
start += len; \
} while (0)
@@ -512,8 +512,8 @@ static void confirm_record(const char *template,
#undef ASSERT_CHAR
}
assert_ptr_eq(record, records + n_records, DUMP_ERROR);
assert_ptr_eq(start, end, DUMP_ERROR);
expect_ptr_eq(record, records + n_records, DUMP_ERROR);
expect_ptr_eq(start, end, DUMP_ERROR);
}
TEST_BEGIN(test_prof_recent_alloc_dump) {
@@ -527,18 +527,18 @@ TEST_BEGIN(test_prof_recent_alloc_dump) {
confirm_record_t records[2];
future = 0;
assert_d_eq(mallctl("experimental.prof_recent.alloc_max",
expect_d_eq(mallctl("experimental.prof_recent.alloc_max",
NULL, NULL, &future, sizeof(ssize_t)), 0, "Write error");
call_dump();
assert_str_eq(dump_out, "{\"recent_alloc_max\":0,\"recent_alloc\":[]}",
expect_str_eq(dump_out, "{\"recent_alloc_max\":0,\"recent_alloc\":[]}",
DUMP_ERROR);
future = 2;
assert_d_eq(mallctl("experimental.prof_recent.alloc_max",
expect_d_eq(mallctl("experimental.prof_recent.alloc_max",
NULL, NULL, &future, sizeof(ssize_t)), 0, "Write error");
call_dump();
const char *template = "{\"recent_alloc_max\":2,\"recent_alloc\":[]}";
assert_str_eq(dump_out, template, DUMP_ERROR);
expect_str_eq(dump_out, template, DUMP_ERROR);
p = malloc(7);
call_dump();
@@ -563,7 +563,7 @@ TEST_BEGIN(test_prof_recent_alloc_dump) {
confirm_record(template, records, 2);
future = OPT_ALLOC_MAX;
assert_d_eq(mallctl("experimental.prof_recent.alloc_max",
expect_d_eq(mallctl("experimental.prof_recent.alloc_max",
NULL, NULL, &future, sizeof(ssize_t)), 0, "Write error");
confirm_prof_setup(tsd);
}
@@ -632,7 +632,7 @@ static void *f_thread(void *arg) {
last_max =
prof_recent_alloc_max_ctl_write(tsd, test_max / 2);
}
assert_zd_ge(last_max, -1, "Illegal last-N max");
expect_zd_ge(last_max, -1, "Illegal last-N max");
}
while (data_p->count > 0) {
@@ -660,7 +660,7 @@ TEST_BEGIN(test_prof_recent_stress) {
}
test_max = STRESS_ALLOC_MAX;
assert_d_eq(mallctl("experimental.prof_recent.alloc_max",
expect_d_eq(mallctl("experimental.prof_recent.alloc_max",
NULL, NULL, &test_max, sizeof(ssize_t)), 0, "Write error");
for (size_t i = 0; i < N_THREADS; i++) {
thd_data_t *data_p = thd_data + i;
@@ -673,7 +673,7 @@ TEST_BEGIN(test_prof_recent_stress) {
}
test_max = OPT_ALLOC_MAX;
assert_d_eq(mallctl("experimental.prof_recent.alloc_max",
expect_d_eq(mallctl("experimental.prof_recent.alloc_max",
NULL, NULL, &test_max, sizeof(ssize_t)), 0, "Write error");
confirm_prof_setup(tsd);
}