Skip to content

Commit

Permalink
Merge b69d1b9 into e96735d
Browse files Browse the repository at this point in the history
  • Loading branch information
MushMal authored May 7, 2024
2 parents e96735d + b69d1b9 commit 97fb863
Show file tree
Hide file tree
Showing 16 changed files with 79 additions and 101 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -207,5 +207,6 @@ install(
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")

if(BUILD_TEST)
enable_testing()
add_subdirectory(tst)
endif()
3 changes: 0 additions & 3 deletions src/client/src/Stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -1893,9 +1893,6 @@ STATUS putEventMetadata(PKinesisVideoStream pKinesisVideoStream, UINT32 event, P
UINT32 packagedSizes[MAX_FRAGMENT_METADATA_COUNT] = {0};
PSerializedMetadata serializedNodes[MAX_FRAGMENT_METADATA_COUNT] = {0};
UINT8 neededNodes = 0;
PSerializedMetadata pExistingSerializedMetadata;
StackQueueIterator iterator;
UINT64 data;

CHK(pKinesisVideoStream != NULL, STATUS_NULL_ARG);
pKinesisVideoClient = pKinesisVideoStream->pKinesisVideoClient;
Expand Down
2 changes: 1 addition & 1 deletion src/state/src/State.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ STATUS checkForStateTransition(PStateMachine pStateMachine, PBOOL pTransitionRea
ENTERS();
STATUS retStatus = STATUS_SUCCESS;
PStateMachineState pState = NULL;
UINT64 nextState, time;
UINT64 nextState;
UINT64 customData;
PStateMachineImpl pStateMachineImpl = (PStateMachineImpl) pStateMachine;
UINT64 errorStateTransitionWaitTime = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/src/ExponentialBackoffRetryStrategy.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ STATUS normalizeExponentialBackoffConfig(PExponentialBackoffRetryStrategyConfig
pExponentialBackoffRetryStrategyConfig->jitterType, pExponentialBackoffRetryStrategyConfig->jitterFactor);

// Seed rand to generate random number for jitter
SRAND(GETTIME());
SRAND((UINT32) GETTIME());

CleanUp:
LEAVES();
Expand Down
3 changes: 2 additions & 1 deletion tst/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
cmake_minimum_required(VERSION 3.6.3)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake;${CMAKE_MODULE_PATH}")
include(Utilities)
include(GoogleTest)
project(pic_project_tests LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 11)
Expand Down Expand Up @@ -33,4 +34,4 @@ if(UNIX AND NOT APPLE)
target_link_libraries(kvspic_test rt)
endif()

add_test(${PROJECT_NAME} ${PROJECT_NAME})
add_test(TARGET kvspic_test EXTRA_ARGS --arg1 "${CMAKE_CURRENT_SOURCE_DIR}")
5 changes: 3 additions & 2 deletions tst/client/ClientApiTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ TEST_F(ClientApiTest, kinesisVideoClientCreateSync_Valid_Timeout)
TEST_F(ClientApiTest, kinesisVideoClientCreateSync_Store_Alloc)
{
CLIENT_HANDLE clientHandle, failedClientHandle;
UNUSED_PARAM(failedClientHandle);

mClientSyncMode = TRUE;
mDeviceInfo.clientInfo.createClientTimeout = 20 * HUNDREDS_OF_NANOS_IN_A_MILLISECOND;
Expand Down Expand Up @@ -472,7 +473,7 @@ TEST_F(ClientApiTest, getKinesisVideoMetrics_Valid)
ClientMetrics kinesisVideoClientMetrics;
// Testing all versions
for(UINT64 i = 0; i <= CLIENT_METRICS_CURRENT_VERSION; i++) {
kinesisVideoClientMetrics.version = i;
kinesisVideoClientMetrics.version = (UINT32) i;
EXPECT_EQ(STATUS_SUCCESS, getKinesisVideoMetrics(mClientHandle, &kinesisVideoClientMetrics));
}
}
Expand Down Expand Up @@ -505,7 +506,7 @@ TEST_F(ClientApiTest, getStreamMetrics_Valid)
EXPECT_EQ(STATUS_SUCCESS, createKinesisVideoStream(mClientHandle, &mStreamInfo, &streamHandle));
// Testing all versions
for(UINT64 i = 0; i <= STREAM_METRICS_CURRENT_VERSION; i++) {
streamMetrics.version = i;
streamMetrics.version = (UINT32) i;
EXPECT_EQ(STATUS_SUCCESS, getKinesisVideoStreamMetrics(streamHandle, &streamMetrics));
}

Expand Down
3 changes: 2 additions & 1 deletion tst/client/ClientTestFixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ class ClientTestBase : public ::testing::Test {

void initTestMembers()
{
UINT32 logLevel = 0;
UINT32 logLevel = LOG_LEVEL_WARN;
STATUS retStatus = STATUS_SUCCESS;
auto logLevelStr = GETENV("AWS_KVS_LOG_LEVEL");
if (logLevelStr != NULL) {
Expand All @@ -382,6 +382,7 @@ class ClientTestBase : public ::testing::Test {
// Zero things out
mClientHandle = INVALID_CLIENT_HANDLE_VALUE;
MEMSET(&mDeviceInfo, 0x00, SIZEOF(DeviceInfo));
MEMSET(&mStreamInfo, 0x00, SIZEOF(StreamInfo));
MEMSET(&mClientHandle, 0x00, SIZEOF(ClientCallbacks));
MEMSET(mDeviceName, 0x00, MAX_DEVICE_NAME_LEN);
MEMSET(mStreamName, 0x00, MAX_STREAM_NAME_LEN);
Expand Down
17 changes: 8 additions & 9 deletions tst/client/StreamApiFunctionalityTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ TEST_F(StreamApiFunctionalityTest, putFrame_DescribeStreamNotExisting_CreateNotA

TEST_F(StreamApiFunctionalityTest, streamFormatChange_stateCheck)
{
UINT32 i;
BYTE tempBuffer[10000];
UINT64 timestamp;
Frame frame;
UINT32 i = 0;
BYTE tempBuffer[10000] = {0};
UINT64 timestamp = 0;
Frame frame = {0};
BYTE cpd[100];

CreateStream();
Expand Down Expand Up @@ -161,13 +161,12 @@ TEST_F(StreamApiFunctionalityTest, streamFormatChange_stateCheck)

TEST_F(StreamApiFunctionalityTest, setNalAdaptionFlags_stateCheck)
{
UINT32 i;
BYTE tempBuffer[10000];
UINT64 timestamp;
Frame frame;
UINT32 i = 0;
BYTE tempBuffer[10000] = {0};
UINT64 timestamp = 0;
Frame frame = {0};
UINT32 nalFlags = NAL_ADAPTATION_ANNEXB_NALS | NAL_ADAPTATION_ANNEXB_CPD_NALS;
PKinesisVideoStream pKinesisVideoStream;
PStreamMkvGenerator pStreamMkvGenerator;

// The default would be flags NONE
CreateStream();
Expand Down
4 changes: 2 additions & 2 deletions tst/mkvgen/MkvgenApiTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ TEST_F(MkvgenApiTest, mkvgenGenerateTagsChain_OriginalAPICheck)
TEST_F(MkvgenApiTest, mkvgenGenerateTagsChain_MaxStringsCheck)
{
UINT32 size = 100000;
srand(GETTIME());
SRAND((UINT32) GETTIME());
CHAR tagName[MKV_MAX_TAG_NAME_LEN + 2] = {0};
CHAR tagValue[MKV_MAX_TAG_VALUE_LEN + 2] = {0};
CHAR temp;
Expand Down Expand Up @@ -529,7 +529,7 @@ TEST_F(MkvgenApiTest, mkvgenIncreaseTagsTagSize_FunctionalityTest)
{
UINT32 size = 1000, randomSize = 0, encodedSize = 0;
PBYTE tagsMkvHolder = (PBYTE) MEMCALLOC(1, size);
srand(GETTIME());
SRAND((UINT32) GETTIME());

EXPECT_EQ(STATUS_INVALID_ARG, mkvgenIncreaseTagsTagSize(NULL, 0));

Expand Down
9 changes: 5 additions & 4 deletions tst/utils/ExponentialBackoffUtilsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ class ExponentialBackoffUtilsTest : public UtilTestBase {
EXPECT_EQ(expectedExponentialBackoffStatus, pExponentialBackoffRetryStrategyState->status);
// Record the actual wait time for validation
EXPECT_EQ(retryWaitTimeToVerify, pExponentialBackoffRetryStrategyState->lastRetryWaitTime);
EXPECT_TRUE(inRange(retryWaitTimeToVerify/HUNDREDS_OF_NANOS_IN_A_MILLISECOND, acceptableWaitTimeRange));
EXPECT_TRUE(inRange((DOUBLE) retryWaitTimeToVerify / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, acceptableWaitTimeRange));

UINT64 lastRetrySystemTimeMilliSec = pExponentialBackoffRetryStrategyState->lastRetrySystemTime/(HUNDREDS_OF_NANOS_IN_A_MILLISECOND * 1.0);
UINT64 lastRetrySystemTimeMilliSec =
(UINT64) ((DOUBLE) pExponentialBackoffRetryStrategyState->lastRetrySystemTime / (HUNDREDS_OF_NANOS_IN_A_MILLISECOND * 1.0));
UINT64 currentTimeMilliSec = GETTIME()/HUNDREDS_OF_NANOS_IN_A_MILLISECOND;
UINT64 diffInMilliSec = currentTimeMilliSec - lastRetrySystemTimeMilliSec;

Expand Down Expand Up @@ -245,7 +246,7 @@ TEST_F(ExponentialBackoffUtilsTest, testExponentialBackoffBlockingWait_Bounded)

UINT64 retryWaitTimeToVerify;
UINT32 actualRetryCount = 0;
for (int retryCount = 0; retryCount < maxTestRetryCount; retryCount++) {
for (UINT32 retryCount = 0; retryCount < maxTestRetryCount; retryCount++) {
retryWaitTimeToVerify = 0;
EXPECT_EQ(STATUS_SUCCESS, getExponentialBackoffRetryStrategyWaitTime(&kvsRetryStrategy, &retryWaitTimeToVerify));
EXPECT_EQ(STATUS_SUCCESS, getExponentialBackoffRetryCount(&kvsRetryStrategy, &actualRetryCount));
Expand Down Expand Up @@ -302,7 +303,7 @@ TEST_F(ExponentialBackoffUtilsTest, testExponentialBackoffBlockingWait_FullJitte

UINT64 retryWaitTimeToVerify;
UINT32 actualRetryCount = 0;
for (int retryCount = 0; retryCount < maxTestRetryCount; retryCount++) {
for (UINT32 retryCount = 0; retryCount < maxTestRetryCount; retryCount++) {
retryWaitTimeToVerify = 0;
EXPECT_EQ(STATUS_SUCCESS, getExponentialBackoffRetryStrategyWaitTime(&kvsRetryStrategy, &retryWaitTimeToVerify));
EXPECT_EQ(STATUS_SUCCESS, getExponentialBackoffRetryCount(&kvsRetryStrategy, &actualRetryCount));
Expand Down
6 changes: 3 additions & 3 deletions tst/utils/StackQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ TEST_F(StackQueueFunctionalityTest, StackQueueEnqueueAfterValidation)
UINT64 checkIndex[5];
UINT64 indexShift[5] = {0};

srand(GETTIME());
SRAND((UINT32) GETTIME());
// Create the list
EXPECT_EQ(STATUS_SUCCESS, stackQueueCreate(&pStackQueue));

Expand All @@ -195,7 +195,7 @@ TEST_F(StackQueueFunctionalityTest, StackQueueEnqueueAfterValidation)

for (UINT64 j = 0; j < 5; j++) {
checkIndex[j] = rand()%count;
EXPECT_EQ(STATUS_SUCCESS, stackQueueEnqueueAfterIndex(pStackQueue, checkIndex[j], j));
EXPECT_EQ(STATUS_SUCCESS, stackQueueEnqueueAfterIndex(pStackQueue, (UINT32) checkIndex[j], j));
}

for (UINT64 init = 0; init < 5; init++) {
Expand All @@ -209,7 +209,7 @@ TEST_F(StackQueueFunctionalityTest, StackQueueEnqueueAfterValidation)
}

for (UINT64 k = 0; k < 5; k++) {
EXPECT_EQ(STATUS_SUCCESS, stackQueueGetAt(pStackQueue, checkIndex[k] + indexShift[k], &data));
EXPECT_EQ(STATUS_SUCCESS, stackQueueGetAt(pStackQueue, (UINT32) (checkIndex[k] + indexShift[k]), &data));
EXPECT_EQ(k, data);
}

Expand Down
2 changes: 1 addition & 1 deletion tst/utils/StringSearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ auto randStr = [](SIZE_T n) -> std::string {
std::string s;

// not ideal, but it's important to always randomize rand
SRAND(GETTIME());
SRAND((UINT32) GETTIME());
for (int i = 0; i < n; i++) {
// 8 bits contain 255 characters + 1 null character
s += (CHAR)(RAND() % 255) + 1;
Expand Down
77 changes: 26 additions & 51 deletions tst/utils/Thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,40 @@ class ThreadFunctionalityTest : public UtilTestBase {

#define TEST_THREAD_COUNT 500

MUTEX gThreadMutex;
UINT64 gThreadCount;
volatile SIZE_T gThreadCount = 0;

struct sleep_times {
BOOL threadSleepTime;
UINT64 threadSleepTime;
BOOL threadVisited;
BOOL threadCleared;
};

PVOID testThreadRoutine(PVOID arg)
{
MUTEX_LOCK(gThreadMutex);
gThreadCount++;
ATOMIC_INCREMENT(&gThreadCount);
struct sleep_times* st = (struct sleep_times*) arg;

// Mark as visited
st->threadVisited = TRUE;
MUTEX_UNLOCK(gThreadMutex);


UINT64 sleepTime = st->threadSleepTime;
// Just sleep for some time
THREAD_SLEEP(sleepTime);

MUTEX_LOCK(gThreadMutex);

// Mark as cleared
st->threadCleared = TRUE;

gThreadCount--;
MUTEX_UNLOCK(gThreadMutex);
ATOMIC_DECREMENT(&gThreadCount);
return NULL;
}

TEST_F(ThreadFunctionalityTest, ThreadCreateAndReleaseSimpleCheck)
{
UINT64 index;
TID threads[TEST_THREAD_COUNT];
gThreadMutex = MUTEX_CREATE(FALSE);
struct sleep_times st[TEST_THREAD_COUNT];
TID threads[TEST_THREAD_COUNT] = {0};
struct sleep_times st[TEST_THREAD_COUNT] = {0};

ATOMIC_STORE(&gThreadCount, 0);

// Create the threads
for (index = 0; index < TEST_THREAD_COUNT; index++) {
Expand All @@ -59,24 +53,21 @@ TEST_F(ThreadFunctionalityTest, ThreadCreateAndReleaseSimpleCheck)
EXPECT_EQ(STATUS_SUCCESS, THREAD_JOIN(threads[index], NULL));
}

MUTEX_LOCK(gThreadMutex);
EXPECT_EQ(0, gThreadCount);
MUTEX_UNLOCK(gThreadMutex);

EXPECT_EQ(0, ATOMIC_LOAD(&gThreadCount));

for (index = 0; index < TEST_THREAD_COUNT; index++) {
EXPECT_TRUE(st[index].threadVisited) << "Thread didn't visit index " << index;
EXPECT_TRUE(st[index].threadCleared) << "Thread didn't clear index " << index;
}

MUTEX_FREE(gThreadMutex);
}

TEST_F(ThreadFunctionalityTest, ThreadCreateAndCancel)
{
UINT64 index;
TID threads[TEST_THREAD_COUNT];
gThreadMutex = MUTEX_CREATE(FALSE);
struct sleep_times st[TEST_THREAD_COUNT];
TID threads[TEST_THREAD_COUNT] = {0};
struct sleep_times st[TEST_THREAD_COUNT] = {0};

ATOMIC_STORE(&gThreadCount, 0);

// Create the threads
for (index = 0; index < TEST_THREAD_COUNT; index++) {
Expand All @@ -95,8 +86,10 @@ TEST_F(ThreadFunctionalityTest, ThreadCreateAndCancel)
#endif
}

// wait 2 seconds to make sure all threads are executed
THREAD_SLEEP(2 * HUNDREDS_OF_NANOS_IN_A_SECOND);
// Wait for the threads to finish the initial phase
while (ATOMIC_LOAD(&gThreadCount) != TEST_THREAD_COUNT) {
THREAD_SLEEP(5 * HUNDREDS_OF_NANOS_IN_A_MILLISECOND);
}

// Cancel all the threads
for (index = 0; index < TEST_THREAD_COUNT; index++) {
Expand All @@ -105,29 +98,23 @@ TEST_F(ThreadFunctionalityTest, ThreadCreateAndCancel)


// Validate that threads have been killed and didn't finish successfully
MUTEX_LOCK(gThreadMutex);
EXPECT_EQ(TEST_THREAD_COUNT, gThreadCount);
EXPECT_EQ(TEST_THREAD_COUNT, ATOMIC_LOAD(&gThreadCount));

for (index = 0; index < TEST_THREAD_COUNT; index++) {
EXPECT_TRUE(st[index].threadVisited) << "Thread didn't visit index " << index;
EXPECT_FALSE(st[index].threadCleared) << "Thread shouldn't have cleared index " << index;
}

MUTEX_UNLOCK(gThreadMutex);

MUTEX_FREE(gThreadMutex);
}

TEST_F(ThreadFunctionalityTest, ThreadCreateAndReleaseSimpleCheckWithStack)
{
UINT64 index;
TID threads[TEST_THREAD_COUNT];
gThreadMutex = MUTEX_CREATE(FALSE);
srand(GETTIME());
TID threads[TEST_THREAD_COUNT] = {0};
SRAND((UINT32) GETTIME());
SIZE_T threadStack = 64 * 1024;
struct sleep_times st[TEST_THREAD_COUNT];
struct sleep_times st[TEST_THREAD_COUNT] = {0};

gThreadCount = 0;
ATOMIC_STORE(&gThreadCount, 0);

// Create the threads
for (index = 0; index < TEST_THREAD_COUNT; index++) {
Expand All @@ -142,33 +129,21 @@ TEST_F(ThreadFunctionalityTest, ThreadCreateAndReleaseSimpleCheckWithStack)
EXPECT_EQ(STATUS_SUCCESS, THREAD_JOIN(threads[index], NULL));
}

MUTEX_LOCK(gThreadMutex);
EXPECT_EQ(0, gThreadCount);
MUTEX_UNLOCK(gThreadMutex);
EXPECT_EQ(0, ATOMIC_LOAD(&gThreadCount));

for (index = 0; index < TEST_THREAD_COUNT; index++) {
EXPECT_TRUE(st[index].threadVisited) << "Thread didn't visit index " << index;
EXPECT_TRUE(st[index].threadCleared) << "Thread didn't clear index " << index;
}

MUTEX_FREE(gThreadMutex);
}

TEST_F(ThreadFunctionalityTest, NegativeTest)
{
UINT64 index;
TID threads[TEST_THREAD_COUNT];
gThreadMutex = MUTEX_CREATE(FALSE);
SIZE_T threadStack = 16 * 1024;
struct sleep_times st[TEST_THREAD_COUNT];

gThreadCount = 0;
ATOMIC_STORE(&gThreadCount, 0);
EXPECT_NE(STATUS_SUCCESS, THREAD_CREATE_WITH_PARAMS(NULL, testThreadRoutine, threadStack, NULL));
EXPECT_NE(STATUS_SUCCESS, THREAD_CREATE(NULL, testThreadRoutine, NULL));

MUTEX_LOCK(gThreadMutex);
EXPECT_EQ(0, gThreadCount);
MUTEX_UNLOCK(gThreadMutex);

MUTEX_FREE(gThreadMutex);
EXPECT_EQ(0, ATOMIC_LOAD(&gThreadCount));
}
Loading

0 comments on commit 97fb863

Please sign in to comment.