Imported Upstream version 1.2.0
[platform/upstream/iotivity.git] / service / resource-container / unittests / SConscript
1 #******************************************************************
2 #
3 # Copyright 2015 Samsung Electronics All Rights Reserved.
4 #
5 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 #
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 #      http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 #
19 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 ##
22 # ResourceContainer (rcs_container) Unit Test build script
23 ##
24 import os
25 import os.path
26
27 # SConscript file for Local PKI google tests
28 gtest_env = SConscript('#extlibs/gtest/SConscript')
29 lib_env = gtest_env.Clone()
30 target_os = lib_env.get('TARGET_OS')
31 src_dir = lib_env.get('SRC_DIR')
32
33 containerJavaSupport = ARGUMENTS.get('containerJavaSupport',0)
34
35 def filtered_glob(env, pattern, omit=[],
36   ondisk=True, source=False, strings=False):
37     return filter(
38       lambda f: os.path.basename(f.path) not in omit,
39       lib_env.Glob(pattern))
40
41 lib_env.AddMethod(filtered_glob, "FilteredGlob");
42
43 if lib_env.get('RELEASE'):
44     lib_env.AppendUnique(CCFLAGS = ['-Os'])
45     lib_env.AppendUnique(CPPDEFINES = ['NDEBUG'])
46 else:
47     lib_env.AppendUnique(CCFLAGS = ['-g'])
48
49 if lib_env.get('LOGGING'):
50     lib_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
51
52
53
54
55 # Add third party libraries
56 SConscript(src_dir + '/service/third_party_libs.scons', 'lib_env')
57
58 container_gtest_env = lib_env.Clone()
59
60 if int(containerJavaSupport):
61     try:
62         print 'Java Home: ', os.environ['JAVA_HOME']
63         print 'Java Lib: ', os.environ['JAVA_LIB']
64         container_gtest_env.Append(CPPDEFINES={'JAVA_SUPPORT_TEST':1})
65     except KeyError:
66         print '''
67     *********************************** Error *************************************
68     * Building resource container without Java support. JAVA_HOME or JAVA_LIB are not set properly
69     * Please configure JAVA_HOME to point to your Java 7 JDK and
70     * JAVA_LIB to your folder containing libjvm
71     * Example: export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-i386
72     *          export JAVA_LIB=/usr/lib/jvm/java-7-openjdk-i386/jre/lib/i386/server/
73     *******************************************************************************
74         '''
75         container_gtest_env.Append(CPPDEFINES={'JAVA_SUPPORT_TEST':0})
76
77
78
79 ######################### unit test setting ##########################
80 ######################################################################
81
82
83 ######################################################################
84 # Build flags
85 ######################################################################
86 container_gtest_env.AppendUnique(
87     CPPPATH = [
88         src_dir + '/extlibs',
89         '../include',
90         '../../resource-encapsulation/include',
91         '../../resource-encapsulation/src/common/utils/include',
92         '../bundle-api/include',
93         '../src'
94     ])
95
96 if int(containerJavaSupport):
97     try:
98         container_gtest_env.AppendUnique(
99         CPPPATH = [
100             os.environ['JAVA_HOME']+'/include',
101             os.environ['JAVA_HOME']+'/include/linux'
102         ])
103     except KeyError:
104         print ''
105
106 if target_os not in ['windows']:
107     container_gtest_env.AppendUnique(LIBS = ['dl'])
108     container_gtest_env.AppendUnique(CCFLAGS = ['-Wnoexcept'])
109
110 container_gtest_env.PrependUnique(LIBS = ['rcs_container', 'rcs_client', 'rcs_server', 'rcs_common',
111   'oc','octbstack', 'oc_logger', 'oc_logger_core',
112   'connectivity_abstraction'])
113
114 if target_os in ['android']:
115     container_gtest_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
116     container_gtest_env.PrependUnique(LIBS = ['gnustl_shared', 'compatibility', 'log'])
117
118 container_gtest_env.PrependUnique(CPPPATH = [src_dir + '/extlibs/hippomocks-master'])
119
120 if int(containerJavaSupport):
121     try:
122         container_gtest_env.AppendUnique(LIBPATH = [os.environ['JAVA_LIB']])
123     except KeyError:
124         print ''
125 container_gtest_env.PrependUnique(LIBS = ['rcs_container', 'rcs_client', 'rcs_server', 'rcs_common',
126   'oc','octbstack', 'oc_logger', 'oc_logger_core',
127   'connectivity_abstraction',
128   'gtest', 'gtest_main'])
129
130 if int(containerJavaSupport):
131     try:
132         print 'Java Lib: ', os.environ['JAVA_LIB']
133         container_gtest_env.AppendUnique(LIBS = ['jvm'])
134     except KeyError:
135         print ''
136
137 if container_gtest_env.get('SECURED') == '1':
138         if container_gtest_env.get('WITH_TCP') == True:
139                 container_gtest_env.AppendUnique(LIBS = ['mbedtls', 'mbedx509', 'mbedcrypto'])
140
141 ######################################################################
142 # build test bundle
143 ######################################################################
144 test_bundle_env = container_gtest_env.Clone()
145 test_bundle_env.AppendUnique(CCFLAGS = ['-fPIC'])
146
147 if target_os not in ['darwin', 'ios', 'windows']:
148     test_bundle_env.AppendUnique(LINKFLAGS = ['-Wl,--no-undefined'])
149
150 TEST_BUNDLE_DIR = 'TestBundle/'
151 test_bundle_env.AppendUnique(CPPPATH = [
152         TEST_BUNDLE_DIR + 'include'
153         ])
154
155 test_bundle_src = [ Glob(TEST_BUNDLE_DIR + 'src/*.cpp'), Glob('src/*.cpp')]
156
157 TestBundle = test_bundle_env.SharedLibrary('TestBundle', test_bundle_src)
158 test_bundle_env.InstallTarget(TestBundle, 'libTestBundle')
159
160
161 ######################################################################
162 # Build Test
163 ######################################################################
164 container_gtest_src = container_gtest_env.Glob('./*.cpp')
165
166 container_test = container_gtest_env.Program('container_test', container_gtest_src)
167 Alias("container_test", container_test)
168 container_gtest_env.AppendTarget('container_test')
169
170 # Copy test configuration
171 Command("./ResourceContainerTestConfig.xml","./ResourceContainerTestConfig.xml", Copy("$TARGET", "$SOURCE"))
172 Ignore("./ResourceContainerTestConfig.xml", "./ResourceContainerTestConfig.xml")
173 Command("./ResourceContainerInvalidConfig.xml","./ResourceContainerInvalidConfig.xml", Copy("$TARGET", "$SOURCE"))
174 Ignore("./ResourceContainerInvalidConfig.xml", "./ResourceContainerInvalidConfig.xml")
175 Command("./TestBundleJava/hue-0.1-jar-with-dependencies.jar","./TestBundleJava/hue-0.1-jar-with-dependencies.jar", Copy("$TARGET", "$SOURCE"))
176 Ignore("./TestBundleJava/hue-0.1-jar-with-dependencies.jar", "./TestBundleJava/hue-0.1-jar-with-dependencies.jar")
177
178 if container_gtest_env.get('TEST') == '1':
179     if target_os in ['linux']:
180         from tools.scons.RunTest import *
181         run_test(container_gtest_env,
182             '',
183             'service/resource-container/unittests/container_test')