Skip to content

Commit

Permalink
explicitly calling the code in SharedCrtManager to initialize allocat…
Browse files Browse the repository at this point in the history
…or and api handle. This will resolve the Sensor pullish unit tests which manually creates and initializes allocator and eventloop.
  • Loading branch information
HarshGandhi-AWS committed Jul 5, 2023
1 parent 4d4a60d commit 6eb723b
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 2 deletions.
2 changes: 1 addition & 1 deletion source/SharedCrtResourceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace Aws
bool locateCredentials(const PlainConfig &config) const;

public:
SharedCrtResourceManager() { initializeAllocator(); }
SharedCrtResourceManager() { }

virtual ~SharedCrtResourceManager();

Expand Down
1 change: 1 addition & 0 deletions source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ int main(int argc, char *argv[])
}

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

CliArgs cliArgs;
if (!Config::ParseCliArgs(argc, argv, cliArgs) || !config.init(cliArgs))
Expand Down
4 changes: 3 additions & 1 deletion test/config/TestConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class ConfigTestFixture : public ::testing::Test

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 @@ -156,7 +159,6 @@ TEST_F(ConfigTestFixture, AllFeaturesEnabled)
"secure-element-token-label": "token-label"
}
})";
SharedCrtResourceManager resourceManager;

JsonObject jsonObject(jsonString);
JsonView jsonView = jsonObject.View();
Expand Down
2 changes: 2 additions & 0 deletions test/config/TestConfigSerialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ TEST(SerializeConfigTestFixture, SerializeConfigTest)
]
}
})";
//Initializing allocator, so we can use CJSON lib from SDK in our unit tests.
SharedCrtResourceManager resourceManager;
resourceManager.initializeAllocator();
PlainConfig config;

JsonObject jsonObject(jsonString);
Expand Down
3 changes: 3 additions & 0 deletions test/devicedefender/TestDeviceDefender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ class TestDeviceDefender : public testing::Test
{
deviceDefender = unique_ptr<MockDDFeature>(new MockDDFeature());
manager = shared_ptr<SharedCrtResourceManager>(new SharedCrtResourceManager());
//Initializing allocator, so we can use CJSON lib from SDK in our unit tests.
manager->initializeAllocator();

notifier = shared_ptr<MockNotifier>(new MockNotifier());
task = shared_ptr<MockReportTask>(new MockReportTask());
config = getSimpleDDConfig();
Expand Down
6 changes: 6 additions & 0 deletions test/fleetprovisioning/TestFleetProvisioning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ TEST(FleetProvisioning, EmptyTemplateParameters)
TEST(FleetProvisioning, MalformedTemplateParameters)
{
Aws::Iot::DeviceClient::SharedCrtResourceManager resourceManager;
//Initializing allocator, so we can use CJSON lib from SDK in our unit tests.
resourceManager.initializeAllocator();

Aws::Crt::Optional<std::string> params("{\"SerialNumber\" \"Device-SN\"}"); // test missing colon
FleetProvisioning fp;
ASSERT_FALSE(fp.MapParameters(params));
Expand All @@ -33,6 +36,9 @@ TEST(FleetProvisioning, MalformedTemplateParameters)
TEST(FleetProvisioning, ValidTemplateParameters)
{
Aws::Iot::DeviceClient::SharedCrtResourceManager resourceManager;
//Initializing allocator, so we can use CJSON lib from SDK in our unit tests.
resourceManager.initializeAllocator();

Aws::Crt::Optional<std::string> params("{\"SerialNumber\": \"Device-SN\"}"); // test single JSON property
FleetProvisioning fp;
ASSERT_TRUE(fp.MapParameters(params));
Expand Down
16 changes: 16 additions & 0 deletions test/jobs/TestJobDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ TEST(JobDocument, SampleJobDocument)
}
})";

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

JsonObject jsonObject(jsonString);
JsonView jsonView = jsonObject.View();
Expand Down Expand Up @@ -380,7 +382,9 @@ TEST(JobDocument, MissingRequiredFields)
}
})";

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

JsonObject jsonObject(jsonString);
JsonView jsonView = jsonObject.View();
Expand Down Expand Up @@ -435,7 +439,9 @@ TEST(JobDocument, MinimumJobDocument)
]
})";

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

