summaryrefslogtreecommitdiffstats
path: root/pintos-progos/tests/intro/userprog-args/args-limit.c
blob: 159d8689d72a8974a3d9f86e90449e20cc5d9c3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* Test the limit for (1) number of arguments and (2) total size of arguments */
#include <syscall.h>
#include <string.h>
#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;
}