ATF-devel archive

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

Re: set variables at runtime with atf-run



On Sat, May 1, 2010 at 2:08 AM, Stathis Kamperis <ekamperi%gmail.com@localhost> 
wrote:
> 2010/5/1 Julio Merino <jmmv%netbsd.org@localhost>:
>> On Fri, Apr 30, 2010 at 10:05 PM, Stathis Kamperis 
>> <ekamperi%gmail.com@localhost> wrote:
>>> Hi all,
>>>
>>> is it possible to declare a variable inside an atf test program,
>>> assign it a default value and be able to change it during runtime ?
>>
>> Yes, it is.  You can use the atf_tc_{has,get}_config_var functions for
>> this purpose.  See the atf-c/tc.h header file.
>
> Excellent; I also saw atf_tc_get_config_var_wd() for falling back to a
> default value if non is given. Works great.

Oops, true, forgot to mention that :-)

> As I understand ATF treats all config variables as strings. This makes
> it cumbersome when you need an integer value and you have to call
> strtol() and do all the error handling. Do you think that it would
> make sense to have some ATF function  to take care of that ? Say for
> example: atf_tc_get_config_var_as_int(). If not, I can always write
> one of my own, put it in subr_atf.c and link against it from my test
> programs.

Yeah, it makes sense.  As for now, you may also fall back to using
atf_text_to_{bool,long}, which have better error handling.  I
shouldn't say that, though: these functions are supposed to be
private...  but... well, if we implement what you suggest, they will
end up being used anyway :-)

You might want to wrap them around with your own
get_config_var_as_{bool,int}() for now and stick them in that
subr_atf.c.  This would have the advantage of having a consistent call
to atf_fail with a nice error message if the format of a variable is
invalid.  (Or to follow the current -- ugly -- convention, you could
create a tests/h_lib.{ch} with these helper functions and assimilate
the current contents of tests/h_macros.h.  h_ stands for helper.
These paths are relative to the netbsd src tree.)

The idea behind creating these abstractions in the netbsd test suite
would be to allow copying the code later on verbatim into atf. :-)

Hope this helps,

-- 
Julio Merino


Home | Main Index | Thread Index | Old Index