Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Narvaez <dwnarvaez@gmail.com>2013-01-10 15:04:30 (GMT)
committer Daniel Narvaez <dwnarvaez@gmail.com>2013-01-10 15:04:30 (GMT)
commit055979c8c4471564745c86b1b9ece34750c0b3bb (patch)
treeea4b0f0e1938719da762cf865b93f97dadd7cb75
parent2787dfc1e09974e6b1212175f6971c4ed1009717 (diff)
Add a --test-path argument
To be able to run tests inside the sugar environment.
-rw-r--r--scripts/sugar-runner.in22
-rw-r--r--scripts/xinitrc32
2 files changed, 39 insertions, 15 deletions
diff --git a/scripts/sugar-runner.in b/scripts/sugar-runner.in
index 50d3fbe..e8aa9c8 100644
--- a/scripts/sugar-runner.in
+++ b/scripts/sugar-runner.in
@@ -14,6 +14,12 @@ helpers_dir = "@helpersdir@"
xinit_process = None
window_process = None
+result = 0
+
+
+def _usr1_signal_handler(number, frame):
+ global result
+ result = 1
def _term_signal_handler(number, frame):
@@ -125,8 +131,11 @@ def _setup_variables(args, home_dirs):
if args.output is not None:
os.environ["SUGAR_RUNNER_OUTPUT"] = args.output
- if args.display_path is not None:
- os.environ["SUGAR_RUNNER_DISPLAY_PATH"] = args.display_path
+ if args.test_command is not None:
+ os.environ["SUGAR_RUNNER_TEST_COMMAND"] = args.test_command
+
+ if args.test_log is not None:
+ os.environ["SUGAR_RUNNER_TEST_LOG"] = args.test_log
os.environ["XDG_CACHE_HOME"] = home_dirs["cache"]
os.environ["XDG_DATA_HOME"] = home_dirs["data"]
@@ -139,10 +148,10 @@ parser = argparse.ArgumentParser(description="Run sugar")
parser.add_argument("--resolution", help="screen resolution")
parser.add_argument("--output", help="name of the output")
parser.add_argument("--home-dir", help="path to the home directory")
+parser.add_argument("--test-log", help="path where to log the test output")
+parser.add_argument("--test-command", help="command line of the test to run")
parser.add_argument("--virtual", action="store_true",
help="use an a virtual server")
-parser.add_argument("--display-path",
- help="write the display number at this path")
args = parser.parse_args()
home_dirs = _get_home_dirs(args)
@@ -171,7 +180,10 @@ else:
xinit_args.append(display)
xinit_args.append("vt%s" % _get_tty_number())
+os.environ["SUGAR_RUNNER_PID"] = str(os.getpid())
+
signal.signal(signal.SIGTERM, _term_signal_handler)
+signal.signal(signal.SIGUSR1, _usr1_signal_handler)
try:
xinit_process = subprocess.Popen(xinit_args)
@@ -185,3 +197,5 @@ except KeyboardInterrupt:
if window_process:
window_process.terminate()
+
+sys.exit(result)
diff --git a/scripts/xinitrc b/scripts/xinitrc
index a87019a..8ebb208 100644
--- a/scripts/xinitrc
+++ b/scripts/xinitrc
@@ -3,20 +3,16 @@
import os
import subprocess
import signal
+import sys
+import shlex
+import signal
from gi.repository import SugarRunner
devnull = open("/dev/null")
main_loop = None
-
-def _write_display(display_path):
- tmp_display_path = "%s.tmp" % display_path
-
- with open(tmp_display_path, "w") as f:
- f.write(os.environ["DISPLAY"])
-
- os.rename(tmp_display_path, display_path)
+_SUGAR_ARGS = ["sugar"]
def _setup_outputs():
@@ -72,12 +68,26 @@ def _start_keyring():
"--components=secrets,pkcs11,ssh,gpg"])
_add_output_to_environ(output)
-if "SUGAR_RUNNER_DISPLAY_PATH" in os.environ:
- _write_display(os.environ["SUGAR_RUNNER_DISPLAY_PATH"])
+
+def _run_sugar():
+ subprocess.check_call(_SUGAR_ARGS)
+
+
+def _run_sugar_and_test(test_command):
+ sugar_process = subprocess.Popen(_SUGAR_ARGS)
+ result = subprocess.call(shlex.split(test_command))
+ sugar_process.terminate()
+
+ return result == 0
_setup_outputs()
_load_xkb_config()
_start_dbus()
_start_keyring()
-subprocess.check_call(["sugar"])
+test_command = os.environ.get("SUGAR_RUNNER_TEST_COMMAND", None)
+if test_command:
+ if not _run_sugar_and_test(test_command):
+ os.kill(int(os.environ["SUGAR_RUNNER_PID"]), signal.SIGUSR1)
+else:
+ _run_sugar()