Whitespace and indentation changes.
Whitespace and indentation changes of log manager test programs.
This commit is contained in:
@ -18,7 +18,7 @@
|
||||
|
||||
|
||||
/** @file
|
||||
@brief (brief description)
|
||||
@brief (brief description)
|
||||
|
||||
*/
|
||||
#include <stdio.h>
|
||||
@ -27,7 +27,8 @@
|
||||
#include <skygw_utils.h>
|
||||
#include <log_manager.h>
|
||||
|
||||
typedef struct thread_st {
|
||||
typedef struct thread_st
|
||||
{
|
||||
skygw_message_t* mes;
|
||||
simple_mutex_t* mtx;
|
||||
size_t* nactive;
|
||||
@ -97,17 +98,20 @@ int main(int argc, char* argv[])
|
||||
"structure. Exiting.\n");
|
||||
err = 1;
|
||||
goto return_err;
|
||||
|
||||
}
|
||||
i = atexit(skygw_logmanager_exit);
|
||||
|
||||
if (i != 0) {
|
||||
if (i != 0)
|
||||
{
|
||||
fprintf(stderr, "Couldn't register exit function.\n");
|
||||
}
|
||||
|
||||
succp = skygw_logmanager_init("/tmp", log_argc, log_argv);
|
||||
if(!succp)
|
||||
|
||||
if (!succp)
|
||||
{
|
||||
fprintf(stderr, "Log manager initialization failed.\n");
|
||||
}
|
||||
ss_dassert(succp);
|
||||
|
||||
t = time(NULL);
|
||||
@ -179,15 +183,21 @@ int main(int argc, char* argv[])
|
||||
logstr = ("I'm doing fine!");
|
||||
err = skygw_log_write(LOGFILE_MESSAGE, logstr);
|
||||
|
||||
logstr = ("Rather more surprising, at least at first sight, is the fact that a reference to a[i] can also be written as *(a+i). In evaluating a[i], C converts it to *(a+i) immediately; the two forms are equivalent. Applying the operators & to both parts of this equivalence, it follows that &a[i] and a+i are also identical: a+i is the address of the i-th element beyond a.");
|
||||
logstr = ("Rather more surprising, at least at first sight, is the fact that a reference to "
|
||||
"a[i] can also be written as *(a+i). In evaluating a[i], C converts it to *(a+i) "
|
||||
"immediately; the two forms are equivalent. Applying the operators & to both parts "
|
||||
"of this equivalence, it follows that &a[i] and a+i are also identical: a+i is the "
|
||||
"address of the i-th element beyond a.");
|
||||
err = skygw_log_write(LOGFILE_ERROR, logstr);
|
||||
|
||||
logstr = ("I was wondering, you know, it has been such a lovely weather whole morning and I thought that would you like to come to my place and have a little piece of cheese with us. Just me and my mom - and you, of course. Then, if you wish, we could listen to the radio and keep company for our little Steven, my mom's cat, you know.");
|
||||
logstr = ("I was wondering, you know, it has been such a lovely weather whole morning and I "
|
||||
"thought that would you like to come to my place and have a little piece of cheese "
|
||||
"with us. Just me and my mom - and you, of course. Then, if you wish, we could "
|
||||
"listen to the radio and keep company for our little Steven, my mom's cat, you know.");
|
||||
err = skygw_log_write(LOGFILE_MESSAGE, logstr);
|
||||
skygw_logmanager_done();
|
||||
|
||||
#if defined(TEST1)
|
||||
|
||||
mes = skygw_message_init();
|
||||
mtx = simple_mutex_init(NULL, "testmtx");
|
||||
/** Test starts */
|
||||
@ -195,7 +205,8 @@ int main(int argc, char* argv[])
|
||||
fprintf(stderr, "\nStarting test #1 \n");
|
||||
|
||||
/** 1 */
|
||||
for (i=0; i<nthr; i++) {
|
||||
for (i = 0; i < nthr; i++)
|
||||
{
|
||||
thr[i] = (thread_t*)calloc(1, sizeof(thread_t));
|
||||
thr[i]->mes = mes;
|
||||
thr[i]->mtx = mtx;
|
||||
@ -203,23 +214,27 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
nactive = nthr;
|
||||
|
||||
for (i=0; i<nthr; i++) {
|
||||
for (i = 0; i < nthr; i++)
|
||||
{
|
||||
pthread_t p;
|
||||
pthread_create(&p, NULL, thr_run, thr[i]);
|
||||
thr[i]->tid = p;
|
||||
}
|
||||
|
||||
do {
|
||||
do
|
||||
{
|
||||
skygw_message_wait(mes);
|
||||
simple_mutex_lock(mtx, true);
|
||||
if (nactive > 0) {
|
||||
if (nactive > 0)
|
||||
{
|
||||
simple_mutex_unlock(mtx);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
} while(true);
|
||||
|
||||
for (i=0; i<nthr; i++) {
|
||||
for (i = 0; i < nthr; i++)
|
||||
{
|
||||
pthread_join(thr[i]->tid, NULL);
|
||||
}
|
||||
/** This is to release memory */
|
||||
@ -227,7 +242,8 @@ int main(int argc, char* argv[])
|
||||
|
||||
simple_mutex_unlock(mtx);
|
||||
|
||||
for (i=0; i<nthr; i++) {
|
||||
for (i = 0; i < nthr; i++)
|
||||
{
|
||||
free(thr[i]);
|
||||
}
|
||||
#endif
|
||||
@ -237,7 +253,8 @@ int main(int argc, char* argv[])
|
||||
fprintf(stderr, "\nStarting test #2 \n");
|
||||
|
||||
/** 2 */
|
||||
for (i=0; i<nthr; i++) {
|
||||
for (i = 0; i < nthr; i++)
|
||||
{
|
||||
thr[i] = (thread_t*)calloc(1, sizeof(thread_t));
|
||||
thr[i]->mes = mes;
|
||||
thr[i]->mtx = mtx;
|
||||
@ -250,7 +267,8 @@ int main(int argc, char* argv[])
|
||||
nthr,
|
||||
NITER);
|
||||
|
||||
for (i=0; i<nthr; i++) {
|
||||
for (i = 0; i < nthr; i++)
|
||||
{
|
||||
pthread_t p;
|
||||
pthread_create(&p, NULL, thr_run_morelog, thr[i]);
|
||||
thr[i]->tid = p;
|
||||
@ -260,17 +278,20 @@ int main(int argc, char* argv[])
|
||||
|
||||
fprintf(stderr, "\nStarting to wait threads.\n");
|
||||
|
||||
do {
|
||||
do
|
||||
{
|
||||
skygw_message_wait(mes);
|
||||
simple_mutex_lock(mtx, true);
|
||||
if (nactive > 0) {
|
||||
if (nactive > 0)
|
||||
{
|
||||
simple_mutex_unlock(mtx);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
} while(true);
|
||||
|
||||
for (i=0; i<nthr; i++) {
|
||||
for (i = 0; i < nthr; i++)
|
||||
{
|
||||
pthread_join(thr[i]->tid, NULL);
|
||||
}
|
||||
/** This is to release memory */
|
||||
@ -280,7 +301,8 @@ int main(int argc, char* argv[])
|
||||
|
||||
fprintf(stderr, "\nFreeing thread memory.");
|
||||
|
||||
for (i=0; i<nthr; i++) {
|
||||
for (i = 0; i < nthr; i++)
|
||||
{
|
||||
free(thr[i]);
|
||||
}
|
||||
|
||||
@ -451,10 +473,8 @@ int main(int argc, char* argv[])
|
||||
|
||||
ss_dassert(err == 0);
|
||||
|
||||
|
||||
skygw_logmanager_done();
|
||||
|
||||
|
||||
#endif /* TEST 4 */
|
||||
fprintf(stderr, ".. done.\n");
|
||||
return_err:
|
||||
@ -466,8 +486,7 @@ return_err:
|
||||
}
|
||||
|
||||
|
||||
static void* thr_run(
|
||||
void* data)
|
||||
static void* thr_run(void* data)
|
||||
{
|
||||
thread_t* td = (thread_t *)data;
|
||||
char* logstr;
|
||||
@ -478,22 +497,33 @@ static void* thr_run(
|
||||
skygw_log_flush(LOGFILE_MESSAGE);
|
||||
logstr = ("Hi, how are you?");
|
||||
err = skygw_log_write(LOGFILE_MESSAGE, logstr);
|
||||
if(err != 0)
|
||||
|
||||
if (err != 0)
|
||||
{
|
||||
fprintf(stderr,"Error, log write failed.\n");
|
||||
}
|
||||
ss_dassert(err == 0);
|
||||
skygw_logmanager_done();
|
||||
skygw_log_flush(LOGFILE_TRACE);
|
||||
skygw_log_flush(LOGFILE_MESSAGE);
|
||||
logstr = ("I was wondering, you know, it has been such a lovely weather whole morning and I thought that would you like to come to my place and have a little piece of cheese with us. Just me and my mom - and you, of course. Then, if you wish, we could listen to the radio and keep company for our little Steven, my mom's cat, you know.");
|
||||
if(err != 0)
|
||||
logstr = ("I was wondering, you know, it has been such a lovely weather whole morning and "
|
||||
"I thought that would you like to come to my place and have a little piece of "
|
||||
"cheese with us. Just me and my mom - and you, of course. Then, if you wish, "
|
||||
"we could listen to the radio and keep company for our little Steven, my mom's "
|
||||
"cat, you know.");
|
||||
if (err != 0)
|
||||
{
|
||||
fprintf(stderr,"Error, log write failed.\n");
|
||||
}
|
||||
ss_dassert(err == 0);
|
||||
err = skygw_log_write(LOGFILE_MESSAGE, logstr);
|
||||
skygw_logmanager_init("/tmp", 0, NULL);
|
||||
logstr = ("Testing. One, two, three\n");
|
||||
err = skygw_log_write(LOGFILE_ERROR, logstr);
|
||||
if(err != 0)
|
||||
if (err != 0)
|
||||
{
|
||||
fprintf(stderr,"Error, log write failed.\n");
|
||||
}
|
||||
ss_dassert(err == 0);
|
||||
skygw_logmanager_init("/tmp", 0, NULL);
|
||||
skygw_logmanager_init("/tmp", 0, NULL);
|
||||
@ -502,15 +532,23 @@ static void* thr_run(
|
||||
|
||||
skygw_log_enable(LOGFILE_TRACE);
|
||||
err = skygw_log_write(LOGFILE_TRACE, logstr);
|
||||
if(err != 0)
|
||||
if (err != 0)
|
||||
{
|
||||
fprintf(stderr,"Error, log write failed.\n");
|
||||
}
|
||||
ss_dassert(err == 0);
|
||||
skygw_logmanager_done();
|
||||
skygw_logmanager_init("/tmp", 0, NULL);
|
||||
logstr = ("Rather more surprising, at least at first sight, is the fact that a reference to a[i] can also be written as *(a+i). In evaluating a[i], C converts it to *(a+i) immediately; the two forms are equivalent. Applying the operatos & to both parts of this equivalence, it follows that &a[i] and a+i are also identical: a+i is the address of the i-th element beyond a.");
|
||||
logstr = ("Rather more surprising, at least at first sight, is the fact that a reference "
|
||||
"to a[i] can also be written as *(a+i). In evaluating a[i], C converts it to *(a+i) "
|
||||
"immediately; the two forms are equivalent. Applying the operatos & to both parts "
|
||||
"of this equivalence, it follows that &a[i] and a+i are also identical: a+i is the "
|
||||
"address of the i-th element beyond a.");
|
||||
err = skygw_log_write(LOGFILE_ERROR, logstr);
|
||||
if(err != 0)
|
||||
if (err != 0)
|
||||
{
|
||||
fprintf(stderr,"Error, log write failed.\n");
|
||||
}
|
||||
ss_dassert(err == 0);
|
||||
skygw_logmanager_init("/tmp", 0, NULL);
|
||||
skygw_logmanager_done();
|
||||
@ -519,8 +557,10 @@ static void* thr_run(
|
||||
skygw_logmanager_done();
|
||||
logstr = ("..and you?");
|
||||
err = skygw_log_write(LOGFILE_MESSAGE, logstr);
|
||||
if(err != 0)
|
||||
if (err != 0)
|
||||
{
|
||||
fprintf(stderr,"Error, log write failed.\n");
|
||||
}
|
||||
ss_dassert(err == 0);
|
||||
skygw_logmanager_init("/tmp", 0, NULL);
|
||||
skygw_logmanager_init("/tmp", 0, NULL);
|
||||
@ -529,20 +569,30 @@ static void* thr_run(
|
||||
skygw_log_enable(LOGFILE_TRACE);
|
||||
#endif
|
||||
err = skygw_log_write(LOGFILE_TRACE, logstr);
|
||||
if(err != 0)
|
||||
if (err != 0)
|
||||
{
|
||||
fprintf(stderr,"Error, log write failed.\n");
|
||||
}
|
||||
ss_dassert(err == 0);
|
||||
skygw_logmanager_init("/tmp", 0, NULL);
|
||||
logstr = ("Rather more surprising, at least at first sight, is the fact that a reference to a[i] can also be written as *(a+i). In evaluating a[i], C converts it to *(a+i) immediately; the two forms are equivalent. Applying the operatos & to both parts of this equivalence, it follows that &a[i] and a+i are also identical: a+i is the address of the i-th element beyond a.");
|
||||
logstr = ("Rather more surprising, at least at first sight, is the fact that a reference to "
|
||||
"a[i] can also be written as *(a+i). In evaluating a[i], C converts it to *(a+i) "
|
||||
"immediately; the two forms are equivalent. Applying the operatos & to both parts "
|
||||
"of this equivalence, it follows that &a[i] and a+i are also identical: a+i is the "
|
||||
"address of the i-th element beyond a.");
|
||||
err = skygw_log_write(LOGFILE_ERROR, logstr);
|
||||
if(err != 0)
|
||||
if (err != 0)
|
||||
{
|
||||
fprintf(stderr,"Error, log write failed.\n");
|
||||
}
|
||||
ss_dassert(err == 0);
|
||||
skygw_logmanager_init("/tmp", 0, NULL);
|
||||
logstr = ("..... and you too?");
|
||||
err = skygw_log_write(LOGFILE_MESSAGE, logstr);
|
||||
if(err != 0)
|
||||
if (err != 0)
|
||||
{
|
||||
fprintf(stderr,"Error, log write failed.\n");
|
||||
}
|
||||
ss_dassert(err == 0);
|
||||
skygw_logmanager_done();
|
||||
#if !defined(SS_DEBUG)
|
||||
@ -554,20 +604,26 @@ static void* thr_run(
|
||||
skygw_log_enable(LOGFILE_TRACE);
|
||||
#endif
|
||||
err = skygw_log_write(LOGFILE_TRACE, logstr);
|
||||
if(err != 0)
|
||||
if (err != 0)
|
||||
{
|
||||
fprintf(stderr,"Error, log write failed.\n");
|
||||
}
|
||||
ss_dassert(err == 0);
|
||||
skygw_logmanager_done();
|
||||
logstr = ("Testing. One, two, three, four\n");
|
||||
err = skygw_log_write(LOGFILE_ERROR, logstr);
|
||||
if(err != 0)
|
||||
if (err != 0)
|
||||
{
|
||||
fprintf(stderr,"Error, log write failed.\n");
|
||||
}
|
||||
ss_dassert(err == 0);
|
||||
skygw_logmanager_init("/tmp", 0, NULL);
|
||||
logstr = ("Testing. One, two, three, .. where was I?\n");
|
||||
err = skygw_log_write(LOGFILE_ERROR, logstr);
|
||||
if(err != 0)
|
||||
if (err != 0)
|
||||
{
|
||||
fprintf(stderr,"Error, log write failed.\n");
|
||||
}
|
||||
ss_dassert(err == 0);
|
||||
skygw_logmanager_init("/tmp", 0, NULL);
|
||||
skygw_logmanager_init("/tmp", 0, NULL);
|
||||
@ -580,12 +636,12 @@ static void* thr_run(
|
||||
}
|
||||
|
||||
|
||||
static int nstr(
|
||||
char** str_arr)
|
||||
static int nstr(char** str_arr)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; str_arr[i] != NULL; i++) {
|
||||
for (i = 0; str_arr[i] != NULL; i++)
|
||||
{
|
||||
}
|
||||
return i;
|
||||
}
|
||||
@ -596,7 +652,9 @@ char* logs[] = {
|
||||
"done",
|
||||
"critical test logging",
|
||||
"longer test l o g g g i n g",
|
||||
"reeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeally loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong line",
|
||||
"reeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"
|
||||
"eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeally looooooooooooooooooooooooooooooooooooooo"
|
||||
"ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong line",
|
||||
"shoorter one",
|
||||
"two",
|
||||
"scrap : 834nuft984pnw8ynup4598yp8wup8upwn48t5gpn45",
|
||||
@ -606,9 +664,7 @@ char* logs[] = {
|
||||
};
|
||||
|
||||
|
||||
|
||||
static void* thr_run_morelog(
|
||||
void* data)
|
||||
static void* thr_run_morelog(void* data)
|
||||
{
|
||||
thread_t* td = (thread_t *)data;
|
||||
int err;
|
||||
@ -617,15 +673,19 @@ static void* thr_run_morelog(
|
||||
|
||||
nmsg = nstr(logs);
|
||||
|
||||
for (i=0; i<NITER; i++) {
|
||||
char* str = logs[rand()%nmsg];
|
||||
for (i = 0; i < NITER; i++)
|
||||
{
|
||||
char* str = logs[rand() % nmsg];
|
||||
err = skygw_log_write((logfile_id_t)(rand()%(LOGFILE_LAST+1)),
|
||||
"%s - iteration # %d",
|
||||
str,
|
||||
i);
|
||||
if(err != 0)
|
||||
fprintf(stderr,"Error, log write failed.\n");
|
||||
if (err != 0)
|
||||
{
|
||||
fprintf(stderr, "Error, log write failed.\n");
|
||||
}
|
||||
}
|
||||
|
||||
simple_mutex_lock(td->mtx, true);
|
||||
*td->nactive -= 1;
|
||||
simple_mutex_unlock(td->mtx);
|
||||
|
@ -36,8 +36,9 @@ int main(int argc, char** argv)
|
||||
struct timespec ts1;
|
||||
ts1.tv_sec = 0;
|
||||
|
||||
memset(cwd,0,1024);
|
||||
if( argc <4){
|
||||
memset(cwd, 0, 1024);
|
||||
if (argc < 4)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"Log Manager Log Order Test\n"
|
||||
"Writes an ascending number into the error log to determine if log writes are in order.\n"
|
||||
@ -46,22 +47,24 @@ int main(int argc, char** argv)
|
||||
}
|
||||
|
||||
block_size = atoi(argv[3]);
|
||||
if(block_size < 1 || block_size > 1024){
|
||||
fprintf(stderr,"Message size too small or large, must be at least 1 byte long and must not exceed 1024 bytes.");
|
||||
if (block_size < 1 || block_size > 1024)
|
||||
{
|
||||
fprintf(stderr,"Message size too small or large, must be at least 1 byte long and "
|
||||
"must not exceed 1024 bytes.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
if(getcwd(cwd,sizeof(cwd)) == NULL ||
|
||||
(optstr = (char**)malloc(sizeof(char*)*4)) == NULL ||
|
||||
(message = (char*)malloc(sizeof(char)*block_size))== NULL){
|
||||
if (getcwd(cwd, sizeof(cwd)) == NULL ||
|
||||
(optstr = (char**)malloc(sizeof(char*) * 4)) == NULL ||
|
||||
(message = (char*)malloc(sizeof(char) * block_size)) == NULL)
|
||||
{
|
||||
fprintf(stderr,"Fatal Error, exiting...");
|
||||
return 1;
|
||||
}
|
||||
|
||||
memset(tmp,0,1024);
|
||||
memset(tmp, 0, 1024);
|
||||
|
||||
sprintf(tmp,"%s",cwd);
|
||||
sprintf(tmp, "%s", cwd);
|
||||
optstr[0] = strdup("log_manager");
|
||||
optstr[1] = NULL;
|
||||
|
||||
@ -69,34 +72,42 @@ int main(int argc, char** argv)
|
||||
interval = atoi(argv[2]);
|
||||
|
||||
succp = skygw_logmanager_init(tmp, 1, optstr);
|
||||
if(!succp)
|
||||
|
||||
if (!succp)
|
||||
{
|
||||
fprintf(stderr,"Error, log manager initialization failed.\n");
|
||||
}
|
||||
ss_dassert(succp);
|
||||
|
||||
skygw_log_disable(LOGFILE_TRACE);
|
||||
skygw_log_disable(LOGFILE_MESSAGE);
|
||||
skygw_log_disable(LOGFILE_DEBUG);
|
||||
|
||||
for(i = 0;i<iterations;i++){
|
||||
|
||||
sprintf(message,"message|%ld",msg_index++);
|
||||
for (i = 0; i < iterations; i++)
|
||||
{
|
||||
sprintf(message, "message|%ld", msg_index++);
|
||||
int msgsize = block_size - strlen(message);
|
||||
if(msgsize < 0 || msgsize > 8192){
|
||||
if (msgsize < 0 || msgsize > 8192)
|
||||
{
|
||||
fprintf(stderr,"Error: Message too long");
|
||||
break;
|
||||
}
|
||||
memset(message + strlen(message), ' ', msgsize);
|
||||
memset(message + block_size - 1,'\0',1);
|
||||
if(interval > 0 && i % interval == 0){
|
||||
memset(message + block_size - 1, '\0', 1);
|
||||
if (interval > 0 && i % interval == 0)
|
||||
{
|
||||
err = skygw_log_write_flush(LOGFILE_ERROR, message);
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
err = skygw_log_write(LOGFILE_ERROR, message);
|
||||
}
|
||||
if(err){
|
||||
if (err)
|
||||
{
|
||||
fprintf(stderr,"Error: log_manager returned %d",err);
|
||||
break;
|
||||
}
|
||||
ts1.tv_nsec = 100*1000000;
|
||||
ts1.tv_nsec = 100 * 1000000;
|
||||
nanosleep(&ts1, NULL);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user