]>
git.proxmox.com Git - ceph.git/blob - ceph/src/zstd/tests/datagencli.c
2 * Copyright (c) 2015-present, Yann Collet, Facebook, Inc.
5 * This source code is licensed under both the BSD-style license (found in the
6 * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7 * in the COPYING file in the root directory of this source tree).
8 * You may select, at your option, one of the above-listed licenses.
12 /*-************************************
14 **************************************/
15 #include "util.h" /* Compiler options */
16 #include <stdio.h> /* fprintf, stderr */
17 #include "datagen.h" /* RDG_generate */
20 /*-************************************
22 **************************************/
27 #define SIZE_DEFAULT ((64 KB) + 1)
28 #define SEED_DEFAULT 0
29 #define COMPRESSIBILITY_DEFAULT 50
32 /*-************************************
34 **************************************/
35 #define DISPLAY(...) fprintf(stderr, __VA_ARGS__)
36 #define DISPLAYLEVEL(l, ...) if (displayLevel>=l) { DISPLAY(__VA_ARGS__); }
37 static unsigned displayLevel
= 2;
40 /*-*******************************************************
42 *********************************************************/
43 static int usage(const char* programName
)
45 DISPLAY( "Compressible data generator\n");
46 DISPLAY( "Usage :\n");
47 DISPLAY( " %s [args]\n", programName
);
49 DISPLAY( "Arguments :\n");
50 DISPLAY( " -g# : generate # data (default:%i)\n", SIZE_DEFAULT
);
51 DISPLAY( " -s# : Select seed (default:%i)\n", SEED_DEFAULT
);
52 DISPLAY( " -P# : Select compressibility in %% (default:%i%%)\n",
53 COMPRESSIBILITY_DEFAULT
);
54 DISPLAY( " -h : display help and exit\n");
59 int main(int argc
, const char** argv
)
61 unsigned probaU32
= COMPRESSIBILITY_DEFAULT
;
62 double litProba
= 0.0;
63 U64 size
= SIZE_DEFAULT
;
64 U32 seed
= SEED_DEFAULT
;
65 const char* const programName
= argv
[0];
68 for(argNb
=1; argNb
<argc
; argNb
++) {
69 const char* argument
= argv
[argNb
];
71 if(!argument
) continue; /* Protection if argument empty */
73 /* Handle commands. Aggregated commands are allowed */
76 while (*argument
!=0) {
80 return usage(programName
);
84 while ((*argument
>='0') && (*argument
<='9'))
85 size
*= 10, size
+= *argument
++ - '0';
86 if (*argument
=='K') { size
<<= 10; argument
++; }
87 if (*argument
=='M') { size
<<= 20; argument
++; }
88 if (*argument
=='G') { size
<<= 30; argument
++; }
89 if (*argument
=='B') { argument
++; }
94 while ((*argument
>='0') && (*argument
<='9'))
95 seed
*= 10, seed
+= *argument
++ - '0';
100 while ((*argument
>='0') && (*argument
<='9'))
101 probaU32
*= 10, probaU32
+= *argument
++ - '0';
102 if (probaU32
>100) probaU32
= 100;
104 case 'L': /* hidden argument : Literal distribution probability */
107 while ((*argument
>='0') && (*argument
<='9'))
108 litProba
*= 10, litProba
+= *argument
++ - '0';
109 if (litProba
>100.) litProba
=100.;
117 return usage(programName
);
119 } } } /* for(argNb=1; argNb<argc; argNb++) */
121 DISPLAYLEVEL(4, "Compressible data Generator \n");
122 if (probaU32
!=COMPRESSIBILITY_DEFAULT
)
123 DISPLAYLEVEL(3, "Compressibility : %i%%\n", probaU32
);
124 DISPLAYLEVEL(3, "Seed = %u \n", (unsigned)seed
);
126 RDG_genStdout(size
, (double)probaU32
/100, litProba
, seed
);
127 DISPLAYLEVEL(1, "\n");