condensed test

svn path=/trunk/boinc/; revision=404
This commit is contained in:
Eric Heien 2002-09-04 18:42:14 +00:00
parent 2c18c2f209
commit 30720e3f4c
5 changed files with 107 additions and 160 deletions

View File

@ -17,7 +17,7 @@ LIBS = ../api/boinc_api.o ../api/mfile.o ../lib/parse.o ../lib/filesys.o ../lib/
CLIBS = @LIBS@
APPS = upper_case concat uc_slow concat_slow 1sec uc_cpu
APPS = upper_case concat 1sec
.C.o:
$(CC) -c -o $*.o $<
@ -32,15 +32,6 @@ upper_case: upper_case.o
concat: concat.o
$(CC) concat.o $(LIBS) -o concat
concat_slow: concat_slow.o
$(CC) concat_slow.o $(LIBS) -o concat_slow
uc_slow: uc_slow.o
$(CC) uc_slow.o $(LIBS) -o uc_slow
uc_cpu: uc_cpu.o
$(CC) uc_cpu.o $(LIBS) -o uc_cpu
1sec: 1sec.o
$(CC) 1sec.o $(LIBS) -o 1sec
@ -48,8 +39,6 @@ install: all
-mkdir -p $(INSTALL_DIR)/apps
cp upper_case $(INSTALL_DIR)/apps/upper_case
cp concat $(INSTALL_DIR)/apps/concat
cp uc_slow $(INSTALL_DIR)/apps/uc_slow
cp concat_slow $(INSTALL_DIR)/apps/concat_slow
cp 1sec $(INSTALL_DIR)/apps/1sec
uninstall:

View File

