-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
integration: add background runner script
To eventually run these in parallel, we want to not have a single test instance hogging the console. Add a background-runner script which uses a detached screen session that also preserves the exit code of the program we're testing.
- Loading branch information
Showing
3 changed files
with
63 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/python | ||
|
||
# Use screen to run a terminal program in the background until it exists. | ||
# This process stays around in the forground. | ||
# Exit code from the program being run is returned here. | ||
|
||
import argparse | ||
import subprocess | ||
import sys | ||
import tempfile | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('-l', '--logfile', default=None, | ||
help='append output to logfile') | ||
args, program = parser.parse_known_args() | ||
|
||
cmd = [ | ||
'screen', | ||
'-c', '/dev/null', # ignore any user configuration | ||
'-D', '-m', # run detached from a terminal perspective, | ||
# but the screen process doesn't background | ||
] | ||
if args.logfile: | ||
cmd.extend(('-L', '-Logfile', args.logfile)) | ||
|
||
with tempfile.NamedTemporaryFile() as exitfile: | ||
cmd.extend(('./scripts/capture-exit-code', exitfile.name, *program)) | ||
subprocess.run(cmd, check=True) | ||
sys.exit(int(exitfile.read())) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/sh -u | ||
|
||
# Take a filename argument. The rest of the arguments are a program to run. | ||
# Save the exit code of that program to the filename arg. | ||
|
||
exitfile="$1" | ||
shift | ||
"$@" | ||
ec=$? | ||
echo $ec > "$exitfile" | ||
exit $ec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters