[PATCH 2/3] Add --cross-test-dir parameter to save tests for running on target
Uri Simchoni
urisimchoni at gmail.com
Thu Apr 30 14:21:49 MDT 2015
Add a parameter to the configure process that allows storing
compiled tests for which there is no answer in the cross-answers
file. These tests can later run on the target to get the proper answer.
---
buildtools/wafsamba/samba_cross.py | 54 ++++++++++++++++++++++++++++++--------
buildtools/wafsamba/wscript | 4 +++
2 files changed, 47 insertions(+), 11 deletions(-)
diff --git a/buildtools/wafsamba/samba_cross.py b/buildtools/wafsamba/samba_cross.py
index 4d80dd5..11c6260 100644
--- a/buildtools/wafsamba/samba_cross.py
+++ b/buildtools/wafsamba/samba_cross.py
@@ -1,6 +1,6 @@
# functions for handling cross-compilation
-import Utils, Logs, sys, os, Options, re
+import Utils, Logs, sys, os, Options, re, shutil
from Configure import conf
real_Popen = None
@@ -10,13 +10,17 @@ ANSWER_FAIL = (255, "")
ANSWER_OK = (0, "")
cross_answers_incomplete = False
+cross_answers_index = 1
cross_answers = None
-def write_cross_answers(ca_file):
+def write_cross_answers(ca_file, write_progs):
'''write answers file'''
lines = []
- for msg, (ans,anstext) in cross_answers.iteritems():
- lines.append('%s: %s\n' % (msg, anstext))
+ for msg, (ans,anstext,prog) in cross_answers.iteritems():
+ if ans == ANSWER_UNKNOWN and write_progs and prog:
+ lines.append('%s: %s,%s\n' % (msg, anstext, prog))
+ else:
+ lines.append('%s: %s\n' % (msg, anstext))
try:
f = open(ca_file, 'w')
@@ -45,7 +49,7 @@ def init_cross_answers(ca_file):
ans = a[1].strip()
if ans == "OK" or ans == "YES":
thisans = ANSWER_OK
- elif ans == "UNKNOWN":
+ elif ans == "UNKNOWN" or ans.startswith("UNKNOWN,"):
continue
elif ans == "FAIL" or ans == "NO":
thisans = ANSWER_FAIL
@@ -59,7 +63,7 @@ def init_cross_answers(ca_file):
thisans = (int(m.group(1)), m.group(2))
else:
raise Utils.WafError("Bad answer format '%s' in %s" % (line, ca_file))
- cross_answers[thismsg] = (thisans, ans)
+ cross_answers[thismsg] = (thisans, ans, None)
f.close()
@@ -67,11 +71,14 @@ def cross_answer(msg):
'''retrieves (retcode, retstring) cross-answer, if unknown then update
the cross-answers dictionary'''
if msg in cross_answers:
- ans, anstext = cross_answers[msg]
+ ans, anstext, p = cross_answers[msg]
return ans
- cross_answers[msg] = (ANSWER_UNKNOWN, "UNKNOWN")
- return ANSWER_UNKNOWN
+ return None
+def mark_unknown(msg,prog):
+ '''mark a test as unknown, optionally storing the
+ program to run to determine result'''
+ cross_answers[msg] = (ANSWER_UNKNOWN, "UNKNOWN", prog)
class cross_Popen(Utils.pproc.Popen):
'''cross-compilation wrapper for Popen'''
@@ -90,11 +97,32 @@ class cross_Popen(Utils.pproc.Popen):
# to use the cross answers if available
i = args.index('--cross-answers')
msg = args[i+1]
+
ans = cross_answer(msg)
- if ans == ANSWER_UNKNOWN:
+ if ans is None:
global cross_answers_incomplete
cross_answers_incomplete = True
+ ans = ANSWER_UNKNOWN
+ prog = None
+ if args[i+2:]:
+ #tests dir exists - store test binary and take
+ #a note in the dictionary
+ global cross_answers_index
+ targ_basename = 'test%03d' % (cross_answers_index)
+ cross_answers_index += 1
+ shutil.copy(args[0],os.path.join(args[i+2],targ_basename))
+ progargs = args[1:i]
+ progargs.insert(0,'./%s' % targ_basename)
+ prog = ' '.join(progargs)
+ mark_unknown(msg, prog)
+
(retcode, retstring) = ans
+ if ans == ANSWER_UNKNOWN:
+ # we already msrked configuration a failed. Now
+ # help configure run to completion - mock values
+ # that are less likely to fail configure in the middle
+ retcode = 0
+ retstring = "0" # both a number and a string
args = ['/bin/sh', '-c', "echo -n '%s'; exit %d" % (retstring, retcode)]
real_Popen.__init__(*(obj, args), **kw)
@@ -120,6 +148,8 @@ def SAMBA_CROSS_ARGS(conf, msg=None):
if cross_answers is None:
init_cross_answers(os.path.join(Options.launch_dir, conf.env.CROSS_ANSWERS))
ret.extend(['--cross-answers', msg])
+ if conf.env.CROSS_TEST_DIR:
+ ret.extend([conf.env.CROSS_TEST_DIR])
if ret == []:
raise Utils.WafError("Cannot cross-compile without either --cross-execute or --cross-answers")
@@ -131,6 +161,8 @@ def SAMBA_CROSS_CHECK_COMPLETE(conf):
'''check if we have some unanswered questions'''
global cross_answers_incomplete
if conf.env.CROSS_COMPILE and cross_answers_incomplete:
- write_cross_answers(os.path.join(Options.launch_dir, conf.env.CROSS_ANSWERS))
+ write_cross_answers(os.path.join(Options.launch_dir, conf.env.CROSS_ANSWERS), False)
+ if conf.env.CROSS_TEST_DIR:
+ write_cross_answers(os.path.join(conf.env.CROSS_TEST_DIR, os.path.basename(conf.env.CROSS_ANSWERS)), True)
raise Utils.WafError("Cross answers file %s is incomplete" % conf.env.CROSS_ANSWERS)
return True
diff --git a/buildtools/wafsamba/wscript b/buildtools/wafsamba/wscript
index c81a7b3..aa3f8cc 100755
--- a/buildtools/wafsamba/wscript
+++ b/buildtools/wafsamba/wscript
@@ -159,6 +159,9 @@ def set_options(opt):
gr.add_option('--cross-answers',
help=("answers to cross-compilation configuration (auto modified)"),
action='store', dest='CROSS_ANSWERS', default='')
+ gr.add_option('--cross-test-dir',
+ help=("directory in which to put cross-compiled test for running on target"),
+ action='store', dest='CROSS_TEST_DIR', default='')
gr.add_option('--hostcc',
help=("set host compiler when cross compiling"),
action='store', dest='HOSTCC', default=False)
@@ -257,6 +260,7 @@ def configure(conf):
conf.env.CROSS_COMPILE = Options.options.CROSS_COMPILE
conf.env.CROSS_EXECUTE = Options.options.CROSS_EXECUTE
conf.env.CROSS_ANSWERS = Options.options.CROSS_ANSWERS
+ conf.env.CROSS_TEST_DIR = Options.options.CROSS_TEST_DIR
conf.env.HOSTCC = Options.options.HOSTCC
conf.env.AUTOCONF_BUILD = Options.options.AUTOCONF_BUILD
--
1.9.1
More information about the samba-technical
mailing list