Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Need help using tcltest

2 views
Skip to first unread message

tcl_tk_project

unread,
Jan 26, 2003, 2:54:17 PM1/26/03
to

I went thru the tcltest(ver 1.0) (I m using tcl 8.3.4.3) documentation
,but itwasn't very clear as how to use tcltest to test a 'C' function .I
m just a beginner n need help .

supposing there is a small file add.c -

main()
{
int a,b,c;
a=5;b=10;
c=a+b;
return;
}

the syntax for 'test' is -
test <name> <discription> <constraints> <script> <expected ans>
here <name> is --> <target>-<majornum>.<minornum>

I want to know how to perform some test on the above code ..i.e. how to
test a 'C' function ..?? i.e. what should be the <target> and
<majornum>,<minornum> ....

Please reply ...I am an comp. engg. student doing a final yr project
.-"white box testing of C/C++ programs" ....

Also ..if someone has an Idea about the complexity of the above proj.
please reply ..
Thanking u all ...Please reply ..
Varun Sawhney .

--
Posted via http://dbforums.com

Marco Maggi

unread,
Jan 27, 2003, 2:30:02 AM1/27/03
to

"tcl_tk_project" (?) wrote:
>I went thru the tcltest(ver 1.0) (I m using tcl 8.3.4.3)
>documentation ,but itwasn't very clear as how to use tcltest
>to test a 'C' function .I m just a beginner n need help .

Hello,

you can take a look at the tests in the TCL source
tree. You have to remember that you need a compiler to build
the C program from sources, then read the documentation of
the [exec] and [open] commands.

Then...

>Please reply ...I am an comp. engg. student doing a final yr
>project .-"white box testing of C/C++ programs" ....

well, what to do then it's your job. :)

Ciao,
Marco

--
"Love & Peace" -- Vash the Stampede

Gerald W. Lester

unread,
Jan 27, 2003, 2:59:17 AM1/27/03
to
Your C function needs to be exposed as a Tcl extension.

Check out critcl or, if you are on Windows, the dll caller (forgot the
exact name).

--
+--------------------------------+---------------------------------------+
| Gerald W. Lester | "The man who fights for his ideals is
|
| Gerald...@cox.net | the man who is alive." -- Cervantes
|
+--------------------------------+---------------------------------------+

David Gravereaux

unread,
Jan 27, 2003, 4:16:15 AM1/27/03
to
tcl_tk_project <membe...@dbforums.com> wrote:

>I went thru the tcltest(ver 1.0) (I m using tcl 8.3.4.3) documentation
>,but itwasn't very clear as how to use tcltest to test a 'C' function .

1) expose the function so it has a tcl command to exercise it. See
win/tclWinTest.c for ideas.

2) Use the test command to apply an assertion for a case.

Here's something outside the core that might help explain it. I wrote an
IRC attribute convertor once and used tcltest to verify it. The parser
half is a C++ virtual base class. To use it, one makes a derived 'action'
class on top of it. So I made a tcl extension as a derived class and used
that for how tcltest calls it to assert about 200 cases.

http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/tomasoft/ctcp2_parser/
http://cvs.sf.net/cgi-bin/viewcvs.cgi/tomasoft/ctcp2_parser/generic/tclTestAdaptor.cpp?rev=HEAD&content-type=text/vnd.viewcvs-markup
http://cvs.sf.net/cgi-bin/viewcvs.cgi/tomasoft/ctcp2_parser/tests/ansi.test?rev=HEAD&content-type=text/vnd.viewcvs-markup
--
David Gravereaux <davy...@pobox.com>
[species: human; planet: earth,milkyway,alpha sector]

se...@fishpool.com

unread,
Jan 26, 2003, 11:48:57 PM1/26/03
to
tcl_tk_project <membe...@dbforums.com> wrote:
>
> I want to know how to perform some test on the above code ..i.e. how to
> test a 'C' function ..?? i.e. what should be the <target> and
> <majornum>,<minornum> ....

tcltest cannot test C functions, it can only test tcl commands.
The best way to build your application would be to have a core written
in C, controlled by a Tcl script via commands added to the Tcl interpreter.
You can then use tcltest to test these commands, and thus the functionality
of the C core.

--
/ http://www.fishpool.com/~setok/

tcl_tk_project

unread,
Jan 27, 2003, 5:30:35 AM1/27/03
to

This is regarding "help using tcltest ..to test a 'C' function.."

I have gone thru ur replies ...Thanks a ton ..Good to have people ready
to help ..

I'll go into the details of what was written ..n I'll get back to u
.(for moral support) .. :-) ..

The same topic has also been posted by some Mr. Harm Voordenhout .. I'll
try to contact ..

