function gen_variation_test($fn_det, $sections) { $name = $fn_det['name']; $proto = $fn_det['proto']; $desc = $fn_det['desc']; $source_file = $fn_det['source_file']; $arg_det = $fn_det['arg_det']; $arg_c = $fn_det['arg_c']; $optional_args = $fn_det['optional_args']; $alias = $fn_det['alias']; $test_case = array(); $test_case = gen_template($fn_det, $sections, 'variation'); // if the function has zero argument then quit here because we only need the template if ($arg_c == 0) { return; } // generate a sequence of other tests which loop over each function arg trying different values $name_seq = 1; $arg_count = 1; if ($arg_c > 0) { for ($i = 0; $i < $arg_c; $i++) { //generate a different variation test case for each argument $test_case = array(); $test_case = gen_test_header($name, $proto, $desc, $source_file, "usage variation", "", $alias, $test_case); // add variation code $test_case['--FILE--'] = gen_variation_diff_arg_values_test($name, $arg_det, $arg_count, $test_case['--FILE--']); // end the script $test_case = gen_test_trailer($test_case, '--EXPECTF--'); $tc_name = 'variation' . $name_seq; write_file($test_case, $name, $tc_name, $sections); $arg_count++; // next time generate the code for next argument of the function; $name_seq++; // next seqence number for variation test name } } }
function start($aspid = false) { $unix = new unix(); $sock = new sockets(); $GLOBALS["CLASS_SOCKETS"] = $sock; if (!$aspid) { $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: c-icap service Already Artica task running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); } $cicapbin = $unix->find_program("c-icap"); if (!is_file($cicapbin)) { $nohup = $unix->find_program("nohup"); if (is_file("/home/artica/c-icap.tar.gz.old")) { $tar = $unix->find_program("tar"); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: c-icap service re-install C-ICAP...\n"; } shell_exec("{$tar} xf /home/artica/c-icap.tar.gz.old -C /"); } else { if ($GLOBALS["VERBOSE"]) { echo "/home/artica/c-icap.tar.gz.old no such file\n"; } if (is_dir("/var/run/c-icap")) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: c-icap service compile C-ICAP...\n"; } shell_exec("{$nohup} /usr/share/artica-postfix/bin/artica-make APP_C_ICAP >/dev/null 2>&1 &"); } else { if ($GLOBALS["VERBOSE"]) { echo "/var/run/c-icap no such dir\n"; } $CicapEnabled = $GLOBALS["CLASS_SOCKETS"]->GET_INFO("CicapEnabled"); if ($CicapEnabled == 1) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: c-icap service compile C-ICAP...\n"; } shell_exec("{$nohup} /usr/share/artica-postfix/bin/artica-make APP_C_ICAP >/dev/null 2>&1 &"); } } } } $daemonbin = $unix->find_program("c-icap"); if (!is_file($daemonbin)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: c-icap service, not installed\n"; } return; } $pid = PID_NUM(); if ($unix->process_exists($pid)) { $timepid = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: c-icap Service already started {$pid} since {$timepid}Mn...\n"; } return; } $CicapEnabled = $sock->GET_INFO("CicapEnabled"); $SQUIDEnable = $sock->GET_INFO("SQUIDEnable"); if (is_file("/etc/artica-postfix/WEBSTATS_APPLIANCE")) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: c-icap service WebStats Appliance..\n"; } $CicapEnabled = 1; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: c-icap service Proxy service enabled:{$SQUIDEnable}\n"; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: c-icap service C-ICAP service enabled:{$CicapEnabled}\n"; } if (!is_numeric($CicapEnabled)) { $CicapEnabled = 0; } if (!is_numeric($SQUIDEnable)) { $SQUIDEnable = 1; } if ($SQUIDEnable == 0) { $CicapEnabled = 0; } if ($CicapEnabled == 0) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: c-icap service disabled ( see CicapEnabled )\n"; } return; } $nohup = $unix->find_program("nohup"); $php5 = $unix->LOCATE_PHP5_BIN(); $tmpdir = $unix->TEMP_DIR(); build(true); echo "Starting......: " . date("H:i:s") . " [INIT]: c-icap service Generate template..\n"; gen_template(); @chmod("/var/run", 0777); @mkdir("/var/run/c-icap", 0755, true); echo "Starting......: " . date("H:i:s") . " [INIT]: c-icap Apply permissions..\n"; $unix->chown_func("squid", "squid", "/var/run/c-icap"); libicapapi(); $rm = $unix->find_program("rm"); shell_exec("{$rm} -f /var/lib/c_icap/temporary/* >/dev/null 2>&1"); $debug = " -d 10"; $debug = null; $cmd = "{$nohup} {$daemonbin} -f /etc/c-icap.conf {$debug} >{$tmpdir}/c_icap_start 2>&1 &"; echo "Starting......: " . date("H:i:s") . " [INIT]: c-icap service run daemon\n"; if ($GLOBALS["VERBOSE"]) { echo "{$cmd}\n"; } shell_exec($cmd); for ($i = 0; $i < 6; $i++) { $pid = PID_NUM(); if ($unix->process_exists($pid)) { break; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: c-icap service waiting {$i}/6...\n"; } sleep(1); } $pid = PID_NUM(); if ($unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: c-icap service Success service started pid:{$pid}...\n"; } @unlink("{$tmpdir}/c_icap_start"); return; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: c-icap service failed analyze...\n"; } $f = explode("\n", @file_get_contents("{$tmpdir}/c_icap_start")); while (list($index, $line) = each($f)) { $line = trim($line); if ($line == null) { continue; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: c-icap service {$line}\n"; } if (preg_match("#error while loading shared libraries#", $line)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " **************************************************\n"; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: c-icap service please re-install package...\n"; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " **************************************************\n"; } $sock->SET_INFO("CicapEnabled", 0); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: c-icap service restarting watchdogs\n"; } shell_exec("/etc/init.d/monit restart"); shell_exec("/etc/init.d/artica-status reload"); } } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$cmd}\n"; } if ($GLOBALS["VERBOSE"]) { echo "{$cmd}\n"; } }