• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3#
4# Copyright (c) 2022 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
17import os
18import argparse
19import subprocess
20
21
22def parse_args():
23    parser = argparse.ArgumentParser()
24    parser.add_argument(
25        '--testcase-list', help='the file path of testcase list', required=True)
26    parser.add_argument(
27        '--build-dir', help='the build dir of ts2abc', required=True)
28    parser.add_argument(
29        '--dst-dir', help='the output dst path', required=True)
30    return parser.parse_args()
31
32
33def create_dir(out_dir, mode=0o775):
34    if os.path.isabs(out_dir) and not os.path.exists(out_dir):
35        os.makedirs(out_dir, mode)
36
37
38def run_command(cmd):
39    cmd = ' '.join(cmd)
40    print(cmd)
41    subprocess.Popen(cmd, shell=True)
42
43
44def get_command(s, ts2js, tc_dir, dst_dir):
45    testcase, m_flag = s.split(' ')
46    tc_name = os.path.basename(testcase)
47    tc_name = tc_name[0: tc_name.rfind('.')]
48    cmd = ['node', '--expose-gc', ts2js, '--opt-level=0']
49    if m_flag == '1':
50        cmd.append('-m')
51    out_dir = os.path.join(dst_dir, 'defectscanaux_tests',
52                           testcase[0: testcase.rfind('/')])
53    create_dir(out_dir)
54    cmd.append('-o')
55    cmd.append(os.path.join(out_dir, tc_name + '.abc'))
56    tc_path = os.path.join(tc_dir, testcase)
57    cmd.append(tc_path)
58    return cmd
59
60
61def generate_abc(args):
62    ts2js = os.path.join(args.build_dir, 'src/index.js')
63    tc_dir = os.path.dirname(args.testcase_list)
64    with open(args.testcase_list) as f:
65        for line in f.readlines():
66            line = line.strip()
67            if len(line) == 0:
68                continue
69            cmd = get_command(line, ts2js, tc_dir, args.dst_dir)
70            run_command(cmd)
71
72
73if __name__ == '__main__':
74    input_args = parse_args()
75    generate_abc(input_args)
76