--- /dev/null
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <aul.h>
+#include <aul_watchdog.h>
+#include <aul_cmd.h>
+#include <aul_sock.h>
+#include <gtest/gtest.h>
+#include <stdlib.h>
+
+#include <bundle_cpp.h>
+
+#include <iostream>
+#include <memory>
+
+#include "mock/mock_hook.h"
+#include "mock/socket_mock.h"
+#include "mock/test_fixture.h"
+#include "src/launch.h"
+
+using ::testing::_;
+using ::testing::DoAll;
+using ::testing::Return;
+using ::testing::SetArgPointee;
+using ::testing::Invoke;
+using ::testing::SaveArg;
+
+namespace {
+
+class Mocks : virtual public ::testing::NiceMock<SocketMock> {};
+
+} // namespace
+
+class WatchdogTest : public TestFixture {
+ public:
+ WatchdogTest() : TestFixture(std::make_unique<::Mocks>()) {}
+
+ virtual void SetUp() {
+ if (aul_is_initialized())
+ return;
+
+ EXPECT_CALL(GetMock<SocketMock>(), send(_, _, _, _))
+ .WillOnce(Invoke([&](int fd, const void* buf, size_t n, int flags)
+ -> ssize_t {
+ return n;
+ }));
+ aul_launch_init(nullptr, nullptr);
+ }
+
+ virtual void TearDown() {
+ aul_launch_fini();
+ }
+};
+
+TEST_F(WatchdogTest, aul_watchdog_enable_P) {
+ int cmd = -1;
+
+ EXPECT_CALL(GetMock<SocketMock>(), send(_, _, _, _))
+ .Times(2)
+ .WillRepeatedly(Invoke([&](int fd, const void* buf, size_t n, int flags)
+ -> ssize_t {
+ const app_pkt_t* header = reinterpret_cast<const app_pkt_t*>(buf);
+ cmd = header->cmd;
+ return n;
+ }));
+
+ int ret = aul_watchdog_enable();
+ EXPECT_EQ(ret, AUL_R_OK);
+ EXPECT_EQ(cmd, WATCHDOG_ENABLE);
+
+ // Post: Disable watchdog
+ aul_watchdog_disable();
+}
+
+TEST_F(WatchdogTest, aul_watchdog_disable_P) {
+ int cmd = -1;
+
+ EXPECT_CALL(GetMock<SocketMock>(), send(_, _, _, _))
+ .Times(2)
+ .WillRepeatedly(Invoke([&](int fd, const void* buf, size_t n, int flags)
+ -> ssize_t {
+ const app_pkt_t* header = reinterpret_cast<const app_pkt_t*>(buf);
+ cmd = header->cmd;
+ return n;
+ }));
+
+ // Pre: Enable watchdog
+ int ret = aul_watchdog_enable();
+ EXPECT_EQ(ret, AUL_R_OK);
+
+ ret = aul_watchdog_disable();
+ EXPECT_EQ(ret, AUL_R_OK);
+ EXPECT_EQ(cmd, WATCHDOG_DISABLE);
+}
+
+TEST_F(WatchdogTest, aul_watchdog_disable_N) {
+ int ret = aul_watchdog_disable();
+ EXPECT_EQ(ret, AUL_R_ERROR);
+}
+
+TEST_F(WatchdogTest, aul_watchdog_kick_P) {
+ int cmd = -1;
+
+ EXPECT_CALL(GetMock<SocketMock>(), send(_, _, _, _))
+ .Times(3)
+ .WillRepeatedly(Invoke([&](int fd, const void* buf, size_t n, int flags)
+ -> ssize_t {
+ const app_pkt_t* header = reinterpret_cast<const app_pkt_t*>(buf);
+ cmd = header->cmd;
+ return n;
+ }));
+
+ // Pre: Enable watchdog
+ int ret = aul_watchdog_enable();
+ EXPECT_EQ(ret, AUL_R_OK);
+
+ ret = aul_watchdog_kick();
+ EXPECT_EQ(ret, AUL_R_OK);
+ EXPECT_EQ(cmd, WATCHDOG_KICK);
+
+ // Post: Disable watchdog
+ aul_watchdog_disable();
+}
+
+TEST_F(WatchdogTest, aul_watchdog_kick_N) {
+ int ret = aul_watchdog_kick();
+ EXPECT_EQ(ret, AUL_R_ERROR);
+}