Skip to content

Commit 95b1e75

Browse files
committed
Merge branch 'dtls' of https://github.com/SeppoTakalo/mbed-os into dev_rollup
2 parents 7995e8b + 5459a7b commit 95b1e75

25 files changed

+1709
-65
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (c) 2018, Arm Limited and affiliates
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#ifndef UNITTESTS_FEATURES_NETSOCKET_DTLSSOCKET_DTLS_TEST_CONFIG_H_
19+
#define UNITTESTS_FEATURES_NETSOCKET_DTLSSOCKET_DTLS_TEST_CONFIG_H_
20+
21+
#define MBEDTLS_SSL_CLI_C
22+
23+
24+
#endif /* UNITTESTS_FEATURES_NETSOCKET_DTLSSOCKET_DTLS_TEST_CONFIG_H_ */
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright (c) 2018, Arm Limited and affiliates
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "gtest/gtest.h"
19+
#include "features/netsocket/DTLSSocket.h"
20+
#include "NetworkStack_stub.h"
21+
22+
#include "mbed_error.h"
23+
mbed_error_status_t mbed_error(mbed_error_status_t error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number)
24+
{
25+
return 0;
26+
}
27+
28+
// Control the rtos EventFlags stub. See EventFlags_stub.cpp
29+
extern std::list<uint32_t> eventFlagsStubNextRetval;
30+
31+
class TestDTLSSocket : public testing::Test {
32+
public:
33+
unsigned int dataSize = 10;
34+
char dataBuf[10];
35+
protected:
36+
DTLSSocket *socket;
37+
NetworkStackstub stack;
38+
39+
virtual void SetUp()
40+
{
41+
socket = new DTLSSocket();
42+
}
43+
44+
virtual void TearDown()
45+
{
46+
stack.return_values.clear();
47+
eventFlagsStubNextRetval.clear();
48+
delete socket;
49+
}
50+
};
51+
52+
TEST_F(TestDTLSSocket, constructor)
53+
{
54+
EXPECT_TRUE(socket);
55+
}
56+
57+
/* connect */
58+
59+
TEST_F(TestDTLSSocket, connect)
60+
{
61+
socket->open((NetworkStack *)&stack);
62+
63+
stack.return_value = NSAPI_ERROR_OK;
64+
EXPECT_EQ(socket->connect("127.0.0.1", 1024), NSAPI_ERROR_OK);
65+
}
66+
67+
TEST_F(TestDTLSSocket, connect_error)
68+
{
69+
socket->open((NetworkStack *)&stack);
70+
71+
stack.return_value = NSAPI_ERROR_DNS_FAILURE;
72+
EXPECT_EQ(socket->connect("127.0.0.1", 1024), NSAPI_ERROR_DNS_FAILURE);
73+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
####################
3+
# UNIT TESTS
4+
####################
5+
6+
set(unittest-sources
7+
../features/netsocket/SocketAddress.cpp
8+
../features/netsocket/NetworkStack.cpp
9+
../features/netsocket/InternetSocket.cpp
10+
../features/netsocket/UDPSocket.cpp
11+
../features/netsocket/DTLSSocket.cpp
12+
../features/netsocket/DTLSSocketWrapper.cpp
13+
../features/netsocket/TLSSocketWrapper.cpp
14+
../features/frameworks/nanostack-libservice/source/libip4string/ip4tos.c
15+
../features/frameworks/nanostack-libservice/source/libip6string/ip6tos.c
16+
../features/frameworks/nanostack-libservice/source/libip4string/stoip4.c
17+
../features/frameworks/nanostack-libservice/source/libip6string/stoip6.c
18+
../features/frameworks/nanostack-libservice/source/libBits/common_functions.c
19+
)
20+
21+
set(unittest-test-sources
22+
features/netsocket/DTLSSocket/test_DTLSSocket.cpp
23+
stubs/Mutex_stub.cpp
24+
stubs/mbed_assert_stub.c
25+
stubs/equeue_stub.c
26+
../features/nanostack/coap-service/test/coap-service/unittest/stub/mbedtls_stub.c
27+
stubs/EventQueue_stub.cpp
28+
stubs/mbed_shared_queues_stub.cpp
29+
stubs/nsapi_dns_stub.cpp
30+
stubs/EventFlags_stub.cpp
31+
stubs/stoip4_stub.c
32+
stubs/ip4tos_stub.c
33+
stubs/Kernel_stub.cpp
34+
)
35+
36+
set(MBEDTLS_USER_CONFIG_FILE_PATH "\"../UNITTESTS/features/netsocket/DTLSSocket/dtls_test_config.h\"")
37+
set_source_files_properties(features/netsocket/DTLSSocket/test_DTLSSocket.cpp PROPERTIES COMPILE_DEFINITIONS MBEDTLS_USER_CONFIG_FILE=${MBEDTLS_USER_CONFIG_FILE_PATH})
38+
set_source_files_properties(../features/netsocket/DTLSSocket.cpp PROPERTIES COMPILE_DEFINITIONS MBEDTLS_USER_CONFIG_FILE=${MBEDTLS_USER_CONFIG_FILE_PATH})
39+
set_source_files_properties(../features/netsocket/DTLSSocketWrapper.cpp PROPERTIES COMPILE_DEFINITIONS MBEDTLS_USER_CONFIG_FILE=${MBEDTLS_USER_CONFIG_FILE_PATH})
40+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (c) 2018, Arm Limited and affiliates
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#ifndef UNITTESTS_FEATURES_NETSOCKET_DTLSSOCKETWRAPPER_TLS_TEST_CONFIG_H_
19+
#define UNITTESTS_FEATURES_NETSOCKET_DTLSSOCKETWRAPPER_TLS_TEST_CONFIG_H_
20+
21+
#define MBEDTLS_SSL_CLI_C
22+
23+
24+
#endif /* UNITTESTS_FEATURES_NETSOCKET_DTLSSOCKETWRAPPER_TLS_TEST_CONFIG_H_ */

0 commit comments

Comments
 (0)