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