Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated SDK commit to use the latest SDK code #416

Merged
merged 36 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
61d5485
Updated SDK commit to use the latest SDK code
HarshGandhi-AWS Jun 12, 2023
50b1f21
Addressed reviewers comments and updated unit tests to support the ch…
HarshGandhi-AWS Jun 19, 2023
1516023
Resolved indentation errors
HarshGandhi-AWS Jun 20, 2023
09af0fb
Resolved indentation errors
HarshGandhi-AWS Jun 20, 2023
d196c07
Resolved indentation errors
HarshGandhi-AWS Jun 20, 2023
b4358ef
Resolved indentation errors
HarshGandhi-AWS Jun 20, 2023
866712c
Resolved indentation errors
HarshGandhi-AWS Jun 20, 2023
d0c2eb9
update device mqtt connection logic
HarshGandhi-AWS Jun 20, 2023
a90659d
removing DC initialization code to create multiple lock files
HarshGandhi-AWS Jun 20, 2023
730d839
addressed reviewers comments to resolve test failures
HarshGandhi-AWS Jun 27, 2023
3897903
resolved unit test failure
HarshGandhi-AWS Jun 27, 2023
8e1ce2c
remove MemoryTrace unit test
HarshGandhi-AWS Jun 27, 2023
4d4a60d
resolved Lint errors
HarshGandhi-AWS Jun 27, 2023
6eb723b
explicitly calling the code in SharedCrtManager to initialize allocat…
HarshGandhi-AWS Jul 5, 2023
926147b
addressed lint errors
HarshGandhi-AWS Jul 5, 2023
f9c50fe
addressed lint errors
HarshGandhi-AWS Jul 5, 2023
0597270
addressed reviewers comment and added the config serialization test back
HarshGandhi-AWS Jul 6, 2023
676882c
Update GTestMain.cpp to not cleanup resources after testing is completed
HarshGandhi-AWS Jul 13, 2023
f357df6
Update e2e-tests-ubutu-x86 test to skip secure tunneling test
HarshGandhi-AWS Jul 14, 2023
95db8c9
Compile device client binaries as Release build type (#422)
marcoemorais-aws Aug 3, 2023
f50db70
update sdk commit again
RogerZhongAWS Aug 7, 2023
129f662
Updated code to shutdown on tunnel close callback and updated zlib de…
HarshGandhi-AWS Sep 29, 2023
d0e773d
Updated Secure Tunneling close logic for Secure Tunneling Component (…
HarshGandhi-AWS Oct 3, 2023
6ee7ff9
Added null check before closing connection (#429)
HarshGandhi-AWS Oct 11, 2023
f207eaf
fixed bug to read SIGTERM signal when sent form kernal (#430)
HarshGandhi-AWS Oct 12, 2023
af69d33
Fix docker-build.sh (#423)
RogerZhongAWS Oct 12, 2023
2efead6
Updated google-test lib version to v1.12.0 (#431)
HarshGandhi-AWS Oct 14, 2023
b75dc3a
disabled jobs and secure tunneling if they are not compiled into bina…
HarshGandhi-AWS Nov 7, 2023
0f91380
Update Dockerfile OpenSSL version (#435)
RogerZhongAWS Nov 8, 2023
00f68ce
Removed number of slash validation for MQTT topics (#438)
HarshGandhi-AWS Nov 27, 2023
7f569e9
updated SDK again
HarshGandhi-AWS Dec 5, 2023
d11c527
conflict fix
HarshGandhi-AWS Dec 5, 2023
fb58d1f
add http proxy support for secure tunneling
RogerZhongAWS Dec 11, 2023
1beb832
cleanup http proxy changes
RogerZhongAWS Dec 12, 2023
2aff02a
fix format
RogerZhongAWS Dec 12, 2023
0a3172b
fix format
RogerZhongAWS Dec 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt.awssdk
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ project(aws-iot-device-sdk-cpp-v2-download NONE)
include(ExternalProject)
ExternalProject_Add(aws-iot-device-sdk-cpp-v2
GIT_REPOSITORY https://github.com/aws/aws-iot-device-sdk-cpp-v2.git
GIT_TAG ac3ba3774b031dde1b988e698880d6064d53b9d9
GIT_TAG b12656085b9bf1ecff1a0b8a4c7d496acc3f684f
SOURCE_DIR "${CMAKE_BINARY_DIR}/aws-iot-device-sdk-cpp-v2-src"
BINARY_DIR "${CMAKE_BINARY_DIR}/aws-iot-device-sdk-cpp-v2-build"
CONFIGURE_COMMAND ""
Expand Down
19 changes: 12 additions & 7 deletions source/SharedCrtResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ bool SharedCrtResourceManager::initialize(
std::shared_ptr<Util::FeatureRegistry> featureRegistry)
{
features = featureRegistry;
initializeAllocator(config);
initialized = buildClient(config) == SharedCrtResourceManager::SUCCESS;
return initialized;
}
Expand Down Expand Up @@ -174,22 +173,22 @@ bool SharedCrtResourceManager::setupLogging(const PlainConfig &config) const
return true;
}

void SharedCrtResourceManager::initializeAllocator(const PlainConfig &config)
void SharedCrtResourceManager::initializeAllocator(const aws_mem_trace_level &configMemTraceLevel)
{
allocator = aws_default_allocator();
HarshGandhi-AWS marked this conversation as resolved.
Show resolved Hide resolved
memTraceLevel = config.memTraceLevel;
memTraceLevel = configMemTraceLevel;
if (memTraceLevel != AWS_MEMTRACE_NONE)
{
// If memTraceLevel == AWS_MEMTRACE_STACKS(2), then by default 8 frames per stack are used.
allocator = aws_mem_tracer_new(allocator, nullptr, memTraceLevel, 0);
}
}

int SharedCrtResourceManager::buildClient(const PlainConfig &config)
{
// We MUST declare an instance of the ApiHandle to perform global initialization
// of the SDK libraries
apiHandle = unique_ptr<ApiHandle>(new ApiHandle());
}

int SharedCrtResourceManager::buildClient(const PlainConfig &config)
{
if (config.logConfig.sdkLoggingEnabled)
{
if (!setupLogging(config))
Expand Down Expand Up @@ -516,6 +515,12 @@ Aws::Crt::Io::ClientBootstrap *SharedCrtResourceManager::getClientBootstrap()
void SharedCrtResourceManager::disconnect()
{
LOG_DEBUG(TAG, "Attempting to disconnect MQTT connection");
if (connection == NULL)
{
LOG_WARN(TAG, "Tried to disconnect MQTT connection but the MQTT connection has not yet been established!");
return;
}

if (connection->Disconnect())
{
if (connectionClosedPromise.get_future().wait_for(std::chrono::seconds(DEFAULT_WAIT_TIME_SECONDS)) ==
Expand Down
4 changes: 2 additions & 2 deletions source/SharedCrtResourceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ namespace Aws

int buildClient(const PlainConfig &config);

void initializeAllocator(const PlainConfig &config);

protected:
/**
* inheritable for testing
Expand Down Expand Up @@ -80,6 +78,8 @@ namespace Aws

bool initialize(const PlainConfig &config, std::shared_ptr<Util::FeatureRegistry> featureRegistry);

void initializeAllocator(const aws_mem_trace_level &config);

void initializeAWSHttpLib();

int establishConnection(const PlainConfig &config);
Expand Down
5 changes: 4 additions & 1 deletion source/config/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ bool PlainConfig::LoadFromCliArgs(const CliArgs &cliArgs)
return loadFeatureCliArgs;
}

bool PlainConfig::LoadFromEnvironment()
void PlainConfig::LoadMemTraceLevelFromEnvironment()
HarshGandhi-AWS marked this conversation as resolved.
Show resolved Hide resolved
{
const char *memTraceLevelStr = std::getenv("AWS_CRT_MEMORY_TRACING");
if (memTraceLevelStr)
Expand All @@ -306,7 +306,10 @@ bool PlainConfig::LoadFromEnvironment()
break;
}
}
}

bool PlainConfig::LoadFromEnvironment()
{
const char *lockFilePathIn = std::getenv("LOCK_FILE_PATH");
if (lockFilePathIn)
{
Expand Down
1 change: 1 addition & 0 deletions source/config/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ namespace Aws
mutable std::vector<SensorSettings> settings;
};
SensorPublish sensorPublish;
void LoadMemTraceLevelFromEnvironment();
};

class Config
Expand Down
45 changes: 22 additions & 23 deletions source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,20 @@ namespace Aws

int main(int argc, char *argv[])
{
CliArgs cliArgs;

if (Config::CheckTerminalArgs(argc, argv))
{
LoggerFactory::getLoggerInstance()->shutdown();
return 0;
}

resourceManager = std::make_shared<SharedCrtResourceManager>();

config.config.LoadMemTraceLevelFromEnvironment();

resourceManager.get()->initializeAllocator(config.config.memTraceLevel);

CliArgs cliArgs;
if (!Config::ParseCliArgs(argc, argv, cliArgs) || !config.init(cliArgs))
{
LOGM_ERROR(
Expand All @@ -321,6 +329,19 @@ int main(int argc, char *argv[])
LOG_WARN(TAG, "Unable to append current working directory to PATH environment variable.");
}

#if !defined(DISABLE_MQTT)
/**
* init() is currently responsible for making sure only 1 instance of Device Client is running at a given time.
* In the future, we may want to move other Device Client startup logic into this function.
* returns false if an exception is thrown
*/
if (!init(argc, argv))
{
LOGM_ERROR(TAG, "*** %s: An instance of Device Client is already running.", DC_FATAL_ERROR);
deviceClientAbort("An instance of Device Client is already running.");
}
#endif

features = make_shared<FeatureRegistry>();

LOGM_INFO(TAG, "Now running AWS IoT Device Client version %s", DEVICE_CLIENT_VERSION_FULL);
Expand All @@ -334,8 +355,6 @@ int main(int argc, char *argv[])
sigprocmask(SIG_BLOCK, &sigset, nullptr);

auto listener = std::make_shared<DefaultClientBaseNotifier>();
resourceManager = std::make_shared<SharedCrtResourceManager>();

if (!resourceManager.get()->initialize(config.config, features))
{
LOGM_ERROR(TAG, "*** %s: Failed to initialize AWS CRT SDK.", DC_FATAL_ERROR);
Expand All @@ -346,16 +365,6 @@ int main(int argc, char *argv[])
if (config.config.fleetProvisioning.enabled &&
!config.config.fleetProvisioningRuntimeConfig.completedFleetProvisioning)
{
/**
* init() is currently responsible for making sure only 1 instance of Device Client is running at a given time.
* In the future, we may want to move other Device Client startup logic into this function.
* returns false if an exception is thrown
*/
if (!init(argc, argv))
{
LOGM_ERROR(TAG, "*** %s: An instance of Device Client is already running.", DC_FATAL_ERROR);
deviceClientAbort("An instance of Device Client is already running.");
}
/*
* Establish MQTT connection using claim certificates and private key to provision the device/thing.
*/
Expand Down Expand Up @@ -394,16 +403,6 @@ int main(int argc, char *argv[])
#endif

#if !defined(DISABLE_MQTT)
/**
* init() is currently responsible for making sure only 1 instance of Device Client is running at a given time.
* In the future, we may want to move other Device Client startup logic into this function.
* returns false if an exception is thrown
*/
if (!init(argc, argv))
{
LOGM_ERROR(TAG, "*** %s: An instance of Device Client is already running.", DC_FATAL_ERROR);
deviceClientAbort("An instance of Device Client is already running.");
}
/*
* Establish MQTT connection using permanent certificate and private key to start and run AWS IoT Device Client
* features.
Expand Down
10 changes: 9 additions & 1 deletion test/config/TestConfig.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

#include "../../source/SharedCrtResourceManager.h"
#include "../../source/config/Config.h"
#include "../../source/util/FileUtils.h"
#include "../../source/util/UniqueString.h"
Expand Down Expand Up @@ -33,6 +34,7 @@ class ConfigTestFixture : public ::testing::Test
public:
ConfigTestFixture() = default;
string outputPath;
shared_ptr<SharedCrtResourceManager> resourceManager;

void SetUp() override
{
Expand Down Expand Up @@ -61,6 +63,12 @@ class ConfigTestFixture : public ::testing::Test
outputPathStream << Config::DEFAULT_SAMPLE_SHADOW_OUTPUT_DIR << Config::DEFAULT_SAMPLE_SHADOW_DOCUMENT_FILE;

outputPath = FileUtils::ExtractExpandedPath(outputPathStream.str().c_str());

resourceManager = std::make_shared<SharedCrtResourceManager>();

PlainConfig configuration;
configuration.LoadMemTraceLevelFromEnvironment();
resourceManager.get()->initializeAllocator(configuration.memTraceLevel);
}

void TearDown() override
Expand Down Expand Up @@ -1729,7 +1737,7 @@ TEST(Config, MemoryTrace)
{
auto levelstr = std::to_string(level);
::setenv("AWS_CRT_MEMORY_TRACING", levelstr.c_str(), 1);
ASSERT_TRUE(config.LoadFromEnvironment()) << "read AWS_CRT_MEMORY_TRACING=" << level;
config.LoadMemTraceLevelFromEnvironment();
ASSERT_EQ(config.memTraceLevel, level);
}
}
82 changes: 18 additions & 64 deletions test/config/TestConfigSerialization.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

#include "../../source/SharedCrtResourceManager.h"
#include "../../source/config/Config.h"
#include "../../source/util/FileUtils.h"
#include "../../source/util/UniqueString.h"
Expand All @@ -20,32 +21,16 @@ using namespace Aws::Crt;
using namespace Aws::Iot::DeviceClient;
using namespace Aws::Iot::DeviceClient::Util;

class SerializeConfigTestFixture : public ::testing::TestWithParam<const char *>
TEST(SerializeConfigTestFixture, SerializeConfigTest)
{
protected:
const char *jsonString;
};
shared_ptr<SharedCrtResourceManager> resourceManager;
resourceManager = std::make_shared<SharedCrtResourceManager>();

TEST_P(SerializeConfigTestFixture, SerializeConfigTest)
{
const char *jsonString = GetParam();
PlainConfig config;
JsonObject jsonObject(jsonString);
config.LoadFromJson(jsonObject.View());
auto inputJsonString = jsonObject.View().WriteCompact();

JsonObject serializedConfig;
config.SerializeToObject(serializedConfig);
auto serializedJsonString = serializedConfig.View().WriteCompact();

ASSERT_STREQ(inputJsonString.c_str(), serializedJsonString.c_str());
}
config.LoadMemTraceLevelFromEnvironment();
resourceManager.get()->initializeAllocator(config.memTraceLevel);

INSTANTIATE_TEST_CASE_P(
SerializationTests,
SerializeConfigTestFixture,
::testing::Values(
R"(
constexpr char jsonString[] = R"(
{
"endpoint": "endpoint value",
"cert": "/tmp/aws-iot-device-client-test-file",
Expand Down Expand Up @@ -138,45 +123,14 @@ INSTANTIATE_TEST_CASE_P(
}
]
}
})",
R"({
HarshGandhi-AWS marked this conversation as resolved.
Show resolved Hide resolved
"logging": {
"level": "DEBUG",
"type": "file",
"file": "./aws-iot-device-client.log",
"enable-sdk-logging": false,
"sdk-log-level": "TRACE",
"sdk-log-file": "/var/log/aws-iot-device-client/sdk.log"
},
"jobs": {
"enabled": true,
"handler-directory": ""
},
"tunneling": {
"enabled": true
},
"device-defender": {
"enabled": true,
"interval": 300
},
"fleet-provisioning": {
"enabled": true
},
"runtime-config": {
"completed-fp": false
},
"samples": {
"pub-sub": {
"enabled": true
}
},
"config-shadow": {
"enabled": true
},
"sample-shadow": {
"enabled": true
},
"secure-element": {
"enabled": true
}
})"));
})";
JsonObject jsonObject(jsonString);
config.LoadFromJson(jsonObject.View());
auto inputJsonString = jsonObject.View().WriteCompact();

JsonObject serializedConfig;
config.SerializeToObject(serializedConfig);
auto serializedJsonString = serializedConfig.View().WriteCompact();

ASSERT_STREQ(inputJsonString.c_str(), serializedJsonString.c_str());
}
5 changes: 4 additions & 1 deletion test/devicedefender/TestDeviceDefender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,11 @@ class TestDeviceDefender : public testing::Test
public:
void SetUp()
{
deviceDefender = unique_ptr<MockDDFeature>(new MockDDFeature());
manager = shared_ptr<SharedCrtResourceManager>(new SharedCrtResourceManager());
config.LoadMemTraceLevelFromEnvironment();
manager.get()->initializeAllocator(config.memTraceLevel);

deviceDefender = unique_ptr<MockDDFeature>(new MockDDFeature());
notifier = shared_ptr<MockNotifier>(new MockNotifier());
task = shared_ptr<MockReportTask>(new MockReportTask());
config = getSimpleDDConfig();
Expand Down
22 changes: 19 additions & 3 deletions test/fleetprovisioning/TestFleetProvisioning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,31 @@
using namespace std;
using namespace Aws::Iot::DeviceClient::FleetProvisioningNS;

TEST(FleetProvisioning, EmptyTemplateParameters)
class FleetProvisioningFeature : public ::testing::Test
{
public:
FleetProvisioningFeature() = default;
shared_ptr<Aws::Iot::DeviceClient::SharedCrtResourceManager> resourceManager;

void SetUp() override
{
resourceManager = std::make_shared<Aws::Iot::DeviceClient::SharedCrtResourceManager>();

Aws::Iot::DeviceClient::PlainConfig configuration;
configuration.LoadMemTraceLevelFromEnvironment();
resourceManager.get()->initializeAllocator(configuration.memTraceLevel);
}
};

TEST_F(FleetProvisioningFeature, EmptyTemplateParameters)
{
Aws::Crt::Optional<std::string> params; // start with empty value
FleetProvisioning fp;
ASSERT_TRUE(fp.MapParameters(params));
params = "{}"; // test empty JSON
}

TEST(FleetProvisioning, MalformedTemplateParameters)
TEST_F(FleetProvisioningFeature, MalformedTemplateParameters)
{
Aws::Crt::Optional<std::string> params("{\"SerialNumber\" \"Device-SN\"}"); // test missing colon
FleetProvisioning fp;
Expand All @@ -28,7 +44,7 @@ TEST(FleetProvisioning, MalformedTemplateParameters)
ASSERT_FALSE(fp.MapParameters(params));
}

TEST(FleetProvisioning, ValidTemplateParameters)
TEST_F(FleetProvisioningFeature, ValidTemplateParameters)
{
Aws::Crt::Optional<std::string> params("{\"SerialNumber\": \"Device-SN\"}"); // test single JSON property
FleetProvisioning fp;
Expand Down
Loading