diff options
Diffstat (limited to 'pintos-progos/tests/intro/userprog-args/args-limit.c')
| -rw-r--r-- | pintos-progos/tests/intro/userprog-args/args-limit.c | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/pintos-progos/tests/intro/userprog-args/args-limit.c b/pintos-progos/tests/intro/userprog-args/args-limit.c new file mode 100644 index 0000000..159d868 --- /dev/null +++ b/pintos-progos/tests/intro/userprog-args/args-limit.c | |||
| @@ -0,0 +1,70 @@ | |||
| 1 | /* Test the limit for (1) number of arguments and (2) total size of arguments */ | ||
| 2 | #include <syscall.h> | ||
| 3 | #include <string.h> | ||
| 4 | #include "tests/lib.h" | ||
| 5 | |||
| 6 | #define MAX_SIZE 4096 | ||
| 7 | |||
| 8 | static bool recurse (int, int); | ||
| 9 | |||
| 10 | char cmd[MAX_SIZE * 4]; | ||
| 11 | |||
| 12 | static bool | ||
| 13 | recurse (int argsize, int argcount) | ||
| 14 | { | ||
| 15 | int i, j; | ||
| 16 | char *p; | ||
| 17 | strlcpy (cmd, "args-limit", 11); | ||
| 18 | p = cmd+strlen(cmd); | ||
| 19 | for (i = 0; i < argcount; i++) { | ||
| 20 | *p++ = ' '; | ||
| 21 | for (j = 0; j < argsize; j++) { | ||
| 22 | *p++ = 'X'; | ||
| 23 | } | ||
| 24 | } | ||
| 25 | *p = 0; | ||
| 26 | if (wait (exec (cmd)) < 0) { | ||
| 27 | return false; | ||
| 28 | } else { | ||
| 29 | return true; | ||
| 30 | } | ||
| 31 | } | ||
| 32 | |||
| 33 | int | ||
| 34 | main (int argc, char **argv) | ||
| 35 | { | ||
| 36 | test_name = argv[0]; | ||
| 37 | if(argc <= 1) { | ||
| 38 | int step; | ||
| 39 | int max_args = 0, max_size = 0; | ||
| 40 | |||
| 41 | msg ("begin"); | ||
| 42 | |||
| 43 | /* Binary search number of arguments */ | ||
| 44 | for (step = MAX_SIZE; step > 0 && max_args < MAX_SIZE; step>>=1) { | ||
| 45 | int t = max_args + step; | ||
| 46 | if (recurse (1, t)) { | ||
| 47 | max_args = t; | ||
| 48 | } | ||
| 49 | } | ||
| 50 | if (max_args > 63) { | ||
| 51 | msg ("success. at least 64 command line arguments are supported."); | ||
| 52 | } else { | ||
| 53 | msg ("FAIL: Only %d command line arguments are supported",max_args); | ||
| 54 | } | ||
| 55 | /* Binary search size of arguments */ | ||
| 56 | for (step = MAX_SIZE; step > 0 && max_size < MAX_SIZE; step>>=1) { | ||
| 57 | int t = max_size + step; | ||
| 58 | if (recurse (t, 1)) { | ||
| 59 | max_size = t; | ||
| 60 | } | ||
| 61 | } | ||
| 62 | if (max_size >= 100) { | ||
| 63 | msg ("success. arguments with at least 100 bytes are supported."); | ||
| 64 | } else { | ||
| 65 | msg ("FAIL: Arguments with more than %d bytes are not supported.",max_size); | ||
| 66 | } | ||
| 67 | msg ("end"); | ||
| 68 | } | ||
| 69 | return 0; | ||
| 70 | } | ||
