From 776215b3a0ceb7b7f9524d37b0c120f0f39b090e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Bollo?= Date: Wed, 5 Feb 2014 14:27:53 +0100 Subject: [PATCH] Adding a program generating test data. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The program that generate this gen.c produces a set of rules to be loaded to load/load2 file system interace of smacke. Or to be used as input file for smackload. The count of differents labels (option l=N) and of different access rights (option r=N) can be specified. The count of rules produced to the ouput can also be specified (option o=N). By default, l=5, r=100 and o=500. The generated labels are made of 4 to 7 random letters. The standard C function 'rand' is used without seeding it; what means that same options produces same results. Signed-off-by: José Bollo --- tests/gen.c | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 tests/gen.c diff --git a/tests/gen.c b/tests/gen.c new file mode 100644 index 0000000..b65b07a --- /dev/null +++ b/tests/gen.c @@ -0,0 +1,112 @@ +#include +#include +#include + +int r(int count) { + return random() % count; +} + +int cb(int n) { + int result = 0; + while(n) { + result += n & 1; + n >>= 1; + } + return result; +} + +int rc(int ref) { + int nb = 6 - cb(ref); + int b = r(1 << nb); + int iter = 1; + int result = 0; + while(nb) { + if (!(iter & ref)) { + if (b & 1) + result |= iter; + b >>= 1; + nb--; + } + iter <<= 1; + } + return result; +} + +void* check(void *ptr) { + if(!ptr){ + fprintf(stderr,"memory depletion!\n"); + exit(1); + } + return ptr; +} + +char** genlabels(int count, int lenmin, int lenmax) { + char **result; + int i; + result = check(calloc(sizeof*result,count)); + for(i=0;i>= 1; + } + if (!len) buffer[len++] = '-'; + return len; +} + +char** genrights(int count) { + char buffer[20]; + char **result; + int i; + result = check(calloc(sizeof*result,count)); + for(i=0;i0) { + switch(c) { + case 'l': nlab=n; break; + case 'r': nrig=n; break; + case 'o': nout=n; break; + } + } + else { + fprintf(stderr,"usage: gen [[lro]=VALUE]... (where VALUE is a number > 0)\n"); + exit(1); + } + } + labels = genlabels(nlab,4,8); + rights = genrights(nrig); + while(nout--) + printf("%s %s %s\n", labels[r(nlab)], labels[r(nlab)], rights[r(nrig)]); + return 0; +} + -- 2.7.4