test613.pl 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #!/usr/bin/env perl
  2. # Prepare a directory with known files and clean up afterwards
  3. use Time::Local;
  4. if ( $#ARGV < 1 )
  5. {
  6. print "Usage: $0 prepare|postprocess dir [logfile]\n";
  7. exit 1;
  8. }
  9. # <precheck> expects an error message on stdout
  10. sub errout {
  11. print $_[0] . "\n";
  12. exit 1;
  13. }
  14. if ($ARGV[0] eq "prepare")
  15. {
  16. my $dirname = $ARGV[1];
  17. mkdir $dirname || errout "$!";
  18. chdir $dirname;
  19. # Create the files in alphabetical order, to increase the chances
  20. # of receiving a consistent set of directory contents regardless
  21. # of whether the server alphabetizes the results or not.
  22. mkdir "asubdir" || errout "$!";
  23. chmod 0777, "asubdir";
  24. open(FILE, ">plainfile.txt") || errout "$!";
  25. binmode FILE;
  26. print FILE "Test file to support curl test suite\n";
  27. close(FILE);
  28. utime time, timegm(0,0,12,1,0,100), "plainfile.txt";
  29. chmod 0666, "plainfile.txt";
  30. open(FILE, ">rofile.txt") || errout "$!";
  31. binmode FILE;
  32. print FILE "Read-only test file to support curl test suite\n";
  33. close(FILE);
  34. utime time, timegm(0,0,12,31,11,100), "rofile.txt";
  35. chmod 0444, "rofile.txt";
  36. exit 0;
  37. }
  38. elsif ($ARGV[0] eq "postprocess")
  39. {
  40. my $dirname = $ARGV[1];
  41. my $logfile = $ARGV[2];
  42. # Clean up the test directory
  43. unlink "$dirname/rofile.txt";
  44. unlink "$dirname/plainfile.txt";
  45. rmdir "$dirname/asubdir";
  46. rmdir $dirname || die "$!";
  47. if ($logfile) {
  48. # Process the directory file to remove all information that
  49. # could be inconsistent from one test run to the next (e.g.
  50. # file date) or may be unsupported on some platforms (e.g.
  51. # Windows). Also, since 7.17.0, the sftp directory listing
  52. # format can be dependent on the server (with a recent
  53. # enough version of libssh2) so this script must also
  54. # canonicalize the format. Here are examples of the general
  55. # format supported:
  56. # -r--r--r-- 12 ausername grp 47 Dec 31 2000 rofile.txt
  57. # -r--r--r-- 1 1234 4321 47 Dec 31 2000 rofile.txt
  58. # The "canonical" format is similar to the first (which is
  59. # the one generated on a typical Linux installation):
  60. # -r-?r-?r-? 12 U U 47 Dec 31 2000 rofile.txt
  61. my @canondir;
  62. open(IN, "<$logfile") || die "$!";
  63. while (<IN>) {
  64. /^(.)(..).(..).(..).\s*(\S+)\s+\S+\s+\S+\s+(\S+)\s+(\S+\s+\S+\s+\S+)(.*)$/;
  65. if ($1 eq "d") {
  66. # Erase all directory metadata except for the name, as it is not
  67. # consistent for across all test systems and filesystems
  68. push @canondir, "d????????? N U U N ??? N NN:NN$8\n";
  69. } elsif ($1 eq "-") {
  70. # Erase user and group names, as they are not consistent across
  71. # all test systems
  72. my $line = sprintf("%s%s?%s?%s?%5d U U %15d %s%s\n", $1,$2,$3,$4,$5,$6,$7,$8);
  73. push @canondir, $line;
  74. } else {
  75. # Unexpected format; just pass it through and let the test fail
  76. push @canondir, $_;
  77. }
  78. }
  79. close(IN);
  80. @canondir = sort {substr($a,57) cmp substr($b,57)} @canondir;
  81. my $newfile = $logfile . ".new";
  82. open(OUT, ">$newfile") || die "$!";
  83. print OUT join('', @canondir);
  84. close(OUT);
  85. unlink $logfile;
  86. rename $newfile, $logfile;
  87. }
  88. exit 0;
  89. }
  90. print "Unsupported command $ARGV[0]\n";
  91. exit 1;