please give some more inputs ..

The tcltest 1.0 (that comes with tcl 8.3.4.3) documentation says "the
<target> should be the name of the tcl procedure or the 'C' function to
test" ..this should imply that something like just giving the name of
the 'C' function should work ..HOW ? The big How for me (as a beginner
,n a kid in tcl)..--I must say-the documentation is insufficient .. any
more words of advise will be great .

As u said "person who stands for his ideas ..is the one who survives .."
-: But THE IDEAS HAVE TO BE CLEAR enough ..

Thank you ..all ..God Bless ..
Varun Sawhney.

David Gravereaux

unread,
Jan 27, 2003, 7:09:19 AM1/27/03
to
tcl_tk_project <membe...@dbforums.com> wrote:

>The tcltest 1.0 (that comes with tcl 8.3.4.3) documentation says "the
><target> should be the name of the tcl procedure or the 'C' function to
>test" ..this should imply that something like just giving the name of
>the 'C' function should work ..HOW ? The big How for me (as a beginner
>,n a kid in tcl)..--I must say-the documentation is insufficient .. any
>more words of advise will be great .

Yeah, the docs are a bit harsh on tcltest. Not user friendly, I agree.
Don't worry much about the naming convention. It's just a name. Pick
something descriptive that means something to you.

test TransmorphHtmlInput-1.0 {Ignoring a NULL input} {
set result [catch {mytest::transmorphHtml {}} err]
list $result $err
} {1 {no input}}

