Improved test_api.php, added app_completed to api, removed #ifdef solaris.

svn path=/trunk/boinc/; revision=156
This commit is contained in:
Michael Gary 2002-07-03 20:48:01 +00:00
parent 2655a6dbb9
commit e68ae27f0b
14 changed files with 261 additions and 66 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -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

109
api/api_app.C Normal file
View File

@ -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 <stdlib.h>
#ifdef UNIX
#include <sys/time.h>
#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;
}

View File

@ -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 <stdio.h>
#include <stdlib.h>
#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;
}

View File

@ -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

2
client/configure vendored
View File

@ -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

View File

@ -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;
}

View File

@ -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.

View File

@ -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

View File

@ -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");
}
?>

View File

@ -1,7 +1,2 @@
blah 17 34.500000
foo
checkpoint
checkpoint
checkpoint
checkpoint
checkpoint

View File

@ -2,9 +2,9 @@
<?php
include_once("init.inc");
initialize_api();
clean_api();
run_api_test();
compare_files("app_to_core.xml", "ta_correct_atc");
compare_files("foobar", "ta_correct_f");
clean_api();
?>

View File

@ -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();