From: mquinson Date: Mon, 10 Nov 2008 14:01:32 +0000 (+0000) Subject: Change sg_unit_extractor so that it takes all units to generate on its command line... X-Git-Tag: v3.3~112 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/e5e5accbefb1b4a360da4247ce287d1466b0f352?hp=3ce8957cfe6f904f244fdd79731800f0c61e50b0 Change sg_unit_extractor so that it takes all units to generate on its command line. That way, make don't have to call it several times, and this is good because parallel invocations of the script were subject to breakage since they all change the same src/sg_main_tests.c file (in short, fix parallel build of the tool) git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@6009 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/src/Makefile.am b/src/Makefile.am index 3d3d312140..5562273fc6 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -386,7 +386,7 @@ TEST_CFILES=xbt/cunit.c xbt/ex.c \ xbt/config.c TEST_UNITS= @builddir@/cunit_unit.c @builddir@/ex_unit.c \ @builddir@/dynar_unit.c @builddir@/dict_unit.c @builddir@/set_unit.c @builddir@/swag_unit.c \ - @builddir@/xbt_str_unit.c @builddir@/xbt_sha_unit.c\ + @builddir@/xbt_str_unit.c @builddir@/xbt_strbuff_unit.c @builddir@/xbt_sha_unit.c\ @builddir@/config_unit.c BUILT_SOURCES=../include/surf/simgrid_dtd.h surf/simgrid_dtd.c \ @@ -404,23 +404,8 @@ EXTRA_DIST+=$(testall_SOURCES) if MAINTAINER_MODE CLEANFILES=$(TEST_UNITS) -@builddir@/cunit_unit.c: xbt/cunit.c - @top_srcdir@/tools/sg_unit_extractor.pl $^ -@builddir@/ex_unit.c: xbt/ex.c - @top_srcdir@/tools/sg_unit_extractor.pl $^ -@builddir@/xbt_str_unit.c: xbt/xbt_str.c - @top_srcdir@/tools/sg_unit_extractor.pl $^ -@builddir@/xbt_sha_unit.c: xbt/xbt_sha.c - @top_srcdir@/tools/sg_unit_extractor.pl $^ -@builddir@/dynar_unit.c: xbt/dynar.c - @top_srcdir@/tools/sg_unit_extractor.pl $^ -@builddir@/dict_unit.c: xbt/dict.c - @top_srcdir@/tools/sg_unit_extractor.pl $^ -@builddir@/set_unit.c: xbt/set.c - @top_srcdir@/tools/sg_unit_extractor.pl $^ -@builddir@/swag_unit.c: xbt/swag.c - @top_srcdir@/tools/sg_unit_extractor.pl $^ -@builddir@/config_unit.c: xbt/config.c +$(TEST_UNITS): xbt/cunit.c xbt/ex.c xbt/xbt_str.c xbt/xbt_strbuff.c xbt/xbt_sha.c\ + xbt/dynar.c xbt/dict.c xbt/set.c xbt/swag.c xbt/config.c @top_srcdir@/tools/sg_unit_extractor.pl $^ @builddir@/simgrid_units_main.c: $(TEST_UNITS) diff --git a/tools/sg_unit_extractor.pl b/tools/sg_unit_extractor.pl index 9ef69f986c..4e233f1e17 100755 --- a/tools/sg_unit_extractor.pl +++ b/tools/sg_unit_extractor.pl @@ -4,96 +4,98 @@ use strict; my $progname="sg_unit_extractor"; # Get the args -die "USAGE: $progname infile [outfile]\n" - if (scalar @ARGV == 0 || scalar @ARGV > 2); -my ($infile,$outfile) = @ARGV; +die "USAGE: $progname infile [infile+]\n" + if (scalar @ARGV == 0); -if (not defined($outfile)) { - $outfile = $infile; - $outfile =~ s/\.c$/_unit.c/; - $outfile =~ s|.*/([^/]*)$|$1| if $outfile =~ m|/|; -} - -# Get the unit data -my ($unit_source,$suite_name,$suite_title)=("","",""); -my (%tests); # to detect multiple definition -my (@tests); # actual content - -open IN, "$infile" || die "$progname: Cannot open input file '$infile': $!\n"; - -my $takeit=0; -my $line=0; -my $beginline=0; -while () { - $line++; - if (m/ifdef +SIMGRID_TEST/) { - $beginline = $line; - $takeit = 1; - next; - } - if (m/endif.*SIMGRID_TEST/) { - $takeit = 0; - next - } +map {process_one($_)} @ARGV; - if (m/XBT_TEST_SUITE\(\w*"([^"]*)"\w*,(.*?)\);/) { #" - die "$progname: Multiple suites in the same file ($infile) are not supported yet\n" - if length($suite_name); - ($suite_name,$suite_title)=($1,$2); - next; - } - - if (m/XBT_TEST_UNIT\(\w*"([^"]*)"\w*,([^,]*),(.*?)\)/) { #" - die "$progname: multiply defined unit in file $infile: $1\n" - if (defined($tests{$1})); +sub process_one($) { + + my $infile = shift; + my $outfile; + + $outfile = $infile; + $outfile =~ s/\.c$/_unit.c/; + $outfile =~ s|.*/([^/]*)$|$1| if $outfile =~ m|/|; + + + # Get the unit data + my ($unit_source,$suite_name,$suite_title)=("","",""); + my (%tests); # to detect multiple definition + my (@tests); # actual content + + open IN, "$infile" || die "$progname: Cannot open input file '$infile': $!\n"; + + my $takeit=0; + my $line=0; + my $beginline=0; + while () { + $line++; + if (m/ifdef +SIMGRID_TEST/) { + $beginline = $line; + $takeit = 1; + next; + } + if (m/endif.*SIMGRID_TEST/) { + $takeit = 0; + next + } + + if (m/XBT_TEST_SUITE\(\w*"([^"]*)"\w*,(.*?)\);/) { #" { + die "$progname: Multiple suites in the same file ($infile) are not supported yet\n" if length($suite_name); + ($suite_name,$suite_title)=($1,$2); + next; + } + + if (m/XBT_TEST_UNIT\(\w*"([^"]*)"\w*,([^,]*),(.*?)\)/) { #"{ + die "$progname: multiply defined unit in file $infile: $1\n" if (defined($tests{$1})); - my @t=($1,$2,$3); - push @tests,\@t; - $tests{$1} = 1; - } - $unit_source .= $_ if $takeit; -} -close IN || die "$progname: cannot close input file '$infile': $!\n"; + my @t=($1,$2,$3); + push @tests,\@t; + $tests{$1} = 1; + } + $unit_source .= $_ if $takeit; + } + close IN || die "$progname: cannot close input file '$infile': $!\n"; -if ($takeit) { - die "$progname: end of file reached in SIMGRID_TEST block.\n". - "You should end each of the with a line matching: /endif.*SIMGRID_TEST/\n". - "Example:\n". - "#endif /* SIMGRID_TEST */\n" -} + if ($takeit) { + die "$progname: end of file reached in SIMGRID_TEST block.\n". + "You should end each of the with a line matching: /endif.*SIMGRID_TEST/\n". + "Example:\n". + "#endif /* SIMGRID_TEST */\n" + } -die "$progname: no suite defined in $infile\n" - unless (length($suite_name)); + die "$progname: no suite defined in $infile\n" unless (length($suite_name)); -# Write the test - -my ($GENERATED)=("/*******************************/\n". - "/* GENERATED FILE, DO NOT EDIT */\n". - "/*******************************/\n\n"); -$beginline+=2; -open OUT,">$outfile" || die "$progname: Cannot open output file '$outfile': $!\n"; -print OUT $GENERATED; -print OUT "#include \n"; -print OUT "#include \"xbt.h\"\n"; -print OUT $GENERATED; -print OUT "# $beginline \"$infile\" \n"; -print OUT "$unit_source"; -print OUT $GENERATED; -close OUT || die "$progname: Cannot close output file '$outfile': $!\n"; - -# write the main skeleton if needed -if (! -e "simgrid_units_main.c") { - open OUT,">simgrid_units_main.c" || die "$progname: Cannot open main file 'simgrid_units_main.c': $!\n"; - print OUT $GENERATED; - print OUT "#include \n\n"; - print OUT "#include \"xbt.h\"\n\n"; - print OUT "extern xbt_test_unit_t _xbt_current_unit;\n\n"; - print OUT "/* SGU: BEGIN PROTOTYPES */\n"; - print OUT "/* SGU: END PROTOTYPES */\n\n"; - print OUT $GENERATED; -# print OUT "# 93 \"sg_unit_extractor.pl\"\n"; - print OUT <$outfile" || die "$progname: Cannot open output file '$outfile': $!\n"; + print OUT $GENERATED; + print OUT "#include \n"; + print OUT "#include \"xbt.h\"\n"; + print OUT $GENERATED; + print OUT "# $beginline \"$infile\" \n"; + print OUT "$unit_source"; + print OUT $GENERATED; + close OUT || die "$progname: Cannot close output file '$outfile': $!\n"; + + # write the main skeleton if needed + if (! -e "simgrid_units_main.c") { + open OUT,">simgrid_units_main.c" || die "$progname: Cannot open main file 'simgrid_units_main.c': $!\n"; + print OUT $GENERATED; + print OUT "#include \n\n"; + print OUT "#include \"xbt.h\"\n\n"; + print OUT "extern xbt_test_unit_t _xbt_current_unit;\n\n"; + print OUT "/* SGU: BEGIN PROTOTYPES */\n"; + print OUT "/* SGU: END PROTOTYPES */\n\n"; + print OUT $GENERATED; + # print OUT "# 93 \"sg_unit_extractor.pl\"\n"; + print OUT <) { - $newmain .= $_; -# print "Look for proto: $_"; - last if /SGU: BEGIN PROTOTYPES/; - } - - # search my prototype - while () { -# print "Seek protos: $_"; - last if (/SGU: END PROTOTYPES/ || /SGU: BEGIN FILE $infile/); - $newmain .= $_; - } - if (/SGU: BEGIN FILE $infile/) { # found an old section for this file. Kill it - while () { - last if /SGU: END FILE/; + print OUT $GENERATED; + close OUT || die "$progname: Cannot close main file 'simgrid_units_main.c': $!\n"; } - $_ = ; # pass extra blank line - chomp; - die "this line should be blank ($_). Did you edit the file?" if /\W/; - } - my ($old_)=($_); - # add my section - $newmain .= " /* SGU: BEGIN FILE $infile */\n"; - map { - my ($name,$func,$title) = @{$_}; - $newmain .= " void $func(void);\n" - } @tests; - - $newmain .= " /* SGU: END FILE */\n\n"; - if ($old_ =~ /SGU: BEGIN FILE/ || $old_ =~ /SGU: END PROTOTYPES/) { - $newmain .= $old_; - } - - # pass remaining prototypes, search declarations - while () { - $newmain .= $_ unless /SGU: END PROTOTYPES/; - last if /SGU: BEGIN SUITES DECLARATION/; - } - - ### Done with prototypes. And now, the actual code - - # search my prototype - while () { - last if (/SGU: END SUITES DECLARATION/ || /SGU: BEGIN FILE $infile/); - $newmain .= $_; - } - if (/SGU: BEGIN FILE $infile/) { # found an old section for this file. Kill it - while () { - last if /SGU: END FILE/; - } - $_ = ; # pass extra blank line - chomp; - die "this line should be blank ($_). Did you edit the file?" if /\W/; - } - my ($old_)=($_); - # add my section - $newmain .= " /* SGU: BEGIN FILE $infile */\n"; - $newmain .= " suite = xbt_test_suite_by_name(\"$suite_name\",$suite_title);\n"; - map { - my ($name,$func,$title) = @{$_}; - $newmain .= " xbt_test_suite_push(suite, \"$name\", $func, $title);\n"; - } @tests; - - $newmain .= " /* SGU: END FILE */\n\n"; - if ($old_ =~ /SGU: BEGIN FILE/ || $old_ =~ /SGU: END SUITES DECLARATION/) { - $newmain .= $old_; - } - - # pass the remaining - while () { - $newmain .= $_; - } -close IN || die "$progname: Cannot close main file 'simgrid_units_main.c': $!\n"; -# write it back to main -open OUT,">simgrid_units_main.c" || die "$progname: Cannot open main file 'simgrid_units_main.c': $!\n"; -print OUT $newmain; -close OUT || die "$progname: Cannot close main file 'simgrid_units_main.c': $!\n"; + print " Suite $suite_name: $suite_title (".(scalar @tests)." tests)\n"; + map { + my ($name,$func,$title) = @{$_}; + print " unit $name: func=$func; title=$title\n"; + } @tests; + + #while (my $t = shift @tests) { + + # add this suite to the main + my $newmain=""; + open IN,"simgrid_units_main.c" || die "$progname: Cannot open main file 'simgrid_units_main.c': $!\n"; + # search prototypes + while () { + $newmain .= $_; + # print "Look for proto: $_"; + last if /SGU: BEGIN PROTOTYPES/; + } + + # search my prototype + while () { + # print "Seek protos: $_"; + last if (/SGU: END PROTOTYPES/ || /SGU: BEGIN FILE $infile/); + $newmain .= $_; + } + if (/SGU: BEGIN FILE $infile/) { # found an old section for this file. Kill it + while () { + last if /SGU: END FILE/; + } + $_ = ; # pass extra blank line + chomp; + die "this line should be blank ($_). Did you edit the file?" if /\W/; + } + my ($old_)=($_); + # add my section + $newmain .= " /* SGU: BEGIN FILE $infile */\n"; + map { + my ($name,$func,$title) = @{$_}; + $newmain .= " void $func(void);\n" + } @tests; + + $newmain .= " /* SGU: END FILE */\n\n"; + if ($old_ =~ /SGU: BEGIN FILE/ || $old_ =~ /SGU: END PROTOTYPES/) { + $newmain .= $old_; + } + + # pass remaining prototypes, search declarations + while () { + $newmain .= $_ unless /SGU: END PROTOTYPES/; + last if /SGU: BEGIN SUITES DECLARATION/; + } + + ### Done with prototypes. And now, the actual code + + # search my prototype + while () { + last if (/SGU: END SUITES DECLARATION/ || /SGU: BEGIN FILE $infile/); + $newmain .= $_; + } + if (/SGU: BEGIN FILE $infile/) { # found an old section for this file. Kill it + while () { + last if /SGU: END FILE/; + } + $_ = ; # pass extra blank line + chomp; + die "this line should be blank ($_). Did you edit the file?" if /\W/; + } + my ($old_)=($_); + # add my section + $newmain .= " /* SGU: BEGIN FILE $infile */\n"; + $newmain .= " suite = xbt_test_suite_by_name(\"$suite_name\",$suite_title);\n"; + map { + my ($name,$func,$title) = @{$_}; + $newmain .= " xbt_test_suite_push(suite, \"$name\", $func, $title);\n"; + } @tests; + + $newmain .= " /* SGU: END FILE */\n\n"; + if ($old_ =~ /SGU: BEGIN FILE/ || $old_ =~ /SGU: END SUITES DECLARATION/) { + $newmain .= $old_; + } + + # pass the remaining + while () { + $newmain .= $_; + } + close IN || die "$progname: Cannot close main file 'simgrid_units_main.c': $!\n"; + + # write it back to main + open OUT,">simgrid_units_main.c" || die "$progname: Cannot open main file 'simgrid_units_main.c': $!\n"; + print OUT $newmain; + close OUT || die "$progname: Cannot close main file 'simgrid_units_main.c': $!\n"; +} # end if process_one($) 0;