LOCAL_PATH := $(call my-dir)
+wificond_cpp_flags := -std=c++11 -Wall -Werror -Wno-unused-parameter
+wificond_cpp_src := looper_backed_event_loop.cpp
+
###
### wificond daemon.
###
include $(CLEAR_VARS)
LOCAL_MODULE := wificond
-LOCAL_CLANG := true
-LOCAL_CPPFLAGS := -std=c++11 -Wall -Werror -Wno-unused-parameter
+LOCAL_CPPFLAGS := $(wificond_cpp_flags)
LOCAL_INIT_RC := wificond.rc
LOCAL_SRC_FILES := \
- main.cpp \
- looper_backed_event_loop.cpp
+ main.cpp
LOCAL_SHARED_LIBRARIES := \
libbase \
libutils
-LOCAL_MODULE_HOST_OS := linux
+LOCAL_STATIC_LIBRARIES := \
+ libwificond
include $(BUILD_EXECUTABLE)
###
-### wificond unit tests.
+### wificond static library
+###
+include $(CLEAR_VARS)
+LOCAL_MODULE := libwificond
+LOCAL_CPPFLAGS := $(wificond_cpp_flags)
+LOCAL_SRC_FILES := $(wificond_cpp_src)
+LOCAL_SHARED_LIBRARIES := \
+ libbase \
+ libutils
+include $(BUILD_STATIC_LIBRARY)
+
+###
+### wificond host static library
+###
+include $(CLEAR_VARS)
+LOCAL_MODULE := libwificond_host
+LOCAL_CPPFLAGS := $(wificond_cpp_flags)
+LOCAL_SRC_FILES := $(wificond_cpp_src)
+LOCAL_STATIC_LIBRARIES := \
+ libbase \
+ libutils
+LOCAL_MODULE_HOST_OS := linux
+include $(BUILD_HOST_STATIC_LIBRARY)
+
+###
+### wificond host unit tests.
###
include $(CLEAR_VARS)
LOCAL_MODULE := wificond_unit_test
-LOCAL_CPPFLAGS := -std=c++11 -Wall -Werror -Wno-unused-parameter
+LOCAL_CPPFLAGS := $(wificond_cpp_flags)
LOCAL_SRC_FILES := \
tests/main.cpp \
- tests/wificond_unittest.cpp
+ tests/looper_backed_event_loop_unittest.cpp
LOCAL_STATIC_LIBRARIES := \
- libgmock_host
+ libgmock_host \
+ libwificond_host \
+ libbase \
+ libutils \
+ liblog
+LOCAL_MODULE_HOST_OS := linux
include $(BUILD_HOST_NATIVE_TEST)
-//
-// Copyright (C) 2016 The Android Open Source Project
-//
-// 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.
-//
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * 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.
+ */
#ifndef WIFICOND_EVENT_LOOP_H_
#define WIFICOND_EVENT_LOOP_H_
-//
-// Copyright (C) 2016 The Android Open Source Project
-//
-// 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.
-//
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * 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 <looper_backed_event_loop.h>
-//
-// Copyright (C) 2016 The Android Open Source Project
-//
-// 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.
-//
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * 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.
+ */
#ifndef WIFICOND_LOOPER_BACKED_EVENT_LOOP_H_
#define WIFICOND_LOOPER_BACKED_EVENT_LOOP_H_
--- /dev/null
+/*
+ * Copyright (C) 2016, The Android Open Source Project
+ *
+ * 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 <memory>
+
+#include <gtest/gtest.h>
+#include <utils/StopWatch.h>
+
+#include <looper_backed_event_loop.h>
+
+namespace {
+
+const int kTimingToleranceMs = 25;
+
+} // namespace
+
+namespace android {
+namespace wificond {
+
+class WificondLooperBackedEventLoopTest : public ::testing::Test {
+ protected:
+ std::unique_ptr<LooperBackedEventLoop> event_loop_;
+
+ virtual void SetUp() {
+ event_loop_.reset(new LooperBackedEventLoop());
+ }
+};
+
+TEST_F(WificondLooperBackedEventLoopTest, LooperBackedEventLoopPostTaskTest) {
+ bool task_executed = false;
+ event_loop_->PostTask([this, &task_executed]() mutable {
+ task_executed = true; event_loop_->TriggerExit();});
+ EXPECT_FALSE(task_executed);
+ event_loop_->Poll();
+ EXPECT_TRUE(task_executed);
+}
+
+TEST_F(WificondLooperBackedEventLoopTest,
+ LooperBackedEventLoopPostDelayedTaskTest) {
+ bool task_executed = false;
+ event_loop_->PostDelayedTask([this, &task_executed]() mutable {
+ task_executed = true; event_loop_->TriggerExit();}, 500);
+ EXPECT_FALSE(task_executed);
+ StopWatch stopWatch("DelayedTask");
+ event_loop_->Poll();
+ int32_t elapsedMillis = ns2ms(stopWatch.elapsedTime());
+ EXPECT_NEAR(500, elapsedMillis, kTimingToleranceMs);
+ EXPECT_TRUE(task_executed);
+}
+
+} // namespace wificond
+} // namespace android
+++ /dev/null
-/*
- * Copyright (C) 2016, The Android Open Source Project
- *
- * 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 <gtest/gtest.h>
-
-namespace android {
-namespace wificond {
-
-class WificondTest : public ::testing::Test {
-};
-
-TEST_F(WificondTest, dummyTest) {
- EXPECT_TRUE(true);
-}
-
-} // namespace wificond
-} // namespace android