JsonObject jsonObject(jsonString);
JsonView jsonView = jsonObject.View();
Expand Down Expand Up @@ -530,7 +536,9 @@ TEST(JobDocument, MissingRequiredFieldsValue)
}
})";

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

JsonObject jsonObject(jsonString);
JsonView jsonView = jsonObject.View();
Expand Down Expand Up @@ -559,7 +567,9 @@ TEST(JobDocument, CommandFieldsIsEmpty)
]
})";

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

JsonObject jsonObject(jsonString);
JsonView jsonView = jsonObject.View();
Expand Down Expand Up @@ -588,7 +598,9 @@ TEST(JobDocument, CommandContainsSpaceCharacters)
]
})";

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

JsonObject jsonObject(jsonString);
JsonView jsonView = jsonObject.View();
Expand Down Expand Up @@ -617,7 +629,9 @@ TEST(JobDocument, SpaceCharactersContainedWithinFirstWordOfCommand)
]
})";

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

JsonObject jsonObject(jsonString);
JsonView jsonView = jsonObject.View();
Expand All @@ -637,7 +651,9 @@ TEST(JobDocument, oldJobDocumentCompatibility)
"path": "default"
})";

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

JsonObject jsonObject(jsonString);
JsonView jsonView = jsonObject.View();
Expand Down
3 changes: 3 additions & 0 deletions test/jobs/TestJobsFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@ class TestJobsFeature : public ::testing::Test
public:
void SetUp()
{
//Initializing allocator, so we can use CJSON lib from SDK in our unit tests.
resourceManager.initializeAllocator();

ThingName = Aws::Crt::String("thing-name value");
notifier = shared_ptr<MockNotifier>(new MockNotifier());
config = getSimpleConfig();
Expand Down
5 changes: 5 additions & 0 deletions test/shadow/TestConfigShadowFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ TEST(ConfigShadowFeature, resetClientConfigWithValidJSON)
})";

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

JsonObject oldJsonObject(oldJsonString);
JsonView jsonView = oldJsonObject.View();
PlainConfig config;
Expand Down Expand Up @@ -151,6 +154,8 @@ TEST(ConfigShadowFeature, resetClientConfigWithInvalidJSON)
}
})";
SharedCrtResourceManager resourceManager;
//Initializing allocator, so we can use CJSON lib from SDK in our unit tests.
resourceManager.initializeAllocator();

JsonObject oldJsonObject(oldJsonString);
JsonView jsonView = oldJsonObject.View();
Expand Down
3 changes: 3 additions & 0 deletions test/tunneling/TestSecureTunnelingFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ class TestSecureTunnelingFeature : public testing::Test
void SetUp() override
{
manager = shared_ptr<SharedCrtResourceManager>(new SharedCrtResourceManager());
//Initializing allocator, so we can use CJSON lib from SDK in our unit tests.
manager->initializeAllocator();

thingName = Aws::Crt::String("thing-name value");
secureTunnelingFeature = shared_ptr<MockSecureTunnelingFeature>(new MockSecureTunnelingFeature());
mockClient = shared_ptr<MockIotSecureTunnelingClient>(new MockIotSecureTunnelingClient());
Expand Down
3 changes: 3 additions & 0 deletions test/util/TestSharedResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class SharedResourceManagerTest : public ::testing::Test

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

// SharedCrtResourceManager::locateCredentials will check that cert, key files
// have valid permissions. Create a temporary file to use as a placeholder for this purpose.
FileUtils::CreateDirectoryWithPermissions(certDir.c_str(), 0700);
Expand Down
4 changes: 4 additions & 0 deletions test/util/TestStringUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ TEST(StringUtils, leavesNewLineAndTabAlone)

TEST(StringUtils, maptoString)
{
//Initializing allocator, so we can use CJSON lib from SDK in our unit tests.
SharedCrtResourceManager resourceManager;
resourceManager.initializeAllocator();

Aws::Crt::Map<Aws::Crt::String, Aws::Crt::String> map;
map.insert(std::pair<Aws::Crt::String, Aws::Crt::String>("a", "b"));
Expand Down Expand Up @@ -134,7 +136,9 @@ TEST(StringUtils, ParseToStringVector)
{
"args": ["hello", "world"]
})";
//Initializing allocator, so we can use CJSON lib from SDK in our unit tests.
SharedCrtResourceManager resourceManager;
resourceManager.initializeAllocator();

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

0 comments on commit 6eb723b

Please sign in to comment.