aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2013-10-18 22:04:07 +0300
committerJussi Pakkanen <jpakkane@gmail.com>2013-10-18 22:04:07 +0300
commit11cfb3ce22dfbe189969575832d51a925abc8fee (patch)
tree6ae67dd7b4ff9e26d9ff49d03bb329b978a99670
parentae06ca2afc58901d9d72f13f662701cf12281b51 (diff)
downloadmeson-11cfb3ce22dfbe189969575832d51a925abc8fee.zip
meson-11cfb3ce22dfbe189969575832d51a925abc8fee.tar.gz
meson-11cfb3ce22dfbe189969575832d51a925abc8fee.tar.bz2
Can set test cmd arguments and environment variables.
-rw-r--r--backends.py7
-rw-r--r--interpreter.py25
-rwxr-xr-xmeson_test.py20
-rw-r--r--test cases/common/48 test args/cmd_args.c18
-rw-r--r--test cases/common/48 test args/envvars.c15
-rw-r--r--test cases/common/48 test args/meson.build7
6 files changed, 78 insertions, 14 deletions
diff --git a/backends.py b/backends.py
index b66c80e..01e782c 100644
--- a/backends.py
+++ b/backends.py
@@ -96,12 +96,14 @@ def do_conf_file(src, dst, confdata):
os.replace(dst_tmp, dst)
class TestSerialisation:
- def __init__(self, name, fname, is_cross, exe_wrapper, is_parallel):
+ def __init__(self, name, fname, is_cross, exe_wrapper, is_parallel, cmd_args, env):
self.name = name
self.fname = fname
self.is_cross = is_cross
self.exe_runner = exe_wrapper
self.is_parallel = is_parallel
+ self.cmd_args = cmd_args
+ self.env = env
# It may seem a bit silly that this Backend class exists on its own
# rather than being a part of NinjaBackend, which is the only class
@@ -498,7 +500,8 @@ class NinjaBackend(Backend):
exe_wrapper = self.environment.cross_info.get('exe_wrapper', None)
else:
exe_wrapper = None
- ts = TestSerialisation(t.get_name(), fname, is_cross, exe_wrapper, t.is_parallel)
+ ts = TestSerialisation(t.get_name(), fname, is_cross, exe_wrapper,
+ t.is_parallel, t.cmd_args, t.env)
arr.append(ts)
pickle.dump(arr, datafile)
diff --git a/interpreter.py b/interpreter.py
index fe1efd5..76d9f4a 100644
--- a/interpreter.py
+++ b/interpreter.py
@@ -338,11 +338,13 @@ class SharedLibraryHolder(BuildTargetHolder):
super().__init__(build.SharedLibrary, name, subdir, is_cross, sources, environment, kwargs)
class Test(InterpreterObject):
- def __init__(self, name, exe, is_parallel):
+ def __init__(self, name, exe, is_parallel, cmd_args, env):
InterpreterObject.__init__(self)
self.name = name
self.exe = exe
self.is_parallel = is_parallel
+ self.cmd_args = cmd_args
+ self.env = env
def get_exe(self):
return self.exe
@@ -835,7 +837,26 @@ class Interpreter():
par = kwargs.get('is_parallel', True)
if not isinstance(par, bool):
raise InterpreterException('Keyword argument is_parallel must be a boolean.')
- t = Test(args[0], args[1].target, par)
+ cmd_args = kwargs.get('args', [])
+ if not isinstance(cmd_args, list):
+ cmd_args = [cmd_args]
+ for i in cmd_args:
+ if not isinstance(i, str):
+ raise InterpreterException('Command line arguments must be strings')
+ envlist = kwargs.get('env', [])
+ if not isinstance(envlist, list):
+ envlist = [envlist]
+ env = {}
+ for e in envlist:
+ if '=' not in e:
+ raise InterpreterException('Env var definition must be of type key=val.')
+ (k, val) = e.split('=', 1)
+ k = k.strip()
+ val = val.strip()
+ if ' ' in k:
+ raise InterpreterException('Env var key must not have spaces in it.')
+ env[k] = val
+ t = Test(args[0], args[1].target, par, cmd_args, env)
self.build.tests.append(t)
mlog.debug('Adding test "', mlog.bold(args[0]), '".', sep='')
diff --git a/meson_test.py b/meson_test.py
index 4a9925c..3bba960 100755
--- a/meson_test.py
+++ b/meson_test.py
@@ -39,26 +39,27 @@ def write_log(logfile, test_name, result_str, stdo, stde):
logfile.write(stde)
logfile.write('\n-------\n\n')
-def run_single_test(wrap, fname, is_cross, exe_runner):
+def run_single_test(wrap, test):
global tests_failed
- if is_cross:
- if exe_runner is None:
+ if test.is_cross:
+ if test.exe_runner is None:
# 'Can not run test on cross compiled executable
# because there is no execute wrapper.
cmd = None
else:
- cmd = [exe_runner, fname]
+ cmd = [exe_runner, test.fname]
else:
- cmd = [fname]
+ cmd = [test.fname]
if cmd is None:
res = 'SKIP'
duration = 0.0
stdo = 'Not run because can not execute cross compiled binaries.'
stde = ''
else:
- cmd = wrap + cmd
+ cmd = wrap + cmd + test.cmd_args
starttime = time.time()
- p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
+ env=test.env)
(stdo, stde) = p.communicate()
endtime = time.time()
duration = endtime - starttime
@@ -113,11 +114,10 @@ def run_tests(options, datafilename):
if not test.is_parallel:
drain_futures(futures)
futures = []
- res = run_single_test(wrap, test.fname, test.is_cross, test.exe_runner)
+ res = run_single_test(wrap, t)
print_stats(numlen, tests, test.name, res, i, logfile)
else:
- f = executor.submit(run_single_test, wrap, test.fname,
- test.is_cross, test.exe_runner)
+ f = executor.submit(run_single_test, wrap, test)
futures.append((f, numlen, tests, test.name, i, logfile))
drain_futures(futures)
print('\nFull log written to %s.' % logfilename)
diff --git a/test cases/common/48 test args/cmd_args.c b/test cases/common/48 test args/cmd_args.c
new file mode 100644
index 0000000..545b795
--- /dev/null
+++ b/test cases/common/48 test args/cmd_args.c
@@ -0,0 +1,18 @@
+#include<stdio.h>
+#include<string.h>
+
+int main(int argc, char **argv) {
+ if(argc != 3) {
+ fprintf(stderr, "Incorrect number of arguments.\n");
+ return 1;
+ }
+ if(strcmp(argv[1], "first") != 0) {
+ fprintf(stderr, "First argument is wrong.\n");
+ return 1;
+ }
+ if(strcmp(argv[2], "second") != 0) {
+ fprintf(stderr, "Second argument is wrong.\n");
+ return 1;
+ }
+ return 0;
+}
diff --git a/test cases/common/48 test args/envvars.c b/test cases/common/48 test args/envvars.c
new file mode 100644
index 0000000..114df5e
--- /dev/null
+++ b/test cases/common/48 test args/envvars.c
@@ -0,0 +1,15 @@
+#include<stdio.h>
+#include<string.h>
+#include<stdlib.h>
+
+int main(int argc, char **argv) {
+ if(strcmp(getenv("first"), "val1") != 0) {
+ fprintf(stderr, "First envvar is wrong.\n");
+ return 1;
+ }
+ if(strcmp(getenv("second"), "val2") != 0) {
+ fprintf(stderr, "Second envvar is wrong.\n");
+ return 1;
+ }
+ return 0;
+}
diff --git a/test cases/common/48 test args/meson.build b/test cases/common/48 test args/meson.build
new file mode 100644
index 0000000..1243c21
--- /dev/null
+++ b/test cases/common/48 test args/meson.build
@@ -0,0 +1,7 @@
+project('test features', 'c')
+
+e1 = executable('cmd_args', 'cmd_args.c')
+e2 = executable('envvars', 'envvars.c')
+
+test('command line arguments', e1, args : ['first', 'second'])
+test('environment variables', e2, env : ['first=val1', 'second=val2'])