#!/usr/bin/perl -Tw

use strict qw(subs);
use Graph::TopoSort;
my $G = new Graph::TopoSort;
$G->Scanner('DEPENDENCY');

#Insert the calling tree
my $F;
open F, "<calltree.m" or die "Can't find the calltree!\n";
$G->Insert (\*F);
close F;
#Insert the call sequence graph (rules)
open F, "<callseq.m" or die "Can't find the call sequence!\n";
$G->Insert (\*F);
close F;

print <<"__END__";
// Generated by gentest
#include "tests/tests.h"

__END__
my $Ts= $G->sort_dfs;
foreach my $I (@{$Ts})
{
   print "extern int t_$I(void);\n";
}

print <<"__END__";

int TestNum=1;
int main(int argc, char** argv)
{
   int I,S;
   for (S = 0; S < Num_SCycles; S++)
    {

__END__

foreach my $I (@{$Ts})
{
   print "      for(I=0;I <(S?Num_ICycles:1);I++) {TestSeq(t_$I);}\n";
}

print << "__END__";
    }
   fprintf(stderr, "%d Tests passed successfully\\n", TestNum-1);
   return 0;
}
__END__
