76d05c69c5ce8beef30506cef3b1d716fb1c3d13
[WebKit-https.git] / Websites / test-results / admin / index.php
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>WebKit Test Results</title>
5 <link rel="stylesheet" href="/common.css">
6 <style type="text/css">
7
8 .unfetched {
9     color: gray;
10 }
11
12 </style>
13 </head>
14 <body>
15 <header id="title">
16 <h1><a href="/">WebKit Test Results</a></h1>
17 <ul>
18     <li><a href="/admin/update-master">Update Master</a></li>
19 </ul>
20 </header>
21
22 <div id="mainContents">
23 <p><strong>FIXME: This page is broken!</strong></p>
24 <?php
25
26 require_once('../include/db.php');
27 require_once('../include/test-results.php');
28
29 function notice($message) {
30     echo "<p class='notice'>$message</p>";
31 }
32
33 define('MAX_FETCH_COUNT', 10);
34
35 function fetch_builders($db, $master) {
36     flush();
37     $builders_json = fetch_and_parse_test_results_json("http://$master/json/builders/");
38     if (!$builders_json)
39         return notice("Failed to fetch or decode /json/builders from $master");
40
41     echo "<h2>Fetching builds from $master</h2>\n";
42     echo "<ul>\n";
43
44     foreach ($builders_json as $builder_name => $builder_data) {
45         if (!stristr($builder_name, 'Test') || stristr($builder_name, 'Apple Win'))
46             continue;
47         $builder_id = $db->select_or_insert_row('builders', NULL, array('master' => $master, 'name' => $builder_name));
48         $escaped_builder_name = htmlspecialchars($builder_name);
49         echo "<li><em>$escaped_builder_name</em> (id: $builder_id) - ";
50
51         $fetchCount = 0;
52         $builds = $builder_data['cachedBuilds'];
53         foreach (array_reverse($builds) as $build_number) {
54             $build_number = intval($build_number);
55             $build = $db->select_or_insert_row('builds', NULL, array('builder' => $builder_id, 'number' => $build_number), NULL, '*');
56             if ($db->is_true($build['fetched']))
57                 $class = 'fetched';
58             else if ($fetchCount >= MAX_FETCH_COUNT)
59                 $class = 'unfetched';
60             else {
61                 $class = fetch_build($db, $master, $builder_name, $build['id'], $build_number) ? 'fetched' : 'unfetched';
62                 $fetchCount++;
63             }
64             echo "<span class=\"$class\">$build_number</a> ";
65         }
66         echo "</li>\n";
67     }
68     echo "<ul>\n";
69
70     return TRUE;
71 }
72
73 function urlencode_without_plus($url) {
74     return str_replace('+', '%20', urlencode($url));
75 }
76
77 function fetch_build($db, $master, $builder_name, $build_id, $build_number) {
78     flush();
79     $builder_name = urlencode_without_plus($builder_name);
80     $build_json = fetch_and_parse_test_results_json("http://$master/json/builders/$builder_name/builds/$build_number");
81     if (!$build_json || !array_key_exists('times', $build_json) || count($build_json['times']) != 2)
82         return FALSE;
83
84     $revision = NULL;
85     $slavename = NULL;
86     foreach ($build_json['properties'] as $property) {
87         if ($property[0] == 'got_revision')
88             $revision = $property[1];
89         if ($property[0] == 'slavename')
90             $slavename = $property[2];
91     }
92     if (!$revision || !$slavename)
93         return FALSE;
94
95     $start_time = float_to_time($build_json['times'][0]);
96     $end_time = float_to_time($build_json['times'][1]);
97
98     flush();
99     $full_results = fetch_and_parse_test_results_json("http://$master/results/$builder_name/r$revision%20($build_number)/full_results.json", TRUE);
100     return store_test_results($db, $full_results, $build_id, $revision, $start_time, $end_time, $slavename);
101 }
102
103 $db = new Database;
104 if (!$db->connect())
105     notice('Failed to connect to the database');
106 else if (array_key_exists('master', $_GET)) {
107     $master = htmlspecialchars($_GET['master']); // Okay since hostname shoudln't contain any HTML special characters.
108     if (in_array($master, config('masters')))
109         fetch_builders($db, $master);
110     else
111         notice("The master $master not found");
112 } else {
113     echo "<ul>\n";
114     foreach (config('masters') as $master)
115         echo "<li><a href=\"?master=$master\">$master</a></li>\n";
116     echo "</ul>\n";
117 }
118
119 ?></div>
120
121 </body>
122 </html>