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