@ -17,43 +17,122 @@
// Contributor(s):
//
// concat file1 ... filen outfile
// concat [-run_slow] file1 ... filen outfile
//
// concatenate files, write to outfile
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "filesys.h"
#include "boinc_api.h"
void file_append(FILE* in, FILE* out) {
char buf[1024];
int n;
int run_slow = 0;
#define CHECKPOINT_FILE "concat_state"
int do_checkpoint(MFILE& mf, int filenum, int nchars ) {
int retval;
char resolved_name[512],res_name2[512];
FILE* f = fopen("temp", "w");
if (!f) return 1;
fprintf(f, "%d %d", filenum, nchars);
fclose(f);
fprintf(stderr, "APP: concat checkpointing\n");
boinc_resolve_filename( CHECKPOINT_FILE, res_name2 );
retval = mf.flush();
if (retval) return retval;
retval = boinc_rename("temp", res_name2);
if (retval) return retval;
return 0;
}
void file_append(FILE* in, MFILE &out, int skip, int filenum) {
char buf[1];
int n,nread,retval;
fseek( in, skip, SEEK_SET );
nread = skip;
while (1) {
n = fread(buf, 1, 1024, in);
n = fread(buf, 1, 1, in);
if (n == 0) break;
fwrite(buf, 1, n, out);
out.write(buf, 1, n);
nread += n;
if( boinc_time_to_checkpoint() ) {
fprintf( stderr, "Checkpoint.\n" );
retval = do_checkpoint( out, filenum, nread );
if( retval ) {
fprintf( stderr, "APP: concat checkpoint failed %d\n", retval );
exit(1);
}
boinc_checkpoint_completed();
}
if (run_slow) sleep(1);
}
}
#ifdef _WIN32
#include <windows.h>
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR Args, int WinMode) {
LPWSTR command_line;
LPWSTR *args;
char* argv[100];
int i, argc;
command_line = GetCommandLineW();
args = CommandLineToArgvW(command_line, &argc);
// uh, why did MS have to "improve" on char*?
for (i=0; i<argc; i++) {
argv[i] = (char*)args[i];
}
return main(argc, argv);
}
#endif
int main(int argc, char** argv) {
FILE* in, *out;
FILE* in, *state;
MFILE out;
char file_name[512];
int i;
int file_num,nchars,retval;
char *mode;
boinc_init();
fprintf(stderr, "APP: concat: starting, argc %d\n", argc);
for (i=0; i<argc; i++) {
fprintf(stderr, "APP: concat: argv[%d] is %s\n", i, argv[i]);
if (!strcmp(argv[i], "-run_slow")) run_slow = 1;
}
boinc_resolve_filename( CHECKPOINT_FILE, file_name );
state = fopen( file_name, "r" );
if( state ) {
fscanf( state, "%d %d", &file_num, &nchars );
mode = "a";
} else {
file_num = (run_slow ? 2 : 1);
nchars = 0;
mode = "w";
}
boinc_resolve_filename( argv[argc-1], file_name );
fprintf( stderr, "res: %s\n", file_name );
out = fopen(file_name, "w");
if (!out) {
retval = out.open(file_name, mode);
if (retval) {
fprintf(stderr, "APP: concat: can't open out file %s\n", argv[argc-1]);
exit(1);
}
for (i=1; i<argc-1; i++) {
for (i=file_num; i<argc-1; i++) {
boinc_resolve_filename( argv[i], file_name );
fprintf( stderr, "res: %s\n", file_name );
in = fopen(file_name, "r");
@ -61,10 +140,11 @@ int main(int argc, char** argv) {
fprintf(stderr, "APP: concat: can't open in file %s\n", argv[i]);
exit(1);
}
file_append(in, out);
file_append(in, out, nchars, i);
nchars = 0;
fclose(in);
}
fclose(out);
out.close();
fprintf(stderr, "APP: concat: done\n");
boinc_finish(0);
return 0;

View File

@ -1,132 +0,0 @@
// 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):
//
// concat file1 ... filen outfile
//
// concatenate files, write to outfile
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "filesys.h"
#include "boinc_api.h"
#define CHECKPOINT_FILE "concat_slow_state"
int do_checkpoint(MFILE& mf, int filenum, int nchars ) {
int retval;
char resolved_name[512],res_name2[512];
FILE* f = fopen("temp", "w");
if (!f) return 1;
fprintf(f, "%d %d", filenum, nchars);
fclose(f);
fprintf(stderr, "APP: concat_slow checkpointing\n");
boinc_resolve_filename( CHECKPOINT_FILE, res_name2 );
retval = mf.flush();
if (retval) return retval;
retval = boinc_rename("temp", res_name2);
if (retval) return retval;
return 0;
}
void file_append(FILE* in, MFILE &out, int skip, int filenum) {
char buf[1];
int n,nread,retval;
fseek( in, skip, SEEK_SET );
nread = skip;
while (1) {
n = fread(buf, 1, 1, in);
if (n == 0) break;
out.write(buf, 1, n);
nread += n;
fprintf( stderr, "Wrote 1 char.\n" );
// Burn cycles
for( n=0;n<5000000;n++ )
retval += n;
if( retval == 0 )
n = 1;
if( boinc_time_to_checkpoint() ) {
fprintf( stderr, "Checkpoint.\n" );
retval = do_checkpoint( out, filenum, nread );
if( retval ) {
fprintf( stderr, "APP: concat_slow checkpoint failed %d\n", retval );
exit(1);
}
boinc_checkpoint_completed();
}
sleep(1);
}
}
int main(int argc, char** argv) {
FILE* in, *state;
MFILE out;
char file_name[512];
int i;
int file_num,nchars,retval;
char *mode;
boinc_init();
fprintf(stderr, "APP: concat: starting, argc %d\n", argc);
for (i=0; i<argc; i++) {
fprintf(stderr, "APP: concat: argv[%d] is %s\n", i, argv[i]);
}
boinc_resolve_filename( CHECKPOINT_FILE, file_name );
state = fopen( file_name, "r" );
if( state ) {
fscanf( state, "%d %d", &file_num, &nchars );
mode = "a";
} else {
file_num = 1;
nchars = 0;
mode = "w";
}
boinc_resolve_filename( argv[argc-1], file_name );
fprintf( stderr, "res: %s\n", file_name );
retval = out.open(file_name, mode);
if (retval) {
fprintf(stderr, "APP: concat: can't open out file %s\n", argv[argc-1]);
exit(1);
}
for (i=file_num; i<argc-1; i++) {
boinc_resolve_filename( argv[i], file_name );
fprintf( stderr, "res: %s\n", file_name );
in = fopen(file_name, "r");
if (!in) {
fprintf(stderr, "APP: concat: can't open in file %s\n", argv[i]);
exit(1);
}
file_append(in, out, nchars, i);
nchars = 0;
fclose(in);
}
out.close();
fprintf(stderr, "APP: concat: done\n");
boinc_finish(0);
return 0;
}

View File

@ -1826,17 +1826,21 @@ David August 30 2002
md5_file.C
Eric September 4, 2002
- condensed uc_slow, uc_cpu into upper_case, using command line arguments
- condensed uc_slow, uc_cpu into upper_case, concat_slow into concat, using command line arguments
- changed test_uc to use files rather than stdin/stdout
apps/
uc_slow.C (removed)
concat_slow.C (removed)
uc_cpu.C (removed)
upper_case.C
concat.C
Makefile.in
lib/
error_numbers.h
test/
test_uc_slow.php
test_concat.php
uc_result
uc_wu
ucs_wu

View File

@ -8,14 +8,20 @@
check_env_vars();
clear_db();
clear_data_dirs();
create_keys();
if (true) {
clear_server_dirs(false);
} else {
clear_server_dirs(true);
create_keys();
}
clear_client_dirs();
init_client_dirs("prefs1.xml");
copy_to_download_dir("input");
add_project("Test Project");
add_platform(null);
//add_core_client(null);
add_user("prefs.xml");
add_app("concat",null,null);
add_core_client(null);
create_work("-appname concat -wu_name concat_wu -wu_template concat_wu -result_template concat_result -nresults 2 input input");
start_feeder();
run_client("-exit_when_idle");