test TransmorphHtmlInput-1.1 {Ignoring a bad URI} {
set result [catch {mytest::transmorphHtml {htp://www.foo/}} err]
list $result $err
} {1 {bad uri}}

Cameron Laird

unread,
Jan 27, 2003, 7:29:31 AM1/27/03
to
In article <2441937.1...@dbforums.com>,

tcl_tk_project <membe...@dbforums.com> wrote:
>
>This is regarding "help using tcltest ..to test a 'C' function.."
.
.

.
>The tcltest 1.0 (that comes with tcl 8.3.4.3) documentation says "the
><target> should be the name of the tcl procedure or the 'C' function to
>test" ..this should imply that something like just giving the name of
>the 'C' function should work ..HOW ? The big How for me (as a beginner
.
.
.
Hmmm!

I can't explain why tcltest is documented that way; using
it for C-side testing is not trivial. Tcltest is quite an
apt vehicle for such testing, but it's neither well enough
documented nor so falling-off-a-log-easy that I'd recommend
it to a beginner in Tcl, as you characterized yourself.

I strongly favor use of Critcl <URL: http://wiki.tcl.tk/critcl >
in such an application, as Gerald mentioned. I repeat,
though, that none of this is sufficiently well documented
to recommend to any but the most diligent beginner. Good
luck to you.
--

Cameron Laird <Cam...@Lairds.com>
Business: http://www.Phaseit.net
Personal: http://phaseit.net/claird/home.html

Don Porter

unread,
Jan 27, 2003, 8:56:49 AM1/27/03
to
In article <jn7a3vctn6m2nrgtu...@4ax.com>, David Gravereaux wrote:
> tcl_tk_project <membe...@dbforums.com> wrote:
>
>>The tcltest 1.0 (that comes with tcl 8.3.4.3) documentation says "the
>><target> should be the name of the tcl procedure or the 'C' function to
>>test" ..this should imply that something like just giving the name of
>>the 'C' function should work ..HOW ? The big How for me (as a beginner
>>,n a kid in tcl)..--I must say-the documentation is insufficient .. any
>>more words of advise will be great .

> Yeah, the docs are a bit harsh on tcltest. Not user friendly, I agree.

While constructive criticism about the tcltest package is welcome,
it would be much more useful if you looked at and criticized the
current version (tcltest 2.2.1) and not an abandoned branch of
development. I cannot think of any reason why a new testing project
would choose tcltest 1 over tcltest 2.

Are these docs better?

http://tmml.sourceforge.net/doc/tcl/tcltest.html

--
| Don Porter Mathematical and Computational Sciences Division |
| donald...@nist.gov Information Technology Laboratory |
| http://math.nist.gov/~DPorter/ NIST |
|______________________________________________________________________|

Don Porter

unread,
Jan 27, 2003, 10:35:06 AM1/27/03
to
tcl_tk_project wrote:
> I went thru the tcltest(ver 1.0) (I m using tcl 8.3.4.3) documentation

As I mentioned elsewhere, for any new project start with tcltest 2.2
(bundled with Tcl 8.4).

> ,but itwasn't very clear as how to use tcltest to test a 'C' function.

The tcltest package tests Tcl scripts. In order to test a C function,
it will need to be exposed as a Tcl script. This will involve creating
a program that links together your C functions and the Tcl library.
Use Tcl_CreateCommand() from the Tcl library to define a Tcl command
that exercises your C functions in a manner suitable for good testing.

Some people make use of a programming tool called SWIG to automate
some of this. There are also many other tools available for working
with C and Tcl together; each seems to have its camp.

I find it simple enough to just do these things "by hand".

> supposing there is a small file add.c -
>
> main()
> {
> int a,b,c;
> a=5;b=10;
> c=a+b;
> return;
> }

Uhhhh... you do know that "main" is a special function name in C, right?
Do you intend that specialness?

> the syntax for 'test' is -
> test <name> <discription> <constraints> <script> <expected ans>

Yes.

> here <name> is --> <target>-<majornum>.<minornum>

Well, that's just a recommended convention. You can choose test names
as you like. It's a good idea to embed the name of your C function
in the test name so that when you notice that test foo-3.4 is failing,
you need to go fix the bug in the foo() C function.

> I want to know how to perform some test on the above code ..i.e. how to
> test a 'C' function ..?? i.e. what should be the <target> and
> <majornum>,<minornum> ....

The convention is useful for people; it doesn't make tcltest itself do
any magic.

David Gravereaux

unread,
Jan 27, 2003, 5:46:18 PM1/27/03
to
Don Porter <d...@email.nist.gov> wrote:

>In article <jn7a3vctn6m2nrgtu...@4ax.com>, David Gravereaux wrote:
>> tcl_tk_project <membe...@dbforums.com> wrote:
>>
>>>The tcltest 1.0 (that comes with tcl 8.3.4.3) documentation says "the
>>><target> should be the name of the tcl procedure or the 'C' function to
>>>test" ..this should imply that something like just giving the name of
>>>the 'C' function should work ..HOW ? The big How for me (as a beginner
>>>,n a kid in tcl)..--I must say-the documentation is insufficient .. any
>>>more words of advise will be great .
>
>> Yeah, the docs are a bit harsh on tcltest. Not user friendly, I agree.
>
>While constructive criticism about the tcltest package is welcome,
>it would be much more useful if you looked at and criticized the
>current version (tcltest 2.2.1) and not an abandoned branch of
>development. I cannot think of any reason why a new testing project
>would choose tcltest 1 over tcltest 2.
>
>Are these docs better?
>
> http://tmml.sourceforge.net/doc/tcl/tcltest.html
>

Same content. I was referring to that. These parts I had trouble with.

1) [tcltest::singleProcess] (that is a short for the config -singleproc)
should describe in more human terms that any sourc'ing one does in the
main suite entrance script will not have those items available in the same
interp the test scripts are run in, unless that config is set.

To me, this seems the *most important* config setting when putting
together a large suite regarding how one 'bootloads' the environment one
is testing (aka model or architecture of the suite itself).

2) Constraints. When constructing a test suite to run on multiple
versions of a product should one add constraints for new feature tests?
Should one mark baseline tests in constraints?

The document doesn't describe the concept aside from just how constraints
work. Say I have a baseline, called version 1.0 followed by 1.1 and 1.2.
1.1 has all the tests of 1.0 plus a couple more. 1.2 has all the test of
1.1 and 1.0 plus a couple new ones for itself. So I either not mark each
test case in a constraint for the baseline or add either {1.1} or {1.2}.

In the bootloader of the test suite I found to be running in product 1.2,
so I set -constraints {1.1 1.2} in the call to tcltest to enable the
baseline (not constrained tests, can't unconstaint them unless I ask for
only those in constraints) plus ones marked 1.1 and 1.2. Is that the best
model?

Don Porter

unread,
Jan 28, 2003, 12:53:00 AM1/28/03
to
David Gravereaux wrote:
>>> Yeah, the docs are a bit harsh on tcltest. Not user friendly, I agree.

In part this is the old tension between the "Unix man page" style
that focuses solely on interface specification, leaving out more
"user friendly" things like examples, and usage templates, and "HOWTO"
documents.

Recent revisions to the tcltest documentation have added more examples,
and there's more we can do in that direction.

David Gravereaux wrote:
> 1) [tcltest::singleProcess] (that is a short for the config -singleproc)
> should describe in more human terms that any sourc'ing one does in the
> main suite entrance script will not have those items available in the same
> interp the test scripts are run in, unless that config is set.
>
> To me, this seems the *most important* config setting when putting
> together a large suite regarding how one 'bootloads' the environment one
> is testing (aka model or architecture of the suite itself).

This is one of the known weaknesses of the tcltest package, recorded
as Tcl Feature Request 577038.

The mechanism supplied by tcltest for making common code available
to multiple test files is [configure -loadfile] and [loadTestedCommands].
For an example of this (and the weaknesses) see the Tk test suite.

> 2) Constraints. When constructing a test suite to run on multiple
> versions of a product should one add constraints for new feature tests?
> Should one mark baseline tests in constraints?
>
> The document doesn't describe the concept aside from just how constraints
> work. Say I have a baseline, called version 1.0 followed by 1.1 and 1.2.
> 1.1 has all the tests of 1.0 plus a couple more. 1.2 has all the test of
> 1.1 and 1.0 plus a couple new ones for itself. So I either not mark each
> test case in a constraint for the baseline or add either {1.1} or {1.2}.
>
> In the bootloader of the test suite I found to be running in product 1.2,
> so I set -constraints {1.1 1.2} in the call to tcltest to enable the
> baseline (not constrained tests, can't unconstaint them unless I ask for
> only those in constraints) plus ones marked 1.1 and 1.2. Is that the best
> model?

