[IOT-1089] Merge remote-tracking branch 'origin/master' into generic-java
[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 rd_mode = srmtest_env.get('RD_MODE')
30
31 ######################################################################
32 # Build flags
33 ######################################################################
34 with_upstream_libcoap = srmtest_env.get('WITH_UPSTREAM_LIBCOAP')
35 if with_upstream_libcoap == '1':
36         # For bring up purposes only, we manually copy the forked version to where the unforked version is downloaded.
37         srmtest_env.AppendUnique(CPPPATH = ['#extlibs/libcoap/libcoap/include'])
38 else:
39         # For bring up purposes only, the forked version will live here.
40         srmtest_env.AppendUnique(CPPPATH = ['../../connectivity/lib/libcoap-4.1.1/include'])
41
42 srmtest_env.PrependUnique(CPPPATH = [
43                 '../../../c_common/oic_malloc/include',
44                 '../../connectivity/inc',
45                 '../../connectivity/inc/pkix',
46                 '../../connectivity/api',
47                 '../../connectivity/external/inc',
48                 '../include/internal',
49                 '../../logger/include',
50                 '../../stack/include',
51                 '../../stack/include/internal',
52                 '../../../oc_logger/include',
53                 '../../../../extlibs/cjson/',
54                 '../provisioning/include',
55                 '../include'
56                 ])
57
58 srmtest_env.AppendUnique(LIBPATH = [srmtest_env.get('BUILD_DIR')])
59 srmtest_env.PrependUnique(LIBS = ['ocsrm',
60                                     'octbstack_test',
61                                     'oc_logger',
62                                     'connectivity_abstraction',
63                                     'coap'])
64
65 if srmtest_env.get('SECURED') == '1':
66     srmtest_env.AppendUnique(LIBS = ['mbedtls','mbedx509','mbedcrypto'])
67     srmtest_env.AppendUnique(LIBS = ['tinydtls'])
68
69 if srmtest_env.get('LOGGING') == '1':
70         srmtest_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
71
72 if srmtest_env.get('MULTIPLE_OWNER') == '1':
73         srmtest_env.AppendUnique(CPPDEFINES=['_ENABLE_MULTIPLE_OWNER_'])
74
75 if target_os == 'windows':
76         srmtest_env.AppendUnique(LINKFLAGS = ['/subsystem:CONSOLE'])
77         srmtest_env.AppendUnique(LIBS = ['advapi32', 'bcrypt', 'kernel32', 'ws2_32', 'iphlpapi', 'octbstack_static'])
78 else:
79         # TODO: Implement feature check.
80         srmtest_env.AppendUnique(CPPDEFINES = ['HAVE_LOCALTIME_R'])
81         srmtest_env.AppendUnique(LIBS = ['octbstack'])
82
83 if 'CLIENT' in rd_mode or 'SERVER' in rd_mode:
84         srmtest_env.PrependUnique(LIBS = ['resource_directory'])
85
86 ######################################################################
87 # Source files and Targets
88 ######################################################################
89 unittest = srmtest_env.Program('unittest', ['aclresourcetest.cpp',
90                                             'amaclresourcetest.cpp',
91                                             'pstatresource.cpp',
92                                             'doxmresource.cpp',
93                                             'policyengine.cpp',
94                                             'securityresourcemanager.cpp',
95                                             'credentialresource.cpp',
96                                             'srmutility.cpp',
97                                             'iotvticalendartest.cpp',
98                                             'base64tests.cpp',
99                                             'svcresourcetest.cpp',
100                                             'srmtestcommon.cpp',
101                                             'directpairingtest.cpp',
102                                             'crlresourcetest.cpp'])
103
104 Alias("test", [unittest])
105
106 unittest_src_dir = os.path.join(src_dir, 'resource', 'csdk', 'security', 'unittest') + os.sep
107 unittest_build_dir = os.path.join(srmtest_env.get('BUILD_DIR'), 'resource', 'csdk', 'security', 'unittest') + os.sep
108
109 srmtest_env.AppendUnique(CPPDEFINES = ['SECURITY_BUILD_UNITTEST_DIR='+unittest_build_dir.encode('string_escape')])
110
111 srmtest_env.Alias("install", srmtest_env.Install( unittest_build_dir,
112     unittest_src_dir + 'oic_unittest.json'))
113 srmtest_env.Alias("install", srmtest_env.Install( unittest_build_dir,
114     unittest_src_dir + 'oic_unittest_acl1.json'))
115 srmtest_env.Alias("install", srmtest_env.Install( unittest_build_dir,
116     unittest_src_dir + 'oic_unittest_default_acl.json'))
117 srmtest_env.Alias("install", srmtest_env.Install( unittest_build_dir,
118     unittest_src_dir + 'oic_svr_db.json'))
119
120 srmtest_env.Alias("install", srmtest_env.Install( unittest_build_dir,
121     unittest_src_dir + 'oic_unittest.dat'))
122 srmtest_env.Alias("install", srmtest_env.Install( unittest_build_dir,
123     unittest_src_dir + 'oic_unittest_acl1.dat'))
124 srmtest_env.Alias("install", srmtest_env.Install( unittest_build_dir,
125     unittest_src_dir + 'oic_unittest_default_acl.dat'))
126 srmtest_env.Alias("install", srmtest_env.Install( unittest_build_dir,
127     unittest_src_dir + 'oic_svr_db_prov.dat'))
128 srmtest_env.Alias("install", srmtest_env.Install( unittest_build_dir,
129     unittest_src_dir + 'oic_svr_db.dat'))
130     
131 srmtest_env.AppendTarget('test')
132 if srmtest_env.get('TEST') == '1':
133         if target_os in ['linux', 'windows']:
134                 out_dir = srmtest_env.get('BUILD_DIR')
135                 result_dir = os.path.join(srmtest_env.get('BUILD_DIR'), 'test_out') + os.sep
136                 if not os.path.isdir(result_dir):
137                         os.makedirs(result_dir)
138                 srmtest_env.AppendENVPath('GTEST_OUTPUT', ['xml:'+ result_dir])
139                 srmtest_env.AppendENVPath('LD_LIBRARY_PATH', [out_dir])
140                 from tools.scons.RunTest import *
141                 run_test(srmtest_env,'ut','resource/csdk/security/unittest/unittest')