2 /*-------------------------------------------------------------------------
3 regtests.php - regression tests page
5 Copyright (C) 2011, 2012, Borut Razem <borut.razem AT gmail.com>
7 This program is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2.1, or (at your option) any
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this library; see the file COPYING. If not, write to the
19 Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
21 -------------------------------------------------------------------------*/
23 $ini = parse_ini_file('sdcc.ini');
24 $regTestDb = new mysqli($ini['host'], $ini['username'], $ini['passwd'], $ini['dbname']);
26 $query = 'SELECT DISTINCT `platform` FROM `regtest_results`';
28 $result = $regTestDb->query($query);
32 while ($row = $result->fetch_array(MYSQLI_NUM
)) {
33 $platforms[] = $row[0];
38 $query = 'SELECT DISTINCT `target` FROM `regtest_results`';
40 $result = $regTestDb->query($query);
44 while ($row = $result->fetch_array(MYSQLI_NUM
)) {
52 function genForm($id, $platforms, $targets)
54 echo(' <form action="" class="diff" id="' . $id . "\" method=\"post\">\n");
58 <td align="right"><label for="date">Build date:</label></td>
59 <td><input name="date" id="{$id}_date" class="date-pick" /></td>
62 <td align="right">Build number:</td>
70 <td align="right">Platform:</td>
72 <select name="platform">
75 foreach ($platforms as $platform) {
76 echo(' <option value="' . $platform . '">' . $platform . "</option>\n");
84 <td align="right">Target:</td>
86 <select name="target">
89 foreach ($targets as $target) {
90 echo(' <option value="' . $target . '">' . $target . "</option>\n");
98 <!-- <button class="button positive"> <img src="../images/icons/tick.png" alt=""> Add Client </button> -->
103 <!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
104 <html xmlns
="http://www.w3.org/1999/xhtml" xml
:lang
="en" lang
="en">
106 <meta content
="text/html; charset=UTF-8" http
-equiv
="content-type" />
107 <title
>SDCC
- Regression Tests
</title
>
108 <link type
="text/css" href
="styles/style.css" rel
="stylesheet" />
109 <link rel
="shortcut icon" type
="image/x-icon" href
="/images/sdcc.ico" />
110 <link rel
="icon" type
="image/svg+xml" href
="/images/sdcc.svg">
112 <script type
="text/javascript" src
="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script
>
113 <!-- required plugins
-->
114 <script type
="text/javascript" src
="scripts/date.js"></script
>
115 <!-- jquery
.datePicker
.js
-->
116 <script type
="text/javascript" src
="scripts/jquery.datePicker.js"></script
>
117 <!-- datePicker required styles
-->
118 <link rel
="stylesheet" type
="text/css" media
="screen" href
="styles/datePicker.css"></link
>
119 <!-- jquery
.tablesorter
.js
-->
120 <script type
="text/javascript" src
="scripts/jquery.tablesorter.js"></script
>
121 <!-- tablesorter required styles
-->
122 <link rel
="stylesheet" type
="text/css" media
="screen" href
="styles/tablesorter.css"></link
>
123 <!-- page specific scripts
-->
124 <script type
="text/javascript" charset
="utf-8">
126 Date
.format
= 'yyyy-mm-dd';
129 $
('.date-pick').datePicker(
131 startDate
: '1970-01-01',
132 endDate
: (new Date()).asString()
137 function validateBuildDate(date
)
139 // validate the build date
140 if (!/^\d
{4}-\d
{2}-\d
{2}$
/.test(date
)) {
141 alert("Bad build date!\n");
147 function validateBuildNumber(build
)
149 // validate the build number
150 if (!/^\d+$
/.test(build
)) {
151 alert("Bad build number!\n");
157 function validateTarget(target
)
159 // validate the target
160 var targets
= [ <?php
echo('"' . implode('", "', $targets) . '"'); ?
> ];
162 var is_target
= false;
163 for (var i
= 0; i
< targets
.length
; ++i
) {
164 if (targets
[i
] == target
) {
170 alert("Bad / unknown target!\n");
176 function validateFormOnSubmit(theForm
)
178 var date
= theForm
.date
.value
;
179 var build
= theForm
.build
.value
;
180 var platform
= theForm
.platform
.value
;
182 if (validateBuildDate(date
) && validateBuildNumber(build
)) {
183 // validate the platform
184 var platforms
= [ <?php
echo('"' . implode('", "', $platforms) . '"'); ?
> ];
186 var is_platform
= false;
187 for (var i
= 0; i
< platforms
.length
; ++i
) {
188 if (platforms
[i
] == platform
) {
204 function validateFormOnSubmitTarget(theForm
)
206 var target
= theForm
.target
.value
;
208 ret
= validateFormOnSubmit(theForm
);
210 if (ret
&& validateTarget(target
)) {
211 ret
['target'] = target
;
219 function keyArray(obj
) {
221 $
.each(obj
, function(key
)
228 function genHiddenWhere(theForm
)
230 var val
= validateFormOnSubmit(theForm
);
232 var whereFirst
= true;
233 $
.each(val
, function(key
)
241 where +
= '`' + key +
"` = '" + val
[key
] +
"' ";
244 theForm
.where
.value
= where
;
250 // http://www.webtoolkit.info/scrollable-html-table-plugin-for-jquery.html
251 jQuery.fn.Scrollable = function(tableHeight, tableWidth) {
252 this.each(function(){
253 if (jQuery.browser.msie || jQuery.browser.mozilla) {
254 var table = new ScrollableTable(this, tableHeight, tableWidth);
260 function htmlTable (data
)
264 ret +
= '<table id="dataTable" class="tablesorter"><thead><tr>';
265 var keys
= keyArray(data
[0]);
266 for (var i
= 0; i
< keys
.length
; ++i
) {
267 ret +
= '<th>' + keys
[i
] +
'</th>';
269 ret +
= '</tr></thead>';
271 for (var i
= 0; i
< data
.length
; ++i
) {
273 $
.each(data
[i
], function(key
)
275 ret +
= '<td>' + data
[i
][key
] +
'</td>';
285 function composeQuery(data
)
287 var fields
= [ 'failures', 'tests', 'cases', 'bytes', 'ticks' ];
289 var select
= 'SELECT `t0`.`regtest_name`, ';
290 var from
= ' FROM `regtest_results` AS t0 ';
292 var where
= 'WHERE ';
295 var whereFirst
= true;
296 for (var i
= 0; i
< data
.length
; ++i
) {
297 for (var j
= 0; j
< fields
.length
; ++j
) {
304 select +
= '`t' + i +
'`.`' + fields
[j
] +
'` AS `' + fields
[j
] + i +
'`'
307 from +
= 'JOIN `regtest_results` AS t' + i +
' ';
311 on +
= '`t' + i +
'`.`regtest_name` = `t0`.`regtest_name` ';
314 $
.each(data
[i
], function(key
)
322 where +
= '`t' + i +
'`.`' + key +
"` = '" + data
[i
][key
] +
"' ";
325 query
= select + from + on + where
;
330 function buttonClick()
332 $
('body').css('cursor', 'wait')
335 $
('form.diff').each(function()
337 params
.push(validateFormOnSubmitTarget(this
));
340 var query
= composeQuery(params
);
345 url
: 'get_regtest.php',
347 data
: { query
: query
},
348 success
: function(data
) {
349 $
('div.success').replaceWith('<div class="success">' +
((data
.length
> 0) ?
htmlTable(data
) : 'No data available!') +
'</div>');
350 $
('body').css('cursor','auto');
351 $
("#dataTable").tablesorter({
362 $(document).ready(function()
364 jQuery('table').Scrollable(200, 800);
369 $
("input.date-pick").change(function() {
370 if (this
.value
!= '' && validateBuildDate(this
.value
)) {
371 var me
= this
.form
.build
;
373 // delete previous content
377 url
: 'get_regtest.php',
379 data
: {query
: 'SELECT DISTINCT `build_number` FROM `regtest_results` WHERE `date` = \'' + this
.value +
'\''},
380 success
: function(data
) {
382 for (var i
= 0; i
< data
.length
; i++
) {
383 options +
= '<option value="' + data
[i
].build_number +
'">' + data
[i
].build_number +
'</option>';
385 me
.innerHTML
= options
;
393 <style type
="text/css">
394 /* located in demo.css and creates a little calendar icon
395 * instead of a text link for "Choose date"
404 text
-indent
: -2000px
;
406 background
: url(images
/timespan
.png
) no
-repeat
;
408 a
.dp
-choose
-date
.dp
-disabled
{
409 background
-position
: 0 -20px
;
412 /* makes the input field shorter once the date picker code
413 * has run (to allow space for the calendar icon
421 <body bgcolor
="white" link
="teal" vlink
="#483d8b">
423 <h1
>SDCC
- Regression Tests
</h1
>
424 <table border
="0" cellpadding
="2" cellspacing
="1" width
="100%" bgcolor
="white">
427 <td width
="15%" valign
="top"><?php
echo(file_get_contents('./left_menu.inc'));?
></td
>
428 <td valign
="top" width
="85%">
429 <h2
><a name
="Database"></a
>Regression Tests Database
</h2
>
431 Download full
<a href
="download_regtests_db.php?compress=bz2">regression test results database
</a
> in csv
.bz2 format
.
433 <form name
="regtest" onsubmit
="return genHiddenWhere(this)" action
="download_regtests_db.php" method
="post">
434 Download regression test results in csv format
for<br
/>
437 <td align
="right"><label
for="date">Build date
:</label
></td
>
438 <td
><input name
="date" id
="date" class="date-pick" /></td
>
441 <td align
="right">Build number
:</td
>
443 <select name
="build">
449 <td align
="right">Platform
:</td
>
451 <select name
="platform">
453 foreach ($platforms as $platform) {
454 echo(' <option value="' . $platform . '">' . $platform . "</option>\n");
461 <input type
="hidden" name
="where" />
462 <input type
="submit" value
="Download CSV" />
464 <h2
><a name
="Diffs"></a
>Regression Tests Diffs
</h2
>
469 genForm('form1', $platforms, $targets);
474 genForm('form2', $platforms, $targets);
479 <button id
="form" class="button positive" onclick
="return buttonClick()">Show table
</button
>
480 <!-- placeholder
for table
-->
481 <div
class="success"></div
>
482 <?php
include('./footer.php')?
>