Hi Canh I see that functions in OpenSAF base is already used. This means that base/osaf_time.h also can be included and functions in there can be used to handle timeout and sleep. Should simplify try again loop handling
Thanks Lennart > -----Original Message----- > From: Canh Van Truong [mailto:[email protected]] > Sent: den 5 maj 2017 10:08 > To: Lennart Lund <[email protected]>; Vu Minh Nguyen > <[email protected]>; [email protected] > Cc: [email protected]; Canh Van Truong > <[email protected]> > Subject: [PATCH 1/1] log: process TRY AGAIN in logtest 2 40 and logtest 2 41 > [#2453] > > Re-write again in case test cases receive write ack with TRY AGAIN > error > --- > src/log/apitest/logutil.c | 11 +++++++++ > src/log/apitest/logutil.h | 3 +++ > src/log/apitest/tet_saLogStreamOpen_2.c | 1 - > src/log/apitest/tet_saLogWriteLogCallbackT.c | 34 > ++++++++++++++++++++++------ > 4 files changed, 41 insertions(+), 8 deletions(-) > > diff --git a/src/log/apitest/logutil.c b/src/log/apitest/logutil.c > index efc39204b..fc8886549 100644 > --- a/src/log/apitest/logutil.c > +++ b/src/log/apitest/logutil.c > @@ -15,6 +15,7 @@ > * > */ > > +#include <time.h> > #include "base/saf_error.h" > #include "logtest.h" > > @@ -63,6 +64,16 @@ int systemCall(const char *command) > return rc; > } > > +/** > + * Sleep in milliseconds > + */ > +void msleep(uint64_t ms) { > + struct timespec req, rem; > + req.tv_sec = (int)(ms / 1000); > + req.tv_nsec = (ms - ((long)req.tv_sec * 1000)) * 1000000; > + nanosleep(&req , &rem); > +} > + > /* > * Wrapper function for 'saLogInitialize' > */ > diff --git a/src/log/apitest/logutil.h b/src/log/apitest/logutil.h > index fafadcb2e..5dc879856 100644 > --- a/src/log/apitest/logutil.h > +++ b/src/log/apitest/logutil.h > @@ -42,6 +42,9 @@ struct LogProfile { > /* Same as system() but returns WEXITSTATUS if not -1 */ > int systemCall(const char *command); > > +// Sleep in milliseconds > +void msleep(uint64_t ms); > + > // Common interfaces > const char *hostname(void); > bool is_test_done_on_pl(void); > diff --git a/src/log/apitest/tet_saLogStreamOpen_2.c > b/src/log/apitest/tet_saLogStreamOpen_2.c > index 248b7d380..ada98a4c8 100644 > --- a/src/log/apitest/tet_saLogStreamOpen_2.c > +++ b/src/log/apitest/tet_saLogStreamOpen_2.c > @@ -1125,7 +1125,6 @@ extern void saLogWriteLogAsync_18(void); > extern void saLogWriteLogAsync_19(void); > extern void saLogWriteLogCallbackT_01(void); > extern void saLogWriteLogCallbackT_02(void); > -extern void saLogWriteLogCallbackT_03(void); > extern void saLogStreamClose_01(void); > > __attribute__((constructor)) static void saLibraryLifeCycle_constructor(void) > diff --git a/src/log/apitest/tet_saLogWriteLogCallbackT.c > b/src/log/apitest/tet_saLogWriteLogCallbackT.c > index 184ece521..ee05e3031 100644 > --- a/src/log/apitest/tet_saLogWriteLogCallbackT.c > +++ b/src/log/apitest/tet_saLogWriteLogCallbackT.c > @@ -39,7 +39,7 @@ SaAisErrorT logWrite(SaInvocationT invocation, > SaLogAckFlagsT ackFlags, > ackFlags, logRecord); > unsigned int nTries = 1; > while (rc == SA_AIS_ERR_TRY_AGAIN && nTries < logProfile.nTries) { > - usleep(logProfile.retryInterval * 1000); > + msleep(logProfile.retryInterval); > rc = saLogWriteLogAsync(logStreamHandle, invocation, > ackFlags, > logRecord); > nTries++; > @@ -55,7 +55,7 @@ void saLogWriteLogCallbackT_01(void) > { > SaInvocationT invocation; > struct pollfd fds[1]; > - int ret; > + int ret, nTries = 1; > > invocation = random(); > logCallbacks.saLogWriteLogCallback = logWriteLogCallbackT; > @@ -76,9 +76,11 @@ void saLogWriteLogCallbackT_01(void) > test_validate(rc, SA_AIS_OK); > goto done; > } > - cb_index = 0; > strcpy((char *)genLogRecord.logBuffer->logBuf, __FUNCTION__); > genLogRecord.logBuffer->logBufSize = strlen(__FUNCTION__); > + > +write_log: > + cb_index = 0; > rc = logWrite(invocation, SA_LOG_RECORD_WRITE_ACK, > &genLogRecord); > if (rc != SA_AIS_OK) { > test_validate(rc, SA_AIS_OK); > @@ -100,6 +102,13 @@ void saLogWriteLogCallbackT_01(void) > goto done; > } > > + if (cb_error[0] == SA_AIS_ERR_TRY_AGAIN && nTries < > logProfile.nTries) { > + nTries++; > + msleep(100); > + printf("Get try again error, re-write %d times\n", nTries); > + goto write_log; > + } > + > if (cb_invocation[0] == invocation) > test_validate(cb_error[0], SA_AIS_OK); > else > @@ -113,7 +122,7 @@ void saLogWriteLogCallbackT_02(void) > { > SaInvocationT invocation[3]; > struct pollfd fds[1]; > - int ret, i; > + int ret, i, nTries = 1; > > invocation[0] = random(); > invocation[1] = random(); > @@ -138,9 +147,11 @@ void saLogWriteLogCallbackT_02(void) > goto done; > } > > - cb_index = 0; > strcpy((char *)genLogRecord.logBuffer->logBuf, __FUNCTION__); > genLogRecord.logBuffer->logBufSize = strlen(__FUNCTION__); > + > +write_log: > + cb_index = 0; > rc = logWrite(invocation[0], SA_LOG_RECORD_WRITE_ACK, > &genLogRecord); > if (rc == SA_AIS_OK) > rc = logWrite(invocation[1], SA_LOG_RECORD_WRITE_ACK, > @@ -171,15 +182,24 @@ void saLogWriteLogCallbackT_02(void) > } > > if (cb_index != 3) { > - printf("cb_index = %u\n", cb_index); > + printf("cb_index = %d\n", cb_index); > test_validate(SA_AIS_ERR_LIBRARY, SA_AIS_OK); > return; > } > > for (i = 0; i < 3; i++) { > + if (cb_error[i] == SA_AIS_ERR_TRY_AGAIN && > + nTries < logProfile.nTries) { > + nTries++; > + msleep(100); > + printf("Get try again error, re-write %d times\n", > + nTries); > + goto write_log; > + } > + > if ((cb_invocation[i] != invocation[i]) || > (cb_error[i] != SA_AIS_OK)) { > - printf("%llu expected %llu, %u\n", cb_invocation[i], > + printf("%llu expected %llu, %d\n", cb_invocation[i], > invocation[i], cb_error[i]); > test_validate(cb_error[i], SA_AIS_OK); > return; > -- > 2.11.0 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ Opensaf-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/opensaf-devel
