This commit is contained in:
Costa Shulyupin 2018-08-08 09:08:05 +03:00
parent 37ec4a8d0d
commit 077ddeea94
1 changed files with 28 additions and 6 deletions

View File

@ -29,6 +29,8 @@ import difflib
import glob import glob
from pathlib import * from pathlib import *
import pygraphviz import pygraphviz
import unittest
import types
default_root = 'starts' default_root = 'starts'
black_list = ('aligned __attribute__ unlikely typeof u32 ' black_list = ('aligned __attribute__ unlikely typeof u32 '
@ -866,29 +868,49 @@ def usage():
print(me, c, "<identifier>") print(me, c, "<identifier>")
print("Try this:") print("Try this:")
print("cd linux/init") print("cd linux/init")
print(me, "unittest")
print(me, "referers_tree nfs_root_data") print(me, "referers_tree nfs_root_data")
print(me, "call_tree start_kernel") print(me, "call_tree start_kernel")
print(me, "Emergency termination: ^Z, kill %1") print(me, "Emergency termination: ^Z, kill %1")
class _unittest_autotest(unittest.TestCase):
def test_1(self):
self.assertTrue(os.path.isdir('include/linux/'))
os.chdir('init')
self.assertEqual('\t\t\t\t\tprepare_namespace ^', popen('srcxray.py referers_tree nfs_root_data')[-1])
self.assertEqual('initrd_load: prepare_namespace', popen('srcxray.py referers_dep nfs_root_data')[-1])
self.assertEqual('calibrate_delay_converge: __delay', popen('srcxray.py call_dep start_kernel')[-2])
self.assertEqual('\t\tcpu_startup_entry', popen('srcxray.py call_tree start_kernel')[-1])
os.chdir('..')
self.assertTrue(syscalls().number_of_edges() > 400)
# digraph_print:
self.assertEqual("\thandle_initrd ^", popen("srcxray.py import_cflow init/do_mounts_initrd.c")[-1])
self.assertEqual("\t\t4", popen('srcxray.py "nx.DiGraph([{1,2},{2,3},{2,4}])"')[-1])
def main(): def main():
try: try:
ret = False ret = False
if len(sys.argv) == 1: if len(sys.argv) == 1:
print('Run', me, 'usage') print('Run', me, 'usage')
else: else:
if '(' in sys.argv[1]: a1 = sys.argv[1]
ret = eval(sys.argv[1]) sys.argv = sys.argv[1:]
if isinstance(eval(a1), types.ModuleType):
ret = eval(a1+".main()")
elif '(' in a1:
ret = eval(a1)
# ret = exec(sys.argv[1]) # ret = exec(sys.argv[1])
else: else:
ret = eval(sys.argv[1] + '(' + ', '.join("'%s'" % (a) ret = eval(a1 + '(' + ', '.join("'%s'" % (a1)
for a in sys.argv[2:]) + ')') for a1 in sys.argv[1:]) + ')')
if isinstance(ret, nx.DiGraph): if isinstance(ret, nx.DiGraph):
digraph_print(ret) digraph_print(ret)
if isinstance(ret, bool) and ret is False: if isinstance(ret, bool) and ret is False:
sys.exit(os.EX_CONFIG) sys.exit(os.EX_CONFIG)
if (ret is not None): # if (ret is not None):
print(ret) # print(ret)
except KeyboardInterrupt: except KeyboardInterrupt:
log("\nInterrupted") log("\nInterrupted")