Skip to content

Commit

Permalink
clkmgr: Add utest for client_state
Browse files Browse the repository at this point in the history
Signed-off-by: Noor Azura Ahmad Tarmizi <[email protected]>
  • Loading branch information
AzuraTarmiziIntel authored and yoongsiang2 committed Oct 21, 2024
1 parent 7652326 commit 4ebd80f
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clkmgr/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ ALL+=$(CLKMGR_LIB_LA) $(CLKMGR_PROXY)
ifdef GTEST_LIB_FLAGS

CLKMGR_CLIENT_UTEST:=$(CLKMGR_UTEST_DIR)/utest_client
CLKMGR_CLIENT_SRC:=subscription
CLKMGR_CLIENT_SRC:=subscription client_state
CLKMGR_CLIENT_OBJS:=$(foreach n,$(CLKMGR_CLIENT_SRC),$(CLKMGR_UTEST_DIR)/$n.o)

$(CLKMGR_UTEST_DIR)/%.o: $(CLKMGR_UTEST_DIR)/%.cpp | $(COMP_DEPS)
Expand Down
62 changes: 62 additions & 0 deletions clkmgr/utest/client_state.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/* SPDX-License-Identifier: BSD-3-Clause
SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */

/** @file
* @brief ClientState class unit tests
*
* @author Noor Azura Ahmad Tarmizi <[email protected]>
* @copyright © 2024 Intel Corporation.
*
*/

#define NSEC_PER_SEC (1000000000)

#include "clockmanager.h"
#include <gmock/gmock.h>
#include <gtest/gtest.h>

using namespace clkmgr;

TEST(ClientStateTest, ApiTest)
{
ClientState cstate = {};
struct timespec current_time = {};
TransportClientId refClientID = { 0x41, 0x42, 0x43 };
clkmgr_event_state eState = {};
clkmgr_event_count eCount = {};
cstate.set_connected(true);
EXPECT_EQ(cstate.get_connected(), true);
cstate.set_subscribed(true);
EXPECT_EQ(cstate.get_subscribed(), true);
cstate.set_sessionId(0x3f);
EXPECT_EQ(cstate.get_sessionId(), 0x3f);
cstate.set_ptp4l_id(0x55);
EXPECT_EQ(cstate.get_ptp4l_id(), 0x55);
cstate.set_clientID(refClientID);
if(clock_gettime(CLOCK_REALTIME, &current_time) == -1)
printf("clock_gettime function failure\n");
else {
cstate.set_last_notification_time(current_time);
EXPECT_EQ(cstate.get_last_notification_time().tv_sec, \
current_time.tv_sec);
EXPECT_EQ(cstate.get_last_notification_time().tv_nsec, \
current_time.tv_nsec);
}
eState.notification_timestamp = current_time.tv_sec;
eState.notification_timestamp *= NSEC_PER_SEC;
eState.notification_timestamp += current_time.tv_nsec;
eState.as_capable = true;
eState.offset_in_range = true;
eState.synced_to_primary_clock = true;
eState.composite_event = false;
eState.gm_changed = false;
eState.clock_offset = 0x1234;
eCount.as_capable_event_count = 0x2;
eCount.offset_in_range_event_count = 0x4;
cstate.set_eventState(eState);
cstate.set_eventStateCount(eCount);
EXPECT_EQ(cstate.get_eventStateCount().as_capable_event_count, 0x2);
EXPECT_EQ(cstate.get_eventStateCount().offset_in_range_event_count, 0x4);
EXPECT_EQ(cstate.get_eventState().as_capable, true);
EXPECT_EQ(cstate.get_eventState().composite_event, false);
}

0 comments on commit 4ebd80f

Please sign in to comment.