%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
--- /dev/null
+#
+# 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)
--- /dev/null
+/*
+ * 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;
+}
--- /dev/null
+/*
+ * 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");
+ }
+}