Ack.
-----Original Message-----
From: Thien Minh Huynh <[email protected]>
Sent: Thursday, March 18, 2021 10:08 AM
To: Thang Duc Nguyen <[email protected]>; Hieu Hong Hoang
<[email protected]>
Cc: [email protected]; Thien Minh Huynh
<[email protected]>
Subject: [PATCH 1/1] log: improve logtest testsuite 22 [#3253]
- retry more to reveive another message if not same the sent message
- prevent ignore test case when role is unexpected.
---
src/log/apitest/log_server.cc | 21 ++++++-
src/log/apitest/log_server.h | 2 +-
.../apitest/tet_saLogStreamConfigFacilityId.c | 58 +++++++++++++------
3 files changed, 59 insertions(+), 22 deletions(-)
diff --git a/src/log/apitest/log_server.cc b/src/log/apitest/log_server.cc
index d6de505c5..93970fad1 100644
--- a/src/log/apitest/log_server.cc
+++ b/src/log/apitest/log_server.cc
@@ -26,14 +26,31 @@ void StartUnixServer() {
server->fd();
}
-bool FindPRI(const char* pri_field) {
+bool FindPRI(const char* pri_field, char* msg) {
char buf[1024];
+ const size_t max_retry = 20;
+ size_t n_retry = 0;
+
+retry:
memset(buf, 0, sizeof(buf));
size_t len = 0;
do {
len = server->Recv(buf + len, 1024);
} while (len < strlen(pri_field));
- return strncmp(buf, pri_field, strlen(pri_field)) == 0;
+
+ if (strstr(buf, msg) == NULL) {
+ n_retry++;
+ if (n_retry < max_retry) goto retry;
+ fprintf(stderr, "message receive: %s\n", buf);
+ return false;
+ }
+
+ if (strncmp(buf, pri_field, strlen(pri_field)) != 0) {
+ fprintf(stderr, "message receive: %s\n", buf);
+ return false;
+ }
+
+ return true;
}
void StopUnixServer() { delete server; } diff --git
a/src/log/apitest/log_server.h b/src/log/apitest/log_server.h index
f3e2140a8..2ac747ed0 100644
--- a/src/log/apitest/log_server.h
+++ b/src/log/apitest/log_server.h
@@ -25,7 +25,7 @@ extern "C" {
#endif
void StartUnixServer();
-bool FindPRI(const char* pri_field);
+bool FindPRI(const char* pri_field, char* msg);
void StopUnixServer();
#ifdef __cplusplus
diff --git a/src/log/apitest/tet_saLogStreamConfigFacilityId.c
b/src/log/apitest/tet_saLogStreamConfigFacilityId.c
index ff27f7337..191736123 100644
--- a/src/log/apitest/tet_saLogStreamConfigFacilityId.c
+++ b/src/log/apitest/tet_saLogStreamConfigFacilityId.c
@@ -30,7 +30,11 @@ static bool set_facility_id(uint32_t value)
snprintf(command, sizeof(command),
"immcfg -a saLogStreamFacilityId=%d %s 2>/dev/null", value,
SA_LOG_STREAM_SYSTEM);
- return systemCall(command) == EXIT_SUCCESS;
+ if (systemCall(command) != EXIT_SUCCESS) {
+ fprintf(stderr, "set facilityId=%d failed\n", value);
+ return false;
+ }
+ return true;
}
static void restore_facility_id()
@@ -77,11 +81,15 @@ static void disable_streaming()
restore_facility_id();
}
-static void switch_over()
+static bool switch_over()
{
const char *command =
"amf-adm si-swap safSi=SC-2N,safApp=OpenSAF 2>/dev/null";
- (void)systemCall(command);
+ if (systemCall(command) != EXIT_SUCCESS) {
+ fprintf(stderr, "switch_over failed\n");
+ return false;
+ }
+ return true;
}
static uint8_t get_role()
@@ -96,6 +104,23 @@ static uint8_t get_role()
return STANDBY_NODE;
}
+static bool can_run_test(uint8_t expected_role) {
+ uint8_t role = get_role();
+ if (role == PAYLOAD_NODE) {
+ fprintf(stdout, "ignore this test due to run on PAYLOAD\n");
+ test_validate(true, true);
+ return false;
+ }
+ if (role != expected_role) {
+ if (!switch_over()) {
+ test_validate(false, true);
+ return false;
+ }
+ }
+ return true;
+}
+
//>
// 02 test cases about configuring `saLogStreamFacilityId`:
// 1) try to set valid values, expect getting OK.
@@ -130,10 +155,7 @@ void config_saLogStreamFacilityId_2() //< void
streaming_log_record_then_verify_PRI_1()
{
- if (get_role() != ACTIVE_NODE) {
- test_validate(true, true);
- return;
- }
+ if(!can_run_test(ACTIVE_NODE)) return;
enable_streaming();
set_facility_id(4);
@@ -162,7 +184,7 @@ void streaming_log_record_then_verify_PRI_1()
goto done;
}
- test_validate(FindPRI("<38>"), true);
+ test_validate(FindPRI("<38>", (char *)__FUNCTION__), true);
done:
StopUnixServer();
@@ -180,10 +202,7 @@ done:
//<
void streaming_log_record_then_verify_PRI_2()
{
- if (get_role() != ACTIVE_NODE) {
- test_validate(true, true);
- return;
- }
+ if(!can_run_test(ACTIVE_NODE)) return;
enable_streaming();
restore_facility_id();
@@ -212,7 +231,7 @@ void streaming_log_record_then_verify_PRI_2()
goto done;
}
- test_validate(FindPRI("<134>"), true);
+ test_validate(FindPRI("<134>", (char *)__FUNCTION__), true);
done:
StopUnixServer();
@@ -227,14 +246,15 @@ done:
//<
void streaming_log_record_then_verify_PRI_3()
{
- if (get_role() != STANDBY_NODE) {
- test_validate(true, true);
- return;
- }
+ if(!can_run_test(STANDBY_NODE)) return;
enable_streaming();
set_facility_id(4);
- switch_over();
+
+ if (!switch_over()) {
+ test_validate(false, true);
+ goto done;
+ }
strcpy((char *)genLogRecord.logBuffer->logBuf, __FUNCTION__);
genLogRecord.logBuffer->logBufSize = strlen(__FUNCTION__); @@ -260,7
+280,7 @@ void streaming_log_record_then_verify_PRI_3()
goto done;
}
- test_validate(FindPRI("<38>"), true);
+ test_validate(FindPRI("<38>", (char *)__FUNCTION__), true);
done:
StopUnixServer();
--
2.25.1
_______________________________________________
Opensaf-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensaf-devel