It sounds like we have the same concept for that. Just to be more
explicit, the common code (stored in the -loadfile) could look like
this:

package require example 1
package require tcltest 2.2
namespace eval ::example::test {
namespace import ::tcltest::testConstraint
variable minor 0
while {[testConstraint example-1.$minor \
[package vsatisfies [package provide example] 1.$minor]} {
incr minor
}
}

Then constrain each of your blackbox tests with the constraint
corresponding to the first release that contains the feature:

test example-5.2 {New in release 1.1!} example-1.1 {
foo bar
} baz

Following this strategy, you can even add tests for features you
plan to include in future releases, completing the tests in advance
of the code.

Arjen Markus

unread,
Jan 28, 2003, 2:37:53 AM1/28/03
to
tcl_tk_project wrote:
>
> This is regarding "help using tcltest ..to test a 'C' function.."
>
> I have gone thru ur replies ...Thanks a ton ..Good to have people ready
> to help ..
>
> I'll go into the details of what was written ..n I'll get back to u
> .(for moral support) .. :-) ..
>

You might try an alternative approach that I described in a paper,
called "Generating test programs with TestMake" (I can send you
the scripts if you are interested), <http://wiki.tcl.tk/2604>

The application that I describe there generates test programs
from specifications, rather than requiring you to make your
routines available in Tcl.

For certain types of routines this is a useful approach - and
takes away some of the boring repetitve programming stuff too.

Regards,

Arjen

tcl_tk_project

unread,
Jan 28, 2003, 5:54:28 AM1/28/03
to

Hello,

First ,a big thanks to all of you for so much help ...I wasn't
expecting such a response ..thanks ..

I am speaking to my group partners(2 other students) and also some
other friends ..

One of my friend has some programming exp with tcl ..He is also of
the same view as Mr. Don Porter ..

Thank u Mr. Porter -Those Docs were definitely better than the ones
I was referring ..we would be doing the project -using tcltest 2.2
..as u advised ..

Thanks also to Mr. David Gravereaux ,Mr. Arjen Markus ...and
everybody else ..

Yes, Mr. Arjen ..please ,if u can send the scripts ...would
be helpful .

My e-mail ID is : tcl_tk_...@indiatimes.com

The Idea is now very much clear ..Still any other words of advise
are welcome ..

I'm just a final yr Engg. student ..but the help n support u people
have given is great ..

Thanking everybody,
Varun Sawhney

David Gravereaux

unread,
Jan 28, 2003, 7:58:31 AM1/28/03
to
Don Porter <d...@email.nist.gov> wrote:

A big thanks for the advice. This is much clearer to me now. Gazing
through the core test, I found main.test along what you described about
bootloading. There's some new ideas in there, I hadn't seen before.

>Following this strategy, you can even add tests for features you
>plan to include in future releases, completing the tests in advance
>of the code.

Well said. A technique I feel comfortable with.

se...@fishpool.com

unread,
Jan 28, 2003, 7:24:29 PM1/28/03
to
Don Porter <d...@email.nist.gov> wrote:
>
> In part this is the old tension between the "Unix man page" style
> that focuses solely on interface specification, leaving out more
> "user friendly" things like examples, and usage templates, and "HOWTO"
> documents.
>
> Recent revisions to the tcltest documentation have added more examples,
> and there's more we can do in that direction.

I think the approach in the man page is quite OK: that is a reference,
not a tutorial. Most of the time when you use man pages you just want the
most important bits quickly and easily.

Having said that, we should probably have a good tcltest tutorial somewhere
with tips and examples. Would do me a lot of good too, because I keep
asking myself things like "what are those version numbers supposed to be?" when
making tests.


--
/ http://www.fishpool.com/~setok/

0 new messages