def sh_mod_child_env(child): child.env = test_utils.modified_env(child.env, { '_': child.executable, 'OLDPWD': None, # remove 'PWD': child.cwd.as_posix(), 'PS1': None, # remove 'SHLVL': str(int(self.env.get('SHLVL', 0)) + 1), })
def gcc_mod_child_env(child): collect_options = [] skip_next = False for arg in self.argv[1:]: if skip_next: skip_next = False else: collect_options.append(arg) if arg == '-c': skip_next = True collect_options.extend(['-mtune=generic', '-march=x86-64']) child.env = test_utils.modified_env(child.env, { 'COLLECT_GCC': self.argv[0], 'COLLECT_GCC_OPTIONS': ' '.join( "'{}'".format(opt) for opt in collect_options), })
def test_simple_makefile(self): with TemporaryDirectory() as tmpdir: makefile_path = Path(tmpdir, 'Makefile') with makefile_path.open('w') as f: f.write(self.makefile) argv = ['make', '-C', tmpdir] actual = self.run_trace(argv) # split into two lists, one for each PID pids = {} for pid, event, args in actual: pids.setdefault(pid, []).append((pid, event, args)) self.assertEqual(len(pids), 2) ppid, cpid = sorted(pids.keys()) # parent PID < child PID # Check events generated by make process self.check_events(pids[ppid], ppid, argv, INIT_MAKE + [ ('chdir', (tmpdir,)), ('check', ('/usr/include', True)), ('check', ('/usr/gnu/include', False)), ('check', ('/usr/local/include', True)), ('check', ('/usr/include', True)), ('check', ('.', True)), ('read', ('.',)), ('read', ('Makefile',)), ('check', ('RCS', False)), ('check', ('SCCS', False)), ('check', ('Makefile', True)), ('check', ('output_file', False)), ('fork', (cpid,)), ('check', ('output_file', True)), ('chdir', (os.getcwd(),)), ]) # Check events generated by make subprocess # make applies the following env changes to its subprocesses env = test_utils.modified_env(os.environ, { 'MAKEFLAGS': 'w', 'MAKELEVEL': '1', 'MFLAGS': '-w', }) argv = ['/bin/sh', '-c', 'echo "Hello, World!" > output_file'] self.check_events(pids[cpid], cpid, argv, INIT_SH + [ ('write', ('output_file',)), ], env=env) self.assertTrue(Path(tmpdir, 'output_file').exists())
def test_shell_scipt_with_fork(self): with TemporaryDirectory() as tmpdir: script = Path(tmpdir, 'hello.sh') with script.open('w') as f: f.write(self.shell_script_with_fork) script.chmod(0o755) argv = [script.as_posix()] actual = self.run_trace(argv) # split into two lists, one for each PID pids = {} for pid, event, args in actual: pids.setdefault(pid, []).append((pid, event, args)) self.assertEqual(len(pids), 2) ppid, cpid = sorted(pids.keys()) # parent PID < child PID dmesg_checks = [] for p in test_utils.do_sh_path_lookup('dmesg'): dmesg_checks.append(('check', (p.as_posix(), p.exists()))) last = dmesg_checks.pop() assert last[1][1] is True dmesg_checks.extend([last] * 10) # Check events generated by sh process self.check_events(pids[ppid], ppid, argv, INIT_SH + [ ('read', (script.as_posix(),)), ('check', ('.', True)), ] + dmesg_checks + [ ('fork', (cpid,)), ]) # Check events generated by dmesg process # sh applies the following env changes to its subprocesses env = test_utils.modified_env(os.environ, { '_': p.as_posix(), 'SHLVL': str(int(os.environ.get('SHLVL', 0)) + 1), 'OLDPWD': None, # delete 'PS1': None, # delete }) self.check_events( pids[cpid], cpid, ['dmesg'], INIT_C_LOCALE + [ ('read', ('/dev/kmsg',)), ], env=env)
def make_mod_child_env(child): child.env = test_utils.modified_env(child.env, { 'MAKEFLAGS': '', 'MAKELEVEL': str(int(child.env.get('MAKELEVEL', 0)) + 1), 'MFLAGS': '', })