Skip to content

Commit

Permalink
updated SDK again
Browse files Browse the repository at this point in the history
  • Loading branch information
HarshGandhi-AWS committed Dec 5, 2023
2 parents 00f68ce + f50db70 commit 7f569e9
Show file tree
Hide file tree
Showing 21 changed files with 177 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ RUN mkdir sdk-cpp-workspace \
&& cd sdk-cpp-workspace \
&& git clone https://github.com/aws/aws-iot-device-sdk-cpp-v2.git \
&& cd aws-iot-device-sdk-cpp-v2 \
&& git checkout ac3ba3774b031dde1b988e698880d6064d53b9d9 \
&& git checkout 74c8b683ebe5b1cbf484f6acaa281f56aaa63948 \
&& git submodule update --init --recursive \
&& cd .. \
&& mkdir aws-iot-device-sdk-cpp-v2-build \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ RUN mkdir sdk-cpp-workspace \
&& cd sdk-cpp-workspace \
&& git clone https://github.com/aws/aws-iot-device-sdk-cpp-v2.git \
&& cd aws-iot-device-sdk-cpp-v2 \
&& git checkout ac3ba3774b031dde1b988e698880d6064d53b9d9 \
&& git checkout 74c8b683ebe5b1cbf484f6acaa281f56aaa63948 \
&& git submodule update --init --recursive \
&& cd .. \
&& mkdir aws-iot-device-sdk-cpp-v2-build \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ RUN mkdir sdk-cpp-workspace \
&& cd sdk-cpp-workspace \
&& git clone https://github.com/aws/aws-iot-device-sdk-cpp-v2.git \
&& cd aws-iot-device-sdk-cpp-v2 \
&& git checkout ac3ba3774b031dde1b988e698880d6064d53b9d9 \
&& git checkout 74c8b683ebe5b1cbf484f6acaa281f56aaa63948 \
&& git submodule update --init --recursive \
&& cd .. \
&& mkdir aws-iot-device-sdk-cpp-v2-build \
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ jobs:
DEVICE_KEY_SECRET: ${{ secrets.FP_DEVICE_KEY_SECRET }}
AMAZON_ROOT_CA: ${{ secrets.AMAZON_ROOT_CA }}
run: |
docker run -e AWS_ACCESS_KEY_ID="$(echo ${{ secrets.INTEG_USER_KEY_ID }})" -e AWS_SECRET_ACCESS_KEY="$(echo ${{ secrets.INTEG_USER_KEY_SECRET }})" -e IOT_ENDPOINT="$(echo $IOT_ENDPOINT)" -e CERTIFICATE="$(echo $CERTIFICATE)" -e DEVICE_KEY_SECRET="$(echo $DEVICE_KEY_SECRET)" -e AMAZON_ROOT_CA="$(echo $AMAZON_ROOT_CA)" -e THING_NAME=fleetprovisioning ${{ steps.build-test-runner.outputs.imageid }} --clean-up
docker run -e AWS_ACCESS_KEY_ID="$(echo ${{ secrets.INTEG_USER_KEY_ID }})" -e AWS_SECRET_ACCESS_KEY="$(echo ${{ secrets.INTEG_USER_KEY_SECRET }})" -e IOT_ENDPOINT="$(echo $IOT_ENDPOINT)" -e CERTIFICATE="$(echo $CERTIFICATE)" -e DEVICE_KEY_SECRET="$(echo $DEVICE_KEY_SECRET)" -e AMAZON_ROOT_CA="$(echo $AMAZON_ROOT_CA)" -e THING_NAME=fleetprovisioning ${{ steps.build-test-runner.outputs.imageid }} --skip-st --clean-up
e2e-tests-ubuntu-aarch64:
runs-on: ubuntu-latest
if: ${{ false }} # Disabled for now. aarch64 local proxy build takes too long
Expand Down
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 74c8b683ebe5b1cbf484f6acaa281f56aaa63948
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
4 changes: 2 additions & 2 deletions integration-tests/source/GTestMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ bool parseCliArgs(int argc, char **argv)
}
else if (currentArg == CLI_CLEAN_UP)
{
CLEAN_UP = true;
CLEAN_UP = false;
}
else
{
Expand Down Expand Up @@ -185,4 +185,4 @@ int main(int argc, char **argv)
printf("Tests Complete!\n");
Aws::ShutdownAPI(options);
return rc;
}
}
36 changes: 30 additions & 6 deletions source/SharedCrtResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,31 @@ bool SharedCrtResourceManager::initialize(
std::shared_ptr<Util::FeatureRegistry> featureRegistry)
{
features = featureRegistry;
initializeAllocator(config);
initialized = buildClient(config) == SharedCrtResourceManager::SUCCESS;
return initialized;
}

void SharedCrtResourceManager::loadMemTraceLevelFromEnvironment()
{
const char *memTraceLevelStr = std::getenv("AWS_CRT_MEMORY_TRACING");
if (memTraceLevelStr)
{
switch (atoi(memTraceLevelStr))
{
case AWS_MEMTRACE_BYTES:
LOG_DEBUG(Config::TAG, "Set AWS_CRT_MEMORY_TRACING=AWS_MEMTRACE_BYTES");
memTraceLevel = AWS_MEMTRACE_BYTES;
break;
case AWS_MEMTRACE_STACKS:
LOG_DEBUG(Config::TAG, "Set AWS_CRT_MEMORY_TRACING=AWS_MEMTRACE_STACKS");
memTraceLevel = AWS_MEMTRACE_STACKS;
break;
default:
break;
}
}
}

