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