From e68ae27f0baf2caee6483f4a3ae0c950baf60322 Mon Sep 17 00:00:00 2001 From: Michael Gary Date: Wed, 3 Jul 2002 20:48:01 +0000 Subject: [PATCH] Improved test_api.php, added app_completed to api, removed #ifdef solaris. svn path=/trunk/boinc/; revision=156 --- api/Makefile.in | 19 +++++-- api/api.C | 19 +++++++ api/api.h | 4 +- api/api_app.C | 109 ++++++++++++++++++++++++++++++++++++++ api/api_test.C | 117 ++++++++++++++++++++++++++++------------- checkin_notes | 21 ++++++++ client/configure | 2 +- client/hostinfo_unix.C | 13 +++-- configure.in | 2 +- sched/handle_request.C | 2 +- test/init.inc | 8 +-- test/ta_correct_f | 5 -- test/test_api.php | 4 +- test/test_uc.php | 2 +- 14 files changed, 261 insertions(+), 66 deletions(-) create mode 100644 api/api_app.C diff --git a/api/Makefile.in b/api/Makefile.in index 8ca1c7f12c..04269ce7d1 100644 --- a/api/Makefile.in +++ b/api/Makefile.in @@ -9,26 +9,35 @@ CFLAGS = -g -Wall -I../lib/ CC = @CC@ $(CFLAGS) -PROGS = api_test +PROGS = api_app api_test all: $(PROGS) -OBJS = \ - api_test.o \ +APP_OBJS = \ + api_app.o \ api.o \ ../lib/parse.o +TEST_OBJS = \ + api.o \ + api_test.o \ + ../lib/parse.o + .C.o: $(CC) -c -o $*.o $< .c.o: $(CC) -c -o $*.o $< -api_test: $(OBJS) - $(CC) $(OBJS) -o api_test +api_app: $(APP_OBJS) + $(CC) $(APP_OBJS) -o api_app + +api_test: $(TEST_OBJS) + $(CC) $(TEST_OBJS) -o api_test install: all -mkdir -p /usr/local/boinc/api cp api_test /usr/local/boinc/api/api_test + cp api_app /usr/local/boinc/api/api_app clean: rm -f *.o $(PROGS) core dependencies diff --git a/api/api.C b/api/api.C index 3a62fe666f..a6e37a3b33 100644 --- a/api/api.C +++ b/api/api.C @@ -302,6 +302,25 @@ int checkpoint_completed(APP_OUT &ao) { return 0; } +int app_completed(APP_OUT& ao) { + int retval; + FILE* f=fopen(APP_TO_CORE_FILE, "w"); + ao.cpu_time_at_checkpoint = get_cpu_time(); + write_app_file(f, ao); + retval=fflush(f); + if(retval) { + fprintf(stderr, "error: could not flush %s\n", APP_TO_CORE_FILE); + return retval; + } + retval=fclose(f); + if(retval) { + fprintf(stderr, "error: could not close %s\n", APP_TO_CORE_FILE); + return retval; + } + _checkpoint = false; + return 0; +} + void on_timer(int a) { _checkpoint = true; } diff --git a/api/api.h b/api/api.h index 9fedf53f5c..2b7719f645 100644 --- a/api/api.h +++ b/api/api.h @@ -96,9 +96,11 @@ int boinc_resolve_link(char *file_name, char *resolved_name); #define BOINC_INIT_FILE "boinc_init.xml" //the following are provided for implementation of the checkpoint system +int checkpoint_completed(APP_OUT& ao); +int app_completed(APP_OUT& ao); + extern bool _checkpoint; #define time_to_checkpoint() _checkpoint -int checkpoint_completed(APP_OUT &ao); int set_timer(double period); //period is seconds spent in process void on_timer(int not_used); double get_cpu_time(); //return cpu time for this process diff --git a/api/api_app.C b/api/api_app.C new file mode 100644 index 0000000000..c323636058 --- /dev/null +++ b/api/api_app.C @@ -0,0 +1,109 @@ +// The contents of this file are subject to the Mozilla Public License +// Version 1.0 (the "License"); you may not use this file except in +// compliance with the License. You may obtain a copy of the License at +// http://www.mozilla.org/MPL/ +// +// Software distributed under the License is distributed on an "AS IS" +// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +// License for the specific language governing rights and limitations +// under the License. +// +// The Original Code is the Berkeley Open Infrastructure for Network Computing. +// +// The Initial Developer of the Original Code is the SETI@home project. +// Portions created by the SETI@home project are Copyright (C) 2002 +// University of California at Berkeley. All Rights Reserved. +// +// Contributor(s): +// + +// test program for MFILE class + +#include +#ifdef UNIX +#include +#endif + +#include "api.h" + +int recover(char* file, unsigned long int* i); +int timer(int secs, int usecs); +int parse_args(int argc, char **argv, int& secs, int& usecs); + +int main(int argc, char **argv) { + MFILE mf, check; + unsigned long int i = 0; + int temp=0, secs, usecs; + APP_IN ai; + APP_OUT ao; + boinc_init(ai); + mf.open("foobar", "w"); + mf.printf("blah %d %f\n", 17, 34.5); + mf.printf("foo\n"); + if(!recover("counter", &i)) { + check.open("counter", "w"); + check.printf("%d", 0); + check.flush(); + check.close(); + } + if(parse_args(argc, argv, secs, usecs)) { + fprintf(stderr, "error: could not parse arguments\n"); + return 1; + } + if(timer(secs, usecs)) { + fprintf(stderr, "error: could not initialize timer\n"); + return 1; + } + for(; i<100000000; i++) { + if(time_to_checkpoint()) { + check.open("counter", "w"); + check.printf("%d", i); + check.flush(); + check.close(); + ao.percent_done = ((double)i)/100000000.0; + checkpoint_completed(ao); + } + temp++; + } + mf.close(); + ao.percent_done = 1; + app_completed(ao); + return 0; +} + +int recover(char* file, unsigned long int* i) { + FILE* f = fopen(file, "r"); + if(f==NULL) { + *i=0; + return 0; + } + fscanf(f, "%lu", i); + if(fclose(f)) { + fprintf(stderr, "error: could not close file %s\n", file); + exit(-1); + } + return *i; +} + +int timer(int secs, int usecs) { + int retval=0; +#ifdef unix + itimerval value; + value.it_value.tv_sec=secs; + value.it_value.tv_usec=usecs; + value.it_interval.tv_sec=0; + value.it_interval.tv_usec=0; + retval = setitimer(ITIMER_REAL, &value, NULL); +#endif + return retval; +} + +int parse_args(int argc, char **argv, int& secs, int& usecs) { + if(argc != 3) { + fprintf(stderr, "error: incorrect number of arguments %d\n", argc); + return 1; + } + secs = atoi(argv[1]); + usecs = atoi(argv[2]); + return 0; +} diff --git a/api/api_test.C b/api/api_test.C index 6d205971e3..aa46e454ef 100644 --- a/api/api_test.C +++ b/api/api_test.C @@ -1,45 +1,86 @@ -// The contents of this file are subject to the Mozilla Public License -// Version 1.0 (the "License"); you may not use this file except in -// compliance with the License. You may obtain a copy of the License at -// http://www.mozilla.org/MPL/ -// -// Software distributed under the License is distributed on an "AS IS" -// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the -// License for the specific language governing rights and limitations -// under the License. -// -// The Original Code is the Berkeley Open Infrastructure for Network Computing. -// -// The Initial Developer of the Original Code is the SETI@home project. -// Portions created by the SETI@home project are Copyright (C) 2002 -// University of California at Berkeley. All Rights Reserved. -// -// Contributor(s): -// - -// test program for MFILE class +#include +#include #include "api.h" +int get_run_info(double& time, unsigned long int& counter); +void run_api_test(char* args); +int print_results(double time1, double time2, + unsigned long int counter1, unsigned long int counter2 +); +int initialize_api(); + int main() { - MFILE mf; - unsigned long int i = 0; - int temp=0; - APP_IN ai; - APP_OUT ao; - boinc_init(ai); - mf.open("foobar", "w"); - mf.printf("blah %d %f\n", 17, 34.5); - mf.printf("foo\n"); - for(; i<100000000; i++) { - if(time_to_checkpoint()) { - mf.printf("checkpoint: %d\n", temp); - mf.flush(); - ao.percent_done = 1; - checkpoint_completed(ao); - } - temp++; + double time1, time2; + unsigned long int counter1, counter2; + if(initialize_api()) { + fprintf(stderr, "error: could not initialize api\n"); + return 1; + } + run_api_test("2 100"); + get_run_info(time1, counter1); + if(initialize_api()) { + fprintf(stderr, "error: could not initialize api\n"); + return 1; + } + run_api_test("0 0"); + get_run_info(time2, counter2); + print_results(time1, time2, counter1, counter2); +} + +int get_run_info(double& time, unsigned long int& counter) { + APP_OUT ao; + FILE* f=fopen(APP_TO_CORE_FILE, "r"); + if(f == NULL) { + fprintf(stderr, "error: could not open %s\n", APP_TO_CORE_FILE); + return 1; + } + parse_app_file(f, ao); + time = ao.cpu_time_at_checkpoint; + if(fclose(f)) { + fprintf(stderr, "error: could not close %s\n", APP_TO_CORE_FILE); + return 1; + } + f=fopen("counter", "r"); + fscanf(f, "%lu", &counter); + if(fclose(f)) { + fprintf(stderr, "error: could not close counter\n"); + return 1; } - mf.close(); + return 0; +} + +void run_api_test(char* args) { + char buf[256]; + sprintf(buf, "../api/api_app %s", args); + system(buf); +} + +int initialize_api() { + APP_IN ai; + FILE* f; + ai.graphics.xsize=0; + ai.graphics.ysize=0; + ai.graphics.refresh_period=0; + ai.checkpoint_period = 1.0; + ai.poll_period = 0; + ai.cpu_time = 0; + f = fopen(CORE_TO_APP_FILE, "w"); + write_core_file(f, ai); + if(fclose(f)) { + fprintf(stderr, "error: could not close %s\n", CORE_TO_APP_FILE); + return 1; + } + return 0; +} + +int print_results(double time1, double time2, unsigned long int counter1, + unsigned long int counter2 +) { + if(counter2 < counter1) printf("api test counter did not work properly\n"); + if(time1 == 0) printf("api test did not work first time\n"); + if(time2 == 0) printf("api test did not work second time\n"); + if(counter1 == counter2) printf("api test did not resume from restart\n"); + printf("total run time for api test was %f\n", time1+time2); return 0; } diff --git a/checkin_notes b/checkin_notes index 6e47ff7c32..efaf999cd8 100755 --- a/checkin_notes +++ b/checkin_notes @@ -704,3 +704,24 @@ Michael Gary 7/01/2002 main.C test/ prefs1.xml + +Michael Gary 7/03/2002 + - api test is now more thorough, tests time accounting and restarting + - added app_completed function to api + - api_test.C was moved to api_app.C + - removed #ifdef solaris from hostinfo_unix.C + + api/ + Makefile.in + api.C + api.h + api_test.C + api_app.C (new) + test/ + init.inc + ta_correct_f + test_api.php + client/ + hostinfo_unix.C + configure + diff --git a/client/configure b/client/configure index 7848155b3c..6304a96839 100644 --- a/client/configure +++ b/client/configure @@ -1505,7 +1505,7 @@ EOF fi -for ac_hdr in fcntl.h sys/time.h unistd.h sys/select.h sys/statvfs.h sys/swap.h +for ac_hdr in fcntl.h sys/time.h unistd.h sys/select.h sys/statvfs.h sys/swap.h sys/systeminfo.h do ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 diff --git a/client/hostinfo_unix.C b/client/hostinfo_unix.C index a700f06d90..1ad2943947 100644 --- a/client/hostinfo_unix.C +++ b/client/hostinfo_unix.C @@ -89,10 +89,9 @@ void get_timezone(int& tz) { tzset(); // TODO: take daylight savings time into account -#ifdef linux +#ifdef __timezone tz = __timezone; -#endif -#ifdef solaris +#else tz = timezone; #endif } @@ -170,7 +169,7 @@ int get_host_info(HOST_INFO& host) { host.m_nbytes = 0; host.m_cache = 0; host.m_swap = 0; -#ifdef solaris +#ifdef HAVE_SYS_SYSTEMINFO_H struct statvfs foo; char buf[256]; @@ -206,15 +205,15 @@ int get_host_info(HOST_INFO& host) { #ifdef linux memset(&host, 0, sizeof(host)); - +#endif get_local_domain_name(host.domain_name); get_local_ip_addr_str(host.ip_addr); - +#ifdef linux parse_cpuinfo(host); parse_meminfo(host); get_osinfo(host); - get_timezone(host.timezone); #endif + get_timezone(host.timezone); return 0; } diff --git a/configure.in b/configure.in index 435f74b394..b0e3fefdb2 100644 --- a/configure.in +++ b/configure.in @@ -23,7 +23,7 @@ dnl Checks for header files. AC_HEADER_DIRENT AC_HEADER_STDC AC_HEADER_SYS_WAIT -AC_CHECK_HEADERS(fcntl.h strings.h sys/time.h unistd.h) +AC_CHECK_HEADERS(fcntl.h strings.h sys/time.h unistd.h sys/system_info.h) AC_CHECK_HEADERS(mysql/include/mysql_com.h mysql/mysql_com.h) dnl Checks for typedefs, structures, and compiler characteristics. diff --git a/sched/handle_request.C b/sched/handle_request.C index 7b334ba222..516fcef750 100644 --- a/sched/handle_request.C +++ b/sched/handle_request.C @@ -27,7 +27,7 @@ #include "server_types.h" #include "handle_request.h" -#define MIN_SECONDS_TO_SEND 3600 //1 hour +#define MIN_SECONDS_TO_SEND 0 #define MAX_SECONDS_TO_SEND 2419200 //4 weeks // return true if the WU can be executed on the host diff --git a/test/init.inc b/test/init.inc index 3e10dcc430..5abd9de55e 100644 --- a/test/init.inc +++ b/test/init.inc @@ -195,12 +195,12 @@ function compare_files($out, $correct) { } } -function initialize_api() { - PassThru("cp core_to_app.xml.in core_to_app.xml"); -} - function run_api_test() { PassThru("../api/api_test"); } +function clean_api() { + PassThru("rm -f counter app_to_core.xml core_to_app.xml foobar"); +} + ?> diff --git a/test/ta_correct_f b/test/ta_correct_f index f34ce8fe5f..678cd697f7 100644 --- a/test/ta_correct_f +++ b/test/ta_correct_f @@ -1,7 +1,2 @@ blah 17 34.500000 foo -checkpoint -checkpoint -checkpoint -checkpoint -checkpoint diff --git a/test/test_api.php b/test/test_api.php index 4d1dd278fe..a897237df7 100644 --- a/test/test_api.php +++ b/test/test_api.php @@ -2,9 +2,9 @@ diff --git a/test/test_uc.php b/test/test_uc.php index 29899161d8..c7e672d8e2 100644 --- a/test/test_uc.php +++ b/test/test_uc.php @@ -16,7 +16,7 @@ add_app("upper_case"); create_work("-appname upper_case -rsc_iops 180000000000.0 -rsc_fpops 0.0 -wu_name uc_wu -wu_template uc_wu -result_template uc_result -nresults 5 input input input input input"); start_feeder(); - //run_client("-exit_after 2"); + //run_client("-exit_after 10"); run_client("-exit_when_idle"); stop_feeder();