From 2080130c6770ee90ad4127f95e4034e741d3853c Mon Sep 17 00:00:00 2001 From: Hamid Aghdaee Date: Fri, 8 Nov 2002 23:53:56 +0000 Subject: [PATCH] Added a few functions two test.inc, host. Host has now run_asynch, which will fork off a new process that will run the client. host->kill waits for $time seconds and then kill the $pid specified. host->get_new_boincpid will block until there's a new client running different from the pid specified and then return the pid of this new process. svn path=/trunk/boinc/; revision=589 --- test/test.inc | 53 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 6 deletions(-) diff --git a/test/test.inc b/test/test.inc index 0123f8b226..df128bca13 100644 --- a/test/test.inc +++ b/test/test.inc @@ -400,19 +400,60 @@ class Host { PassThru("cp $this->global_prefs.xml $this->host_dir/global_prefs.xml"); } } + + function kill($boinc_pid,$time) + { + assert($boinc_pid != null); + if($time != null) + { + echo "\nsleepinf for $time seconds"; + PassThru("sleep $time"); + } - function run($args) { - echo "Running core client\n"; - $source_dir = get_env_var("BOINC_SRC_DIR"); - $platform = get_env_var("BOINC_PLATFORM"); - PassThru("cd $this->host_dir; $source_dir/client/boinc_0.02_$platform $args> client.out"); + PassThru("kill -9 $boinc_pid"); + } + + //forks off a new process to run this host with the given $args. the pid returned is the pid of the newly forked php process. + + //NOTE: to kill the newly started host, get_new_boincpid() must be called and kill() must be called on it. + function run_asynch($args) { + $pid = pcntl_fork(); + if ($pid == -1) { + return -1; + } else if ($pid) { + return $pid; // we are the parent + } else { //we are the child + echo "\nRunning core client asynch\n"; + $source_dir = get_env_var("BOINC_SRC_DIR"); + $platform = get_env_var("BOINC_PLATFORM"); + + PassThru("cd $this->host_dir; $source_dir/client/boinc_0.02_$platform $args > client.out"); + exit(0); + } } + //returns a pid for a boinc process running in the system that is different from $boinc_pid. This call blocks until such process is started. + function get_new_boincpid($boinc_pid) + { + while(true) + { + $pid = exec("pgrep -n boinc"); + if(($pid != null) && ($pid != $boinc_pid)) + return $pid; + } + } + function run($args) + { + echo "\nRunning core client\n"; + $source_dir = get_env_var("BOINC_SRC_DIR"); + $platform = get_env_var("BOINC_PLATFORM"); + PassThru("cd $this->host_dir; $source_dir/client/boinc_0.02_$platform $args > client.out"); + } // read a CPU time file written by the client. // This is sort of a kludge. // function read_cpu_time_file($file_name) { - $time_file = fopen($this->host_dir/$file_name, "r"); + $time_file = fopen($this->host_dir/$file_name, "r"); if($time_file == NULL) return 0; fscanf($time_file, "%f", $app_time); fclose($f);