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