2006-09-08 07:53:32 +00:00
|
|
|
/*
|
|
|
|
* condor/tm.c
|
|
|
|
*
|
|
|
|
* DC-API test application, master
|
|
|
|
*
|
|
|
|
* (c) Daniel Drotos, 2006
|
|
|
|
*/
|
2006-05-17 12:12:09 +00:00
|
|
|
|
2006-05-10 09:22:58 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2006-08-25 11:09:08 +00:00
|
|
|
#include <unistd.h>
|
2006-05-10 09:22:58 +00:00
|
|
|
|
|
|
|
#include "dc.h"
|
|
|
|
|
2006-08-25 11:09:08 +00:00
|
|
|
#include "tc.h"
|
|
|
|
|
2007-01-16 12:51:55 +00:00
|
|
|
#define MAX_WU 100
|
|
|
|
|
|
|
|
DC_Workunit *wut[MAX_WU];
|
2006-05-10 09:22:58 +00:00
|
|
|
|
2006-08-25 11:09:08 +00:00
|
|
|
extern char *_DC_state_name(DC_WUState state);
|
|
|
|
|
2006-08-24 12:58:57 +00:00
|
|
|
static void
|
|
|
|
fail(char *what, int ret)
|
2006-05-10 09:22:58 +00:00
|
|
|
{
|
2006-08-24 12:58:57 +00:00
|
|
|
printf("%s failed: %d\n", what, ret);
|
|
|
|
exit(ret);
|
2006-05-10 09:22:58 +00:00
|
|
|
}
|
|
|
|
|
2006-08-24 12:58:57 +00:00
|
|
|
static DC_Workunit *
|
|
|
|
create_short(void)
|
2006-05-10 09:22:58 +00:00
|
|
|
{
|
2006-08-24 12:58:57 +00:00
|
|
|
DC_Workunit *wu;
|
|
|
|
|
|
|
|
printf("Creating short...\n");
|
|
|
|
wu= DC_createWU("short", NULL, 0, NULL);
|
|
|
|
printf("Created short wu: %p\n", wu);
|
|
|
|
if (!wu)
|
|
|
|
fail("DC_createWU", 0);
|
|
|
|
return(wu);
|
2006-05-10 09:22:58 +00:00
|
|
|
}
|
|
|
|
|
2006-08-24 12:58:57 +00:00
|
|
|
static DC_Workunit *
|
2006-08-25 11:09:08 +00:00
|
|
|
create_long(int how_long)
|
2006-05-10 09:22:58 +00:00
|
|
|
{
|
2006-08-24 12:58:57 +00:00
|
|
|
DC_Workunit *wu;
|
2006-08-25 11:09:08 +00:00
|
|
|
char *argv[]= {
|
2006-08-24 12:58:57 +00:00
|
|
|
"15",
|
|
|
|
"2",
|
|
|
|
"3",
|
|
|
|
"2",
|
|
|
|
NULL
|
|
|
|
};
|
2006-08-25 11:09:08 +00:00
|
|
|
char l[100];
|
2007-01-16 12:51:55 +00:00
|
|
|
|
2006-08-24 12:58:57 +00:00
|
|
|
printf("Creating long...\n");
|
2006-08-25 11:09:08 +00:00
|
|
|
if (how_long > 0)
|
|
|
|
{
|
|
|
|
sprintf(l, "%d", how_long);
|
|
|
|
argv[0]= l;
|
|
|
|
}
|
|
|
|
wu= DC_createWU("long", (const char **)argv, 0, NULL);
|
2007-01-16 12:51:55 +00:00
|
|
|
printf("Created long wu: %p\n", wu);
|
2006-08-24 12:58:57 +00:00
|
|
|
if (!wu)
|
|
|
|
fail("DC_createWU", 0);
|
|
|
|
return(wu);
|
2006-05-10 09:22:58 +00:00
|
|
|
}
|
|
|
|
|
2006-08-24 12:58:57 +00:00
|
|
|
static void
|
|
|
|
result_cb(DC_Workunit *wu, DC_Result *result)
|
2006-05-10 09:22:58 +00:00
|
|
|
{
|
2006-08-25 11:09:08 +00:00
|
|
|
printf("\nresult_cb, wustate=%s\n",
|
|
|
|
_DC_state_name(DC_getWUState(wu)));
|
2006-08-24 12:58:57 +00:00
|
|
|
printf("exit= %d\n", DC_getResultExit(result));
|
2006-05-10 09:22:58 +00:00
|
|
|
}
|
|
|
|
|
2006-08-24 12:58:57 +00:00
|
|
|
static void
|
|
|
|
subresult_cb(DC_Workunit *wu,
|
|
|
|
const char *logical_file_name,
|
|
|
|
const char *path)
|
2006-05-10 09:22:58 +00:00
|
|
|
{
|
2006-08-25 11:09:08 +00:00
|
|
|
printf("\nsubresult_cb, wustate=%s\n",
|
|
|
|
_DC_state_name(DC_getWUState(wu)));
|
2006-08-24 12:58:57 +00:00
|
|
|
printf("logical= \"%s\"\n", logical_file_name);
|
|
|
|
printf("path = \"%s\"\n", path);
|
2006-08-25 11:09:08 +00:00
|
|
|
printf("Content: \"%s\"\n", get_file((char*)path));
|
|
|
|
printf("Deleting %s...\n", path);
|
|
|
|
unlink(path);
|
2006-08-24 12:58:57 +00:00
|
|
|
}
|
2006-05-10 09:22:58 +00:00
|
|
|
|
2006-08-24 12:58:57 +00:00
|
|
|
static void
|
|
|
|
message_cb(DC_Workunit *wu, const char *message)
|
|
|
|
{
|
2006-08-25 11:09:08 +00:00
|
|
|
printf("\nmessage_cb, wustate=%s\n",
|
|
|
|
_DC_state_name(DC_getWUState(wu)));
|
2006-08-24 12:58:57 +00:00
|
|
|
printf("Message= \"%s\"\n", message);
|
2006-05-10 09:22:58 +00:00
|
|
|
}
|
|
|
|
|
2006-08-24 12:58:57 +00:00
|
|
|
|
2006-08-25 11:09:08 +00:00
|
|
|
static void
|
|
|
|
ls_lR(int i)
|
|
|
|
{
|
|
|
|
char cmd[100];
|
|
|
|
sprintf(cmd, "./ls_lR.sh %03d", i);
|
|
|
|
//system(cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
int cycle= 0;
|
|
|
|
|
|
|
|
static void
|
|
|
|
process(DC_Workunit *wu, int timeout)
|
|
|
|
{
|
|
|
|
printf("-- %3d %s\n", cycle, _DC_state_name(DC_getWUState(wu)));
|
|
|
|
DC_processMasterEvents(timeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
procs(DC_Workunit *wu, DC_WUState state, int timeout)
|
|
|
|
{
|
|
|
|
while (DC_getWUState(wu) != state)
|
|
|
|
{
|
|
|
|
cycle++;
|
|
|
|
process(wu, timeout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
proci(DC_Workunit *wu, int nr, int timeout)
|
|
|
|
{
|
|
|
|
int j;
|
|
|
|
for (j= 0; j < nr; j++)
|
|
|
|
{
|
|
|
|
cycle++;
|
|
|
|
process(wu, timeout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-24 12:58:57 +00:00
|
|
|
static void
|
|
|
|
t(int what)
|
2006-05-10 09:22:58 +00:00
|
|
|
{
|
2006-08-24 12:58:57 +00:00
|
|
|
DC_Workunit *wu;
|
2006-05-10 09:22:58 +00:00
|
|
|
|
2006-08-24 12:58:57 +00:00
|
|
|
switch (what)
|
2006-05-10 09:22:58 +00:00
|
|
|
{
|
2006-08-24 12:58:57 +00:00
|
|
|
case 1:
|
2006-05-10 09:22:58 +00:00
|
|
|
{
|
2006-08-25 11:09:08 +00:00
|
|
|
int i= 0;
|
2006-08-24 12:58:57 +00:00
|
|
|
printf("test1: running a short wu\n");
|
|
|
|
wu= create_short();
|
|
|
|
printf("Submitting short...\n");
|
|
|
|
if ((i= DC_submitWU(wu)) != 0)
|
|
|
|
fail("DC_submitWU", i);
|
|
|
|
DC_setMasterCb(result_cb, subresult_cb, message_cb);
|
|
|
|
while (DC_getWUState(wu) != DC_WU_FINISHED)
|
2006-05-10 09:22:58 +00:00
|
|
|
{
|
2007-02-02 10:22:21 +00:00
|
|
|
printf("wu is in state %s\n",
|
|
|
|
_DC_state_name(DC_getWUState(wu)));
|
2006-08-25 11:09:08 +00:00
|
|
|
printf("Processing events for 1 sec...\n");
|
|
|
|
DC_processMasterEvents(1);
|
2006-05-10 09:22:58 +00:00
|
|
|
}
|
2006-08-24 12:58:57 +00:00
|
|
|
printf("Destroying short...\n");
|
|
|
|
DC_destroyWU(wu);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 2:
|
|
|
|
{
|
2006-08-25 11:09:08 +00:00
|
|
|
int i, j;
|
2006-08-24 12:58:57 +00:00
|
|
|
printf("test2: running a long wu\n");
|
2006-08-25 11:09:08 +00:00
|
|
|
wu= create_long(0);
|
2006-08-24 12:58:57 +00:00
|
|
|
printf("Submitting long...\n");
|
|
|
|
if ((i= DC_submitWU(wu)) != 0)
|
|
|
|
fail("DC_submitWU", i);
|
|
|
|
DC_setMasterCb(result_cb, subresult_cb, message_cb);
|
|
|
|
while (DC_getWUState(wu) != DC_WU_FINISHED)
|
2006-05-10 09:22:58 +00:00
|
|
|
{
|
2006-08-25 11:09:08 +00:00
|
|
|
i++;
|
|
|
|
printf("Processing events for 1 sec...\n");
|
|
|
|
printf("-- %3d\n", i);
|
|
|
|
ls_lR(i);
|
|
|
|
DC_processMasterEvents(1);
|
2006-05-10 09:22:58 +00:00
|
|
|
}
|
2006-08-24 12:58:57 +00:00
|
|
|
printf("wu finished, but checking events for more 5 secs...\n");
|
2006-08-25 11:09:08 +00:00
|
|
|
for (j= 0; j < 5; j++)
|
|
|
|
{
|
|
|
|
i++;
|
|
|
|
printf("-- %3d\n", i);
|
|
|
|
ls_lR(i);
|
|
|
|
DC_processMasterEvents(1);
|
|
|
|
}
|
|
|
|
printf("Destroying long...\n");
|
|
|
|
DC_destroyWU(wu);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 3:
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
printf("test3: suspend/resume\n");
|
|
|
|
wu= create_long(20);
|
|
|
|
printf("Submitting long...\n");
|
|
|
|
if ((r= DC_submitWU(wu)) != 0)
|
|
|
|
fail("DC_submitWU", r);
|
|
|
|
DC_setMasterCb(result_cb, subresult_cb, message_cb);
|
|
|
|
|
|
|
|
printf("waiting to be running...\n");
|
|
|
|
procs(wu, DC_WU_RUNNING, 1);
|
|
|
|
|
|
|
|
printf("now running, run a bit...\n");
|
|
|
|
proci(wu, 5, 1);
|
|
|
|
|
|
|
|
printf("Suspending wu...\n");
|
|
|
|
if ((r= DC_suspendWU(wu)) != 0)
|
|
|
|
fail("DC_suspendWU", r);
|
|
|
|
|
|
|
|
printf("waiting to be suspended...\n");
|
|
|
|
procs(wu, DC_WU_SUSPENDED, 1);
|
|
|
|
|
|
|
|
printf("now suspended, wait a bit...\n");
|
2006-08-28 09:19:52 +00:00
|
|
|
proci(wu, 3, 1);
|
2006-08-25 11:09:08 +00:00
|
|
|
|
|
|
|
printf("Resuming wu...\n");
|
|
|
|
if ((r= DC_resumeWU(wu)) != 0)
|
|
|
|
fail("DC_resumeWU", r);
|
|
|
|
|
|
|
|
printf("waiting to be running again...\n");
|
|
|
|
procs(wu, DC_WU_RUNNING, 1);
|
|
|
|
|
|
|
|
printf("waiting to finish...\n");
|
|
|
|
procs(wu, DC_WU_FINISHED, 1);
|
|
|
|
|
2006-08-24 12:58:57 +00:00
|
|
|
printf("Destroying long...\n");
|
|
|
|
DC_destroyWU(wu);
|
|
|
|
break;
|
|
|
|
}
|
2006-09-06 12:49:33 +00:00
|
|
|
case 4:
|
|
|
|
{
|
|
|
|
char *s;
|
2006-09-08 10:59:43 +00:00
|
|
|
int r;
|
|
|
|
wu= create_long(20);
|
2006-09-06 12:49:33 +00:00
|
|
|
printf("Ser=\"%s\"\n", s= DC_serializeWU(wu));
|
2006-09-08 10:59:43 +00:00
|
|
|
create_file("serialized_wu.txt", s);
|
|
|
|
free(s);
|
2007-01-15 13:36:01 +00:00
|
|
|
printf("WU serialized\nSubmitting...\n");
|
2006-09-08 10:59:43 +00:00
|
|
|
if ((r= DC_submitWU(wu)) != 0)
|
|
|
|
fail("DC_submitWU", r);
|
|
|
|
DC_setMasterCb(result_cb, subresult_cb, message_cb);
|
|
|
|
|
|
|
|
printf("waiting to be running...\n");
|
|
|
|
procs(wu, DC_WU_RUNNING, 1);
|
|
|
|
/*DC_destroyWU(wu);*/
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 5:
|
|
|
|
{
|
|
|
|
char *s= get_file("serialized_wu.txt");
|
|
|
|
int r;
|
|
|
|
wu= DC_deserializeWU(s);
|
2006-09-06 12:49:33 +00:00
|
|
|
free(s);
|
2007-01-15 13:36:01 +00:00
|
|
|
if (!wu)
|
|
|
|
{
|
|
|
|
printf("Deserialization failed\n");
|
|
|
|
break;
|
|
|
|
}
|
2006-09-08 10:59:43 +00:00
|
|
|
|
2007-01-15 13:36:01 +00:00
|
|
|
printf("Submitting deserialized WU...\n");
|
2006-09-08 10:59:43 +00:00
|
|
|
if ((r= DC_submitWU(wu)) != 0)
|
|
|
|
fail("DC_submitWU", r);
|
|
|
|
DC_setMasterCb(result_cb, subresult_cb, message_cb);
|
|
|
|
|
|
|
|
printf("waiting to be running...\n");
|
|
|
|
procs(wu, DC_WU_RUNNING, 1);
|
|
|
|
|
|
|
|
printf("waiting to finish...\n");
|
|
|
|
procs(wu, DC_WU_FINISHED, 1);
|
|
|
|
|
|
|
|
printf("Destroying...\n");
|
2006-09-06 12:49:33 +00:00
|
|
|
DC_destroyWU(wu);
|
2006-09-08 10:59:43 +00:00
|
|
|
break;
|
2006-09-06 12:49:33 +00:00
|
|
|
}
|
2007-01-16 12:51:55 +00:00
|
|
|
case 6:
|
|
|
|
{
|
|
|
|
int i, nr= 40;
|
|
|
|
int done= 0;
|
|
|
|
DC_setMasterCb(result_cb, subresult_cb, message_cb);
|
|
|
|
printf("Creating and submitting wus...\n");
|
|
|
|
for (i= 0; i < nr; i++)
|
|
|
|
{
|
|
|
|
wut[i]= create_long(10);
|
|
|
|
DC_submitWU(wut[i]);
|
|
|
|
}
|
|
|
|
while (!done)
|
|
|
|
{
|
|
|
|
done= 1;
|
|
|
|
for (i= 0; i < nr; i++)
|
|
|
|
{
|
|
|
|
printf("waiting to finish %d...\n", i);
|
|
|
|
if (wut[i] &&
|
|
|
|
DC_getWUState(wut[i]) != DC_WU_FINISHED &&
|
|
|
|
DC_getWUState(wut[i]) != DC_WU_UNKNOWN)
|
|
|
|
{
|
|
|
|
done= 0;
|
|
|
|
process(wut[i], 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf("All WUs finished, processing event for a while...\n");
|
|
|
|
DC_processMasterEvents(10);
|
|
|
|
printf("Destroying all WUs...\n");
|
|
|
|
for (i= 0; i < nr; i++)
|
|
|
|
{
|
|
|
|
printf("%2d\n", i);
|
|
|
|
DC_destroyWU(wut[i]);
|
|
|
|
wut[i]= NULL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2006-05-10 09:22:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-24 12:58:57 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
2006-05-10 09:22:58 +00:00
|
|
|
{
|
2006-08-24 12:58:57 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if ((i= DC_initMaster("t.conf")) != 0)
|
|
|
|
fail("DC_initMaster", i);
|
2006-05-10 09:22:58 +00:00
|
|
|
|
2006-08-24 12:58:57 +00:00
|
|
|
if (argc < 2)
|
2006-05-10 09:22:58 +00:00
|
|
|
{
|
2006-08-24 12:58:57 +00:00
|
|
|
printf("Calling all tests...\n");
|
|
|
|
t(1);
|
|
|
|
t(2);
|
2006-08-25 11:09:08 +00:00
|
|
|
t(3);
|
2007-01-15 13:36:01 +00:00
|
|
|
t(4);
|
|
|
|
printf("WU serialized, now wait a bit...\n");
|
|
|
|
sleep(5);
|
|
|
|
printf("Trying to deserialize...\n");
|
|
|
|
t(5);
|
2006-05-10 09:22:58 +00:00
|
|
|
}
|
|
|
|
|
2006-08-24 12:58:57 +00:00
|
|
|
for (i= 1; i < argc; i++)
|
2006-05-10 09:22:58 +00:00
|
|
|
{
|
2006-08-24 12:58:57 +00:00
|
|
|
int l;
|
|
|
|
l= strtol(argv[i], 0, 0);
|
|
|
|
printf("Calling test %d...\n", l);
|
|
|
|
t(l);
|
2006-05-10 09:22:58 +00:00
|
|
|
}
|
|
|
|
|
2006-08-24 12:58:57 +00:00
|
|
|
return 0;
|
2006-05-10 09:22:58 +00:00
|
|
|
}
|
2006-09-08 07:53:32 +00:00
|
|
|
|
|
|
|
/* Local variables: */
|
|
|
|
/* c-file-style: "linux" */
|
|
|
|
/* End: */
|