13 #include <libfossscheduler.h>
21 #include <libfocunit.h>
24 #define COMMIT_HASH "COMMIT_HASH Unknown"
49 #define FROM_UNIT "UNIT\n"
50 #define VERBOSE_TEST 7
51 #define NC_TEST "Not a Command\n"
53 #define write_con(...) \
54 fprintf(write_to, __VA_ARGS__); \
67 FO_ASSERT_TRUE_FATAL(!pipe(in_sub));
68 FO_ASSERT_TRUE_FATAL(!pipe(out_sub));
70 stdin_t = dup(fileno(stdin));
71 stdout_t = dup(fileno(stdout));
73 dup2(out_sub[1], fileno(stdout));
74 dup2(in_sub[0], fileno(stdin));
75 read_from = fdopen(out_sub[0],
"rb");
76 write_to = fdopen(in_sub[1],
"wb");
78 memset(tbuffer,
'\0',
sizeof(tbuffer));
98 dup2(stdin_t, fileno(stdin));
99 dup2(stdout_t, fileno(stdout));
114 FO_ASSERT_FALSE(
valid);
115 FO_ASSERT_STRING_EQUAL(fgets(tbuffer,
sizeof(tbuffer), read_from),
"OK\n");
117 write_con(
"CLOSE\n");
131 FO_ASSERT_FALSE(
valid);
136 write_con(
"CLOSE\n");
147 FO_ASSERT_FALSE(
valid);
148 FO_ASSERT_PTR_NOT_NULL(fgets(tbuffer,
sizeof(tbuffer), read_from));
149 tbuffer[strlen(tbuffer) - 1] =
'\0';
150 FO_ASSERT_STRING_EQUAL(tbuffer, COMMIT_HASH);
152 write_con(
"CLOSE\n");
170 char* argv[] = {
"./test_clibs",
"--config=./scheddata"};
176 FO_ASSERT_FALSE(
valid);
180 fprintf(stdout, FROM_UNIT);
181 FO_ASSERT_PTR_NOT_NULL(fgets(tbuffer,
sizeof(tbuffer), read_from));
182 FO_ASSERT_STRING_EQUAL(tbuffer, FROM_UNIT);
185 while (strcmp(tbuffer, FROM_UNIT) != 0)
186 FO_ASSERT_PTR_NOT_NULL(fgets(tbuffer,
sizeof(tbuffer), read_from));
202 char* argv[] = {
"./test_clibs",
"--config=./scheddata",
"--scheduler_start"};
209 FO_ASSERT_FALSE(
valid);
213 memset(tbuffer,
'\0',
sizeof(tbuffer));
214 tmp = fgets(tbuffer,
sizeof(tbuffer), read_from);
215 FO_ASSERT_PTR_NOT_NULL(tmp);
216 FO_ASSERT_STRING_EQUAL(tbuffer, COMMIT_HASH);
218 tmp = fgets(tbuffer,
sizeof(tbuffer), read_from);
219 FO_ASSERT_PTR_NOT_NULL(tmp);
220 FO_ASSERT_STRING_EQUAL(tmp,
"OK\n");
225 FO_ASSERT_STRING_EQUAL(
226 fgets(tbuffer,
sizeof(tbuffer), read_from),
240 write_con(
"CLOSE\n");
243 FO_ASSERT_FALSE(
valid);
263 FO_ASSERT_FALSE(
valid);
278 write_con(
"VERBOSE %d\n", VERBOSE_TEST);
284 FO_ASSERT_FALSE(
valid);
299 write_con(
"VERSION\n");
305 FO_ASSERT_FALSE(
valid);
324 FO_ASSERT_STRING_EQUAL(ret, NC_TEST);
325 FO_ASSERT_TRUE(
valid);
339 write_con(
"CLOSE\n");
357 FO_ASSERT_STRING_EQUAL(fgets(tbuffer,
sizeof(tbuffer), read_from),
"BYE 2\n");
358 FO_ASSERT_FALSE(
valid);
385 FO_ASSERT_STRING_EQUAL(
386 fgets(tbuffer,
sizeof(tbuffer), read_from),
394 CU_TestInfo fossscheduler_testcases[] =
396 {
"fossscheduler set up",
set_up},
void fo_scheduler_disconnect(int retcode)
Disconnect the scheduler connection.
void fo_scheduler_heart(int i)
This function must be called by agents to let the scheduler know they are alive and how many items th...
char * fo_scheduler_current()
Get the last read string from the scheduler.
char * fo_scheduler_next()
Get the next data to process from the scheduler.
void fo_scheduler_connect(int *argc, char **argv, PGconn **db_conn)
Establish a connection between an agent and the scheduler.
void set_up(void)
Since the fossscheduler library depends on reading and writing very specific data to stdin and stdout...
void fo_heartbeat()
Internal function to send a heartbeat to the scheduler along with the number of items processed.
void test_scheduler_connect()
Test for fo_scheduler_connect() with a new connection.
void test_scheduler_next_oth()
Tests scheduler for non commands.
void test_scheduler_no_connect()
Test for fo_scheduler_connect() with no new connection.
void test_scheduler_next_version()
Tests sending "VERSION\n" to the stdin for the scheduler next function.
void tear_down(void)
This function closes the pipes created in the setup function and returns stdin and stdout to their or...
void test_scheduler_next_end()
Tests sending "END\n" to the stdin for the scheduler next function.
void signal_connect_end()
Test for fo_scheduler_next() blocking.
int agent_verbose
Common verbose flags for the agents, this is used so that the scheduler can change the verbose level ...
int items_processed
The number of items processed by the agent.
void test_scheduler_heart()
Test the scheduler heart function. This function must set up the heartbeat again so that it can check...
void signal_connect_verbose()
Serves the same purpose for the verbose command as the signal_connect_end() function does for the end...
void test_scheduler_current()
Tests the scheduler current function.
void signal_connect_version()
Test for version string.
void test_scheduler_next_verbose()
Tests sending "VERBOSE #\n" to the stdin for the scheduler next function.
void test_scheduler_next_close()
Tests sending "CLOSE\n" to stdin for the scheduler next function.
int sscheduler
Whether the agent was started by the scheduler.
int valid
If the information stored in buffer is valid.
void test_scheduler_disconnect()
Tests the scheduler disconnection function.