[Feature] Framework for integration tests in security-containers.
[Cause] Integration tests in python are to be added to security-containers.
[Solution] Add framework for integration tests using Python's unittest module.
[Verification] Successful build and installation.
Change-Id: I8812f044215fb282de90c1a906a9e433c545f046
Signed-off-by: Lukasz Kostyra <l.kostyra@samsung.com>
ADD_DEFINITIONS(-DPROJECT_SOURCE_DIR="${PROJECT_SOURCE_DIR}")
+## Python packages directory ###################################################
+
+IF(NOT DEFINED PYTHON_SITELIB)
+ EXECUTE_PROCESS(COMMAND python -c
+ "from distutils.sysconfig import get_python_lib; import sys; sys.stdout.write(get_python_lib())"
+ OUTPUT_VARIABLE PYTHON_SITELIB)
+ENDIF(NOT DEFINED PYTHON_SITELIB)
+
+
## Subdirectories ##############################################################
SET(COMMON_FOLDER ${PROJECT_SOURCE_DIR}/common)
SET(CLIENT_FOLDER ${PROJECT_SOURCE_DIR}/client)
%cmake . -DVERSION=%{version} \
-DCMAKE_BUILD_TYPE=%{build_type} \
-DSCRIPT_INSTALL_DIR=%{script_dir} \
- -DSYSTEMD_UNIT_DIR=%{_unitdir}
+ -DSYSTEMD_UNIT_DIR=%{_unitdir} \
+ -DPYTHON_SITELIB=%{python_sitelib}
make -k %{?jobs:-j%jobs}
%install
%defattr(644,root,root,755)
%attr(755,root,root) %{_bindir}/security-containers-server-unit-tests
%attr(755,root,root) %{script_dir}/sc_all_tests.py
+%attr(755,root,root) %{script_dir}/sc_int_tests.py
%attr(755,root,root) %{script_dir}/sc_launch_test.py
%{script_dir}/sc_test_parser.py
%{_datadir}/security-containers
+%{python_sitelib}/sc_integration_tests/
+
#
ADD_SUBDIRECTORY(scripts)
+ADD_SUBDIRECTORY(integration_tests)
ADD_SUBDIRECTORY(unit_tests)
--- /dev/null
+# Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+#
+# 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.
+#
+#
+# @file CMakeLists.txt
+# @author Lukasz Kostyra (l.kostyra@samsung.com)
+#
+
+MESSAGE(STATUS "Generating makefile for Integration Tests...")
+
+
+## Defines for further package installation ####################################
+SET(TEST_DEST_DIR "${PYTHON_SITELIB}/sc_integration_tests")
+
+
+## Search for .py files available ##############################################
+FILE(GLOB py_SCRIPTS *.py)
+FILE(GLOB main_SCRIPT sc_int_tests.py)
+LIST(REMOVE_ITEM py_SCRIPTS ${main_SCRIPT})
+
+
+## Install #####################################################################
+INSTALL(FILES ${py_SCRIPTS} DESTINATION ${TEST_DEST_DIR})
+INSTALL(PROGRAMS ${main_SCRIPT} DESTINATION ${SCRIPT_INSTALL_DIR})
+
+
+## Subdirectories ##############################################################
+ADD_SUBDIRECTORY(common)
+
--- /dev/null
+__all__ = ["common",
+ ]
--- /dev/null
+# Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+#
+# 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.
+#
+#
+# @file CMakeLists.txt
+# @author Lukasz Kostyra (l.kostyra@samsung.com)
+#
+
+MESSAGE(STATUS "Including common package for Integration Tests...")
+
+SET(TEST_COMMON_DEST_DIR "${TEST_DEST_DIR}/common")
+
+FILE(GLOB common_SCRIPTS *.py)
+
+INSTALL(FILES ${common_SCRIPTS} DESTINATION ${TEST_COMMON_DEST_DIR})
+
--- /dev/null
+__all__ = ["sc_test_utils",
+ ]
--- /dev/null
+'''! Module containing utilities for domain-tests
+
+@author Lukasz Kostyra (l.kostyra@samsung.com)
+'''
+import subprocess
+import os
+
+
+
+def launchProc(cmd):
+ '''! Launch specified command as a subprocess.
+
+ Launches provided command using Python's subprocess module. Returns output from stdout and
+ stderr.
+
+ @param cmd Command to be launched
+ @return Output provided by specified command.
+ @exception Exception When a process exits with error code, a Exception object containing message
+ with error data is raised.
+ '''
+ p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+ ret = p.wait()
+ output = p.stdout.read()
+
+ if ret != 0:
+ raise Exception(cmd + " failed. error: " + os.strerror(ret) + ", output: " + output)
+
+ return output
+
+
+
+def mount(dir, opts = []):
+ '''! Mounts specified directory with additional command line options.
+
+ @param dir Directory to be mounted
+ @param opts Additional command line options for mount. This argument is optional.
+ @see launchProc
+ '''
+ launchProc(" ".join(["mount"] + opts + [dir]))
+
+
+
+def umount(dir):
+ '''! Unmounts specified directory.
+
+ @param dir Directory to be umounted
+ @see launchProc
+ '''
+ launchProc(" ".join(["umount"] + [dir]))
+
+
+
+def isNumber(str):
+ '''! Checks if provided String is a number.
+
+ @param str String to be checked if is a number.
+ @return True if string is a number, False otherwise.
+ '''
+ try:
+ int(str)
+ return True
+ except ValueError:
+ return False
--- /dev/null
+#!/usr/bin/env python
+'''@package: sc_integration_tests
+@author: Lukasz Kostyra (l.kostyra@samsung.com)
+
+Security-containers integration tests launcher. Launches all integration tests.
+'''
+import unittest
+
+test_groups = [# add tests here... #
+ ]
+
+def main():
+ for test_group in test_groups:
+ print "Starting", test_group.__name__, " ..."
+ suite = unittest.TestLoader().loadTestsFromModule(test_group)
+ unittest.TextTestRunner(verbosity=2).run(suite)
+ print "\n"
+
+if __name__ == "__main__":
+ main()