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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
|
<?php
define("VERSION", "1");
define("CORE_CLIENT", "boinc_".VERSION."_$BOINC_PLATFORM");
define("PROJECTS", "localhost.localdomain zoot");
function clear_db() {
PassThru("cd ../db; init_db");
}
$BOINC_DOWNLOAD_DIR = null;
$BOINC_UPLOAD_DIR = null;
$BOINC_PLATFORM = null;
$BOINC_EMAIL = null;
$BOINC_DOWNLOAD_URL = null;
$BOINC_KEY_DIR = null;
$BOINC_MASTER_URL = null;
$BOINC_DB_NAME = null;
function open_db() {
global $BOINC_DB_NAME;
$retval = mysql_connect();
if (!$retval) {
echo "mysql_connect() failed\n";
exit();
}
$retval = mysql_select_db($BOINC_DB_NAME);
if (!$retval) {
echo "mysql_select_db() failed\n";
exit();
}
}
function check_env_vars() {
global $BOINC_DOWNLOAD_DIR;
global $BOINC_UPLOAD_DIR;
global $BOINC_PLATFORM;
global $BOINC_EMAIL;
global $BOINC_DOWNLOAD_URL;
global $BOINC_KEY_DIR;
global $BOINC_MASTER_URL;
global $BOINC_DB_NAME;
$bad = false;
$BOINC_DOWNLOAD_DIR = getenv("BOINC_DOWNLOAD_DIR");
if ($BOINC_DOWNLOAD_DIR == null) {
echo "Must define BOINC_DOWNLOAD_DIR\n";
$bad = true;
}
$BOINC_UPLOAD_DIR = getenv("BOINC_UPLOAD_DIR");
if ($BOINC_UPLOAD_DIR == null) {
echo "Must define BOINC_UPLOAD_DIR\n";
$bad = true;
}
$BOINC_PLATFORM = getenv("BOINC_PLATFORM");
if ($BOINC_PLATFORM == null) {
echo "Must define BOINC_PLATFORM\n";
$bad = true;
}
$BOINC_EMAIL = getenv("BOINC_EMAIL");
if ($BOINC_EMAIL == null) {
echo "Must define BOINC_EMAIL\n";
$bad = true;
}
$BOINC_DOWNLOAD_URL = getenv("BOINC_DOWNLOAD_URL");
if ($BOINC_DOWNLOAD_URL == null) {
echo "Must define BOINC_DOWNLOAD_URL\n";
$bad = true;
}
$BOINC_KEY_DIR = getenv("BOINC_KEY_DIR");
if ($BOINC_KEY_DIR == null) {
echo "Must define BOINC_KEY_DIR\n";
$bad = true;
}
$BOINC_MASTER_URL = getenv("BOINC_MASTER_URL");
if ($BOINC_MASTER_URL == null) {
echo "Must define BOINC_MASTER_URL\n";
$bad = true;
}
$BOINC_DB_NAME = getenv("BOINC_DB_NAME");
if ($BOINC_DB_NAME == null) {
echo "Must define BOINC_DB_NAME\n";
$bad = true;
}
if ($bad) exit();
}
function clear_server_dirs($clear_key_dir) {
global $BOINC_DOWNLOAD_DIR;
global $BOINC_UPLOAD_DIR;
global $BOINC_KEY_DIR;
$bad = false;
if ($BOINC_DOWNLOAD_DIR == null) {
echo "Must define BOINC_DOWNLOAD_DIR\n";
$bad = true;
}
if ($BOINC_UPLOAD_DIR == null) {
echo "Must define BOINC_UPLOAD_DIR\n";
$bad = true;
}
if ($BOINC_KEY_DIR == null) {
echo "Must define BOINC_KEY_DIR\n";
$bad = true;
}
if ($bad) exit();
PassThru("rm -f $BOINC_DOWNLOAD_DIR/*");
PassThru("rm -f $BOINC_UPLOAD_DIR/*");
if ($clear_key_dir) {
PassThru("rm -f $BOINC_KEY_DIR/*");
}
}
function clear_client_dirs() {
PassThru("rm -rf projects/*" );
}
function init_client_dirs($prefs_file, $account_file) {
global $BOINC_MASTER_URL;
PassThru("rm -f client_state.xml");
PassThru("rm -rf ".PROJECTS);
PassThru("rm -rf slots");
PassThru("cp $prefs_file prefs.xml");
PassThru("sed -e s/BOINC_MASTER_URL/$BOINC_MASTER_URL/ $account_file > account_foo.xml");
}
function copy_to_download_dir($f) {
global $BOINC_DOWNLOAD_DIR;
PassThru("cp $f $BOINC_DOWNLOAD_DIR");
}
function add_user($global_prefs_file) {
global $BOINC_EMAIL;
global $BOINC_MASTER_URL;
$cmd = "../tools/add user -email_addr $BOINC_EMAIL -user_name David -web_password foobar -authenticator 3f7b90793a0175ad0bda68684e8bd136 ";
if ($global_prefs_file) {
PassThru("sed -e s/BOINC_MASTER_URL/$BOINC_MASTER_URL/ $global_prefs_file > prefs_temp.xml");
$cmd = $cmd." -global_prefs_file prefs_temp.xml";
}
PassThru($cmd);
}
function add_project($short_name,$long_name) {
PassThru("../tools/add project -project_short_name '$short_name' -project_long_name '$long_name'");
}
function add_platform($platform) {
global $BOINC_PLATFORM;
if( $platform ) {
PassThru("../tools/add platform -platform_name $platform");
} else {
PassThru("../tools/add platform -platform_name $BOINC_PLATFORM");
}
}
function add_core_client_message($message, $priority, $platform) {
global $BOINC_DOWNLOAD_DIR;
global $BOINC_UPLOAD_DIR;
global $BOINC_PLATFORM;
global $BOINC_KEY_DIR;
if( $platform == null ) {
$plat = $BOINC_PLATFORM;
} else {
$plat = $platform;
}
PassThru("../tools/add app -app_name core_client -version ".VERSION);
$cmd = "../tools/add app_version -app_name core_client -platform_name $plat -version ".VERSION." -download_dir $BOINC_DOWNLOAD_DIR -download_url $BOINC_DOWNLOAD_URL -message '$message' -message_priority '$priority' -code_sign_keyfile $BOINC_KEY_DIR/code_sign_private -exec_dir ../client -exec_files ".CORE_CLIENT;
//echo "$cmd\n";
PassThru($cmd);
PassThru("cp ../client/".CORE_CLIENT." $BOINC_DOWNLOAD_DIR");
}
function add_core_client($platform) {
add_core_client_message("", "", $platform);
}
function add_app($name, $platform, $exec_name) {
PassThru("../tools/add app -app_name $name -version ".VERSION);
add_app_version( $name, $platform, $exec_name );
}
function add_app_version($name, $platform, $exec_name) {
global $BOINC_DOWNLOAD_DIR;
global $BOINC_PLATFORM;
global $BOINC_DOWNLOAD_URL;
global $BOINC_KEY_DIR;
if( $exec_name == null ) {
$exec_name = $name;
}
if( $platform == null ) {
$plat = $BOINC_PLATFORM;
} else {
$plat = $platform;
}
$cmd = "../tools/add app_version -app_name $name -platform_name $plat -version ".VERSION." -download_dir $BOINC_DOWNLOAD_DIR -download_url $BOINC_DOWNLOAD_URL -code_sign_keyfile $BOINC_KEY_DIR/code_sign_private -exec_dir ../apps -exec_files $exec_name";
//echo "$cmd\n";
PassThru($cmd);
PassThru("cp ../apps/$exec_name $BOINC_DOWNLOAD_DIR");
}
function create_work($x) {
global $BOINC_KEY_DIR;
PassThru("../tools/create_work -keyfile $BOINC_KEY_DIR/upload_private $x");
}
function create_keys() {
global $BOINC_KEY_DIR;
PassThru("../lib/crypt_prog -genkey 1024 $BOINC_KEY_DIR/upload_private $BOINC_KEY_DIR/upload_public");
PassThru("../lib/crypt_prog -genkey 1024 $BOINC_KEY_DIR/code_sign_private $BOINC_KEY_DIR/code_sign_public");
}
function run_client($args) {
PassThru("../client/".CORE_CLIENT." $args");
}
function start_feeder() {
PassThru("cd ../sched; feeder -asynch > feeder_out");
}
function stop_feeder() {
$f = fopen("../sched/feeder_trigger", "w");
fputs($f, "<quit/>\n");
fclose($f);
}
function compare_file($out, $correct) {
global $BOINC_UPLOAD_DIR;
PassThru("diff $BOINC_UPLOAD_DIR/$out $correct", $retval);
if ($retval) {
echo "File mismatch: $out $correct\n";
} else {
echo "Files match: $out $correct\n";
}
}
function check_results_done() {
open_db();
$result = mysql_query("select * from result where state<>4");
while ($x = mysql_fetch_object($result)) {
echo "result $x->id is not done\n";
}
}
function num_wus_left() {
open_db();
$numwus = mysql_query("select count(*) as nres from result where state<>4");
$result = mysql_fetch_object($numwus);
return $result->nres;
}
function compare_files($out, $correct) {
PassThru("diff $out $correct", $retval);
if ($retval) {
echo "File mismatch: $out $correct\n";
} else {
echo "Files match: $out $correct\n";
}
}
function run_api_test() {
PassThru("../api/api_test");
}
function clean_api() {
PassThru("rm -f counter app_to_core.xml core_to_app.xml foobar");
}
function get_time($file_name) {
$time_file = fopen($file_name, "r");
if($time_file == NULL) return 0;
fscanf($time_file, "%f", $app_time);
PassThru("rm -f ".$file_name);
return $app_time;
}
function compare_time($app_time) {
$epsilon = 0.0001;
open_db();
$data = mysql_query("select cpu_time from result where name = 'uccpu_wu_0'");
$result = mysql_fetch_object($data);
$db_time = $result->cpu_time;
$client_time = get_time("client_time");
if(abs($app_time - $client_time) > $epsilon) {
printf("Time mismatch: app %f client %f\n", $app_time, $client_time);
}
else {
printf("Client time %f matches app time %f\n", $client_time, $app_time)
;
}
if(abs($db_time - $app_time) > $epsilon) {
printf("Time mismatch: client %f server %f\n", $client_time, $db_time);
}
else {
printf("Reported time %f matches client time %f\n", $db_time, $client_time);
}
PassThru("rm -f client_time app_time");
}
?>
|