diff --git a/clkmgr/Makefile b/clkmgr/Makefile index 2b991898..6d69e6f0 100644 --- a/clkmgr/Makefile +++ b/clkmgr/Makefile @@ -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) diff --git a/clkmgr/utest/client_state.cpp b/clkmgr/utest/client_state.cpp new file mode 100644 index 00000000..53a3aa8f --- /dev/null +++ b/clkmgr/utest/client_state.cpp @@ -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 + * @copyright © 2024 Intel Corporation. + * + */ + +#define NSEC_PER_SEC (1000000000) + +#include "clockmanager.h" +#include +#include + +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, ¤t_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); +}