Build: reworked unit tests to use gtest in a more generic way
[platform/upstream/iotivity.git] / resource / csdk / connectivity / test / 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 import os
22 import os.path
23
24 # SConscript file for Local PKI google tests
25 gtest_env = SConscript('#extlibs/gtest/SConscript')
26 catest_env = gtest_env.Clone()
27 target_os = catest_env.get('TARGET_OS')
28 target_transport = catest_env.get('TARGET_TRANSPORT')
29
30 ######################################################################
31 # Build flags
32 ######################################################################
33 catest_env.PrependUnique(CPPPATH = [
34                 '../../logger/include',
35                 '../../stack/include',
36                 '../../extlibs/cjson',
37                 '../../../oc_logger/include',
38                ])
39
40 tmplist = catest_env['LINKFLAGS'][:]
41 if '-lpthread' in tmplist:
42     tmplist.remove('-lpthread')
43     catest_env.Replace(LINKFLAGS = tmplist)
44
45 if target_os not in ['windows']:
46         catest_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall', '-pthread'])
47 catest_env.AppendUnique(LIBPATH = [catest_env.get('BUILD_DIR')])
48 catest_env.PrependUnique(LIBS = ['gtest', 'gtest_main'])
49 catest_env.PrependUnique(LIBS = ['octbstack',
50                                     'connectivity_abstraction',
51                                     'coap'])
52
53 if target_os not in ['arduino', 'darwin', 'ios', 'msys_nt', 'windows']:
54         catest_env.AppendUnique(LIBS=['rt'])
55
56 if catest_env.get('SECURED') == '1':
57         catest_env.AppendUnique(LIBS = ['tinydtls'])
58         catest_env.AppendUnique(LIBS = ['timer'])
59
60 if catest_env.get('WITH_RD') == '1':
61         catest_env.PrependUnique(LIBS = ['resource_directory'])
62
63 if catest_env.get('LOGGING'):
64         catest_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
65
66 if target_os in ['msys_nt', 'windows']:
67         catest_env.AppendUnique(LINKFLAGS = ['/subsystem:CONSOLE'])
68         catest_env.AppendUnique(LIBS = ['ws2_32',
69                                         'advapi32',
70                                         'iphlpapi'])
71 else:
72         catest_env.AppendUnique(LIBS = ['m'])
73         catest_env.PrependUnique(LIBS = ['pthread'])
74
75 ######################################################################
76 # Source files and Targets
77 ######################################################################
78
79 if (('IP' in target_transport) or ('ALL' in target_transport)):
80         if target_os != 'arduino':
81                 catests = catest_env.Program('catests', ['catests.cpp',
82                                                          'caprotocolmessagetest.cpp',
83                                                          'cablocktransfertest.cpp',
84                                                          'ca_api_unittest.cpp',
85                                                          'camutex_tests.cpp',
86                                                          'uarraylist_test.cpp'
87                                                                ])
88 else:
89         catests = catest_env.Program('catests', ['catests.cpp',
90                                                  'caprotocolmessagetest.cpp',
91                                                  'ca_api_unittest.cpp',
92                                                  'camutex_tests.cpp',
93                                                  'uarraylist_test.cpp'
94                                                        ])
95
96 Alias("test", [catests])
97
98 catest_env.AppendTarget('test')
99 if catest_env.get('TEST') == '1':
100         if target_os in ['linux', 'windows']:
101                 catest_env.AppendENVPath('PATH', catest_env.get('BUILD_DIR'))
102                 from tools.scons.RunTest import *
103                 run_test(catest_env,
104                          'resource_csdk_connectivity_test.memcheck',
105                          'resource/csdk/connectivity/test/catests')