ATF-devel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: ATF confusion with improperly terminated script



On Sun, Feb 06, 2011 at 01:36:48PM -0800, Garrett Cooper wrote:
> On Sun, Feb 6, 2011 at 12:03 PM, Julio Merino 
> <jmmv%homeworld.netbsd.org@localhost> wrote:
> > On Sun, Feb 06, 2011 at 11:00:59AM -0800, Garrett Cooper wrote:
> 
> >> # $FreeBSD$
> >>
> >> export SH=${SH:=/bin/sh}
> >>
> >> do_test() {
> >> ? ? ? ? local atf_args expected_exit_status testcase_path testcase_prefix
> >>
> >> ? ? ? ? testcase_path=$1
> >
> > If you need access to data files that live in the same directory as the test
> > program, you should query $(atf_get_srcdir).
> 
> Sadly, they're in subdirectories (otherwise I wouldn't care about the
> path a lot).

That's fine.  But my point was: test cases are executed within a temporary
directory not known a priori.  The canonical way to refer to the directory
from which they come from is by using $(atf_get_srcdir) (which just gives
you the value of the argument passed to the test program through the -s
flag).

And now this gives me an idea of why your code does not work; see below.

> It's not even getting that far. When I don't execute the testcase
> standalone it's getting hung up on some logic in libatf-sh.subr (in
> particular the testcase names aren't ending up in calls to
> atf_test_case ... curious). The contents of Defined_Test_Cases is ok
> for a while, but the majority of the content in the value is getting
> dropped about halfway through the invocation.

OK, I think I know what the problem in your code is: your attempts to do
too much magic from the "initialization function" are dangerous.  (Didn't
want to mention it before because they looked sane... but it seems they
won't work after all!)

As I mentioned in some other email to Giorgios, atf-run does the following
to run test cases of the foo_test program:

1) Run 'foo_test -l' to extract the list of test cases.  This happens
   without changing the current work directory (I believe).
2) For every test case, create a _new temp dir_ and run:
   - /path/to/srcdir/foo_test test_case_name:body
   - /path/to/srcdir/foo_test test_case_name:cleanup

All of these 3 invocations go through the initialization function because
they are different processes and thus they need to reconstruct the internal
test program state.

In your example code, the first time the test program is run to extract
its list of test cases, the "find ." command does the right thing because
it happens from the directory in which the files are found.

However, when atf-run decides to run your test programs, it will run them
with the cwd pointing somewhere else and "find ." will yield no results.
Which in turn means that the test program does not define any test cases
and thus it is "bogus".

If you really want to make the test case dynamic, you need to do
"find $(atf_get_srcdir)" instead.  Or you could use some Makefile magic
to generate a static list of names to bundle into the test program.

Take a look at the atf-test-case(4) manpage, as it describes how test cases
are isolated during execution.

But all the above are wild guesses.  Maybe your problem comes from
somewhere else ;-)

-- 
Julio Merino


Home | Main Index | Thread Index | Old Index