Add base codes of unit tests 71/123871/3
authorSungbae Yoo <sungbae.yoo@samsung.com>
Fri, 7 Apr 2017 09:17:57 +0000 (18:17 +0900)
committerSungbae Yoo <sungbae.yoo@samsung.com>
Mon, 10 Apr 2017 06:59:15 +0000 (15:59 +0900)
Change-Id: I56eb570a22a8d1e1b79c7fc3358575f2067edb51
Signed-off-by: Sungbae Yoo <sungbae.yoo@samsung.com>
packaging/audit-trail.spec
tests/CMakeLists.txt [new file with mode: 0755]
tests/main.cpp [new file with mode: 0644]
tests/module.cpp [new file with mode: 0644]

index dcf1be3a99ddbe2dbd1da443dba2570d3c95a458..5ab6c993ed0f212d6c0469b3a1498292ab28334d 100755 (executable)
@@ -30,12 +30,34 @@ The audit-trail-kernel package provides a kernel module which is responsible for
 %build
 make %{?jobs:-j%jobs} KERNEL_DEV_PATH=%{kernel_dev_path}
 
+cd tests
+%cmake . -DKERNEL_MOD_PATH=%{kernel_mod_path}
+make %{?jobs:-j%jobs}
+
 %install
 mkdir -p %{buildroot}%{kernel_mod_path}
 make %{?jobs:-j%jobs} KERNEL_DEV_PATH=%{kernel_dev_path} KERNEL_MOD_PATH=%{buildroot}%{kernel_mod_path} install
 
+cd tests
+%make_install
+
 %clean
 make %{?jobs:-j%jobs} KERNEL_DEV_PATH=%{kernel_dev_path} clean
 rm -rf %{buildroot}
 
 %postun
+
+## Test package #######################################################
+%package -n %{name}-unit-tests
+Summary: Unit tests to verify audit-trail module
+Group: Security/Testing
+Requires: %{name} = %{version}-%{release}
+BuildRequires: pkgconfig(klay)
+
+%description -n %{name}-unit-tests
+The audit-trail-unit-test package includes the unit test program to verify the module
+
+%files -n %{name}-unit-tests
+%manifest audit-trail.manifest
+%defattr(644,root,root,755)
+%attr(755,root,root) %{_bindir}/audit-trail-unit-tests
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..4d96c64
--- /dev/null
@@ -0,0 +1,48 @@
+#
+#  Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
+
+PROJECT(audit-trail-unit-tests)
+
+INCLUDE(FindPkgConfig)
+
+IF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7)
+       SET(CXX_STD "c++0x")
+else()
+       SET(CXX_STD "c++11")
+endif()
+
+SET(COMPILE_BASE_FLAGS "-g -fPIC -Werror -Wall -Wl,--as-needed -Wl,--no-whole-archive")
+SET(CMAKE_C_FLAGS              "${COMPILE_BASE_FLAGS} -O0 -ggdb")
+SET(CMAKE_CXX_FLAGS            "${COMPILE_BASE_FLAGS} -O0 -ggdb -std=${CXX_STD} -fno-rtti")
+
+SET(TEST_SRC   main.cpp
+                               module.cpp
+)
+
+ADD_EXECUTABLE(${PROJECT_NAME} ${TEST_SRC})
+SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES  PREFIX ""
+       COMPILE_DEFINITIONS KERNEL_MOD_PATH="${KERNEL_MOD_PATH}"
+)
+
+PKG_CHECK_MODULES(TEST_DEPS REQUIRED   klay
+)
+
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${TEST_DEPS_LIBRARIES})
+
+INSTALL(TARGETS        ${PROJECT_NAME} DESTINATION bin)
diff --git a/tests/main.cpp b/tests/main.cpp
new file mode 100644 (file)
index 0000000..d32624f
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ *  Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+#include <klay/testbench.h>
+#include <klay/audit/logger.h>
+
+int main(int argc, char** argv)
+{
+       audit::Logger::setLogLevel(audit::LogLevel::Trace);
+
+       system("/sbin/insmod " KERNEL_MOD_PATH "/audit-trail.ko");
+
+       testbench::Testbench::runAllTestSuites();
+
+       system("/sbin/rmmod audit-trail");
+
+       return EXIT_SUCCESS;
+}
diff --git a/tests/module.cpp b/tests/module.cpp
new file mode 100644 (file)
index 0000000..a560e2f
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ *  Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+#include <fstream>
+
+#include <klay/error.h>
+#include <klay/exception.h>
+#include <klay/testbench.h>
+#include <klay/process.h>
+
+TESTCASE(ModuleLoadable)
+{
+       std::ifstream modules("/proc/modules");
+       std::string moduleName;
+
+       modules >> moduleName;
+
+       if (moduleName != "audit_trail") {
+               TEST_FAIL("The module isn't loaded");
+       }
+}