test613.pl 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. # The mtime is specifically chosen to be an even number so that it can be
  29. # represented exactly on a FAT filesystem.
  30. utime time, timegm(0,0,12,1,0,100), "plainfile.txt";
  31. chmod 0666, "plainfile.txt";
  32. open(FILE, ">rofile.txt") || errout "$!";
  33. binmode FILE;
  34. print FILE "Read-only test file to support curl test suite\n";
  35. close(FILE);
  36. # The mtime is specifically chosen to be an even number so that it can be
  37. # represented exactly on a FAT filesystem.
  38. utime time, timegm(0,0,12,31,11,100), "rofile.txt";
  39. chmod 0444, "rofile.txt";
  40. exit 0;
  41. }
  42. elsif ($ARGV[0] eq "postprocess")
  43. {
  44. my $dirname = $ARGV[1];
  45. my $logfile = $ARGV[2];
  46. # Clean up the test directory
  47. unlink "$dirname/rofile.txt";
  48. unlink "$dirname/plainfile.txt";
  49. rmdir "$dirname/asubdir";
  50. rmdir $dirname || die "$!";
  51. if ($logfile) {
  52. # Process the directory file to remove all information that
  53. # could be inconsistent from one test run to the next (e.g.
  54. # file date) or may be unsupported on some platforms (e.g.
  55. # Windows). Also, since 7.17.0, the sftp directory listing
  56. # format can be dependent on the server (with a recent
  57. # enough version of libssh2) so this script must also
  58. # canonicalize the format. Here are examples of the general
  59. # format supported:
  60. # -r--r--r-- 12 ausername grp 47 Dec 31 2000 rofile.txt
  61. # -r--r--r-- 1 1234 4321 47 Dec 31 2000 rofile.txt
  62. # The "canonical" format is similar to the first (which is
  63. # the one generated on a typical Linux installation):
  64. # -r-?r-?r-? 12 U U 47 Dec 31 2000 rofile.txt
  65. my @canondir;
  66. open(IN, "<$logfile") || die "$!";
  67. while (<IN>) {
  68. /^(.)(..).(..).(..).\s*(\S+)\s+\S+\s+\S+\s+(\S+)\s+(\S+\s+\S+\s+\S+)(.*)$/;
  69. if ($1 eq "d") {
  70. # Erase all directory metadata except for the name, as it is not
  71. # consistent for across all test systems and filesystems
  72. push @canondir, "d????????? N U U N ??? N NN:NN$8\n";
  73. } elsif ($1 eq "-") {
  74. # Erase user and group names, as they are not consistent across
  75. # all test systems
  76. my $line = sprintf("%s%s?%s?%s?%5d U U %15d %s%s\n", $1,$2,$3,$4,$5,$6,$7,$8);
  77. push @canondir, $line;
  78. } else {
  79. # Unexpected format; just pass it through and let the test fail
  80. push @canondir, $_;
  81. }
  82. }
  83. close(IN);
  84. @canondir = sort {substr($a,57) cmp substr($b,57)} @canondir;
  85. my $newfile = $logfile . ".new";
  86. open(OUT, ">$newfile") || die "$!";
  87. print OUT join('', @canondir);
  88. close(OUT);
  89. unlink $logfile;
  90. rename $newfile, $logfile;
  91. }
  92. exit 0;
  93. }
  94. print "Unsupported command $ARGV[0]\n";
  95. exit 1;