-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c903f02
commit 78e5176
Showing
8 changed files
with
179 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,8 +90,6 @@ typedef enum { | |
} capture_control_t; | ||
|
||
|
||
int capture_status; | ||
|
||
class capture_service | ||
{ | ||
public: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
void run_eventd_service(); | ||
|
||
int main() | ||
{ | ||
SWSS_LOG_INFO("The eventd service started"); | ||
|
||
run_eventd_service(); | ||
|
||
SWSS_LOG_INFO("The eventd service exited"); | ||
|
||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
#include <iostream> | ||
#include <memory> | ||
#include <thread> | ||
#include <algorithm> | ||
#include <deque> | ||
#include <regex> | ||
#include <chrono> | ||
#include "gtest/gtest.h" | ||
#include "events_common.h" | ||
#include "events.h" | ||
#include "../src/eventd.h" | ||
|
||
using namespace std; | ||
|
||
typedef vector<internal_event_t> lst_events_t; | ||
|
||
void run_sub(void *zctx, bool &term, string &read_source, lst_events_t &lst) | ||
{ | ||
void *mock_sub = zmq_socket (zctx, ZMQ_SUB); | ||
string source; | ||
internal_event_t ev_int; | ||
int block_ms = 200; | ||
|
||
EXPECT_TRUE(NULL != mock_sub); | ||
EXPECT_EQ(0, zmq_connect(mock_sub, get_config(XPUB_END_KEY).c_str())); | ||
EXPECT_EQ(0, zmq_setsockopt(mock_sub, ZMQ_SUBSCRIBE, "", 0)); | ||
EXPECT_EQ(0, zmq_setsockopt(mock_sub, ZMQ_RCVTIMEO, &block_ms, sizeof (block_ms))); | ||
|
||
while(!term) { | ||
if (0 == zmq_message_read(mock_sub, 0, source, ev_int)) { | ||
lst.push_back(ev_int); | ||
read_source.swap(source); | ||
} | ||
} | ||
|
||
zmq_close(mock_sub); | ||
} | ||
|
||
void *init_pub(void *zctx) | ||
{ | ||
void *mock_pub = zmq_socket (zctx, ZMQ_PUB); | ||
EXPECT_TRUE(NULL != mock_pub); | ||
EXPECT_EQ(0, zmq_connect(mock_pub, get_config(XSUB_END_KEY).c_str())); | ||
|
||
return mock_pub; | ||
} | ||
|
||
void run_pub(void *mock_pub, const string wr_source, lst_events_t &lst) | ||
{ | ||
for(lst_events_t::const_iterator itc = lst.begin(); itc != lst.end(); ++itc) { | ||
EXPECT_EQ(0, zmq_message_send(mock_pub, wr_source, *itc)); | ||
} | ||
} | ||
|
||
|
||
static internal_event_t | ||
create_ev(const string rid, sequence_t n, const string d) | ||
{ | ||
stringstream ss; | ||
|
||
ss << d << ":" << n; | ||
|
||
return internal_event_t({ {EVENT_STR_DATA, ss.str()}, | ||
{ EVENT_RUNTIME_ID, rid }, { EVENT_SEQUENCE, seq_to_str(n) }}); | ||
} | ||
|
||
|
||
|
||
TEST(eventd, proxy) | ||
{ | ||
printf("TEST started\n"); | ||
bool term_sub = false; | ||
string rd_source, wr_source("hello"); | ||
lst_events_t rd_evts, wr_evts; | ||
|
||
void *zctx = zmq_ctx_new(); | ||
EXPECT_TRUE(NULL != zctx); | ||
|
||
eventd_proxy *pxy = new eventd_proxy(zctx); | ||
EXPECT_TRUE(NULL != pxy); | ||
|
||
/* Starting proxy */ | ||
EXPECT_EQ(0, pxy->init()); | ||
|
||
/* subscriber in a thread */ | ||
thread thr(&run_sub, zctx, ref(term_sub), ref(rd_source), ref(rd_evts)); | ||
|
||
/* Init pub connection */ | ||
void *mock_pub = init_pub(zctx); | ||
|
||
/* Provide time for async connect to complete */ | ||
this_thread::sleep_for(chrono::milliseconds(100)); | ||
|
||
for(int i=0; i<5; ++i) { | ||
wr_evts.push_back(create_ev("hello", i, "test body")); | ||
} | ||
|
||
EXPECT_TRUE(rd_evts.empty()); | ||
EXPECT_TRUE(rd_source.empty()); | ||
|
||
/* Publish events. */ | ||
run_pub(mock_pub, wr_source, wr_evts); | ||
|
||
while(rd_evts.size() != wr_evts.size()) { | ||
printf("rd_evts.size != wr_evts.size %d != %d\n", | ||
(int)rd_evts.size(), (int)wr_evts.size()); | ||
this_thread::sleep_for(chrono::milliseconds(10)); | ||
} | ||
|
||
term_sub = true; | ||
printf("Waiting for sub thread to join...\n"); | ||
|
||
thr.join(); | ||
zmq_close(mock_pub); | ||
zmq_ctx_term(zctx); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include "gtest/gtest.h" | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
int main(int argc, char* argv[]) | ||
{ | ||
testing::InitGoogleTest(&argc, argv); | ||
return RUN_ALL_TESTS(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
CC := g++ | ||
|
||
TEST_OBJS += ./tests/eventd_ut.o ./tests/main.o | ||
|
||
C_DEPS += ./tests/eventd_ut.d ./tests/main.d | ||
|
||
tests/%.o: tests/%.cpp | ||
@echo 'Building file: $<' | ||
@echo 'Invoking: GCC C++ Compiler' | ||
$(CC) -D__FILENAME__="$(subst src/,,$<)" $(CFLAGS) -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<" | ||
@echo 'Finished building: $<' | ||
@echo ' ' |