From 4f670845ff9ab6c48bcb5f7bf4d4ef6dc3c3064b Mon Sep 17 00:00:00 2001 From: manuel Date: Tue, 27 Mar 2012 11:51:08 +0200 Subject: reorganize file structure to match the upstream requirements --- tests/intro/userprog-args/args-limit.c | 70 ++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 tests/intro/userprog-args/args-limit.c (limited to 'tests/intro/userprog-args/args-limit.c') diff --git a/tests/intro/userprog-args/args-limit.c b/tests/intro/userprog-args/args-limit.c new file mode 100644 index 0000000..159d868 --- /dev/null +++ b/tests/intro/userprog-args/args-limit.c @@ -0,0 +1,70 @@ +/* Test the limit for (1) number of arguments and (2) total size of arguments */ +#include +#include +#include "tests/lib.h" + +#define MAX_SIZE 4096 + +static bool recurse (int, int); + +char cmd[MAX_SIZE * 4]; + +static bool +recurse (int argsize, int argcount) +{ + int i, j; + char *p; + strlcpy (cmd, "args-limit", 11); + p = cmd+strlen(cmd); + for (i = 0; i < argcount; i++) { + *p++ = ' '; + for (j = 0; j < argsize; j++) { + *p++ = 'X'; + } + } + *p = 0; + if (wait (exec (cmd)) < 0) { + return false; + } else { + return true; + } +} + +int +main (int argc, char **argv) +{ + test_name = argv[0]; + if(argc <= 1) { + int step; + int max_args = 0, max_size = 0; + + msg ("begin"); + + /* Binary search number of arguments */ + for (step = MAX_SIZE; step > 0 && max_args < MAX_SIZE; step>>=1) { + int t = max_args + step; + if (recurse (1, t)) { + max_args = t; + } + } + if (max_args > 63) { + msg ("success. at least 64 command line arguments are supported."); + } else { + msg ("FAIL: Only %d command line arguments are supported",max_args); + } + /* Binary search size of arguments */ + for (step = MAX_SIZE; step > 0 && max_size < MAX_SIZE; step>>=1) { + int t = max_size + step; + if (recurse (t, 1)) { + max_size = t; + } + } + if (max_size >= 100) { + msg ("success. arguments with at least 100 bytes are supported."); + } else { + msg ("FAIL: Arguments with more than %d bytes are not supported.",max_size); + } + msg ("end"); + } + return 0; +} -- cgit v1.2.3