From: Hao Fang fanghao11@huawei.com
The old format: Such as: uadk_tool --m zip -b 8192 -s 8192000 -t 8 New: uadk_tool --m zip --blksize 8192 --size 8192000 --thread 8
Signed-off-by: Hao Fang fanghao11@huawei.com Signed-off-by: Qi Tao taoqi10@huawei.com --- uadk_tool/test/comp_lib.c | 273 +++++++++++++++++++++++++++++-------- uadk_tool/test/comp_lib.h | 59 +++++--- uadk_tool/test/comp_main.c | 205 +++------------------------- uadk_tool/test/comp_main.h | 6 +- 4 files changed, 279 insertions(+), 264 deletions(-)
diff --git a/uadk_tool/test/comp_lib.c b/uadk_tool/test/comp_lib.c index 0229a27..6c2062d 100644 --- a/uadk_tool/test/comp_lib.c +++ b/uadk_tool/test/comp_lib.c @@ -5,6 +5,7 @@ */
#include <pthread.h> +#include <getopt.h> #include <signal.h> #include <math.h> #include <sys/mman.h> @@ -640,7 +641,7 @@ static 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) { - COMP_TST_PRT("madvise(MADV_HUGEPAGE)"); + COMP_TST_PRT("failed to madvise(MADV_HUGEPAGE) src_buf(%ld)!\n", info->in_size); goto out_ilist; } } @@ -659,7 +660,7 @@ static int create_send_tdata(struct test_options *opts, if (opts->option & TEST_THP) { ret = madvise(tdata->dst, tdata->dst_sz, MADV_HUGEPAGE); if (ret) { - COMP_TST_PRT("madvise(MADV_HUGEPAGE)"); + COMP_TST_PRT("failed to madvise(MADV_HUGEPAGE) dst_buf(%ld)!\n", tdata->dst_sz); goto out_dst; } } @@ -1060,63 +1061,225 @@ void uninit_config(void *priv, struct wd_sched *sched) wd_sched_rr_release(sched); }
-int parse_common_option(const char opt, const char *optarg, +static void set_thp(struct test_options *opts) +{ +#define MAX_BUFF_SIZE 14 + char *p; + char s[MAX_BUFF_SIZE]; + FILE *file; + + file = fopen("/sys/kernel/mm/transparent_hugepage/enabled", "r"); + if (!file) + goto out_err; + p = fgets(s, MAX_BUFF_SIZE, file); + fclose(file); + if (!p) + goto out_err; + + if (strcmp(s, "never") == 0) { + COMP_TST_PRT("Cannot test THP with enable=never\n"); + return; + } + + file = fopen("/sys/kernel/mm/transparent_hugepage/defrag", "r"); + if (!file) + goto out_err; + p = fgets(s, MAX_BUFF_SIZE, file); + fclose(file); + if (!p) + goto out_err; + + if (strcmp(s, "defer") == 0 || strcmp(s, "never") == 0) { + COMP_TST_PRT("Cannot test THP with defrag=%s\n", s); + return; + } + + return; +out_err: + COMP_TST_PRT("THP unsupported?\n"); +} + +int parse_common_option(int argc, char *argv[], struct test_options *opts) { - switch (opt) { - case 'b': - opts->block_size = strtol(optarg, NULL, 0); - if (opts->block_size <= 0) - return 1; - break; - case 'l': - opts->compact_run_num = strtol(optarg, NULL, 0); - if (opts->compact_run_num <= 0) + int opt, option_idx; + struct option long_options[] = { + {"help", no_argument, 0, 0 }, + {"self", no_argument, 0, 1 }, + {"in", required_argument, 0, 2 }, + {"out", required_argument, 0, 3 }, + {"env", no_argument, 0, 4 }, + {"blksize", required_argument, 0, 5 }, + {"qnum", required_argument, 0, 6 }, + {"loop", required_argument, 0, 7 }, + {"stream", no_argument, 0, 8 }, + {"size", required_argument, 0, 9 }, + {"verify", no_argument, 0, 10 }, + {"alg", required_argument, 0, 11 }, + {"inf", no_argument, 0, 12 }, + {"thread", required_argument, 0, 13 }, + {"mode", required_argument, 0, 14 }, + {"sgl", no_argument, 0, 15 }, + /* still keep these proprietary cmds listd below*/ + {"sformat", required_argument, 0, 20 }, + {"option", required_argument, 0, 21 }, + {"fork", required_argument, 0, 22 }, + {"kill", required_argument, 0, 23 }, + {0, 0, 0, 24 }, + }; + + opts->fd_in = -1; + opts->fd_out = -1; + opts->alg_type = WD_COMP_ALG_MAX; + while ((opt = getopt_long(argc, argv, "", long_options, &option_idx)) != -1) { + switch (opt) { + case 0: return 1; - break; - case 'q': - opts->q_num = strtol(optarg, NULL, 0); - if (opts->q_num <= 0) + case 1: + opts->self = 1; + break; + case 2: /* input file */ + if (optarg) { + opts->fd_in = open(optarg, O_RDONLY); + if (opts->fd_in < 0) { + COMP_TST_PRT("Fail to open %s\n", + optarg); + return 1; + } else + opts->is_file = true; + } else { + COMP_TST_PRT("Input file is missing!\n"); + return 1; + } + if (lseek(opts->fd_in, 0, SEEK_SET) < 0) { + COMP_TST_PRT("Fail on lseek()!\n"); + return 1; + } + break; + case 3: /* output file */ + if (optarg) { + opts->fd_out = open(optarg, + O_CREAT | O_WRONLY, + S_IWUSR | S_IRGRP | + S_IROTH); + if (opts->fd_out < 0) { + COMP_TST_PRT("Fail to open %s\n", + optarg); + return 1; + } else + opts->is_file = true; + } else { + COMP_TST_PRT("Output file is missing!\n"); + return 1; + } + if (lseek(opts->fd_out, 0, SEEK_SET) < 0) { + COMP_TST_PRT("Fail on lseek()!\n"); + return 1; + } + break; + case 4: /* env */ + opts->use_env = true; + break; + case 5: + opts->block_size = strtol(optarg, NULL, 0); + if (opts->block_size <= 0) + return 1; + break; + case 6: + opts->q_num = strtol(optarg, NULL, 0); + if (opts->q_num <= 0) + return 1; + break; + case 7: + opts->compact_run_num = strtol(optarg, NULL, 0); + if (opts->compact_run_num <= 0) + return 1; + break; + case 8: + opts->is_stream = MODE_STREAM; + break; + case 9: + opts->total_len = strtol(optarg, NULL, 0); + SYS_ERR_COND(opts->total_len <= 0, "invalid size '%s'\n", + optarg); + break; + case 10: + opts->verify = true; + break; + case 11: + opts->alg_type = strtol(optarg, NULL, 0); + if (opts->alg_type >= WD_COMP_ALG_MAX) + return 1; + break; + case 12: + opts->op_type = WD_DIR_DECOMPRESS; + break; + case 13: + opts->thread_num = strtol(optarg, NULL, 0); + SYS_ERR_COND(opts->thread_num < 0, "invalid thread num '%s'\n", + optarg); + break; + case 14: + opts->sync_mode = strtol(optarg, NULL, 0); + SYS_ERR_COND(opts->sync_mode < 0 || opts->sync_mode > 1, + "invalid sync mode '%s'\n", optarg); + break; + case 15: /* reserved */ + opts->data_fmt = WD_SGL_BUF; + break; + case 20: + if (strcmp(optarg, "none") == 0) { + opts->display_stats = STATS_NONE; + } else if (strcmp(optarg, "csv") == 0) { + opts->display_stats = STATS_CSV; + } else if (strcmp(optarg, "pretty") == 0) { + opts->display_stats = STATS_PRETTY; + } else { + SYS_ERR_COND(1, "invalid argument to --sformat: '%s'\n", optarg); + break; + } + break; + case 21: + switch (optarg[0]) { + case 'p': + opts->option |= PERFORMANCE; + break; + case 't': + opts->option |= TEST_THP; + set_thp(opts); + break; + case 'c': + opts->option |= TEST_ZLIB; + break; + default: + SYS_ERR_COND(1, "invalid argument to --option: '%s'\n", optarg); + break; + } + break; + case 22: + opts->children = strtol(optarg, NULL, 0); + if (opts->children < 0) + return 1; + break; + case 23: + switch (optarg[0]) { + case 'b': + opts->faults |= INJECT_SIG_BIND; + break; + case 't': + opts->faults |= INJECT_TLB_FAULT; + break; + case 'w': + opts->faults |= INJECT_SIG_WORK; + break; + default: + SYS_ERR_COND(1, "invalid argument to --kill: '%s'\n", optarg); + return 1; + } + break; + default: return 1; - break; - case 'd': - opts->op_type = WD_DIR_DECOMPRESS; - break; - case 'S': - opts->is_stream = MODE_STREAM; - break; - case 's': - opts->total_len = strtol(optarg, NULL, 0); - SYS_ERR_COND(opts->total_len <= 0, "invalid size '%s'\n", - optarg); - break; - case 't': - opts->thread_num = strtol(optarg, NULL, 0); - SYS_ERR_COND(opts->thread_num < 0, "invalid thread num '%s'\n", - optarg); - break; - case 'm': - opts->sync_mode = strtol(optarg, NULL, 0); - SYS_ERR_COND(opts->sync_mode < 0 || opts->sync_mode > 1, - "invalid sync mode '%s'\n", optarg); - break; - case 'V': - opts->verify = true; - break; - case 'a': - opts->alg_type = WD_DEFLATE; - break; - case 'z': - opts->alg_type = WD_ZLIB; - break; - case 'L': - opts->data_fmt = WD_SGL_BUF; - break; - case 'Z': - opts->alg_type = WD_LZ77_ZSTD; - break; - default: - return 1; + } }
return 0; diff --git a/uadk_tool/test/comp_lib.h b/uadk_tool/test/comp_lib.h index ea7a51b..eda1d59 100644 --- a/uadk_tool/test/comp_lib.h +++ b/uadk_tool/test/comp_lib.h @@ -66,6 +66,9 @@ struct test_options { int alg_type; int op_type;
+ /* self-test */ + int self; + /* bytes of data for a request */ int block_size; int q_num; @@ -264,23 +267,43 @@ static inline int zlib_deflate(void *output, unsigned int out_size, void *input,
#define COMMON_OPTSTRING "hb:q:l:Ss:Vzt:m:dacLZ"
-#define COMMON_HELP "%s [opts]\n" \ - " -b <size> block size\n" \ - " -q <num> number of queues\n" \ - " -l <num> number of compact runs\n" \ - " -S stream mode, default block mode\n" \ - " -s <size> total size\n" \ - " -V verify output\n" \ - " -a test deflate algorithm, default gzip\n" \ - " -z test zlib algorithm, default gzip\n" \ - " -t <num> number of thread per process\n" \ - " -m <mode> mode of queues: 0 sync, 1 async\n" \ - " -d test decompression, default compression\n" \ - " -c use cpu to do zlib\n" \ - " -L test sgl type buffer, default pbuffer\n" \ - " -Z test lz77_zstd algorithm, default gzip\n" \ - "\n\n" - -int parse_common_option(const char opt, const char *optarg, +#define COMMON_HELP "%s test --m zip [opts]\n\n" \ + " --self run self test\n" \ + " --blksize single block size, default 128000\n" \ + " --qnum number of queues, default 1\n" \ + " --loop loop count of test runs, default 1\n" \ + " --stream stream mode, default block mode\n" \ + " --size total data size, default 10 * blksize\n" \ + " --verify verify output\n" \ + " --thread number of thread per process\n" \ + " --mode mode of queues: default sync\n" \ + " '0' sync, '1' async\n" \ + " --inf test decompression, default compression\n"\ + " --sgl test sgl type buffer, default pbuffer\n" \ + " --alg test algorithm, default gzip\n" \ + " '0' deflate\n" \ + " '1' zlib\n" \ + " '2' gzip\n" \ + " '3' lz77_zstd\n" \ + " --in intput file to be compressed\n" \ + " --out output file after compressed\n" \ + " --env enable environment variable settings\n" \ + " --sformat output format for the statistics\n" \ + " 'none' do not output statistics\n" \ + " 'pretty' human readable format\n" \ + " 'csv' raw, machine readable\n" \ + " --option options\n" \ + " 'p' prefaults the output pages\n" \ + " 't' try to enable transparent huge pages\n"\ + " 'c' use cpu software zlib\n" \ + " --fork number of children to create\n" \ + " --kill kill thread\n" \ + " 'b' kills the process after bind\n" \ + " 't' tries to access an unmapped buffer\n" \ + " 'w' kills the process while the queue is working\n" \ + " --help command help \n\n" + +int parse_common_option(int argc, char *argv[], struct test_options *opts); + #endif /* TEST_LIB_H_ */ diff --git a/uadk_tool/test/comp_main.c b/uadk_tool/test/comp_main.c index c36dca0..3cf39ac 100644 --- a/uadk_tool/test/comp_main.c +++ b/uadk_tool/test/comp_main.c @@ -6,7 +6,6 @@ #include <linux/perf_event.h> #include <asm/unistd.h> /* For __NR_perf_event_open */ #include <fenv.h> -#include <getopt.h> #include <inttypes.h> #include <math.h> #include <signal.h> @@ -1052,13 +1051,9 @@ int run_self_test(struct test_options *opts) static int set_default_opts(struct test_options *opts) { if (!opts->block_size) - opts->block_size = 8192; - if (!opts->total_len) { - if (opts->block_size) - opts->total_len = opts->block_size * 10; - else - opts->total_len = 8192 * 10; - } + opts->block_size = 128000; + if (!opts->total_len) + opts->total_len = opts->block_size * 10; if (!opts->thread_num) opts->thread_num = 1; if (!opts->q_num) @@ -1098,6 +1093,10 @@ int run_cmd(struct test_options *opts) bool success = true;
set_default_opts(opts); + + if (opts->self) + return run_self_test(opts); + if (opts->children) { pids = calloc(opts->children, sizeof(pid_t)); if (!pids) @@ -1266,43 +1265,6 @@ unsigned long long perf_event_put(int *perf_fds, int nr_fds) return total; }
-static void set_thp(struct test_options *opts) -{ - char *p; - char s[14]; - FILE *file; - - file = fopen("/sys/kernel/mm/transparent_hugepage/enabled", "r"); - if (!file) - goto out_err; - p = fgets(s, 14, file); - fclose(file); - if (!p) - goto out_err; - - if (strcmp(s, "never") == 0) { - COMP_TST_PRT("Cannot test THP with enable=never\n"); - return; - } - - file = fopen("/sys/kernel/mm/transparent_hugepage/defrag", "r"); - if (!file) - goto out_err; - p = fgets(s, 14, file); - fclose(file); - if (!p) - goto out_err; - - if (strcmp(s, "defer") == 0 || strcmp(s, "never") == 0) { - COMP_TST_PRT("Cannot test THP with defrag=%s\n", s); - return; - } - - return; -out_err: - COMP_TST_PRT("THP unsupported?\n"); -} - void stat_setup(struct hizip_test_info *info) { clock_gettime(CLOCK_MONOTONIC_RAW, &info->tv.setup_time); @@ -1393,15 +1355,17 @@ static void handle_sigbus(int sig)
int test_comp_entry(int argc, char *argv[]) { + int show_help = 0; struct test_options opts = { .alg_type = WD_GZIP, .op_type = WD_DIR_COMPRESS, + .self = 0, .q_num = 1, .compact_run_num = 1, .thread_num = 1, .sync_mode = 0, - .block_size = 512000, - .total_len = opts.block_size * 10, + .block_size = 0, + .total_len = 0, .verify = false, .is_decomp = false, .is_stream = false, @@ -1411,155 +1375,18 @@ int test_comp_entry(int argc, char *argv[]) .faults = 0, .data_fmt = 0, }; - struct option long_options[] = { - {"self", no_argument, 0, 0 }, - {"in", required_argument, 0, 0 }, - {"out", required_argument, 0, 0 }, - {"env", no_argument, 0, 0 }, - {0, 0, 0, 0 }, - }; - int show_help = 0; - int opt, option_idx; - int self = 0;
opts.fd_in = -1; opts.fd_out = -1; opts.alg_type = WD_COMP_ALG_MAX; - while ((opt = getopt_long(argc, argv, COMMON_OPTSTRING "f:o:w:k:r:", - long_options, &option_idx)) != -1) { - switch (opt) { - case 0: - switch (option_idx) { - case 0: /* self */ - self = 1; - break; - case 1: /* in */ - if (optarg) { - opts.fd_in = open(optarg, O_RDONLY); - if (opts.fd_in < 0) { - COMP_TST_PRT("Fail to open %s\n", - optarg); - show_help = 1; - } else - opts.is_file = true; - } else { - COMP_TST_PRT("Input file is missing!\n"); - show_help = 1; - } - if (lseek(opts.fd_in, 0, SEEK_SET) < 0) { - COMP_TST_PRT("Fail on lseek()!\n"); - show_help = 1; - } - break; - case 2: /* out */ - if (optarg) { - opts.fd_out = open(optarg, - O_CREAT | O_WRONLY, - S_IWUSR | S_IRGRP | - S_IROTH); - if (opts.fd_out < 0) { - COMP_TST_PRT("Fail to open %s\n", - optarg); - show_help = 1; - } else - opts.is_file = true; - } else { - COMP_TST_PRT("Output file is missing!\n"); - show_help = 1; - } - if (lseek(opts.fd_out, 0, SEEK_SET) < 0) { - COMP_TST_PRT("Fail on lseek()!\n"); - show_help = 1; - } - break; - case 3: /* env */ - opts.use_env = true; - break; - default: - show_help = 1; - break; - } - break; - case 'f': - if (strcmp(optarg, "none") == 0) { - opts.display_stats = STATS_NONE; - } else if (strcmp(optarg, "csv") == 0) { - opts.display_stats = STATS_CSV; - } else if (strcmp(optarg, "pretty") == 0) { - opts.display_stats = STATS_PRETTY; - } else { - SYS_ERR_COND(1, "invalid argument to -f: '%s'\n", optarg); - break; - } - break; - case 'o': - switch (optarg[0]) { - case 'p': - opts.option |= PERFORMANCE; - break; - case 't': - opts.option |= TEST_THP; - set_thp(&opts); - break; - default: - SYS_ERR_COND(1, "invalid argument to -o: '%s'\n", optarg); - break; - } - break; - case 'c': - opts.option |= TEST_ZLIB; - break; - case 'r': - opts.children = strtol(optarg, NULL, 0); - if (opts.children < 0) - show_help = 1; - break; - case 'k': - switch (optarg[0]) { - case 'b': - opts.faults |= INJECT_SIG_BIND; - break; - case 't': - opts.faults |= INJECT_TLB_FAULT; - break; - case 'w': - opts.faults |= INJECT_SIG_WORK; - break; - default: - SYS_ERR_COND(1, "invalid argument to -k: '%s'\n", optarg); - break; - } - break; - default: - show_help = parse_common_option(opt, optarg, &opts); - break; - } - } + show_help = parse_common_option(argc, argv, &opts);
signal(SIGBUS, handle_sigbus);
- if (!show_help) { - if (self) - return run_self_test(&opts); - return run_cmd(&opts); + if (show_help) { + SYS_ERR_COND(show_help || optind > argc, COMMON_HELP, argv[0]); + return 0; }
- SYS_ERR_COND(show_help || optind > argc, - COMMON_HELP - " -f <format> output format for the statistics\n" - " 'none' do not output statistics\n" - " 'pretty' human readable format\n" - " 'csv' raw, machine readable\n" - " -o <mode> options\n" - " 'perf' prefaults the output pages\n" - " 'thp' try to enable transparent huge pages\n" - " 'zlib' use zlib instead of the device\n" - " -r <children> number of children to create\n" - " -k <mode> kill thread\n" - " 'bind' kills the process after bind\n" - " 'tlb' tries to access an unmapped buffer\n" - " 'work' kills the process while the queue is working\n", - argv[0] - ); - return 0; + return run_cmd(&opts); } diff --git a/uadk_tool/test/comp_main.h b/uadk_tool/test/comp_main.h index dcf3980..2550b8d 100644 --- a/uadk_tool/test/comp_main.h +++ b/uadk_tool/test/comp_main.h @@ -1,9 +1,11 @@ /* SPDX-License-Identifier: Apache-2.0 */ +/* + * Copyright 2024 Huawei Technologies Co.,Ltd. All rights reserved. + */
#ifndef TEST_COMP_H #define TEST_COMP_H
- int test_comp_entry(int argc, char *argv[]);
-#endif /* TEST_COMP_H */ +#endif /* TEST_COMP_H */ \ No newline at end of file