-
Notifications
You must be signed in to change notification settings - Fork 149
/
Copy pathrun_tests.py
69 lines (63 loc) · 2.61 KB
/
run_tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Copyright (C) 2016-2017 Korcan Karaokçu <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import unittest, argparse
from libpince import debugcore, utils
desc = "Runs all unit tests by creating or attaching to a process"
ex = (
"Example of Usage:"
+ "\n\tsudo python3 run_tests.py -a kmines"
+ '\n\tsudo python3 run_tests.py -c /usr/games/kmines -o="-v"'
)
parser = argparse.ArgumentParser(description=desc, epilog=ex, formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument("-a", metavar="process_name", type=str, help="Attaches to the process with given name")
parser.add_argument("-c", metavar="file_path", type=str, help="Creates a new process with given path")
parser.add_argument(
"-o",
metavar="options",
type=str,
default="",
help="Arguments that'll be passed to the inferior, only can be used with -c, optional",
)
parser.add_argument(
"-l",
metavar="ld_preload_path",
type=str,
default="",
help="Path of the preloaded .so file, only can be used with -c, optional",
)
args = parser.parse_args()
if args.a:
process_list = utils.search_processes(args.a)
if not process_list:
parser.error("There's no process with the name " + args.a)
if len(process_list) > 1:
for pid, user, name in process_list:
print(name)
print("There are more than one process with the name " + args.a)
exit()
pid = process_list[0][0]
if not debugcore.can_attach(pid):
parser.error("Failed to attach to the process with pid " + pid)
debugcore.attach(pid)
elif args.c:
if not debugcore.create_process(args.c, args.o, args.l):
parser.error("Couldn't create the process with current args")
else:
parser.error("Provide at least one of these arguments: -a or -c")
unittest.main(module="tests.debugcore_tests", exit=False, argv=[""])
unittest.main(module="tests.utils_tests", exit=False, argv=[""])
unittest.main(module="tests.guiutils_tests", exit=False, argv=[""])
debugcore.detach()