1#!/usr/bin/env python3
2#-*- coding: utf-8 -*-
3
4# Copyright (c) 2024 Huawei Device Co., Ltd.
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#     http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17from devicetest.utils.file_util import get_resource_path
18
19
20def get_source_path(need_source, casename):
21    """
22    @func: get the resource path required for a case
23    @param need_source: the resources required for a case
24    @param casename: the case name
25    @return: source absolute paths
26    """
27
28    source_path = {}
29    if need_source["cfg"]:
30        cfg_relative_path = "resource/" + casename + "/listen_test.cfg"
31        json_relative_path = "resource/" + casename + "/listen_test.json"
32        sa_listen_cfg_path = get_resource_path(
33            cfg_relative_path,
34            isdir=None)
35        sa_listen_json_path = get_resource_path(
36            json_relative_path,
37            isdir=None)
38        source_path["sa_listen_cfg_path"] = sa_listen_cfg_path
39        source_path["sa_listen_json_path"] = sa_listen_json_path
40
41    if need_source["fwk"]:
42        sa_lib_fwk_path = get_resource_path(
43            "resource/soResource/libsystem_ability_fwk.z.so",
44            isdir=None)
45        source_path["sa_lib_fwk_path"] = sa_lib_fwk_path
46
47    if need_source["listen_test"]:
48        sa_lib_listen_test_path = get_resource_path(
49            "resource/soResource/liblisten_test.z.so",
50            isdir=None)
51        source_path["sa_lib_listen_test_path"] = sa_lib_listen_test_path
52
53    if need_source["audio_ability"]:
54        sa_lib_audio_ability = get_resource_path(
55            "resource/soResource/libtest_audio_ability.z.so",
56            isdir=None)
57        source_path["sa_lib_audio_ability"] = sa_lib_audio_ability
58
59    if need_source["ondemand"]:
60        sa_ondemand_path = get_resource_path(
61            "resource/soResource/ondemand",
62            isdir=None)
63        source_path["sa_ondemand_path"] = sa_ondemand_path
64
65    if need_source["proxy"]:
66        sa_proxy_path = get_resource_path(
67            "resource/soResource/libtest_sa_proxy_cache.z.so",
68            isdir=None)
69        source_path["sa_proxy_path"] = sa_proxy_path
70
71    if need_source["para"]:
72        sa_para_path = get_resource_path(
73            "resource/level0/case13_param001/samgr.para",
74            isdir=None)
75        sa_para_dac_path = get_resource_path(
76            "resource/level0/case13_param001/samgr.para.dac",
77            isdir=None)
78        sa_para_origin = get_resource_path(
79            "resource/originFile/samgr.para",
80            isdir=None)
81        sa_para_dac_origin = get_resource_path(
82            "resource/originFile/samgr.para.dac",
83            isdir=None)
84        source_path["sa_para_path"] = sa_para_path
85        source_path["sa_para_dac_path"] = sa_para_dac_path
86        source_path["sa_para_origin"] = sa_para_origin
87        source_path["sa_para_dac_origin"] = sa_para_dac_origin
88
89    return source_path
90