Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dgl
Commits
7bdc1619
Unverified
Commit
7bdc1619
authored
May 26, 2019
by
Chao Ma
Committed by
GitHub
May 26, 2019
Browse files
add network cpp test (#565)
parent
9aa5ffca
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
176 additions
and
0 deletions
+176
-0
tests/cpp/graph_index_test.cc
tests/cpp/graph_index_test.cc
+5
-0
tests/cpp/message_queue_test.cc
tests/cpp/message_queue_test.cc
+43
-0
tests/cpp/tcp_socket_test.cc
tests/cpp/tcp_socket_test.cc
+128
-0
No files found.
tests/cpp/graph_index_test.cc
View file @
7bdc1619
/*!
* Copyright (c) 2019 by Contributors
* \file msg_queue.cc
* \brief Message queue for DGL distributed training.
*/
#include <gtest/gtest.h>
#include <gtest/gtest.h>
#include <dgl/graph.h>
#include <dgl/graph.h>
...
...
tests/cpp/message_queue_test.cc
0 → 100644
View file @
7bdc1619
/*!
* Copyright (c) 2019 by Contributors
* \file msg_queue.cc
* \brief Message queue for DGL distributed training.
*/
#include <gtest/gtest.h>
#include <string>
#include "../src/graph/network/msg_queue.h"
using
std
::
string
;
using
dgl
::
network
::
MessageQueue
;
TEST
(
MessageQueueTest
,
AddRemove
)
{
MessageQueue
queue
(
5
,
1
);
// size:5, num_of_producer:1
char
buff
[
10
];
queue
.
Add
(
"111"
,
3
);
queue
.
Add
(
"22"
,
2
);
EXPECT_EQ
(
0
,
queue
.
Add
(
"xxxx"
,
4
,
false
));
// non-blocking add
queue
.
Remove
(
buff
,
3
);
EXPECT_EQ
(
string
(
buff
,
3
),
string
(
"111"
));
queue
.
Remove
(
buff
,
2
);
EXPECT_EQ
(
string
(
buff
,
2
),
string
(
"22"
));
queue
.
Add
(
"33333"
,
5
);
queue
.
Remove
(
buff
,
5
);
EXPECT_EQ
(
string
(
buff
,
5
),
string
(
"33333"
));
EXPECT_EQ
(
0
,
queue
.
Remove
(
buff
,
10
,
false
));
// non-blocking remove
EXPECT_EQ
(
queue
.
Add
(
"666666"
,
6
),
-
1
);
// exceed buffer size
queue
.
Add
(
"55555"
,
5
);
EXPECT_EQ
(
queue
.
Remove
(
buff
,
3
),
-
1
);
// message too long
}
TEST
(
MessageQueueTest
,
EmptyAndNoMoreAdd
)
{
MessageQueue
queue
(
5
,
2
);
// size:5, num_of_producer:2
char
buff
[
10
];
EXPECT_EQ
(
queue
.
EmptyAndNoMoreAdd
(),
false
);
queue
.
Signal
(
1
);
queue
.
Signal
(
1
);
EXPECT_EQ
(
queue
.
EmptyAndNoMoreAdd
(),
false
);
queue
.
Signal
(
2
);
EXPECT_EQ
(
queue
.
EmptyAndNoMoreAdd
(),
true
);
EXPECT_EQ
(
queue
.
Remove
(
buff
,
5
),
0
);
}
\ No newline at end of file
tests/cpp/tcp_socket_test.cc
0 → 100644
View file @
7bdc1619
/*!
* Copyright (c) 2019 by Contributors
* \file msg_queue.cc
* \brief Message queue for DGL distributed training.
*/
#include <gtest/gtest.h>
#include <string.h>
#include <unistd.h>
#include <string>
#include "../src/graph/network/tcp_socket.h"
using
std
::
string
;
using
dgl
::
network
::
TCPSocket
;
const
size_t
kDataLength
=
9999999
;
// 9.5 MB
TEST
(
TCPSocket
,
SendRecieve
)
{
int
pid
=
fork
();
const
char
*
msg
=
"0123456789"
;
ASSERT_GE
(
pid
,
0
);
if
(
pid
>
0
)
{
// parent: server
TCPSocket
server
;
TCPSocket
client
;
string
cl_ip
;
int
cl_port
;
char
serbuff
[
10
];
memset
(
serbuff
,
'\0'
,
10
);
server
.
SetTimeout
(
5
*
60
*
1000
);
ASSERT_TRUE
(
server
.
Bind
(
"127.0.0.1"
,
2049
));
ASSERT_TRUE
(
server
.
Listen
(
3
));
ASSERT_TRUE
(
server
.
Accept
(
&
client
,
&
cl_ip
,
&
cl_port
));
// Small block
for
(
int
i
=
0
;
i
<
9999
;
++
i
)
{
int
tmp
;
int
recieved_bytes
=
0
;
while
(
recieved_bytes
<
10
)
{
int
max_len
=
10
-
recieved_bytes
;
tmp
=
client
.
Receive
(
&
serbuff
[
recieved_bytes
],
max_len
);
ASSERT_GE
(
tmp
,
0
);
recieved_bytes
+=
tmp
;
}
ASSERT_EQ
(
string
(
"0123456789"
),
string
(
serbuff
,
10
));
int
sent_bytes
=
0
;
while
(
sent_bytes
<
10
)
{
int
max_len
=
10
-
sent_bytes
;
tmp
=
client
.
Send
(
&
msg
[
sent_bytes
],
max_len
);
ASSERT_GE
(
tmp
,
0
);
sent_bytes
+=
tmp
;
}
}
// Big block
char
*
bigdata
=
new
char
[
kDataLength
];
char
*
bigbuff
=
new
char
[
kDataLength
];
memset
(
bigdata
,
'x'
,
kDataLength
);
memset
(
bigbuff
,
'\0'
,
kDataLength
);
int
recieved_bytes
=
0
;
while
(
recieved_bytes
<
kDataLength
)
{
int
max_len
=
kDataLength
-
recieved_bytes
;
int
tmp
=
client
.
Receive
(
&
bigbuff
[
recieved_bytes
],
max_len
);
ASSERT_GE
(
tmp
,
0
);
recieved_bytes
+=
tmp
;
}
for
(
size_t
i
=
0
;
i
<
kDataLength
;
++
i
)
{
ASSERT_EQ
(
bigbuff
[
i
],
'x'
);
}
int
sent_bytes
=
0
;
while
(
sent_bytes
<
kDataLength
)
{
int
max_len
=
kDataLength
-
sent_bytes
;
int
tmp
=
client
.
Send
(
&
bigdata
[
sent_bytes
],
max_len
);
ASSERT_GE
(
tmp
,
0
);
sent_bytes
+=
tmp
;
}
}
else
{
// child: client
sleep
(
3
);
// wait for server
TCPSocket
client
;
ASSERT_TRUE
(
client
.
Connect
(
"127.0.0.1"
,
2049
));
char
clibuff
[
10
];
memset
(
clibuff
,
'\0'
,
10
);
// Small block
for
(
int
i
=
0
;
i
<
9999
;
++
i
)
{
int
tmp
;
int
sent_bytes
=
0
;
while
(
sent_bytes
<
10
)
{
int
max_len
=
10
-
sent_bytes
;
tmp
=
client
.
Send
(
&
msg
[
sent_bytes
],
max_len
);
ASSERT_GE
(
tmp
,
0
);
sent_bytes
+=
tmp
;
}
int
recieved_bytes
=
0
;
while
(
recieved_bytes
<
10
)
{
int
max_len
=
10
-
recieved_bytes
;
tmp
=
client
.
Receive
(
&
clibuff
[
recieved_bytes
],
max_len
);
ASSERT_GE
(
tmp
,
0
);
recieved_bytes
+=
tmp
;
}
ASSERT_EQ
(
string
(
"0123456789"
),
string
(
clibuff
,
10
));
}
// Big block
char
*
bigdata
=
new
char
[
kDataLength
];
char
*
bigbuff
=
new
char
[
kDataLength
];
memset
(
bigdata
,
'x'
,
kDataLength
);
memset
(
bigbuff
,
'\0'
,
kDataLength
);
int
sent_bytes
=
0
;
while
(
sent_bytes
<
kDataLength
)
{
int
max_len
=
kDataLength
-
sent_bytes
;
int
tmp
=
client
.
Send
(
&
bigdata
[
sent_bytes
],
max_len
);
ASSERT_GE
(
tmp
,
0
);
sent_bytes
+=
tmp
;
}
int
recieved_bytes
=
0
;
while
(
recieved_bytes
<
kDataLength
)
{
int
max_len
=
kDataLength
-
recieved_bytes
;
int
tmp
=
client
.
Receive
(
&
bigbuff
[
recieved_bytes
],
max_len
);
ASSERT_GE
(
tmp
,
0
);
recieved_bytes
+=
tmp
;
}
for
(
size_t
i
=
0
;
i
<
kDataLength
;
++
i
)
{
ASSERT_EQ
(
bigbuff
[
i
],
'x'
);
}
}
wait
(
0
);
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment