[Lldb-commits] [lldb] r218422 - The beginnings of a gtest-based test framework.

Todd Fiala todd.fiala at gmail.com
Wed Sep 24 15:57:33 PDT 2014


Author: tfiala
Date: Wed Sep 24 17:57:33 2014
New Revision: 218422

URL: http://llvm.org/viewvc/llvm-project?rev=218422&view=rev
Log:
The beginnings of a gtest-based test framework.

Makes use of LLVM gtest support.  This does *not* run as part of
the lldb test suite.

I'm using it to start testing some components that
I'll be adding to the inner guts of NativeThreadLinux to more
maintainably handle thread states and deferred thread state notification.

Runs with default Makefile target "test" using gmake within a given
test directory (currently only test/c++/native_process/thread_state_coordinator).

The Makefile.rules currently assume it is using the LLVM gtest.  It works on
a canonical MacOSX dir structture (i.e. lldb, lldb/llvm, lldb/llvm/tools/clang).
It also works on Ubuntu assuming the standard dir layout of llvm, llvm/tools/clang,
llvm/tools/lldb.  In this case, it expects a directory called build-debug parallel
to the llvm source dir.  All directory assumptions can be overridden with
environment variables.  See test/c++/make/Makefile.rules for details.

We'll want to make this smarter in the future, particularly around finding the LLVM build
output dir.

Added:
    lldb/trunk/test/c++/
    lldb/trunk/test/c++/make/
    lldb/trunk/test/c++/make/Makefile.rules
    lldb/trunk/test/c++/native_process/
    lldb/trunk/test/c++/native_process/thread_state_coordinator/
    lldb/trunk/test/c++/native_process/thread_state_coordinator/Makefile
    lldb/trunk/test/c++/native_process/thread_state_coordinator/ThreadStateCoordinatorTest.cpp

Added: lldb/trunk/test/c++/make/Makefile.rules
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/c%2B%2B/make/Makefile.rules?rev=218422&view=auto
==============================================================================
--- lldb/trunk/test/c++/make/Makefile.rules (added)
+++ lldb/trunk/test/c++/make/Makefile.rules Wed Sep 24 17:57:33 2014
@@ -0,0 +1,58 @@
+# Retrieve this Makefile's location.
+THIS_FILE_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))/
+
+# Set default target to be test
+.DEFAULT_GOAL := test
+
+# Set up GTEST for canonical Linux and MacOSX source trees.
+ifeq ($(wildcard ../../../../llvm/utils/unittest/googletest),)
+    # Assume llvm/tools/lldb (Non-MacOSX) directory form.
+    LLVM_BASE_DIR := $(realpath ../../../../../..)
+else
+    # Assume lldb/llvm (MacOSX Xcode) directory form.
+    LLVM_BASE_DIR := $(realpath ../../../../llvm)
+endif
+
+ifeq ($(GTEST_DIR),)
+    GTEST_DIR := $(LLVM_BASE_DIR)/utils/unittest/googletest
+endif
+GTEST_INCLUDE_DIR := $(GTEST_DIR)/include
+
+ifeq ($(LLVM_BUILD_DIR),)
+    ifneq ($(wildcard $(THIS_FILE_DIR)../../../llvm-build/Release+Asserts/x86_64/Release+Asserts),)
+        LLVM_BUILD_DIR := $(realpath $(THIS_FILE_DIR)../../../llvm-build/Release+Asserts/x86_64/Release+Asserts)
+    else ifneq ($(wildcard $(THIS_FILE_DIR)../../../../../../build-debug/lib),)
+        LLVM_BUILD_DIR := $(realpath $(THIS_FILE_DIR)../../../../../../build-debug)
+    endif
+endif
+
+ifeq ($(LLVM_BUILD_DIR),)
+    $(error Could not find LLVM build output dir, please set it with LLVM_BUILD_DIR)
+endif
+GTEST_STATIC_LIB_DIR := $(LLVM_BUILD_DIR)/lib
+
+ifeq ($(LLVM_BUILD_INCLUDE_DIR),)
+    ifneq ($(wildcard $(LLVM_BUILD_DIR)/../include),)
+        LLVM_BUILD_INCLUDE_DIR := $(realpath $(LLVM_BUILD_DIR)/../include)
+    else ifneq ($(wildcard $(LLVM_BUILD_DIR)/include),)
+        LLVM_BUILD_INCLUDE_DIR := $(realpath $(LLVM_BUILD_DIR)/include)
+    endif
+endif
+
+ifeq ($(LLVM_BUILD_INCLUDE_DIR),)
+    $(error Could not find LLVM build directory include dir, please set it with LLVM_BUILD_INCLUDE_DIR)
+endif
+
+$(info LLVM_BASE_DIR = $(LLVM_BASE_DIR))
+$(info LLVM_BUILD_DIR = $(LLVM_BUILD_DIR))
+$(info GTEST_DIR = $(GTEST_DIR))
+$(info GTEST_INCLUDE_DIR = $(GTEST_INCLUDE_DIR))
+$(info GTEST_STATIC_LIB_DIR = $(GTEST_STATIC_LIB_DIR))
+
+CFLAGS_EXTRAS += -I $(GTEST_INCLUDE_DIR) -I $(LLVM_BASE_DIR)/include -I $(LLVM_BUILD_INCLUDE_DIR)
+LD_EXTRAS += $(GTEST_STATIC_LIB_DIR)/libgtest.a  $(GTEST_STATIC_LIB_DIR)/libgtest_main.a $(GTEST_STATIC_LIB_DIR)/libLLVMSupport.a
+
+include $(THIS_FILE_DIR)../../make/Makefile.rules
+
+test:: $(EXE)
+	$(realpath $(EXE))

Added: lldb/trunk/test/c++/native_process/thread_state_coordinator/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/c%2B%2B/native_process/thread_state_coordinator/Makefile?rev=218422&view=auto
==============================================================================
--- lldb/trunk/test/c++/native_process/thread_state_coordinator/Makefile (added)
+++ lldb/trunk/test/c++/native_process/thread_state_coordinator/Makefile Wed Sep 24 17:57:33 2014
@@ -0,0 +1,14 @@
+LEVEL = ../../make
+
+CFLAGS_EXTRAS := -D__STDC_LIMIT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_CONSTANT_MACROS
+ENABLE_THREADS := YES
+CXX_SOURCES := $(wildcard *.cpp)
+MAKE_DSYM :=NO
+
+OS := $(shell uname -s)
+$(info OS $(OS))
+ifeq ($(OS),Linux)
+    LD_EXTRAS += -lncurses -ldl
+endif
+
+include $(LEVEL)/Makefile.rules

Added: lldb/trunk/test/c++/native_process/thread_state_coordinator/ThreadStateCoordinatorTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/c%2B%2B/native_process/thread_state_coordinator/ThreadStateCoordinatorTest.cpp?rev=218422&view=auto
==============================================================================
--- lldb/trunk/test/c++/native_process/thread_state_coordinator/ThreadStateCoordinatorTest.cpp (added)
+++ lldb/trunk/test/c++/native_process/thread_state_coordinator/ThreadStateCoordinatorTest.cpp Wed Sep 24 17:57:33 2014
@@ -0,0 +1,7 @@
+#include <limits.h>
+#include "gtest/gtest.h"
+
+TEST(ThreadStateCoordinatorTest, ExpectEqualsWorks)
+{
+	EXPECT_EQ(1, 1);
+}





More information about the lldb-commits mailing list