60d468094ceaa4db37eba4e8323a59cf08a1a87e
[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 from tools.scons.RunTest import run_test
27
28 # SConscript file for Local PKI google tests
29 gtest_env = SConscript('#extlibs/gtest/SConscript')
30 lib_env = gtest_env.Clone()
31 target_os = lib_env.get('TARGET_OS')
32 src_dir = lib_env.get('SRC_DIR')
33
34 containerJavaSupport = ARGUMENTS.get('containerJavaSupport',0)
35
36 def filtered_glob(env, pattern, omit=[],
37   ondisk=True, source=False, strings=False):
38     return filter(
39       lambda f: os.path.basename(f.path) not in omit,
40       lib_env.Glob(pattern))
41
42 lib_env.AddMethod(filtered_glob, "FilteredGlob");
43
44 if lib_env.get('RELEASE'):
45     lib_env.AppendUnique(CCFLAGS = ['-Os'])
46     lib_env.AppendUnique(CPPDEFINES = ['NDEBUG'])
47 else:
48     lib_env.AppendUnique(CCFLAGS = ['-g'])
49
50 if lib_env.get('LOGGING'):
51     lib_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
52
53 # Add third party libraries
54 SConscript(src_dir + '/service/third_party_libs.scons', 'lib_env')
55
56 container_gtest_env = lib_env.Clone()
57
58 if int(containerJavaSupport):
59     try:
60         print 'Java Home: ', os.environ['JAVA_HOME']
61         print 'Java Lib: ', os.environ['JAVA_LIB']
62         container_gtest_env.Append(CPPDEFINES={'JAVA_SUPPORT_TEST':1})
63     except KeyError:
64         print '''
65     *********************************** Error *************************************
66     * Building resource container without Java support. JAVA_HOME or JAVA_LIB are not set properly
67     * Please configure JAVA_HOME to point to your Java 7 JDK and
68     * JAVA_LIB to your folder containing libjvm
69     * Example: export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-i386
70     *          export JAVA_LIB=/usr/lib/jvm/java-7-openjdk-i386/jre/lib/i386/server/
71     *******************************************************************************
72         '''
73         container_gtest_env.Append(CPPDEFINES={'JAVA_SUPPORT_TEST':0})
74
75
76
77 ######################### unit test setting ##########################
78 ######################################################################
79
80
81 ######################################################################
82 # Build flags
83 ######################################################################
84 container_gtest_env.AppendUnique(
85     CPPPATH = [
86         src_dir + '/extlibs',
87         '../include',
88         '../../resource-encapsulation/include',
89         '../../resource-encapsulation/src/common/utils/include',
90         '../bundle-api/include',
91         '../src'
92     ])
93
94 if int(containerJavaSupport):
95     try:
96         container_gtest_env.AppendUnique(
97         CPPPATH = [
98             os.environ['JAVA_HOME']+'/include',
99             os.environ['JAVA_HOME']+'/include/linux'
100         ])
101     except KeyError:
102         print ''
103
104 if target_os not in ['windows']:
105     container_gtest_env.AppendUnique(LIBS = ['dl'])
106     container_gtest_env.AppendUnique(CCFLAGS = ['-Wnoexcept'])
107
108 container_gtest_env.PrependUnique(LIBS = ['rcs_container', 'rcs_client', 'rcs_server', 'rcs_common',
109   'oc','octbstack', 'oc_logger', 'oc_logger_core',
110   'connectivity_abstraction'])
111
112 if target_os in ['android']:
113     container_gtest_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
114     container_gtest_env.PrependUnique(LIBS = ['gnustl_shared', 'compatibility', 'log'])
115
116 container_gtest_env.PrependUnique(CPPPATH = [src_dir + '/extlibs/hippomocks-master'])
117
118 if int(containerJavaSupport):
119     try:
120         container_gtest_env.AppendUnique(LIBPATH = [os.environ['JAVA_LIB']])
121     except KeyError:
122         print ''
123 container_gtest_env.PrependUnique(LIBS = ['rcs_container', 'rcs_client', 'rcs_server', 'rcs_common',
124   'oc','octbstack', 'oc_logger', 'oc_logger_core',
125   'connectivity_abstraction',
126   'gtest', 'gtest_main'])
127
128 if int(containerJavaSupport):
129     try:
130         print 'Java Lib: ', os.environ['JAVA_LIB']
131         container_gtest_env.AppendUnique(LIBS = ['jvm'])
132     except KeyError:
133         print ''
134
135 if container_gtest_env.get('SECURED') == '1':
136     container_gtest_env.AppendUnique(CPPDEFINES = ['SECURED'])
137     if container_gtest_env.get('WITH_TCP') == True:
138         container_gtest_env.AppendUnique(LIBS = ['mbedtls', 'mbedx509', 'mbedcrypto'])
139
140 ######################################################################
141 # build test bundle
142 ######################################################################
143 test_bundle_env = container_gtest_env.Clone()
144 test_bundle_env.AppendUnique(CCFLAGS = ['-fPIC'])
145
146 if target_os not in ['darwin', 'ios', 'windows']:
147     test_bundle_env.AppendUnique(LINKFLAGS = ['-Wl,--no-undefined'])
148
149 TEST_BUNDLE_DIR = 'TestBundle/'
150 test_bundle_env.AppendUnique(CPPPATH = [
151         TEST_BUNDLE_DIR + 'include'
152         ])
153
154 test_bundle_src = [ Glob(TEST_BUNDLE_DIR + 'src/*.cpp'), Glob('src/*.cpp')]
155
156 TestBundle = test_bundle_env.SharedLibrary('TestBundle', test_bundle_src)
157 test_bundle_env.InstallTarget(TestBundle, 'libTestBundle')
158
159
160 ######################################################################
161 # Build Test
162 ######################################################################
163 if 'g++' in container_gtest_env.get('CXX'):
164     container_gtest_env.AppendUnique(CXXFLAGS = ['-std=c++0x'])
165
166 container_gtest_src = container_gtest_env.Glob('./ResourceContainerTest.cpp')
167
168 container_test = container_gtest_env.Program('container_test', container_gtest_src)
169 Alias("container_test", container_test)
170 container_gtest_env.AppendTarget('container_test')
171
172 # Copy test configuration
173 Command("./ResourceContainerTestConfig.xml","./ResourceContainerTestConfig.xml", Copy("$TARGET", "$SOURCE"))
174 Ignore("./ResourceContainerTestConfig.xml", "./ResourceContainerTestConfig.xml")
175 Command("./ResourceContainerInvalidConfig.xml","./ResourceContainerInvalidConfig.xml", Copy("$TARGET", "$SOURCE"))
176 Ignore("./ResourceContainerInvalidConfig.xml", "./ResourceContainerInvalidConfig.xml")
177 Command("./TestBundleJava/hue-0.1-jar-with-dependencies.jar","./TestBundleJava/hue-0.1-jar-with-dependencies.jar", Copy("$TARGET", "$SOURCE"))
178 Ignore("./TestBundleJava/hue-0.1-jar-with-dependencies.jar", "./TestBundleJava/hue-0.1-jar-with-dependencies.jar")
179
180 if container_gtest_env.get('TEST') == '1':
181 # TODO: fix this test on linux and remove this comment line
182     if target_os in ['']:
183         run_test(container_gtest_env,
184             '',
185 #           'service_resource-container_unittests_container_test.memcheck',
186             'service/resource-container/unittests/container_test')