run-testsuite 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/usr/bin/perl
  2. # Transform Makefile.am and config.in so they can be executed
  3. # standalone. Then run the test suite.
  4. # There should be a way to use m4 for this.
  5. use 5.010;
  6. use strict;
  7. use warnings;
  8. use Config;
  9. use Cwd;
  10. my $big_endian = sub {
  11. my $bo = $Config{'byteorder'};
  12. ($bo == 87654321) and return 1;
  13. ($bo == 12345678) and return;
  14. die ("Cannot understand byte order: $bo");
  15. }->();
  16. chdir ('test') or die ("Cannot change to test/: $!");
  17. my $PWD = getcwd;
  18. sub transform {
  19. my ($src_file, $dst_file) = @_;
  20. my $fh_in;
  21. my $fh_out;
  22. open ($fh_in, '<', $src_file) or
  23. die ("Cannot open '$src_file': $!");
  24. open ($fh_out, '>', $dst_file) or
  25. die ("Cannot write '$dst_file': $!");
  26. my $in_clause;
  27. my $mute;
  28. while (defined (my $line = <$fh_in>)) {
  29. if ($line =~ /if WORDS_BIGENDIAN/) {
  30. $in_clause and die ('State machine error');
  31. $in_clause = 1;
  32. $mute = !$big_endian;
  33. next;
  34. } elsif ($line =~ /^else/) {
  35. $in_clause or die ('State machine error');
  36. $mute = $big_endian;
  37. next;
  38. } elsif ($line =~ /^endif/) {
  39. $in_clause or die ('State machine error');
  40. $mute = undef;
  41. $in_clause = undef;
  42. next;
  43. }
  44. $mute and next;
  45. $line =~ s/\@PRINTF\@/printf/;
  46. $line =~ s/\@host\@/localhost/;
  47. $line =~ s/\@(target|build|nic1|nic2)\@/'-$1-'/;
  48. $line =~ s:=../src/:=/usr/bin/:;
  49. $line =~ s/\@debug_run_time_flag\@/--dbug=1/;
  50. $line =~ s/^(all: .+) tcpreplay (.+)$/$1 $2/;
  51. $line =~ s/\@srcdir\@/$PWD/g;
  52. print $fh_out $line;
  53. }
  54. close ($fh_in);
  55. close ($fh_out) or die;
  56. system ('diff', '-u', $src_file, $dst_file);
  57. }
  58. transform ('Makefile.am', 'Makefile.test');
  59. transform ('config.in', 'config');
  60. $ENV{'srcdir'} = $PWD;
  61. system ('make', '-f', 'Makefile.test');
  62. my $exit = $? ? 1 : 0;
  63. print "test.log content:\n";
  64. system ('cat', 'test.log');
  65. exit $exit;
  66. __END__