Importing a Jython module and running it via a <script> element runs it
within the same Jython interpreter as the STAX job. You can have your
Jython script return whatever you want (e.g. return 'pass' or return
'Failed with xxx'. So that it could return an indication of the test
status which you can assign to a variable such as "testOutput" and then
check it to determine if the test passed or failed. For example:
<testcase name="'Test1'">
<sequence>
<script>
testOutput = FreqAndLevelTest()
</script>
<if expr="testOutput == 'Success'">
<tcstatus result="'pass'"/>
<else>
<tcstatus result="'fail'">testOutput</tcstatus>
</else>
</if>
</sequence>
</testcase>
If you really neededto use a <process> element instead to run your test,
perhaps because you need to run the program on a remote machine, you could
do this instead as I'll talk about next.
Is there a reason why you're using Jython to call the java programs that
test your APIs instead of just running a Java program (or programs)
directly to test your APIs via a <process> element? For example:
<process>
<location>'local'</process>
<command mode="'shell'">'java Test'</command>
<stderr mode="'stdout'"/>
<returnstdout/>
</process>
If there is a good reason why you're using Jython instead of Java
directly, you could run a Jython script via a <process> element on a
machine if Jython is installed and accessible in the path, or you can
fully qualify the path to the jython executable, on the machine where the
process is run. Also, your Jython script must provide a main() function
and check if the __main__ top level module is called and have it call the
main() function in order to handle being run as a program. To run a
particular function in your Jython script, you would need to modify your
Jython script to accept a argument by having it's main() function check
the argument(s) passed in. See Python documentation such as
http://www.artima.com/weblogs/viewpost.jsp?thread=4829 for more
information on the main() function and on passing arguments to it. You
don't import the Jython module in this case as you are running the Jython
script in a separate program. Here's an example of running a Jython
script via a <process> element:
<process>
<location>'local'</process>
<command mode="'shell'">'jython C:/tests/test1.py'</command>
<stderr mode="'stdout'"/>
<returnstdout/>
</process>
--------------------------------------------------------------
Sharon Lucas
IBM Austin, [EMAIL PROTECTED]
(512) 286-7313 or Tieline 363-7313
[EMAIL PROTECTED]
12/01/2008 12:39 PM
To
Sharon Lucas/Austin/[EMAIL PROTECTED]
cc
staf-users@lists.sourceforge.net
Subject
Re: [staf-users] Unable to execute a process and getting the error: "The
process failed to start, RC: 10"
On Mon, Dec 1, 2008 at 5:05 PM, Sharon Lucas <[EMAIL PROTECTED]> wrote:
Here are my answers to your questions:
1. Is the <process> element not capable of executing a function and is
capable of calling the only the file (as processes)?
No, the <process> element cannot run a specific Python function (unless
you run a Python script with a main method that called that Python
function). The <process> element submits a START request to the STAF
PROCESS service which allows you to run most any process. This process
command can be any executable (e.g. "python test.py", "java Test", "perl
test.pl", "test.exe", etc). It is not specific to Python.
2. How is the best way to execute some functions from a jython code as a
process or a sub-job?
To run Python functions via a STAX job on the local STAX service machine,
you can run them as you normally would via Python after importing them.
For example:
<stax>
<defaultcall function="StartHere"></defaultcall>
<script>
import sys
sys.path.append("C:/Reg Test/jniwrap/jniwrap-2.9.5.jar")
sys.path.append("C:/Reg Test/jython/hwMods/SigGen")
sys.path.append("C:/Reg Test/jython/hwMods")
sys.path.append("C:/Reg Test/jython/hwMods/carrierFreqAndLevelTest.py")
from carrierFreqAndLevelTest import *
</script>
<function name="StartHere">
<sequence>
<script>
pyOutput = FreqAndLevelTest()
</script>
<log message="1">pyOutput</log>
</sequence>
</function>
</stax>
You may want to use import and name qualification instead of "from" when
importing your Python module if you want to be able to reload the Python
module (to pick up any changes to the Python module without having to
unregister and re-register the STAX service. See question "4.1.6 Why
aren't changes to imported Python modules picked up in my STAX job?" in
the STAF/STAX FAQ at
http://staf.sourceforge.net/current/STAFFAQ.htm#d0e2027 for more
information. For example:
<stax>
<defaultcall function="StartHere"></defaultcall>
<script>
import sys
sys.path.append("C:/Reg Test/jniwrap/jniwrap-2.9.5.jar")
sys.path.append("C:/Reg Test/jython/hwMods/SigGen")
sys.path.append("C:/Reg Test/jython/hwMods")
sys.path.append("C:/Reg Test/jython/hwMods/carrierFreqAndLevelTest.py")
import carrierFreqAndLevelTest
</script>
<function name="StartHere">
<sequence>
<script>
reload(carrierFreqAndLevelTest)
pyOutput = carrierFreqAndLevelTest.FreqAndLevelTest()
</script>
<log message="1">pyOutput</log>
</sequence>
</function>
</stax>
Note that if you wanted to run the Python functions on a remote machine,
then you would need to do it differently. Post again if you need an
example of how to run Python functions on a remote machine.
Dear Sharon,
Thanks for those details.
Yes, I can use <script> as you told element to call the Python function.
<script>
outPut = FreqAndLevelTest()
</script>
However, it alone does not solves the purpose. Using <script> forbids me
from checking the status of the test (such as RC and STAXResult). So, in a
way it forbids me from using the various other excellent features of STAX
like testcase, process, block, logging and monitoring.
I have this following test enviorment to test the C Dlls where I'm trying
to use the STAX. I'ld apprciate if you can suggest me some other way
around:
My setup is like:
STAF/STAX <------------> Jython <------------> Java(JNI) <------------> C
DLL
Java together with JNI has wrapper functions for the APIs in C DLL.
Testcases perform certain computations and are written in Jython.(For
clarity I call them as Tests). These tests are basically the jython
modules with functions defined to do the required testing / computation.
Through STAX (stax job file, I call them as Testcases) I'm intending to
call the Tests in Jython. So far I'm able to call create Tests in Jython
and have been able to tests some functionality.
I'm not able to understand what is the best way to call these Tests(or the
functions in modules) in terms of xml elements i,e. <process>, <job>,
<testcases>
I'm under the impression that I would have <testcase> element for each one
of those tests (i,e the functions in jython modules) so that using the
<tcsstatus> I can have a Pass / Fail verdict. Inside <testcase> element I
would call the <process> that will actually call the Test (i.e.the
function) and I will have all its stdout/stderr written to the STAX Job
User Log as wells as to the file (where they actually write).
Please suggest how is the best way to implement this. Should I make
changes to Python Tests by implementing them straight in the <script>
element.
Many thanks.
Regards,
Rajat
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users