working with current SDK
This commit is contained in:
Родитель
24fb05bf9c
Коммит
551b8a0111
|
@ -0,0 +1,29 @@
|
|||
#Copyright (c) Microsoft. All rights reserved.
|
||||
#Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
cmake_minimum_required(VERSION 2.8.11)
|
||||
|
||||
project(azure_external_unit_tests)
|
||||
|
||||
# Set up the C SDK options to build as little as possible
|
||||
option(skip_samples "set skip_samples to ON to skip building samples (default is OFF)[if possible, they are always build]" ON)
|
||||
option(compileOption_C "passes a string to the command line of the C compiler" OFF)
|
||||
option(compileOption_CXX "passes a string to the command line of the C++ compiler" OFF)
|
||||
option(no_logging "disable logging" OFF)
|
||||
option(run_e2e_tests "set run_e2e_tests to ON to run e2e tests (default is OFF)" OFF)
|
||||
option(run_unittests "set run_unittests to ON to run unittests (default is OFF)" OFF)
|
||||
option(use_cppunittest "set use_cppunittest to ON to build CppUnitTest tests on Windows (default is ON)" ON)
|
||||
|
||||
# include the sdk for its header files and libs
|
||||
set(run_unittests OFF)
|
||||
include("sdk/c-utility/configs/azure_iot_external_pal_unit_test_setup.cmake")
|
||||
|
||||
# Configure this external repo
|
||||
# Currently this CMakeLists.txt file is only used for unit tests
|
||||
# EXTERNAL_PAL_REPO_DIR contains this top-level CMakeLists.txt
|
||||
set(EXTERNAL_PAL_REPO_DIR ${CMAKE_CURRENT_LIST_DIR})
|
||||
include_directories(${SHARED_UTIL_PAL_INC_FOLDER})
|
||||
|
||||
|
||||
set(run_unittests ON)
|
||||
add_subdirectory(sdk_tests)
|
16
component.mk
16
component.mk
|
@ -13,13 +13,14 @@ CFLAGS += -DUSE_LWIP_SOCKET_FOR_AZURE_IOT
|
|||
|
||||
COMPONENT_ADD_INCLUDEDIRS := \
|
||||
pal \
|
||||
pal/inc \
|
||||
sdk/c-utility/inc \
|
||||
sdk/c-utility/inc/azure_c_shared_utility \
|
||||
sdk/c-utility/pal/inc \
|
||||
sdk/iothub_client/inc \
|
||||
sdk/umqtt/inc \
|
||||
sdk/umqtt/inc/azure_umqtt_c \
|
||||
sdk/parson
|
||||
sdk/deps/parson
|
||||
|
||||
COMPONENT_OBJS = \
|
||||
sdk/c-utility/src/xlogging.o \
|
||||
|
@ -57,6 +58,7 @@ sdk/iothub_client/src/iothub_client_ll.o \
|
|||
sdk/iothub_client/src/iothub_client_ll_uploadtoblob.o \
|
||||
sdk/iothub_client/src/iothub_client_authorization.o \
|
||||
sdk/iothub_client/src/iothub_client_retry_control.o \
|
||||
sdk/iothub_client/src/iothub_client_diagnostic.o \
|
||||
sdk/iothub_client/src/iothub_message.o \
|
||||
sdk/iothub_client/src/iothubtransport.o \
|
||||
sdk/iothub_client/src/iothubtransportmqtt.o \
|
||||
|
@ -76,17 +78,17 @@ sdk/c-utility/src/singlylinkedlist.o \
|
|||
\
|
||||
sdk/c-utility/pal/dns_async.o \
|
||||
sdk/c-utility/pal/socket_async.o \
|
||||
sdk/c-utility/pal/free_rtos/threadapi.o \
|
||||
sdk/c-utility/pal/free_rtos/tickcounter.o \
|
||||
sdk/c-utility/pal/freertos/threadapi.o \
|
||||
sdk/c-utility/pal/freertos/tickcounter.o \
|
||||
sdk/c-utility/pal/lwip/sntp_lwip.o \
|
||||
\
|
||||
pal/platform_openssl_compact.o \
|
||||
pal/tlsio_openssl_compact.o
|
||||
pal/src/platform_openssl_compact.o \
|
||||
pal/src/tlsio_openssl_compact.o
|
||||
|
||||
COMPONENT_SRCDIRS := \
|
||||
pal \
|
||||
pal/src \
|
||||
sdk/c-utility/pal \
|
||||
sdk/c-utility/pal/free_rtos \
|
||||
sdk/c-utility/pal/freertos \
|
||||
sdk/c-utility/pal/lwip \
|
||||
sdk/c-utility/src \
|
||||
sdk/c-utility/adapters \
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
echo "Cross-compiling a non-working ESP32 example"
|
||||
|
||||
export PATH=$PATH:$ESP32_TOOLS/xtensa-esp32-elf/bin
|
||||
|
||||
# Verify that the ESP32 SDK is at a tested commit
|
||||
pushd $IDF_PATH
|
||||
idf_commit=$(git rev-parse HEAD)
|
||||
tested_idf_commit=53893297299e207029679dc99b7fb33151bdd415
|
||||
popd
|
||||
if [ $idf_commit = $tested_idf_commit ]
|
||||
then echo "ESP32 SDK commit is okay"
|
||||
else
|
||||
echo "ESP32 SDK commit is " $idf_commit
|
||||
echo "ESP32 SDK commit should be " $tested_idf_commit
|
||||
echo "Error: ESP32 SDK commit is wrong"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cd $IDF_PATH/components/azure-iot/sample
|
||||
echo "building in" $(pwd)
|
||||
|
||||
# Copy the sample files
|
||||
sample_dir=$IDF_PATH/components/azure-iot/sdk/iothub_client/samples/iothub_client_sample_mqtt
|
||||
proj_dir=$IDF_PATH/components/azure-iot/sample/main
|
||||
cp $sample_dir/iothub_client_sample_mqtt.c $proj_dir
|
||||
cp $sample_dir/iothub_client_sample_mqtt.h $proj_dir
|
||||
|
||||
make defconfig
|
||||
if [ $? = 0 ]
|
||||
then echo "config generated okay"
|
||||
else
|
||||
echo "!!!FAILED!!! config generation failed"
|
||||
exit $?
|
||||
fi
|
||||
|
||||
make
|
||||
if [ $? = 0 ]
|
||||
then echo "built okay"
|
||||
exit 0
|
||||
else
|
||||
echo "!!!FAILED!!! make failed"
|
||||
exit $?
|
||||
fi
|
|
@ -0,0 +1,11 @@
|
|||
#!/bin/bash
|
||||
# Copyright (c) Microsoft. All rights reserved.
|
||||
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
build_root=$(cd "$(dirname "$0")/.." && pwd)
|
||||
cd $build_root/sdk/c-utility/build_all/linux
|
||||
|
||||
# -- C --
|
||||
./build.sh --run-unittests --run_valgrind --build-root $build_root "$@" #-x
|
||||
[ $? -eq 0 ] || exit $?
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
#!/bin/bash
|
||||
# Copyright (c) Microsoft. All rights reserved.
|
||||
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
build_root=$(cd "$(dirname "$0")/.." && pwd)
|
||||
cd $build_root/sdk/c-utility/build_all/linux
|
||||
|
||||
# -- C --
|
||||
./build.sh --run-unittests --run_valgrind --build-root $build_root "$@" #-x
|
||||
[ $? -eq 0 ] || exit $?
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
@REM Copyright (c) Microsoft. All rights reserved.
|
||||
@REM Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
setlocal
|
||||
|
||||
set build-root=%~dp0..
|
||||
rem // resolve to fully qualified path
|
||||
for %%i in ("%build-root%") do set build-root=%%~fi
|
||||
|
||||
echo %build-root%
|
||||
|
||||
REM -- C --
|
||||
cd %build-root%\sdk\c-utility\build_all\windows
|
||||
|
||||
call build.cmd %* --build-root %build-root% --solution-name azure_external_unit_tests
|
||||
if errorlevel 1 goto :eof
|
||||
cd %build-root%
|
|
@ -1,19 +1,20 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
#ifndef TLSIO_OPENSSL_COMPACT_H
|
||||
#define TLSIO_OPENSSL_COMPACT_H
|
||||
#ifndef TLSIO_PAL_H
|
||||
#define TLSIO_PAL_H
|
||||
|
||||
#include "azure_c_shared_utility/tlsio.h"
|
||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#include "azure_c_shared_utility/tlsio.h"
|
||||
|
||||
MOCKABLE_FUNCTION(, const IO_INTERFACE_DESCRIPTION*, tlsio_openssl_compact_get_interface_description);
|
||||
MOCKABLE_FUNCTION(, const IO_INTERFACE_DESCRIPTION*, tlsio_pal_get_interface_description);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* TLSIO_OPENSSL_COMPACT_H */
|
||||
#endif /* TLSIO_PAL_H */
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include "azure_c_shared_utility/platform.h"
|
||||
#include "sntp.h"
|
||||
#include "tlsio_openssl_compact.h"
|
||||
#include "tlsio_pal.h"
|
||||
|
||||
static const char* const ntpServer = "pool.ntp.org";
|
||||
|
||||
|
@ -24,7 +24,7 @@ int platform_init(void)
|
|||
/* Codes_SRS_PLATFORM_OPENSSL_COMPACT_30_008: [ The platform_get_default_tlsio shall return a set of tlsio functions provided by the OpenSSL micro tlsio implementation. ] */
|
||||
const IO_INTERFACE_DESCRIPTION* platform_get_default_tlsio(void)
|
||||
{
|
||||
return tlsio_openssl_compact_get_interface_description();
|
||||
return tlsio_pal_get_interface_description();
|
||||
}
|
||||
|
||||
STRING_HANDLE platform_get_platform_info(void)
|
|
@ -9,10 +9,9 @@
|
|||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "socket_async.h"
|
||||
#include "tlsio_openssl_compact.h"
|
||||
#include "dns_async.h"
|
||||
#include "tlsio_pal.h"
|
||||
#include "azure_c_shared_utility/gballoc.h"
|
||||
#include "azure_c_shared_utility/tlsio.h"
|
||||
#include "azure_c_shared_utility/xlogging.h"
|
||||
#include "azure_c_shared_utility/agenttime.h"
|
||||
#include "azure_c_shared_utility/singlylinkedlist.h"
|
||||
|
@ -873,7 +872,7 @@ static const IO_INTERFACE_DESCRIPTION tlsio_openssl_interface_description =
|
|||
};
|
||||
|
||||
/* Codes_SRS_TLSIO_30_001: [ The tlsio_openssl_compact shall implement and export all the Concrete functions in the VTable IO_INTERFACE_DESCRIPTION defined in the xio.h. ]*/
|
||||
const IO_INTERFACE_DESCRIPTION* tlsio_openssl_compact_get_interface_description(void)
|
||||
const IO_INTERFACE_DESCRIPTION* tlsio_pal_get_interface_description(void)
|
||||
{
|
||||
return &tlsio_openssl_interface_description;
|
||||
}
|
2
sdk
2
sdk
|
@ -1 +1 @@
|
|||
Subproject commit 04aa51bf78ce819b6ebfda448f8c3a57c9c42b99
|
||||
Subproject commit c75e27bb85b5742f50749c5ba2473a27dbdccf0c
|
|
@ -0,0 +1,9 @@
|
|||
#Copyright (c) Microsoft. All rights reserved.
|
||||
#Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
#this is CMakeLists.txt for the folder tests of C shared utility
|
||||
set(SHARED_UTIL_REAL_TEST_FOLDER ${CMAKE_CURRENT_LIST_DIR}/real_test_files CACHE INTERNAL "this is what needs to be included when doing test sources" FORCE)
|
||||
message(STATUS "including external unit test directory " ${CMAKE_CURRENT_LIST_DIR})
|
||||
if(NOT DEFINED MACOSX)
|
||||
add_subdirectory(tlsio_openssl_compact_ut)
|
||||
endif()
|
|
@ -0,0 +1,30 @@
|
|||
#Copyright (c) Microsoft. All rights reserved.
|
||||
#Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
cmake_minimum_required(VERSION 2.8.11)
|
||||
|
||||
compileAsC11()
|
||||
set(theseTestsName tlsio_openssl_compact_ut)
|
||||
|
||||
set(${theseTestsName}_test_files
|
||||
${theseTestsName}.c
|
||||
)
|
||||
|
||||
set(${theseTestsName}_c_files
|
||||
${SHARED_UTIL_SRC_FOLDER}/singlylinkedlist.c
|
||||
${SHARED_UTIL_SRC_FOLDER}/crt_abstractions.c
|
||||
${EXTERNAL_PAL_REPO_DIR}/pal/src/tlsio_openssl_compact.c
|
||||
)
|
||||
|
||||
set(${theseTestsName}_h_files
|
||||
ssl_impl.h
|
||||
test_defines.h
|
||||
gballoc_ut_impl_1.h
|
||||
gballoc_ut_impl_2.h
|
||||
callbacks.h
|
||||
)
|
||||
|
||||
include_directories(.)
|
||||
include_directories(${EXTERNAL_PAL_REPO_DIR}/pal/inc)
|
||||
|
||||
build_c_test_artifacts(${theseTestsName} ON "tests/azure_c_shared_utility_tests")
|
|
@ -0,0 +1,199 @@
|
|||
// Copyright(c) Microsoft.All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
// This file is made an integral part of tlsio_openssl_compact.c with a #include. It
|
||||
// is broken out for readability.
|
||||
|
||||
#ifndef CALLBACKS_H
|
||||
#define CALLBACKS_H
|
||||
|
||||
|
||||
#define MAX_MESSAGE_COUNT 3
|
||||
|
||||
// Keep track of whether callbacks were performed as expected
|
||||
static int on_io_open_complete_call_count;
|
||||
static bool on_io_open_complete_context_ok;
|
||||
static IO_OPEN_RESULT on_io_open_complete_result;
|
||||
|
||||
static int on_io_error_call_count;
|
||||
static bool on_io_error_context_ok;
|
||||
|
||||
static int on_io_close_call_count;
|
||||
static bool on_io_close_context_ok;
|
||||
|
||||
static int on_io_send_complete_call_count;
|
||||
static bool on_io_send_complete_context_ok;
|
||||
static IO_SEND_RESULT on_io_send_complete_result[MAX_MESSAGE_COUNT];
|
||||
|
||||
static int on_bytes_received_call_count;
|
||||
static bool on_bytes_received_context_ok;
|
||||
|
||||
// Context pointers for the callbacks
|
||||
#define IO_OPEN_COMPLETE_CONTEXT (void*)55
|
||||
#define IO_ERROR_CONTEXT (void*)66
|
||||
#define IO_BYTES_RECEIVED_CONTEXT (void*)77
|
||||
#define IO_CLOSE_COMPLETE_CONTEXT (void*)231
|
||||
#define IO_SEND_COMPLETE_CONTEXT (void*)7658
|
||||
|
||||
static void reset_callback_context_records()
|
||||
{
|
||||
int i;
|
||||
on_io_open_complete_call_count = 0;
|
||||
on_io_open_complete_context_ok = true;
|
||||
on_io_open_complete_result = (IO_OPEN_RESULT)-1;
|
||||
on_io_error_call_count = 0;
|
||||
on_io_error_context_ok = true;
|
||||
on_io_close_call_count = 0;
|
||||
on_io_close_context_ok = true;
|
||||
on_io_send_complete_call_count = 0;
|
||||
on_io_send_complete_context_ok = true;
|
||||
for (i = 0; i < MAX_MESSAGE_COUNT; i++)
|
||||
{
|
||||
on_io_send_complete_result[i] = (IO_SEND_RESULT)-1;
|
||||
}
|
||||
on_bytes_received_call_count = 0;
|
||||
on_bytes_received_context_ok = true;
|
||||
}
|
||||
|
||||
// Callbacks used by the tlsio adapter
|
||||
|
||||
static void on_io_open_complete(void* context, IO_OPEN_RESULT open_result)
|
||||
{
|
||||
bool result_valid = open_result == IO_OPEN_OK || open_result == IO_OPEN_ERROR || open_result == IO_OPEN_CANCELLED;
|
||||
ASSERT_IS_TRUE_WITH_MSG(result_valid, "Invalid IO_OPEN_RESULT");
|
||||
on_io_open_complete_call_count++;
|
||||
on_io_open_complete_result = open_result;
|
||||
if (context != IO_OPEN_COMPLETE_CONTEXT)
|
||||
{
|
||||
on_io_open_complete_context_ok = false;
|
||||
}
|
||||
}
|
||||
|
||||
static void on_io_send_complete(void* context, IO_SEND_RESULT send_result)
|
||||
{
|
||||
on_io_send_complete_result[on_io_send_complete_call_count] = send_result;
|
||||
on_io_send_complete_call_count++;
|
||||
if (context != IO_SEND_COMPLETE_CONTEXT)
|
||||
{
|
||||
on_io_send_complete_context_ok = false;
|
||||
}
|
||||
}
|
||||
|
||||
static void on_io_close_complete(void* context)
|
||||
{
|
||||
on_io_close_call_count++;
|
||||
if (context != IO_CLOSE_COMPLETE_CONTEXT)
|
||||
{
|
||||
on_io_close_context_ok = false;
|
||||
}
|
||||
}
|
||||
|
||||
static void on_bytes_received(void* context, const unsigned char* buffer, size_t size)
|
||||
{
|
||||
size_t i;
|
||||
on_bytes_received_call_count++;
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
ASSERT_BYTE_RECEIVED(buffer[i]);
|
||||
}
|
||||
if (context != IO_BYTES_RECEIVED_CONTEXT)
|
||||
{
|
||||
on_bytes_received_context_ok = false;
|
||||
}
|
||||
}
|
||||
|
||||
static void on_io_error(void* context)
|
||||
{
|
||||
on_io_error_call_count = true;
|
||||
if (context != IO_ERROR_CONTEXT)
|
||||
{
|
||||
on_io_error_context_ok = false;
|
||||
}
|
||||
}
|
||||
|
||||
static void ASSERT_IO_ERROR_CALLBACK(bool called)
|
||||
{
|
||||
int count = called ? 1 : 0;
|
||||
ASSERT_ARE_EQUAL_WITH_MSG(int, count, on_io_error_call_count, "io_error_callback count mismatch");
|
||||
if (count > 0)
|
||||
{
|
||||
ASSERT_IS_TRUE_WITH_MSG(on_io_error_context_ok, "io_error_callback missing context");
|
||||
}
|
||||
}
|
||||
|
||||
static void ASSERT_IO_OPEN_CALLBACK(bool called, int open_result)
|
||||
{
|
||||
if (called)
|
||||
{
|
||||
ASSERT_ARE_EQUAL_WITH_MSG(int, 1, on_io_open_complete_call_count, "on_io_open_complete_callback count mismatch");
|
||||
ASSERT_ARE_EQUAL_WITH_MSG(int, on_io_open_complete_result, open_result, "on_io_open_complete result mismatch");
|
||||
ASSERT_IS_TRUE_WITH_MSG(on_io_open_complete_context_ok, "io_open_complete_context not passed");
|
||||
}
|
||||
else
|
||||
{
|
||||
ASSERT_ARE_EQUAL_WITH_MSG(int, 0, on_io_open_complete_call_count, "unexpected on_io_open_complete_callback");
|
||||
}
|
||||
}
|
||||
|
||||
static void ASSERT_IO_SEND_CALLBACK(bool called, int send_result)
|
||||
{
|
||||
if (called)
|
||||
{
|
||||
ASSERT_ARE_EQUAL_WITH_MSG(int, 1, on_io_send_complete_call_count, "on_io_send_complete_callback count mismatch");
|
||||
ASSERT_ARE_EQUAL_WITH_MSG(int, on_io_send_complete_result[0], send_result, "on_io_send_complete result mismatch");
|
||||
ASSERT_IS_TRUE_WITH_MSG(on_io_send_complete_context_ok, "io_send_complete_context not passed");
|
||||
}
|
||||
else
|
||||
{
|
||||
ASSERT_ARE_EQUAL_WITH_MSG(int, 0, on_io_open_complete_call_count, "unexpected on_io_open_complete_callback");
|
||||
}
|
||||
}
|
||||
|
||||
static void ASSERT_IO_SEND_ABANDONED(int count)
|
||||
{
|
||||
int i;
|
||||
ASSERT_ARE_EQUAL_WITH_MSG(int, count, on_io_send_complete_call_count, "on_io_send_complete_callback count mismatch");
|
||||
ASSERT_IS_TRUE_WITH_MSG(on_io_send_complete_context_ok, "io_send_complete_context not passed");
|
||||
for (i = 0; i < on_io_send_complete_call_count; i++)
|
||||
{
|
||||
ASSERT_ARE_EQUAL_WITH_MSG(int, IO_SEND_CANCELLED, on_io_send_complete_result[i], "send result should be IO_SEND_CANCELLED");
|
||||
}
|
||||
}
|
||||
|
||||
static void ASSERT_IO_CLOSE_CALLBACK(bool called)
|
||||
{
|
||||
if (called)
|
||||
{
|
||||
ASSERT_ARE_EQUAL_WITH_MSG(int, 1, on_io_close_call_count, "on_io_close_complete_callback count mismatch");
|
||||
ASSERT_IS_TRUE_WITH_MSG(on_io_close_context_ok, "io_close_complete_context not passed");
|
||||
}
|
||||
else
|
||||
{
|
||||
ASSERT_ARE_EQUAL_WITH_MSG(int, 0, on_io_close_call_count, "unexpected on_io_close_complete_callback");
|
||||
}
|
||||
}
|
||||
|
||||
static void ASSERT_BYTES_RECEIVED_CALLBACK(bool called, size_t message_size)
|
||||
{
|
||||
if (called)
|
||||
{
|
||||
ASSERT_ARE_EQUAL_WITH_MSG(size_t, message_size, fake_read_bytes_received, "bytes_received count mismatch");
|
||||
ASSERT_IS_TRUE_WITH_MSG(on_bytes_received_context_ok, "bytes_received_context not passed");
|
||||
}
|
||||
else
|
||||
{
|
||||
ASSERT_ARE_EQUAL_WITH_MSG(int, 0, on_bytes_received_call_count, "unexpected bytes_received_callback");
|
||||
}
|
||||
}
|
||||
|
||||
static void ASSERT_NO_CALLBACKS()
|
||||
{
|
||||
ASSERT_IO_ERROR_CALLBACK(false);
|
||||
ASSERT_IO_OPEN_CALLBACK(false, IO_OPEN_ERROR);
|
||||
ASSERT_IO_SEND_CALLBACK(false, IO_SEND_ERROR);
|
||||
ASSERT_IO_CLOSE_CALLBACK(false);
|
||||
ASSERT_BYTES_RECEIVED_CALLBACK(false, 0);
|
||||
}
|
||||
|
||||
#endif // CALLBACKS_H
|
|
@ -0,0 +1,44 @@
|
|||
// Copyright(c) Microsoft.All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
// This file is made an integral part of a unit test implementation with a #include. It
|
||||
// is broken out for reuse and readability.
|
||||
|
||||
#ifndef GBALLOC_UT_IMPL_1_H
|
||||
#define GBALLOC_UT_IMPL_1_H
|
||||
|
||||
// These functions add memory leak checking to the unit test itself rather than
|
||||
// relying on Valgrind, which is inconvenient for troubleshooting.
|
||||
static void add_gballoc_memory_block(void* block);
|
||||
static void remove_gballoc_memory_block(void* block);
|
||||
|
||||
/**
|
||||
* The gballoc.h will replace the malloc, free, and realloc by the my_gballoc functions, in this case,
|
||||
* if you define these mock functions after include the gballoc.h, you will create an infinity recursion,
|
||||
* so, places the my_gballoc functions before the #include "azure_c_shared_utility/gballoc.h"
|
||||
*/
|
||||
static void* my_gballoc_malloc(size_t size)
|
||||
{
|
||||
void* result = malloc(size);
|
||||
add_gballoc_memory_block(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
static void* my_gballoc_realloc(void* ptr, size_t size)
|
||||
{
|
||||
void* result;
|
||||
remove_gballoc_memory_block(ptr);
|
||||
result = realloc(ptr, size);
|
||||
add_gballoc_memory_block(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
static void my_gballoc_free(void* ptr)
|
||||
{
|
||||
remove_gballoc_memory_block(ptr);
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
#endif // GBALLOC_UT_IMPL_1_H
|
||||
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
// Copyright(c) Microsoft.All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
// This file is made an integral part of a unit test implementation with a #include. It
|
||||
// is broken out for reuse and readability.
|
||||
|
||||
#ifndef GBALLOC_UT_IMPL_2_H
|
||||
#define GBALLOC_UT_IMPL_2_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
// This adds memory checking to the gballoc mocking
|
||||
// NOTE: Using ASSERTs wouuld be nice, but this file must preceed their definition
|
||||
// to avoid the malloc infinite recursion problem
|
||||
|
||||
|
||||
#ifndef GBALLOC_UT_IMPL_MAX_ALLOCS
|
||||
#define GBALLOC_UT_IMPL_MAX_ALLOCS 1000
|
||||
#endif
|
||||
|
||||
static void* memory_blocks[GBALLOC_UT_IMPL_MAX_ALLOCS];
|
||||
static uint32_t memory_block_count;
|
||||
|
||||
|
||||
static void init_gballoc_checks()
|
||||
{
|
||||
uint32_t i;
|
||||
memory_block_count = 0;
|
||||
for (i = 0; i < GBALLOC_UT_IMPL_MAX_ALLOCS; i++)
|
||||
{
|
||||
memory_blocks[i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void add_gballoc_memory_block(void* block)
|
||||
{
|
||||
if (block != NULL)
|
||||
{
|
||||
if (memory_block_count < GBALLOC_UT_IMPL_MAX_ALLOCS)
|
||||
{
|
||||
memory_blocks[memory_block_count] = block;
|
||||
memory_block_count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
ASSERT_FAIL("GBALLOC_UT_IMPL_MAX_ALLOCS is too small in add_gballoc_memory_block");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void remove_gballoc_memory_block(void* block)
|
||||
{
|
||||
if (block != NULL)
|
||||
{
|
||||
bool found = false;
|
||||
uint32_t i;
|
||||
for (i = 0; i < memory_block_count; i++)
|
||||
{
|
||||
if (memory_blocks[i] == block)
|
||||
{
|
||||
memory_blocks[i] = NULL;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
{
|
||||
ASSERT_FAIL("unknown block in remove_gballoc_memory_block");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void assert_gballoc_checks()
|
||||
{
|
||||
uint32_t i;
|
||||
for (i = 0; i < memory_block_count; i++)
|
||||
{
|
||||
if (memory_blocks[i] != NULL)
|
||||
{
|
||||
ASSERT_FAIL("undeleted memory block");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // GBALLOC_UT_IMPL_2_H
|
|
@ -0,0 +1,15 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
#include "testrunnerswitcher.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
size_t failedTestCount = 0;
|
||||
/**
|
||||
* Identify the test suite to run here.
|
||||
*/
|
||||
RUN_TEST_SUITE(tlsio_openssl_compact_unittests, failedTestCount);
|
||||
|
||||
return failedTestCount;
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
#ifndef OPEN_SSL_H
|
||||
#define OPEN_SSL_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
extern "C" {
|
||||
#include <cstdint>
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
||||
|
||||
// This header mocks the small subset of the the OpenSSL ssl.h needed for tlsio_openssl_compact testing
|
||||
|
||||
typedef void SSL;
|
||||
typedef void SSL_CTX;
|
||||
|
||||
#define SSL_ERROR_WANT_READ 2
|
||||
#define SSL_ERROR_WANT_WRITE 3
|
||||
|
||||
int TLSv1_2_client_method();
|
||||
void SSL_CTX_set_default_read_buffer_len(SSL_CTX* dummy, int dummy2);
|
||||
|
||||
|
||||
MOCKABLE_FUNCTION(, void, SSL_free, SSL*, ssl);
|
||||
MOCKABLE_FUNCTION(, void, SSL_CTX_free, SSL_CTX*, ctx);
|
||||
MOCKABLE_FUNCTION(, SSL_CTX*, SSL_CTX_new, int, dummy);
|
||||
MOCKABLE_FUNCTION(, SSL*, SSL_new, SSL_CTX*, dummy);
|
||||
MOCKABLE_FUNCTION(, int, SSL_set_fd, SSL*, dummy, int, dummy2);
|
||||
MOCKABLE_FUNCTION(, int, SSL_connect, SSL*, dummy);
|
||||
MOCKABLE_FUNCTION(, int, SSL_write, SSL*, dummy, uint8_t*, buffer, size_t, size);
|
||||
MOCKABLE_FUNCTION(, int, SSL_read, SSL*, dummy, uint8_t*, buffer, size_t, size);
|
||||
MOCKABLE_FUNCTION(, int, SSL_shutdown, SSL*, dummy);
|
||||
MOCKABLE_FUNCTION(, int, SSL_get_error, SSL_CTX*, dummy, int, last_value);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif // OPEN_SSL_H
|
|
@ -0,0 +1,132 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
// This file is made an integral part of tlsio_openssl_compact.c with a #include. It
|
||||
// is broken out for readability.
|
||||
|
||||
#ifndef SSL_ERRORS_H
|
||||
#define SSL_ERRORS_H
|
||||
|
||||
//
|
||||
#define SSL_ERROR__plus__WANT_READ -2
|
||||
#define SSL_ERROR__plus__WANT_WRITE -3
|
||||
#define SSL_ERROR__plus__HARD_FAIL -4
|
||||
|
||||
#define SSL_ERROR_HARD_FAIL 99
|
||||
#define SSL_Good_Ptr (void*)22
|
||||
#define SSL_Good_Context_Ptr (SSL_CTX*)33
|
||||
#define SSL_Good_Socket 44
|
||||
#define SSL_CONNECT_SUCCESS 0
|
||||
#define SSL_SET_FD_SUCCESS 1
|
||||
#define SSL_SET_FD_FAILURE 0
|
||||
#define SSL_READ_NO_DATA 0
|
||||
|
||||
#define SSL_Get_IPv4_OK (uint32_t)0x11223344
|
||||
#define SSL_Get_IPv4_FAIL 0
|
||||
|
||||
#define SSL_good_port_number 447
|
||||
#define SSL_port_number_too_low -1
|
||||
#define SSL_port_number_too_high 0xffff + 1
|
||||
#define SSL_good_host_name "fakehost.com"
|
||||
#define SSL_good_old_host_name "fakehost.com"
|
||||
uint8_t* SSL_send_buffer = (uint8_t*)"111111112222222233333333";
|
||||
size_t SSL_send_message_size = sizeof(SSL_send_buffer) - 1;
|
||||
|
||||
#define DOWORK_RECV_XFER_BUFFER_SIZE 64
|
||||
#define SSL_TEST_MESSAGE_SIZE 64
|
||||
#define SSL_WRITE_MAX_TEST_SIZE 60
|
||||
#define SSL_SHORT_SENT_MESSAGE_SIZE 30
|
||||
#define SSL_FAIL_ME_SENT_MESSAGE_SIZE 1700
|
||||
#define SSL_SHORT_RECEIVED_MESSAGE_SIZE 15
|
||||
#define SSL_LONG_RECEIVED_MESSAGE_SIZE 1500
|
||||
|
||||
static size_t fake_read_byte_out_count = 0;
|
||||
static size_t fake_read_current_byte_out_count = 0;
|
||||
static size_t fake_read_bytes_received = 0;
|
||||
|
||||
|
||||
// The fact that SSL_get_error requires the previous error allows a mocking strategy that
|
||||
// permits encoding the extended error into the main failure
|
||||
static int my_SSL_get_error(SSL* ssl, int callReturn)
|
||||
{
|
||||
(void)ssl;
|
||||
switch (callReturn)
|
||||
{
|
||||
case SSL_ERROR__plus__WANT_READ:
|
||||
return SSL_ERROR_WANT_READ;
|
||||
case SSL_ERROR__plus__WANT_WRITE:
|
||||
return SSL_ERROR_WANT_WRITE;
|
||||
case SSL_ERROR__plus__HARD_FAIL:
|
||||
return SSL_ERROR_HARD_FAIL;
|
||||
}
|
||||
// This foolish-looking code dances around conflicting warnings
|
||||
// in the C and C++ compilers about no return path
|
||||
if (callReturn <= 0)
|
||||
{
|
||||
ASSERT_FAIL("bad enum");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void init_fake_read(size_t byte_count)
|
||||
{
|
||||
fake_read_byte_out_count = byte_count;
|
||||
fake_read_current_byte_out_count = 0;
|
||||
fake_read_bytes_received = 0;
|
||||
}
|
||||
|
||||
static void ASSERT_BYTE_RECEIVED(uint8_t byte)
|
||||
{
|
||||
ASSERT_ARE_EQUAL(size_t, (size_t)byte, (size_t)(fake_read_bytes_received % 256));
|
||||
fake_read_bytes_received++;
|
||||
}
|
||||
|
||||
int my_SSL_read(SSL* ssl, uint8_t* buffer, size_t size)
|
||||
{
|
||||
size_t bytes_to_receive;
|
||||
size_t i;
|
||||
(void)size;
|
||||
ASSERT_ARE_EQUAL(size_t, (size_t)ssl, (size_t)SSL_Good_Ptr);
|
||||
bytes_to_receive = fake_read_byte_out_count - fake_read_current_byte_out_count;
|
||||
bytes_to_receive = bytes_to_receive <= size ? bytes_to_receive : size;
|
||||
for (i = 0; i < bytes_to_receive; i++)
|
||||
{
|
||||
buffer[i] = (uint8_t)(fake_read_current_byte_out_count % 256);
|
||||
fake_read_current_byte_out_count++;
|
||||
}
|
||||
return (int)bytes_to_receive;
|
||||
}
|
||||
|
||||
int my_SSL_write(SSL* ssl, uint8_t* buffer, size_t size)
|
||||
{
|
||||
int result;
|
||||
// "Send" no more than SSL_WRITE_MAX_TEST_SIZE bytes
|
||||
(void)buffer; // not used
|
||||
ASSERT_ARE_EQUAL(size_t, (size_t)ssl, (size_t)SSL_Good_Ptr);
|
||||
if (size == SSL_FAIL_ME_SENT_MESSAGE_SIZE)
|
||||
{
|
||||
result = SSL_ERROR__plus__HARD_FAIL;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (size > SSL_WRITE_MAX_TEST_SIZE)
|
||||
{
|
||||
result = SSL_WRITE_MAX_TEST_SIZE;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = (int)size;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// Empty functions. These must be available to call, but they have no effect
|
||||
int TLSv1_2_client_method() { return 0; }
|
||||
void SSL_CTX_set_default_read_buffer_len(SSL_CTX* dummy, int dummy2) { (void)dummy; (void)dummy2; }
|
||||
|
||||
// End of empty functions
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif // SSL_ERRORS_H
|
|
@ -0,0 +1,43 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
// This file is made an integral part of tlsio_openssl_compact.c with a #include. It
|
||||
// is broken out for readability.
|
||||
|
||||
#ifndef TEST_DEFINES_H
|
||||
#define TEST_DEFINES_H
|
||||
|
||||
#define GOOD_DNS_ASYNC_HANDLE (void*)0x12345678
|
||||
|
||||
#define SETOPTION_PV_COUNT 3
|
||||
#define OPEN_PV_COUNT 4
|
||||
#define SEND_PV_COUNT 4
|
||||
#define CLOSE_PV_COUNT 2
|
||||
|
||||
static TLSIO_CONFIG good_config = { SSL_good_host_name, SSL_good_port_number, NULL, NULL };
|
||||
static TLSIO_CONFIG tlsio_config = { NULL, SSL_good_port_number, NULL, NULL };
|
||||
|
||||
static bool bool_true = true;
|
||||
static bool bool_false = false;
|
||||
static size_t sizeof_bool = sizeof(bool);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
TLSIO_CONFIG* config;
|
||||
const char* fail_msg;
|
||||
} create_parameters_t;
|
||||
|
||||
void populate_create_parameters(create_parameters_t* p, TLSIO_CONFIG* config, const char* hostname, int port, const char* fail_msg)
|
||||
{
|
||||
p->config = config;
|
||||
if (config != NULL)
|
||||
{
|
||||
config->hostname = hostname;
|
||||
config->port = port;
|
||||
config->underlying_io_interface = NULL;
|
||||
config->underlying_io_parameters = NULL;
|
||||
}
|
||||
p->fail_msg = fail_msg;
|
||||
}
|
||||
|
||||
#endif // TEST_DEFINES_H
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Загрузка…
Ссылка в новой задаче