bool SharedCrtResourceManager::locateCredentials(const PlainConfig &config) const
{
struct stat fileInfo;
Expand Down Expand Up @@ -174,22 +194,24 @@ bool SharedCrtResourceManager::setupLogging(const PlainConfig &config) const
return true;
}

void SharedCrtResourceManager::initializeAllocator(const PlainConfig &config)
void SharedCrtResourceManager::initializeAllocator()
{
loadMemTraceLevelFromEnvironment();
allocator = aws_default_allocator();
memTraceLevel = config.memTraceLevel;

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 @@ -520,6 +542,8 @@ void SharedCrtResourceManager::disconnect()
{
return;
}

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

int buildClient(const PlainConfig &config);

void initializeAllocator(const PlainConfig &config);
void loadMemTraceLevelFromEnvironment();

protected:
/**
Expand All @@ -58,7 +58,7 @@ namespace Aws
bool locateCredentials(const PlainConfig &config) const;

public:
SharedCrtResourceManager() = default;
SharedCrtResourceManager() {}

virtual ~SharedCrtResourceManager();

Expand All @@ -80,6 +80,8 @@ namespace Aws

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

void initializeAllocator();

void initializeAWSHttpLib();

int establishConnection(const PlainConfig &config);
Expand Down
18 changes: 0 additions & 18 deletions source/config/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,24 +290,6 @@ bool PlainConfig::LoadFromCliArgs(const CliArgs &cliArgs)

bool PlainConfig::LoadFromEnvironment()
{
const char *memTraceLevelStr = std::getenv("AWS_CRT_MEMORY_TRACING");
if (memTraceLevelStr)
{
switch (atoi(memTraceLevelStr))
{
case AWS_MEMTRACE_BYTES:
LOG_DEBUG(Config::TAG, "Set AWS_CRT_MEMORY_TRACING=AWS_MEMTRACE_BYTES");
memTraceLevel = AWS_MEMTRACE_BYTES;
break;
case AWS_MEMTRACE_STACKS:
LOG_DEBUG(Config::TAG, "Set AWS_CRT_MEMORY_TRACING=AWS_MEMTRACE_STACKS");
memTraceLevel = AWS_MEMTRACE_STACKS;
break;
default:
break;
}
}

const char *lockFilePathIn = std::getenv("LOCK_FILE_PATH");
if (lockFilePathIn)
{
Expand Down
1 change: 0 additions & 1 deletion source/config/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ namespace Aws
Aws::Crt::Optional<std::string> rootCa;
Aws::Crt::Optional<std::string> thingName;

aws_mem_trace_level memTraceLevel{AWS_MEMTRACE_NONE};
std::string lockFilePath{DEFAULT_LOCK_FILE_PATH};

struct LogConfig : public LoadableFromJsonAndCliAndEnvironment
Expand Down
9 changes: 6 additions & 3 deletions source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,17 @@ 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>();
resourceManager->initializeAllocator();

CliArgs cliArgs;
if (!Config::ParseCliArgs(argc, argv, cliArgs) || !config.init(cliArgs))
{
LOGM_ERROR(
Expand Down Expand Up @@ -352,8 +357,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 Down
26 changes: 6 additions & 20 deletions 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,9 +34,13 @@ class ConfigTestFixture : public ::testing::Test
public:
ConfigTestFixture() = default;
string outputPath;
SharedCrtResourceManager resourceManager;

void SetUp() override
{
// Initializing allocator, so we can use CJSON lib from SDK in our unit tests.
resourceManager.initializeAllocator();

// Config::Validate will check that cert, key, and root-ca files exist.
// Create a temporary file to use as a placeholder for this purpose.
ofstream file(filePath, std::fstream::app);
Expand Down Expand Up @@ -154,6 +159,7 @@ TEST_F(ConfigTestFixture, AllFeaturesEnabled)
"secure-element-token-label": "token-label"
}
})";

JsonObject jsonObject(jsonString);
JsonView jsonView = jsonObject.View();

Expand Down Expand Up @@ -1678,23 +1684,3 @@ TEST_F(ConfigTestFixture, HTTPProxyConfigNoAuth)
ASSERT_FALSE(httpProxyConfig.httpProxyAuthEnabled);
ASSERT_STREQ("None", httpProxyConfig.proxyAuthMethod->c_str());
}

TEST(Config, MemoryTrace)
{
PlainConfig config;

// Test all permutations of memory trace set through the environment.
vector<aws_mem_trace_level> levels{
AWS_MEMTRACE_NONE,
AWS_MEMTRACE_BYTES,
AWS_MEMTRACE_STACKS,
};

for (const auto &level : levels)
{
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;
ASSERT_EQ(config.memTraceLevel, level);
}
}
Loading

0 comments on commit 7f569e9

Please sign in to comment.