struct test_struct { int num; unsignedint magic;
};
#define MAGIC 0xf00ff00f /* Size of each of the NULL-terminated input arrays */ #define INPUT_MAX 128 /* Expected number of non-NULL elements in the output array */ #define EXPECT (INPUT_MAX * 2 - 2)
staticint __init test_memcat_p_init(void)
{ struct test_struct **in0, **in1, **out, **p; int err = -ENOMEM, i, r, total = 0;
in0 = kcalloc(INPUT_MAX, sizeof(*in0), GFP_KERNEL); if (!in0) return err;
in1 = kcalloc(INPUT_MAX, sizeof(*in1), GFP_KERNEL); if (!in1) goto err_free_in0;
for (i = 0, r = 1; i < INPUT_MAX - 1; i++) {
in0[i] = kmalloc(sizeof(**in0), GFP_KERNEL); if (!in0[i]) goto err_free_elements;
out = memcat_p(in0, in1); if (!out) goto err_free_all_elements;
err = -EINVAL; for (i = 0, p = out; *p && (i < INPUT_MAX * 2 - 1); p++, i++) {
total += (*p)->num;
if ((*p)->magic != MAGIC) {
pr_err("test failed: wrong magic at %d: %u\n", i,
(*p)->magic); goto err_free_out;
}
}
if (total) {
pr_err("test failed: expected zero total, got %d\n", total); goto err_free_out;
}
if (i != EXPECT) {
pr_err("test failed: expected output size %d, got %d\n",
EXPECT, i); goto err_free_out;
}
for (i = 0; i < INPUT_MAX - 1; i++) if (out[i] != in0[i] || out[i + INPUT_MAX - 1] != in1[i]) {
pr_err("test failed: wrong element order at %d\n", i); goto err_free_out;
}
err = 0;
pr_info("test passed\n");
err_free_out:
kfree(out);
err_free_all_elements:
i = INPUT_MAX;
err_free_elements: for (i--; i >= 0; i--) {
kfree(in1[i]);
kfree(in0[i]);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.