How to test c program using Ruby

Thanks. I have a idea on the search method. Actually, my problem is I have
no idea how to feed the input data to c program,(using ruby inline?)and output
the coverage(I try to add some c code into the c program to get the statement
coverage)to the ruby, some suggest me to use command line to input the data to
c program,but there is a problem
like that :
system “./triangle” #call c program
foo xxxxx

program will excute the c c program first, and after it terminate, then will
excute the next line in ruby.

===== Original Message From “Bill Kelly” billk@cts.com =====

Hi,

My problem is generate a set of test cases automatically in Ruby, and use
it to test the c program get the statement coverage which should be pass to
ruby, the ruby program supposed to use a search method to generate the
better test cases to test the c program again untill find the best test
cases which can fullly cover all of the statements… That means the input
of
c program should be generated from ruby and the result of statement
coverage

···

should be passed to ruby.

Perhaps you could post some sample “test” data to be fed to the ‘C’
program, and an example of what the output data from the coverage
analyzer looks like. (?)

Do you already have an idea what kind of search method you plan to
use to cause the output from the coverage analysis to be useful
in adapting the generated input data toward increased coverage?

It sounds like a difficult problem in any language. :slight_smile:

Seems I should use rubyinline. Is there any one has suggestion about it? Or
any other way to do it?
Thanks.

Regards,

Bill

Thanks. I have a idea on the search method. Actually, my problem is I have
no idea how to feed the input data to c program,(using ruby inline?)and output
the coverage(I try to add some c code into the c program to get the statement
coverage)to the ruby, some suggest me to use command line to input the data to
c program,but there is a problem
like that :
system “./triangle” #call c program
foo xxxxx

program will excute the c c program first, and after it terminate, then will
excute the next line in ruby.

Have you tried pipes? You could connect Ruby to the stdin and stdout
of your ‘C’ program and communicate to it like that.

There’s an IO#popen example in Pickaxe, Chapter 11, under the Running
Multiple Processes section.

It looks like: [any typos are my fault ;)]

pig = IO.popen(“pig”, “w+”)
pig.puts “ice cream after they go to bed”
pig.close_write
puts pig.gets

Where ‘pig’ is the ‘C’ program. (And produces the output,
“iceway eamcray afterway eythay ogay otay edbay”)

This way your ‘C’ program would read its input test data from
stdin, and write its coverage statistics to stdout…

Hope this helps,

Bill