Skip to content

Commit

Permalink
Code for performance test.
Browse files Browse the repository at this point in the history
Contains simulator module, metrics module, main application, and sample gateway.json files.
  • Loading branch information
darobs committed Apr 21, 2017
1 parent 2864652 commit b96ba3a
Show file tree
Hide file tree
Showing 14 changed files with 932 additions and 1 deletion.
2 changes: 2 additions & 0 deletions core/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ add_subdirectory(gwmessage_ut)
add_subdirectory(message_q_ut)
add_subdirectory(dynamic_loader_ut)
add_subdirectory(module_loader_ut)

if(${enable_java_binding})
add_subdirectory(java_loader_ut)
endif()
Expand All @@ -34,5 +35,6 @@ endif()

if(${run_e2e_tests})
add_subdirectory(gateway_e2e)
add_subdirectory(performance_e2e)
endif()

91 changes: 91 additions & 0 deletions core/tests/performance_e2e/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#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.12)

include_directories(./inc)
include_directories(${GW_INC})

set(simulator_sources
./src/simulator.cpp
)

set(simulator_headers
./inc/simulator.h
)


#this builds the simulator module
add_library(simulator MODULE ${simulator_sources} ${simulator_headers})
target_link_libraries(simulator gateway)

add_library(simulator_static STATIC ${simulator_sources} ${simulator_headers})
target_compile_definitions(simulator_static PRIVATE BUILD_MODULE_TYPE_STATIC)
target_link_libraries(simulator_static gateway)

linkSharedUtil(simulator)
linkSharedUtil(simulator_static)

add_module_to_solution(simulator)

if(install_modules)
install(TARGETS simulator LIBRARY DESTINATION "${LIB_INSTALL_DIR}/modules")
endif()


set(metrics_sources
./src/metrics.cpp
)

set(metrics_headers
./inc/metrics.h
)


#this builds the metrics module
add_library(metrics MODULE ${metrics_sources} ${metrics_headers})
target_link_libraries(metrics gateway)

add_library(metrics_static STATIC ${metrics_sources} ${metrics_headers})
target_compile_definitions(metrics_static PRIVATE BUILD_MODULE_TYPE_STATIC)
target_link_libraries(metrics_static gateway)

linkSharedUtil(metrics)
linkSharedUtil(metrics_static)

add_module_to_solution(metrics)

if(install_modules)
install(TARGETS metrics LIBRARY DESTINATION "${LIB_INSTALL_DIR}/modules")
endif()


set(performance_e2e_sources
./src/main.cpp
)
if(WIN32)
set(performance_e2e_sources
${performance_e2e_sources}
./src/performance_win.json
)
set_source_files_properties(./src/performance_win.json PROPERTIES HEADER_FILE_ONLY ON)
else()
set(performance_e2e_sources
${performance_e2e_sources}
./src/performance_lin.json
)
set_source_files_properties(./src/performance_lin.json PROPERTIES HEADER_FILE_ONLY ON)
endif()

add_executable(performance_e2e ${performance_e2e_sources})

add_dependencies(performance_e2e simulator metrics)

target_link_libraries(performance_e2e gateway nanomsg)
linkSharedUtil(performance_e2e)
install_broker(performance_e2e ${CMAKE_CURRENT_BINARY_DIR}/$(Configuration) )
copy_gateway_dll(performance_e2e ${CMAKE_CURRENT_BINARY_DIR}/$(Configuration) )

set_target_properties(performance_e2e
PROPERTIES
FOLDER "tests/E2ETests")
2 changes: 1 addition & 1 deletion core/tests/performance_e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ The information the metrics module produces is:
| Maximum latency | Time (microseconds) | Maximum message latency |
| Devices Discovered | Count | Number of deviceId names received in message. |
The metrics module also produces this information for each deviceId recognized:
The metrics module also produces this information for each deviceId recognized.
| Metric | Measure | Description |
| ------------------------ | ------------------- | ----------- |
Expand Down
20 changes: 20 additions & 0 deletions core/tests/performance_e2e/inc/metrics.h
Original file line number Diff line number Diff line change
@@ -0,0 +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 METRICS_H
#define METRICS_H

#include "module.h"

#ifdef __cplusplus
extern "C"
{
#endif

MODULE_EXPORT const MODULE_API* MODULE_STATIC_GETAPI(METRICS_MODULE)(MODULE_API_VERSION gateway_api_version);

#ifdef __cplusplus
}
#endif

#endif /*METRICS_H*/
30 changes: 30 additions & 0 deletions core/tests/performance_e2e/inc/simulator.h
Original file line number Diff line number Diff line change
@@ -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.

#ifndef SIMULATOR_H
#define SIMULATOR_H

#include "module.h"

#ifdef __cplusplus
extern "C"
{
#endif

typedef struct SIMULATOR_MODULE_CONFIG_TAG
{
char * device_id;
size_t message_delay;
size_t properties_count;
size_t properties_size;
size_t message_size;
} SIMULATOR_MODULE_CONFIG;


MODULE_EXPORT const MODULE_API* MODULE_STATIC_GETAPI(SIMULATOR_MODULE)(MODULE_API_VERSION gateway_api_version);

#ifdef __cplusplus
}
#endif

#endif /*SIMULATOR_H*/
44 changes: 44 additions & 0 deletions core/tests/performance_e2e/src/main.cpp
Original file line number Diff line number Diff line change
@@ -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.

#include <iostream>
#include <string>

#include "gateway.h"
#include "azure_c_shared_utility/threadapi.h"
#include <nanomsg/nn.h>

int main(int argc, char** argv)
{
int sleep_in_ms = 5000;
GATEWAY_HANDLE gateway;
if (argc != 2 && argc != 3)
{
std::cout
<< "usage: performance_sample configFile [duration]" << std::endl
<< "where configFile is the name of the file that contains the gateway configuration" << std::endl
<< "where duration is the length of time in seconds for the test to run" << std::endl;
}
else
{
if (argc==3)
{
sleep_in_ms = std::stoi(argv[2]) * 1000;
}

if ((gateway = Gateway_CreateFromJson(argv[1])) == NULL)
{
std::cout << "failed to create the gateway from JSON" << std::endl;
}
else
{

std::cout << "gateway successfully created from JSON" << std::endl;
std::cout << "gateway shall run for " << sleep_in_ms/1000 << " seconds" << std::endl;
ThreadAPI_Sleep(sleep_in_ms);

Gateway_Destroy(gateway);
}
}
return 0;
}
Loading

0 comments on commit b96ba3a

Please sign in to comment.