From: Hao Fang fanghao11@huawei.com
Add DEBUG_LOG macro to control dbg print.
Use the COMP_TST_PRT() to unified the err log print.
Signed-off-by: Hao Fang fanghao11@huawei.com Signed-off-by: Qi Tao taoqi10@huawei.com --- uadk_tool/test/comp_lib.c | 118 +++++++++++++++--------------- uadk_tool/test/comp_lib.h | 8 +++ uadk_tool/test/comp_main.c | 144 ++++++++++++++++++------------------- 3 files changed, 138 insertions(+), 132 deletions(-)
diff --git a/uadk_tool/test/comp_lib.c b/uadk_tool/test/comp_lib.c index 4009295..c2e4410 100644 --- a/uadk_tool/test/comp_lib.c +++ b/uadk_tool/test/comp_lib.c @@ -21,8 +21,6 @@ struct check_rand_ctx { unsigned short state[3]; };
-#define dbg(msg, ...) fprintf(stderr, msg, ##__VA_ARGS__) - static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_spinlock_t lock; static int count = 0; @@ -56,7 +54,7 @@ void *mmap_alloc(size_t len) p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (p == MAP_FAILED) - WD_ERR("Failed to allocate %zu bytes\n", len); + COMP_TST_PRT("Failed to allocate %zu bytes\n", len);
return p == MAP_FAILED ? NULL : p; } @@ -94,7 +92,7 @@ static int hizip_check_rand(unsigned char *buf, unsigned int size, void *opaque) char actual = buf[i + *j];
if (expected != actual) { - WD_ERR("Invalid decompressed char at offset %lu: expected 0x%x != 0x%x\n", + COMP_TST_PRT("Invalid decompressed char at offset %lu: expected 0x%x != 0x%x\n", rand_ctx->global_off + i + *j, expected, actual); return -EINVAL; @@ -115,7 +113,7 @@ static struct wd_datalist *get_datalist(void *addr, __u32 size)
head = calloc(1, sizeof(struct wd_datalist)); if (!head) { - WD_ERR("failed to alloc datalist head\n"); + COMP_TST_PRT("failed to alloc datalist head\n"); return NULL; }
@@ -162,12 +160,12 @@ int hw_blk_compress(int alg_type, int blksize, __u8 data_fmt, void *priv, setup.sched_param = ¶m; h_sess = wd_comp_alloc_sess(&setup); if (!h_sess) { - fprintf(stderr,"fail to alloc comp sess!\n"); + COMP_TST_PRT("fail to alloc comp sess!\n"); return -EINVAL; }
if (data_fmt) { - WD_ERR("now sge size is %u\n", SGE_SIZE); + COMP_TST_PRT("now sge size is %u\n", SGE_SIZE); list = get_datalist(src, (__u32)srclen); req.list_src = list; list = get_datalist(dst, (__u32)*dstlen); @@ -189,12 +187,12 @@ int hw_blk_compress(int alg_type, int blksize, __u8 data_fmt, void *priv,
ret = wd_do_comp_sync(h_sess, &req); if (ret < 0) { - fprintf(stderr,"fail to do comp sync(ret = %d)!\n", ret); + COMP_TST_PRT("fail to do comp sync(ret = %d)!\n", ret); return ret; }
if (req.status) { - fprintf(stderr,"fail to do comp sync(status = %d)!\n", + COMP_TST_PRT("fail to do comp sync(status = %d)!\n", req.status); wd_comp_free_sess(h_sess); return req.status; @@ -227,12 +225,12 @@ int hw_blk_decompress(int alg_type, int blksize, __u8 data_fmt, setup.sched_param = ¶m; h_sess = wd_comp_alloc_sess(&setup); if (!h_sess) { - fprintf(stderr,"fail to alloc comp sess!\n"); + COMP_TST_PRT("fail to alloc comp sess!\n"); return -EINVAL; }
if (data_fmt) { - WD_ERR("now sge size is %u\n", SGE_SIZE); + COMP_TST_PRT("now sge size is %u\n", SGE_SIZE); list = get_datalist(src, (__u32)srclen); req.list_src = list; list = get_datalist(dst, (__u32)*dstlen); @@ -254,12 +252,12 @@ int hw_blk_decompress(int alg_type, int blksize, __u8 data_fmt,
ret = wd_do_comp_sync(h_sess, &req); if (ret < 0) { - fprintf(stderr,"fail to do comp sync(ret = %d)!\n", ret); + COMP_TST_PRT("fail to do comp sync(ret = %d)!\n", ret); return ret; }
if (req.status) { - fprintf(stderr,"fail to do comp sync(status = %d)!\n", + COMP_TST_PRT("fail to do comp sync(status = %d)!\n", req.status); wd_comp_free_sess(h_sess); return req.status; @@ -293,7 +291,7 @@ int hw_stream_compress(int alg_type, int blksize, __u8 data_fmt, setup.sched_param = ¶m; h_sess = wd_comp_alloc_sess(&setup); if (!h_sess) { - fprintf(stderr,"fail to alloc comp sess!\n"); + COMP_TST_PRT("fail to alloc comp sess!\n"); return -EINVAL; } req.src = src; @@ -309,12 +307,12 @@ int hw_stream_compress(int alg_type, int blksize, __u8 data_fmt,
ret = wd_do_comp_sync2(h_sess, &req); if (ret < 0) { - fprintf(stderr,"fail to do comp sync(ret = %d)!\n", ret); + COMP_TST_PRT("fail to do comp sync(ret = %d)!\n", ret); return ret; }
if (req.status) { - fprintf(stderr,"fail to do comp sync(status = %d)!\n", + COMP_TST_PRT("fail to do comp sync(status = %d)!\n", req.status); wd_comp_free_sess(h_sess); return req.status; @@ -347,7 +345,7 @@ int hw_stream_decompress(int alg_type, int blksize, __u8 data_fmt, setup.sched_param = ¶m; h_sess = wd_comp_alloc_sess(&setup); if (!h_sess) { - fprintf(stderr,"fail to alloc comp sess!\n"); + COMP_TST_PRT("fail to alloc comp sess!\n"); return -EINVAL; } req.src = src; @@ -364,12 +362,12 @@ int hw_stream_decompress(int alg_type, int blksize, __u8 data_fmt,
ret = wd_do_comp_sync2(h_sess, &req); if (ret < 0) { - fprintf(stderr,"fail to do comp sync(ret = %d)!\n", ret); + COMP_TST_PRT("fail to do comp sync(ret = %d)!\n", ret); return ret; }
if (req.status) { - fprintf(stderr,"fail to do comp sync(status = %d)!\n", + COMP_TST_PRT("fail to do comp sync(status = %d)!\n", req.status); wd_comp_free_sess(h_sess); return req.status; @@ -477,7 +475,7 @@ int hizip_verify_random_output(struct test_options *opts, ret = hizip_check_output(info->out_buf + off, out_sz, &checked, hizip_check_rand, &rand_ctx); if (ret) { - WD_ERR("Check output failed with %d\n", ret); + COMP_TST_PRT("Check output failed with %d\n", ret); return ret; } total_checked += checked; @@ -485,7 +483,7 @@ int hizip_verify_random_output(struct test_options *opts, } while (!ret && total_checked < opts->total_len);
if (rand_ctx.global_off != opts->total_len) { - WD_ERR("Invalid output size %lu != %lu\n", + COMP_TST_PRT("Invalid output size %lu != %lu\n", rand_ctx.global_off, opts->total_len); return -EINVAL; } @@ -557,7 +555,7 @@ void *send_thread_func(void *arg) kill(getpid(), SIGTERM); } if (ret < 0) { - WD_ERR("do comp test fail with %d\n", ret); + COMP_TST_PRT("do comp test fail with %d\n", ret); return (void *)(uintptr_t)ret; } else if (tdata->req.status) { return (void *)(uintptr_t)tdata->req.status; @@ -574,7 +572,7 @@ void *send_thread_func(void *arg) tdata->req.dst += dst_block_size; tdata->sum += tdata->req.dst_len; if (tdata->sum > info->out_size) { - fprintf(stderr, + COMP_TST_PRT( "%s: exceed OUT limits (%ld > %ld)\n", __func__, tdata->sum, info->out_size); @@ -662,7 +660,7 @@ int create_send_threads(struct test_options *opts, ret = pthread_create(&info->send_tds[i], &attr, send_thread_func, &tdatas[i]); if (ret < 0) { - fprintf(stderr, "Fail to create send thread %d (%d)\n", + COMP_TST_PRT( "Fail to create send thread %d (%d)\n", i, ret); goto out_thd; } @@ -699,7 +697,7 @@ int create_poll_threads(struct hizip_test_info *info, ret = pthread_create(&info->poll_tds[i], &attr, poll_thread_func, info); if (ret < 0) { - fprintf(stderr, "Fail to create send thread %d (%d)\n", + COMP_TST_PRT( "Fail to create send thread %d (%d)\n", i, ret); goto out; } @@ -729,14 +727,14 @@ int attach_threads(struct test_options *opts, struct hizip_test_info *info) for (i = 0; i < info->poll_tnum; i++) { ret = pthread_join(info->poll_tds[i], NULL); if (ret < 0) - fprintf(stderr, "Fail on poll thread with %d\n", + COMP_TST_PRT( "Fail on poll thread with %d\n", ret); } } for (i = 0; i < info->send_tnum; i++) { ret = pthread_join(info->send_tds[i], &tret); if (ret < 0) - fprintf(stderr, "Fail on send thread with %d\n", ret); + COMP_TST_PRT( "Fail on send thread with %d\n", ret); } return (int)(uintptr_t)tret; } @@ -768,8 +766,8 @@ void dump_md5(comp_md5_t *md5) int i;
for (i = 0; i < MD5_DIGEST_LENGTH - 1; i++) - printf("%02x-", md5->md[i]); - printf("%02x\n", md5->md[i]); + COMP_TST_PRT("%02x-", md5->md[i]); + COMP_TST_PRT("%02x\n", md5->md[i]); }
int cmp_md5(comp_md5_t *orig, comp_md5_t *final) @@ -780,9 +778,9 @@ int cmp_md5(comp_md5_t *orig, comp_md5_t *final) return -EINVAL; for (i = 0; i < MD5_DIGEST_LENGTH; i++) { if (orig->md[i] != final->md[i]) { - printf("Original MD5: "); + COMP_TST_PRT("Original MD5: "); dump_md5(orig); - printf("Final MD5: "); + COMP_TST_PRT("Final MD5: "); dump_md5(final); return -EINVAL; } @@ -881,7 +879,7 @@ static int chunk_deflate2(void *in, size_t in_sz, void *out, size_t *out_sz, windowBits = 15 + 16; break; default: - printf("algorithm %d unsupported by zlib\n", alg_type); + COMP_TST_PRT("algorithm %d unsupported by zlib\n", alg_type); return -EINVAL; } memset(&strm, 0, sizeof(z_stream)); @@ -893,23 +891,23 @@ static int chunk_deflate2(void *in, size_t in_sz, void *out, size_t *out_sz, ret = deflateInit2(&strm, Z_BEST_SPEED, Z_DEFLATED, windowBits, 8, Z_DEFAULT_STRATEGY); if (ret != Z_OK) { - printf("deflateInit2: %d\n", ret); + COMP_TST_PRT("deflateInit2: %d\n", ret); return -EINVAL; }
do { ret = deflate(&strm, Z_FINISH); if ((ret == Z_STREAM_ERROR) || (ret == Z_BUF_ERROR)) { - printf("defalte error %d - %s\n", ret, strm.msg); + COMP_TST_PRT("defalte error %d - %s\n", ret, strm.msg); ret = -ENOSR; break; } else if (!strm.avail_in) { if (ret != Z_STREAM_END) - printf("deflate unexpected return: %d\n", ret); + COMP_TST_PRT("deflate unexpected return: %d\n", ret); ret = 0; break; } else if (!strm.avail_out) { - printf("deflate out of memory\n"); + COMP_TST_PRT("deflate out of memory\n"); ret = -ENOSPC; break; } @@ -934,7 +932,7 @@ static int chunk_inflate2(void *in, size_t in_sz, void *out, size_t *out_sz, /* Window size of 15, +32 for auto-decoding gzip/zlib */ ret = inflateInit2(&strm, 15 + 32); if (ret != Z_OK) { - printf("zlib inflateInit: %d\n", ret); + COMP_TST_PRT("zlib inflateInit: %d\n", ret); return -EINVAL; }
@@ -945,13 +943,13 @@ static int chunk_inflate2(void *in, size_t in_sz, void *out, size_t *out_sz, do { ret = inflate(&strm, Z_NO_FLUSH); if ((ret < 0) || (ret == Z_NEED_DICT)) { - printf("zlib error %d - %s\n", ret, strm.msg); + COMP_TST_PRT("zlib error %d - %s\n", ret, strm.msg); goto out; } if (!strm.avail_out) { if (!strm.avail_in || (ret == Z_STREAM_END)) break; - printf("%s: avail_out is empty!\n", __func__); + COMP_TST_PRT("%s: avail_out is empty!\n", __func__); goto out; } } while (strm.avail_in && (ret != Z_STREAM_END)); @@ -1271,7 +1269,7 @@ int create_send_tdata(struct test_options *opts, if (opts->option & TEST_THP) { ret = madvise(info->in_buf, info->in_size, MADV_HUGEPAGE); if (ret) { - printf("madvise(MADV_HUGEPAGE)"); + COMP_TST_PRT("madvise(MADV_HUGEPAGE)"); goto out_in; } } @@ -1291,7 +1289,7 @@ int create_send_tdata(struct test_options *opts, if (opts->option & TEST_THP) { ret = madvise(tdata->dst, tdata->dst_sz, MADV_HUGEPAGE); if (ret) { - printf("madvise(MADV_HUGEPAGE)"); + COMP_TST_PRT("madvise(MADV_HUGEPAGE)"); goto out_dst; } } @@ -1413,7 +1411,7 @@ int attach2_threads(struct test_options *opts, ret = pthread_create(&info->send_tds[i], &attr, send_thread_func, &info->tdatas[i]); if (ret < 0) { - printf("Fail to create send thread %d (%d)\n", i, ret); + COMP_TST_PRT("Fail to create send thread %d (%d)\n", i, ret); goto out; } } @@ -1423,7 +1421,7 @@ int attach2_threads(struct test_options *opts, poll_thread_func, &info->tdatas[i]); if (ret < 0) { - printf("Fail to create poll thread %d (%d)\n", + COMP_TST_PRT("Fail to create poll thread %d (%d)\n", i, ret); goto out_poll; } @@ -1431,7 +1429,7 @@ int attach2_threads(struct test_options *opts, for (i = 0; i < info->poll_tnum; i++) { ret = pthread_join(info->poll_tds[i], &tret); if (ret < 0) { - fprintf(stderr, "Fail on poll thread with %d\n", + COMP_TST_PRT( "Fail on poll thread with %d\n", ret); goto out_poll; } @@ -1440,7 +1438,7 @@ int attach2_threads(struct test_options *opts, for (i = 0; i < info->send_tnum; i++) { ret = pthread_join(info->send_tds[i], &tret); if (ret < 0) { - fprintf(stderr, "Fail on send thread with %d\n", ret); + COMP_TST_PRT( "Fail on send thread with %d\n", ret); goto out_poll; } } @@ -1522,7 +1520,7 @@ struct uacce_dev_list *get_dev_list(struct test_options *opts, }
if (!p) { - WD_ERR("Request too much contexts: %d\n", + COMP_TST_PRT("Request too much contexts: %d\n", opts->q_num * 4 * children); goto out; } @@ -1557,7 +1555,7 @@ int init_ctx_config(struct test_options *opts, void *priv, __atomic_store_n(&sum_thread_end, 0, __ATOMIC_RELEASE); *sched = wd_sched_rr_alloc(SCHED_POLICY_RR, 2, 2, lib_poll_func); if (!*sched) { - WD_ERR("wd_sched_rr_alloc fail\n"); + COMP_TST_PRT("wd_sched_rr_alloc fail\n"); goto out_sched; }
@@ -1567,14 +1565,14 @@ int init_ctx_config(struct test_options *opts, void *priv, ctx_conf->ctx_num = q_num * 4; ctx_conf->ctxs = calloc(1, q_num * 4 * sizeof(struct wd_ctx)); if (!ctx_conf->ctxs) { - WD_ERR("Not enough memory to allocate contexts.\n"); + COMP_TST_PRT("Not enough memory to allocate contexts.\n"); ret = -ENOMEM; goto out_ctx; } for (i = 0; i < ctx_conf->ctx_num; i++) { ctx_conf->ctxs[i].ctx = wd_request_ctx(info->list->dev); if (!ctx_conf->ctxs[i].ctx) { - WD_ERR("Fail to allocate context #%d\n", i); + COMP_TST_PRT("Fail to allocate context #%d\n", i); ret = -EINVAL; goto out_req; } @@ -1594,7 +1592,7 @@ int init_ctx_config(struct test_options *opts, void *priv, param.end = q_num - 1; ret = wd_sched_rr_instance((const struct wd_sched *)*sched, ¶m); if (ret < 0) { - WD_ERR("Fail to fill sched region.\n"); + COMP_TST_PRT("Fail to fill sched region.\n"); goto out_fill; } for (i = q_num; i < q_num * 2; i++) { @@ -1607,7 +1605,7 @@ int init_ctx_config(struct test_options *opts, void *priv, param.end = q_num * 2 - 1; ret = wd_sched_rr_instance((const struct wd_sched *)*sched, ¶m); if (ret < 0) { - WD_ERR("Fail to fill sched region.\n"); + COMP_TST_PRT("Fail to fill sched region.\n"); goto out_fill; } for (i = q_num * 2; i < q_num * 3; i++) { @@ -1620,7 +1618,7 @@ int init_ctx_config(struct test_options *opts, void *priv, param.end = q_num * 3 - 1; ret = wd_sched_rr_instance((const struct wd_sched *)*sched, ¶m); if (ret < 0) { - WD_ERR("Fail to fill sched region.\n"); + COMP_TST_PRT("Fail to fill sched region.\n"); goto out_fill; } for (i = q_num * 3; i < q_num * 4; i++) { @@ -1633,7 +1631,7 @@ int init_ctx_config(struct test_options *opts, void *priv, param.end = q_num * 4 - 1; ret = wd_sched_rr_instance((const struct wd_sched *)*sched, ¶m); if (ret < 0) { - WD_ERR("Fail to fill sched region.\n"); + COMP_TST_PRT("Fail to fill sched region.\n"); goto out_fill; }
@@ -1772,7 +1770,7 @@ int hizip_check_output(void *buf, size_t size, size_t *checked, /* Window size of 15, +32 for auto-decoding gzip/zlib */ ret = inflateInit2(&stream, 15 + 32); if (ret != Z_OK) { - WD_ERR("zlib inflateInit: %d\n", ret); + COMP_TST_PRT("zlib inflateInit: %d\n", ret); ret = -EINVAL; goto out_free_buf; } @@ -1780,7 +1778,7 @@ int hizip_check_output(void *buf, size_t size, size_t *checked, do { ret = inflate(&stream, Z_NO_FLUSH); if (ret < 0 || ret == Z_NEED_DICT) { - WD_ERR("zlib error %d - %s\n", ret, stream.msg); + COMP_TST_PRT("zlib error %d - %s\n", ret, stream.msg); ret = -ENOSR; break; } @@ -1834,31 +1832,31 @@ int zlib_deflate(void *output, unsigned int out_size, windowBits = 15 + 16; break; default: - WD_ERR("algorithm %d unsupported by zlib\n", alg_type); + COMP_TST_PRT("algorithm %d unsupported by zlib\n", alg_type); return -EINVAL; }
ret = deflateInit2(&stream, Z_BEST_SPEED, Z_DEFLATED, windowBits, 9, Z_DEFAULT_STRATEGY); if (ret != Z_OK) { - WD_ERR("zlib deflateInit: %d\n", ret); + COMP_TST_PRT("zlib deflateInit: %d\n", ret); return -EINVAL; }
do { ret = deflate(&stream, Z_FINISH); if (ret == Z_STREAM_ERROR || ret == Z_BUF_ERROR) { - WD_ERR("zlib error %d - %s\n", ret, stream.msg); + COMP_TST_PRT("zlib error %d - %s\n", ret, stream.msg); ret = -ENOSR; break; } else if (!stream.avail_in) { if (ret != Z_STREAM_END) - WD_ERR("unexpected deflate return value %d\n", ret); + COMP_TST_PRT("unexpected deflate return value %d\n", ret); *produced = stream.total_out; ret = 0; break; } else if (!stream.avail_out) { - WD_ERR("No more output available\n"); + COMP_TST_PRT("No more output available\n"); ret = -ENOSPC; break; } diff --git a/uadk_tool/test/comp_lib.h b/uadk_tool/test/comp_lib.h index 95b5a31..4d11a84 100644 --- a/uadk_tool/test/comp_lib.h +++ b/uadk_tool/test/comp_lib.h @@ -33,6 +33,14 @@ do { \ } \ } while (0)
+#ifdef DEBUG_LOG +#define dbg(msg, ...) fprintf(stderr, msg, ##__VA_ARGS__) +#else +#define dbg(msg, ...) +#endif + +#define COMP_TST_PRT printf + enum mode { MODE_BLOCK, MODE_STREAM, diff --git a/uadk_tool/test/comp_main.c b/uadk_tool/test/comp_main.c index a21a952..39f8525 100644 --- a/uadk_tool/test/comp_main.c +++ b/uadk_tool/test/comp_main.c @@ -120,7 +120,7 @@ static void *sw_dfl_hw_ifl(void *arg) tdata->dst_sz, tdata->dst_sz); ret = sw_deflate2(tdata->in_list, tlist, opts); if (ret) { - printf("Fail to deflate by zlib: %d\n", ret); + COMP_TST_PRT("Fail to deflate by zlib: %d\n", ret); goto out_strm; } tout_sz = tdata->dst_sz; @@ -132,24 +132,24 @@ static void *sw_dfl_hw_ifl(void *arg) tlist->addr, tlist->size); if (ret) { - printf("Fail to inflate by HW: %d\n", ret); + COMP_TST_PRT("Fail to inflate by HW: %d\n", ret); goto out_strm; } ret = calculate_md5(&tdata->md5, tdata->in_list->addr, tdata->in_list->size); if (ret) { - printf("Fail to generate MD5 (%d)\n", ret); + COMP_TST_PRT("Fail to generate MD5 (%d)\n", ret); goto out_strm; } ret = calculate_md5(&final_md5, tdata->out_list->addr, tout_sz); if (ret) { - printf("Fail to generate MD5 (%d)\n", ret); + COMP_TST_PRT("Fail to generate MD5 (%d)\n", ret); goto out_strm; } ret = cmp_md5(&tdata->md5, &final_md5); if (ret) { - printf("MD5 is unmatched (%d) at %dth times on " + COMP_TST_PRT("MD5 is unmatched (%d) at %dth times on " "thread %d\n", ret, i, tdata->tid); goto out_strm; } @@ -181,28 +181,28 @@ static void *sw_dfl_hw_ifl(void *arg) info->out_chunk_sz); ret = sw_deflate2(tdata->in_list, tlist, opts); if (ret) { - printf("Fail to deflate by zlib: %d\n", ret); + COMP_TST_PRT("Fail to deflate by zlib: %d\n", ret); goto out_run; } ret = hw_inflate4(h_ifl, tlist, tdata->out_list, opts, &tdata->sem); if (ret) { - printf("Fail to inflate by HW: %d\n", ret); + COMP_TST_PRT("Fail to inflate by HW: %d\n", ret); goto out_run; } ret = calculate_md5(&tdata->md5, tdata->src, tdata->src_sz); if (ret) { - printf("Fail to generate MD5 (%d)\n", ret); + COMP_TST_PRT("Fail to generate MD5 (%d)\n", ret); goto out_run; } ret = calculate_md5(&final_md5, tdata->dst, tdata->dst_sz); if (ret) { - printf("Fail to generate MD5 (%d)\n", ret); + COMP_TST_PRT("Fail to generate MD5 (%d)\n", ret); goto out_run; } ret = cmp_md5(&tdata->md5, &final_md5); if (ret) { - printf("MD5 is unmatched (%d) at %dth times on " + COMP_TST_PRT("MD5 is unmatched (%d) at %dth times on " "thread %d\n", ret, i, tdata->tid); goto out_run; } @@ -273,30 +273,30 @@ static void *hw_dfl_sw_ifl(void *arg) tdata->src, tdata->src_sz); if (ret) { - printf("Fail to deflate by HW: %d\n", ret); + COMP_TST_PRT("Fail to deflate by HW: %d\n", ret); goto out_strm; } tlist->size = tmp_sz; // write back ret = sw_inflate2(tlist, tdata->out_list, opts); if (ret) { - printf("Fail to inflate by zlib: %d\n", ret); + COMP_TST_PRT("Fail to inflate by zlib: %d\n", ret); goto out_strm; } ret = calculate_md5(&tdata->md5, tdata->in_list->addr, tdata->in_list->size); if (ret) { - printf("Fail to generate MD5 (%d)\n", ret); + COMP_TST_PRT("Fail to generate MD5 (%d)\n", ret); goto out_strm; } ret = calculate_md5(&final_md5, tdata->out_list->addr, tdata->out_list->size); if (ret) { - printf("Fail to generate MD5 (%d)\n", ret); + COMP_TST_PRT("Fail to generate MD5 (%d)\n", ret); goto out_strm; } ret = cmp_md5(&tdata->md5, &final_md5); if (ret) { - printf("MD5 is unmatched (%d) at %dth times on " + COMP_TST_PRT("MD5 is unmatched (%d) at %dth times on " "thread %d\n", ret, i, tdata->tid); goto out_strm; } @@ -328,27 +328,27 @@ static void *hw_dfl_sw_ifl(void *arg) ret = hw_deflate4(h_dfl, tdata->in_list, tlist, opts, &tdata->sem); if (ret) { - printf("Fail to deflate by HW: %d\n", ret); + COMP_TST_PRT("Fail to deflate by HW: %d\n", ret); goto out_run; } ret = sw_inflate2(tlist, tdata->out_list, opts); if (ret) { - printf("Fail to inflate by zlib: %d\n", ret); + COMP_TST_PRT("Fail to inflate by zlib: %d\n", ret); goto out_run; } ret = calculate_md5(&tdata->md5, tdata->src, tdata->src_sz); if (ret) { - printf("Fail to generate MD5 (%d)\n", ret); + COMP_TST_PRT("Fail to generate MD5 (%d)\n", ret); goto out_run; } ret = calculate_md5(&final_md5, tdata->dst, tdata->dst_sz); if (ret) { - printf("Fail to generate MD5 (%d)\n", ret); + COMP_TST_PRT("Fail to generate MD5 (%d)\n", ret); goto out_run; } ret = cmp_md5(&tdata->md5, &final_md5); if (ret) { - printf("MD5 is unmatched (%d) at %dth times on " + COMP_TST_PRT("MD5 is unmatched (%d) at %dth times on " "thread %d\n", ret, i, tdata->tid); goto out_run; } @@ -407,7 +407,7 @@ static void *hw_dfl_hw_ifl(void *arg) tdata->src, tdata->src_sz); if (ret) { - printf("Fail to deflate by HW: %d\n", ret); + COMP_TST_PRT("Fail to deflate by HW: %d\n", ret); goto out; } tout_sz = tdata->dst_sz; @@ -419,23 +419,23 @@ static void *hw_dfl_hw_ifl(void *arg) tbuf, tmp_sz); if (ret) { - printf("Fail to inflate by HW: %d\n", ret); + COMP_TST_PRT("Fail to inflate by HW: %d\n", ret); goto out; } ret = calculate_md5(&tdata->md5, tdata->in_list->addr, tdata->in_list->size); if (ret) { - printf("Fail to generate MD5 (%d)\n", ret); + COMP_TST_PRT("Fail to generate MD5 (%d)\n", ret); goto out; } ret = calculate_md5(&final_md5, tdata->dst, tout_sz); if (ret) { - printf("Fail to generate MD5 (%d)\n", ret); + COMP_TST_PRT("Fail to generate MD5 (%d)\n", ret); goto out; } ret = cmp_md5(&tdata->md5, &final_md5); if (ret) { - printf("MD5 is unmatched (%d) at %dth times on " + COMP_TST_PRT("MD5 is unmatched (%d) at %dth times on " "thread %d\n", ret, i, tdata->tid); goto out; } @@ -481,28 +481,28 @@ static void *hw_dfl_hw_ifl(void *arg) ret = hw_deflate4(h_dfl, tdata->in_list, tlist, opts, &tdata->sem); if (ret) { - printf("Fail to deflate by HW: %d\n", ret); + COMP_TST_PRT("Fail to deflate by HW: %d\n", ret); goto out_run; } ret = hw_inflate4(h_ifl, tlist, tdata->out_list, opts, &tdata->sem); if (ret) { - printf("Fail to inflate by HW: %d\n", ret); + COMP_TST_PRT("Fail to inflate by HW: %d\n", ret); goto out_run; } ret = calculate_md5(&tdata->md5, tdata->src, tdata->src_sz); if (ret) { - printf("Fail to generate MD5 (%d)\n", ret); + COMP_TST_PRT("Fail to generate MD5 (%d)\n", ret); goto out_run; } ret = calculate_md5(&final_md5, tdata->dst, tdata->dst_sz); if (ret) { - printf("Fail to generate MD5 (%d)\n", ret); + COMP_TST_PRT("Fail to generate MD5 (%d)\n", ret); goto out_run; } ret = cmp_md5(&tdata->md5, &final_md5); if (ret) { - printf("MD5 is unmatched (%d) at %dth times on " + COMP_TST_PRT("MD5 is unmatched (%d) at %dth times on " "thread %d\n", ret, i, tdata->tid); goto out_run; } @@ -547,7 +547,7 @@ static void *hw_dfl_perf(void *arg) tdata->src, tdata->src_sz); if (ret) { - printf("Fail to deflate by HW: %d\n", ret); + COMP_TST_PRT("Fail to deflate by HW: %d\n", ret); return (void *)(uintptr_t)ret; } } @@ -573,7 +573,7 @@ static void *hw_dfl_perf(void *arg) ret = hw_deflate4(h_dfl, tdata->in_list, tdata->out_list, opts, &tdata->sem); if (ret) { - printf("Fail to deflate by HW: %d\n", ret); + COMP_TST_PRT("Fail to deflate by HW: %d\n", ret); goto out; } } @@ -608,7 +608,7 @@ static void *hw_ifl_perf(void *arg) tdata->in_list->addr, tdata->in_list->size); if (ret) { - printf("Fail to inflate by HW: %d\n", ret); + COMP_TST_PRT("Fail to inflate by HW: %d\n", ret); return (void *)(uintptr_t)ret; } tdata->out_list->addr = tdata->dst; @@ -634,7 +634,7 @@ static void *hw_ifl_perf(void *arg) ret = hw_inflate4(h_ifl, tdata->in_list, tdata->out_list, opts, &tdata->sem); if (ret) { - printf("Fail to inflate by HW: %d\n", ret); + COMP_TST_PRT("Fail to inflate by HW: %d\n", ret); goto out; } } @@ -670,7 +670,7 @@ void *hw_dfl_perf3(void *arg) tdata->src, tdata->src_sz); if (ret) { - printf("Fail to deflate by HW: %d\n", ret); + COMP_TST_PRT("Fail to deflate by HW: %d\n", ret); return (void *)(uintptr_t)ret; } } @@ -696,7 +696,7 @@ void *hw_dfl_perf3(void *arg) ret = hw_deflate5(h_dfl, tdata->in_list, tdata->out_list, tdata); if (ret) { - printf("Fail to deflate by HW: %d\n", ret); + COMP_TST_PRT("Fail to deflate by HW: %d\n", ret); goto out; } } @@ -732,7 +732,7 @@ void *hw_ifl_perf3(void *arg) tdata->src, tdata->src_sz); if (ret) { - printf("Fail to inflate by HW: %d\n", ret); + COMP_TST_PRT("Fail to inflate by HW: %d\n", ret); return (void *)(uintptr_t)ret; } tdata->out_list->addr = tdata->dst; @@ -758,7 +758,7 @@ void *hw_ifl_perf3(void *arg) ret = hw_inflate5(h_ifl, tdata->in_list, tdata->out_list, tdata); if (ret) { - printf("Fail to inflate by HW: %d\n", ret); + COMP_TST_PRT("Fail to inflate by HW: %d\n", ret); goto out; } } @@ -786,7 +786,7 @@ int load_ilist(struct hizip_test_info *info, char *model) if (!strcmp(model, "hw_ifl_perf")) { if (!opts->is_stream) { if (opts->fd_ilist < 0) { - printf("Missing IN list file!\n"); + COMP_TST_PRT("Missing IN list file!\n"); return -EINVAL; } p = tdata->in_list; @@ -818,7 +818,7 @@ int load_file_data(struct hizip_test_info *info)
file_sz = read(opts->fd_in, info->in_buf, info->in_size); if (file_sz < info->in_size) { - printf("Expect to read %ld bytes. " + COMP_TST_PRT("Expect to read %ld bytes. " "But only read %ld bytes!\n", info->in_size, file_sz); return -EFAULT; @@ -930,7 +930,7 @@ int test_hw(struct test_options *opts, char *model)
if (!event_unavailable && perf_event_get("iommu/dev_fault", &perf_fds, &nr_fds)) { - printf("IOPF statistic unavailable\n"); + COMP_TST_PRT("IOPF statistic unavailable\n"); /* No need to retry and print an error on every run */ event_unavailable = true; } @@ -1012,7 +1012,7 @@ int test_hw(struct test_options *opts, char *model) opts->is_stream ? "STREAM" : "BLOCK"); ifl_flag = 1; } else { - printf("Wrong model is specified:%s\n", model); + COMP_TST_PRT("Wrong model is specified:%s\n", model); ret = -EINVAL; goto out; } @@ -1114,12 +1114,12 @@ int test_hw(struct test_options *opts, char *model) */ ret = munmap(info.in_buf, info.in_size); if (ret) { - printf("Failed to unmap."); + COMP_TST_PRT("Failed to unmap."); goto out_buf; } /* A warning if the parameters might produce false positives */ if (opts->total_len > 0x54000) - fprintf(stderr, "NOTE: test might trash the TLB\n"); + COMP_TST_PRT( "NOTE: test might trash the TLB\n"); } stat_start(&info); ret = attach2_threads(opts, &info, func, poll2_thread_func); @@ -1149,10 +1149,10 @@ int test_hw(struct test_options *opts, char *model) } if (!strcmp(model, "hw_dfl_perf") || !strcmp(model, "hw_ifl_perf") || !strcmp(model, "hw_dfl_perf3") || !strcmp(model, "hw_ifl_perf3")) { - printf("%s at %.2fMB/s in %f usec (BLK:%d, Bnum:%d).\n", + COMP_TST_PRT("%s at %.2fMB/s in %f usec (BLK:%d, Bnum:%d).\n", zbuf, speed, usec, opts->block_size, opts->batch_num); } else { - printf("%s in %f usec (BLK:%d, Bnum:%d).\n", + COMP_TST_PRT("%s in %f usec (BLK:%d, Bnum:%d).\n", zbuf, usec, opts->block_size, opts->batch_num); } free2_threads(&info); @@ -1169,7 +1169,7 @@ out_poll: wd_comp_env_uninit(); else nonenv_resource_uninit(opts, &info, sched); - printf("Fail to run %s() (%d)!\n", model, ret); + COMP_TST_PRT("Fail to run %s() (%d)!\n", model, ret); return ret; out_send: mmap_free(info.in_buf, info.in_size); @@ -1179,7 +1179,7 @@ out_src: else nonenv_resource_uninit(opts, &info, sched); out: - printf("Fail to run %s() (%d)!\n", model, ret); + COMP_TST_PRT("Fail to run %s() (%d)!\n", model, ret); return ret; }
@@ -1188,7 +1188,7 @@ int run_self_test(struct test_options *opts) int i, f_ret = 0; char poll_str[POLL_STRING_LEN];
- printf("Start to run self test!\n"); + COMP_TST_PRT("Start to run self test!\n"); opts->alg_type = WD_ZLIB; opts->data_fmt = WD_FLAT_BUF; opts->sync_mode = 0; @@ -1274,7 +1274,7 @@ int run_self_test(struct test_options *opts) f_ret |= test_hw(opts, "hw_ifl_perf"); } if (!f_ret) - printf("Run self test successfully!\n"); + COMP_TST_PRT("Run self test successfully!\n"); return f_ret; }
@@ -1334,7 +1334,7 @@ int run_cmd(struct test_options *opts) for (i = 0; i < opts->children; i++) { pid = fork(); if (pid < 0) { - printf("cannot fork: %d\n", errno); + COMP_TST_PRT("cannot fork: %d\n", errno); success = false; break; } else if (pid > 0) { @@ -1350,28 +1350,28 @@ int run_cmd(struct test_options *opts) pid = pids[i]; ret = waitpid(pid, &status, 0); if (ret < 0) { - printf("wait(pid=%d) error %d\n", pid, errno); + COMP_TST_PRT("wait(pid=%d) error %d\n", pid, errno); success = false; continue; } if (WIFEXITED(status)) { ret = WEXITSTATUS(status); if (ret) { - printf("child %d returned with %d\n", + COMP_TST_PRT("child %d returned with %d\n", pid, ret); success = false; } } else if (WIFSIGNALED(status)) { ret = WTERMSIG(status); - printf("child %d killed by sig %d\n", pid, ret); + COMP_TST_PRT("child %d killed by sig %d\n", pid, ret); success = false; } else { - printf("unexpected status for child %d\n", pid); + COMP_TST_PRT("unexpected status for child %d\n", pid); success = false; } } if (success == false) { - printf("Failed to run spawn test!\n"); + COMP_TST_PRT("Failed to run spawn test!\n"); if (!ret) ret = -EINVAL; } @@ -1510,7 +1510,7 @@ static void set_thp(struct test_options *opts) goto out_err;
if (strcmp(s, "never") == 0) { - printf("Cannot test THP with enable=never\n"); + COMP_TST_PRT("Cannot test THP with enable=never\n"); return; }
@@ -1523,13 +1523,13 @@ static void set_thp(struct test_options *opts) goto out_err;
if (strcmp(s, "defer") == 0 || strcmp(s, "never") == 0) { - printf("Cannot test THP with defrag=%s\n", s); + COMP_TST_PRT("Cannot test THP with defrag=%s\n", s); return; }
return; out_err: - printf("THP unsupported?\n"); + COMP_TST_PRT("THP unsupported?\n"); }
void stat_setup(struct hizip_test_info *info) @@ -1616,7 +1616,7 @@ void stat_end(struct hizip_test_info *info)
static void handle_sigbus(int sig) { - printf("SIGBUS!\n"); + COMP_TST_PRT("SIGBUS!\n"); _exit(0); }
@@ -1672,17 +1672,17 @@ int test_comp_entry(int argc, char *argv[]) if (optarg) { opts.fd_in = open(optarg, O_RDONLY); if (opts.fd_in < 0) { - printf("Fail to open %s\n", + COMP_TST_PRT("Fail to open %s\n", optarg); show_help = 1; } else opts.is_file = true; } else { - printf("Input file is missing!\n"); + COMP_TST_PRT("Input file is missing!\n"); show_help = 1; } if (lseek(opts.fd_in, 0, SEEK_SET) < 0) { - printf("Fail on lseek()!\n"); + COMP_TST_PRT("Fail on lseek()!\n"); show_help = 1; } break; @@ -1693,42 +1693,42 @@ int test_comp_entry(int argc, char *argv[]) S_IWUSR | S_IRGRP | S_IROTH); if (opts.fd_out < 0) { - printf("Fail to open %s\n", + COMP_TST_PRT("Fail to open %s\n", optarg); show_help = 1; } else opts.is_file = true; } else { - printf("Output file is missing!\n"); + COMP_TST_PRT("Output file is missing!\n"); show_help = 1; } if (lseek(opts.fd_out, 0, SEEK_SET) < 0) { - printf("Fail on lseek()!\n"); + COMP_TST_PRT("Fail on lseek()!\n"); show_help = 1; } break; case 3: /* ilist */ if (!optarg) { - printf("IN list file is missing!\n"); + COMP_TST_PRT("IN list file is missing!\n"); show_help = 1; break; } opts.fd_ilist = open(optarg, O_RDONLY); if (opts.fd_ilist < 0) { - printf("Fail to open %s\n", optarg); + COMP_TST_PRT("Fail to open %s\n", optarg); show_help = 1; break; } opts.is_file = true; if (lseek(opts.fd_ilist, 0, SEEK_SET) < 0) { - printf("Fail on lseek()!\n"); + COMP_TST_PRT("Fail on lseek()!\n"); show_help = 1; break; } break; case 4: /* olist */ if (!optarg) { - printf("OUT list file is missing!\n"); + COMP_TST_PRT("OUT list file is missing!\n"); show_help = 1; break; } @@ -1737,13 +1737,13 @@ int test_comp_entry(int argc, char *argv[]) S_IWUSR | S_IRGRP | S_IROTH); if (opts.fd_olist < 0) { - printf("Fail to open %s\n", optarg); + COMP_TST_PRT("Fail to open %s\n", optarg); show_help = 1; break; } opts.is_file = true; if (lseek(opts.fd_olist, 0, SEEK_SET) < 0) { - printf("Fail on lseek()!\n"); + COMP_TST_PRT("Fail on lseek()!\n"); show_help = 1; break; }