Imported Upstream version 0.9.1
[platform/upstream/iotivity.git] / resource / unittests / SConscript
1 #******************************************************************
2 #
3 # Copyright 2014 Intel Mobile Communications GmbH 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 Import('env')
22 import os
23 import os.path
24 unittests_env = env.Clone()
25
26 src_dir = unittests_env.get('SRC_DIR')
27 ######################################################################
28 # Build flags
29 ######################################################################
30 unittests_env.PrependUnique(CPPPATH = [
31                 '../include',
32                 '../oc_logger/include',
33                 '../csdk/stack/include',
34                 '../csdk/security/include',
35                 '../csdk/stack/include/internal',
36                 '../csdk/connectivity/api',
37                 '../csdk/ocsocket/include',
38                 '../csdk/ocrandom/include',
39                 '../csdk/logger/include',
40                 '../../extlibs/gtest/gtest-1.7.0/include',
41                 '../../extlibs/hippomocks-master/HippoMocks',
42                 '../../extlibs/hippomocks-master/HippoMocksTest'
43                 ])
44
45 unittests_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall', '-pthread'])
46 unittests_env.AppendUnique(LIBS = ['-lpthread'])
47 unittests_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
48 unittests_env.AppendUnique(LIBPATH = [src_dir + '/extlibs/gtest/gtest-1.7.0/lib/.libs'])
49 unittests_env.PrependUnique(LIBS = [
50                 'oc',
51                 'octbstack',
52                 'oc_logger',
53                 'connectivity_abstraction',
54                 'coap',
55                 'gtest',
56                 'gtest_main'
57                 ])
58
59 if env.get('SECURED') == '1':
60     unittests_env.AppendUnique(LIBS = ['tinydtls'])
61
62 if env.get('LOGGING'):
63         unittests_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
64
65 ######################################################################
66 # Source files and Targets
67 ######################################################################
68 unittests = unittests_env.Program('unittests', ['ConstructResourceTest.cpp',
69                                                 'OCPlatformTest.cpp',
70                                                 'OCRepresentationTest.cpp',
71                                                 'OCResourceTest.cpp',
72                                                 'OCExceptionTest.cpp',
73                                                 'OCResourceResponseTest.cpp',
74                                                 'OCHeaderOptionTest.cpp'])
75
76 Alias("unittests", [unittests])
77
78 env.AppendTarget('unittests')
79 if env.get('TEST') == '1':
80         target_os = env.get('TARGET_OS')
81         if target_os == 'linux':
82                 out_dir = env.get('BUILD_DIR')
83                 result_dir = env.get('BUILD_DIR') + '/test_out/'
84                 if not os.path.isdir(result_dir):
85                         os.makedirs(result_dir)
86                 unittests_env.AppendENVPath('GTEST_OUTPUT', ['xml:'+ result_dir])
87                 unittests_env.AppendENVPath('LD_LIBRARY_PATH', [out_dir])
88                 unittests_env.AppendENVPath('LD_LIBRARY_PATH', ['./extlibs/gtest/gtest-1.7.0/lib/.libs'])
89                 ut = unittests_env.Command ('ut', None,
90                  [ 'valgrind --leak-check=full --xml=yes --xml-file=resource_unittests_unittests.memcheck ' + out_dir + 'resource/unittests/unittests'])
91                 AlwaysBuild ('ut')