TLS support
[platform/upstream/iotivity.git] / resource / csdk / security / unittest / SConscript
1 # //******************************************************************
2 # //
3 # // Copyright 2015 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 os
22 import os.path
23
24 # SConscript file for Local PKI google tests
25 gtest_env = SConscript('#extlibs/gtest/SConscript')
26 srmtest_env = gtest_env.Clone()
27 src_dir = srmtest_env.get('SRC_DIR')
28 target_os = srmtest_env.get('TARGET_OS')
29
30 ######################################################################
31 # Build flags
32 ######################################################################
33 srmtest_env.PrependUnique(CPPPATH = [
34                 '../../../c_common/oic_malloc/include',
35                 '../../connectivity/inc',
36                 '../../connectivity/inc/pkix',
37                 '../../connectivity/api',
38                 '../../connectivity/external/inc',
39                 '../../connectivity/lib/libcoap-4.1.1',
40                 '../include/internal',
41                 '../../logger/include',
42                 '../../stack/include',
43                 '../../stack/include/internal',
44                 '../../../oc_logger/include',
45                 '../../../../extlibs/cjson/',
46                 '../provisioning/include',
47                 '../include'
48                 ])
49
50 srmtest_env.AppendUnique(LIBPATH = [srmtest_env.get('BUILD_DIR')])
51 srmtest_env.PrependUnique(LIBS = ['ocsrm',
52                                     'octbstack',
53                                     'oc_logger',
54                                     'connectivity_abstraction',
55                                     'coap'])
56
57 if srmtest_env.get('SECURED') == '1':
58     srmtest_env.AppendUnique(LIBS = ['tinydtls', 'timer'])
59     
60 if srmtest_env.get('WITH_TCP') == True:
61                 srmtest_env.AppendUnique(LIBS = ['mbedtls', 'mbedx509','mbedcrypto'])
62
63 if srmtest_env.get('LOGGING') == '1':
64         srmtest_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
65
66 if target_os == 'windows':
67         srmtest_env.AppendUnique(LINKFLAGS = ['/subsystem:CONSOLE'])
68         srmtest_env.AppendUnique(LIBS = ['advapi32', 'kernel32', 'ws2_32', 'iphlpapi'])
69 else:
70         # TODO: Implement feature check.
71         srmtest_env.AppendUnique(CPPDEFINES = ['HAVE_LOCALTIME_R'])
72
73 ######################################################################
74 # Source files and Targets
75 ######################################################################
76 unittest = srmtest_env.Program('unittest', ['aclresourcetest.cpp',
77                                             'amaclresourcetest.cpp',
78                                             'pstatresource.cpp',
79                                             'doxmresource.cpp',
80                                             'policyengine.cpp',
81                                             'securityresourcemanager.cpp',
82                                             'credentialresource.cpp',
83                                             'srmutility.cpp',
84                                             'iotvticalendartest.cpp',
85                                             'base64tests.cpp',
86                                             'svcresourcetest.cpp',
87                                             'srmtestcommon.cpp',
88                                             'directpairingtest.cpp',
89                                             'crlresourcetest.cpp'])
90
91 Alias("test", [unittest])
92
93 unittest_src_dir = os.path.join(src_dir, 'resource', 'csdk', 'security', 'unittest') + os.sep
94 unittest_build_dir = os.path.join(srmtest_env.get('BUILD_DIR'), 'resource', 'csdk', 'security', 'unittest') + os.sep
95
96 srmtest_env.AppendUnique(CPPDEFINES = ['SECURITY_BUILD_UNITTEST_DIR='+unittest_build_dir.encode('string_escape')])
97
98 srmtest_env.Alias("install", srmtest_env.Install( unittest_build_dir,
99     unittest_src_dir + 'oic_unittest.json'))
100 srmtest_env.Alias("install", srmtest_env.Install( unittest_build_dir,
101     unittest_src_dir + 'oic_unittest_acl1.json'))
102 srmtest_env.Alias("install", srmtest_env.Install( unittest_build_dir,
103     unittest_src_dir + 'oic_unittest_default_acl.json'))
104 srmtest_env.Alias("install", srmtest_env.Install( unittest_build_dir,
105     unittest_src_dir + 'oic_svr_db.json'))
106
107 srmtest_env.Alias("install", srmtest_env.Install( unittest_build_dir,
108     unittest_src_dir + 'oic_unittest.dat'))
109 srmtest_env.Alias("install", srmtest_env.Install( unittest_build_dir,
110     unittest_src_dir + 'oic_unittest_acl1.dat'))
111 srmtest_env.Alias("install", srmtest_env.Install( unittest_build_dir,
112     unittest_src_dir + 'oic_unittest_default_acl.dat'))
113 srmtest_env.Alias("install", srmtest_env.Install( unittest_build_dir,
114     unittest_src_dir + 'oic_svr_db_prov.dat'))
115 srmtest_env.Alias("install", srmtest_env.Install( unittest_build_dir,
116     unittest_src_dir + 'oic_svr_db.dat'))
117     
118 srmtest_env.AppendTarget('test')
119 if srmtest_env.get('TEST') == '1':
120         if target_os in ['linux', 'windows']:
121                 out_dir = srmtest_env.get('BUILD_DIR')
122                 result_dir = os.path.join(srmtest_env.get('BUILD_DIR'), 'test_out') + os.sep
123                 if not os.path.isdir(result_dir):
124                         os.makedirs(result_dir)
125                 srmtest_env.AppendENVPath('GTEST_OUTPUT', ['xml:'+ result_dir])
126                 srmtest_env.AppendENVPath('LD_LIBRARY_PATH', [out_dir])
127                 srmtest_env.AppendENVPath('PATH', [os.path.join(out_dir, 'resource', 'csdk')])
128                 from tools.scons.RunTest import *
129                 run_test(srmtest_env,'ut','resource/csdk/security/unittest/unittest')