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
  
71
  
72
  
73
  
74
  
75
  
76
  
77
  
78
  
79
  
80
  
81
  
82
  
83
  
84
  
85
  
86
  
87
  
88
  
89
  
90
  
 
#pike __REAL_VERSION__ 
 
constant description = "Runs some built in Pike benchmarks."; 
constant help = #" 
Benchmarks Pike with %d built in benchmark tests. 
Arguments: 
 
-h, --help 
  Shows this help text. 
 
-m<number>, --max-runs=<number> 
  Runs a test at most <number> of times. Defaults to 25. 
 
-s<number>, --max-seconds=<number> 
  Runs a test at most <number> of seconds, rounded up to the closest 
  complete test. Defaults to 5. 
 
-t<glob>[,<glob>...], --tests=<glob>[,<glob>...] 
  Only run the specified tests. 
"; 
 
int(0..) main(int num, array(string) args) 
{ 
   mapping(string:Tools.Shoot.Test) tests=([]); 
   array results=({}); 
    
   foreach (indices(Tools.Shoot),string test) 
   { 
      program p; 
      Tools.Shoot.Test t; 
      if ((programp(p=Tools.Shoot[test])) &&  
          (t=p())->perform) 
         tests[test]=t; 
   } 
 
   int seconds_per_test = 5; 
   int maximum_runs = 25; 
   array(string) test_globs = ({"*"}); 
 
   foreach(Getopt.find_all_options(args, ({ 
     ({ "help",    Getopt.NO_ARG,  "-h,--help"/"," }), 
     ({ "maxrun",  Getopt.HAS_ARG, "-m,--max-runs"/"," }), 
     ({ "maxsec",  Getopt.HAS_ARG, "-s,--max-seconds"/"," }), 
     ({ "tests",   Getopt.HAS_ARG, "-t,--tests"/"," }), 
   })), array opt) 
    switch(opt[0]) 
    { 
      case "help": 
        write(help, sizeof(tests)); 
        return 0; 
      case "maxrun": 
        maximum_runs = (int)opt[1]; 
        break; 
      case "maxsec": 
        seconds_per_test = (int)opt[1]; 
        break; 
      case "tests": 
        test_globs = opt[1] / ","; 
    } 
 
   int ecode; 
   ecode += Tools.Shoot.ExecTest("Overhead",Tools.Shoot.Overhead()) 
     ->run(0,1,1); // fill caches 
 
   write("test                        total    user    mem   (runs)\n"); 
 
   /* Run overhead check first by default. */ 
   array(string) to_run = ({"Overhead"}) + (sort (indices (tests)) - ({"Overhead"})); 
   array(string) to_run_names = rows (tests, to_run)->name; 
 
   foreach (test_globs, string test_glob) 
     foreach (to_run; int idx; string id) 
       if (id) { 
         if (!to_run_names[idx]) { 
           write("No name on test %O!\n", id); 
           ecode++; 
           // Don't report the error multiple times. 
           to_run[idx] = 0; 
         } else if (glob (test_glob, to_run_names[idx])) { 
           ecode += Tools.Shoot.ExecTest(id,tests[id]) 
             ->run(seconds_per_test,maximum_runs); 
           // Don't run test more than once if it matches several globs. 
           to_run[idx] = 0; 
         } 
       } 
   return ecode; 
}