home *** CD-ROM | disk | FTP | other *** search
/ PC-Online 1996 May / PCOnline_05_1996.bin / linux / source / kernel-s / ifs-5.1 / ifsprogs / test.pl < prev    next >
Perl Script  |  1995-10-10  |  24KB  |  1,009 lines

  1. #!/usr/bin/perl
  2.  
  3. # This test verifies correct function of the Inheriting File System (IFS) for
  4. # a collection of strictly serial operations. This test does NEITHER guarantee
  5. # total correctness of the file system code NOR does it give any indication,
  6. # whether there are incorrectly handled race conditions or not.
  7.  
  8.  
  9. require("sys/syscall.ph");
  10. require("linux/errno.ph");
  11. require("linux/stat.ph");
  12.  
  13.  
  14. if (!$ARGV[0] || !chdir($ARGV[0])) {
  15.     print "usage: test.pl base_directory\n";
  16.     exit(1);
  17. }
  18.  
  19. $A = "a";
  20. $B = "b";
  21. $AB = "a+b";
  22.  
  23. $first = 1;
  24.  
  25.  
  26. sub pass
  27. {
  28.     local ($status) = @_;
  29.  
  30.     $status || die "PASS failed ($!)";
  31. }
  32.  
  33.  
  34. sub fail
  35. {
  36.     local ($status,$expect) = @_;
  37.  
  38.     $status && die "FAIL passed ($!)";
  39.     die "FAILed with ".($!+0)." instead of $expect." if $! != $expect;
  40. }
  41.  
  42.  
  43. sub create
  44. {
  45.     local ($name,$data) = @_;
  46.  
  47.     open(FILE,">$name") || return 0;
  48.     if ($data) {
  49.     print FILE $data;
  50.     }
  51.     close FILE;
  52.     return 1;
  53. }
  54.  
  55.  
  56. sub touch
  57. {
  58.     return &create(@_[0],"");
  59. }
  60.  
  61.  
  62. sub append
  63. {
  64.     local ($name,$data) = @_;
  65.  
  66.     open(FILE,">>$name") || return 0;
  67.     if ($data) {
  68.     print FILE $data;
  69.     }
  70.     close FILE;
  71.     return 1;
  72. }
  73.  
  74.  
  75. sub unlink
  76. {
  77.     local ($name) = @_;
  78.  
  79.     return !syscall(&SYS_unlink,$name);
  80. }
  81.  
  82.  
  83. sub truncate
  84. {
  85.     local ($name,$length) = @_;
  86.  
  87.     open(FILE,">>$name") || die "$!";
  88.     truncate(FILE,$length);
  89.     close(FILE);
  90.     return 1;
  91. }
  92.  
  93.  
  94. sub rename
  95. {
  96.     local ($old,$new) = @_;
  97.  
  98.     return !syscall(&SYS_rename,$old,$new);
  99. }
  100.  
  101.  
  102. sub unwhiteout
  103. {
  104.     local ($dir,$name) = @_;
  105.     local ($status);
  106.  
  107.     open(DIR,$dir) || die "open directory $dir: $!";
  108.     $status = ioctl(DIR,0x53464900,$name);
  109.     close(DIR);
  110.     return $status;
  111. }
  112.  
  113.  
  114. sub tree
  115. {
  116.     local ($dir) = @_;
  117.     local (@dir,@new,$name,$dot,$dotdot);
  118.  
  119.     opendir(DIR,$dir) || die("opendir $dir: $!");
  120.     @dir = readdir(DIR);
  121.     closedir(DIR);
  122.     @new = ();
  123.     $dor = $dotdot = 0;
  124.     for (@dir) {
  125.     $name = $_;
  126.     if ($name eq ".") {
  127.         if ($dot) { die "duplicate . in $dir"; }
  128.         $dot = 1;
  129.     }
  130.     elsif ($name eq "..") {
  131.         if ($dotdot) { die "duplicate .. in $dir"; }
  132.         $dotdot = 1;
  133.     }
  134.     else {
  135.         push(@new,$name);
  136.         if (&S_ISDIR((lstat($dir."/".$name))[2])) {
  137.             push(@new,grep($_ = $name."/".$_,&tree($dir."/".$name)));
  138.         }
  139.     }
  140.     }
  141.     if (!$dot) { die "no . in $dir"; }
  142.     if (!$dotdot) { die "no .. in $dir"; }
  143.     return @new;
  144. }
  145.  
  146.  
  147. sub clean
  148. {
  149.     &pass(system("smount -u $AB") == 0);
  150. # &pass(chdir("/"));
  151. # &pass(system("umount /scratch") == 0);
  152. # &pass(system("mount /scratch") == 0);
  153. # &pass(chdir("/scratch"));
  154.     $mounted = 0;
  155.     for (reverse @left) {
  156.     if (m,^(.*)/$,) {
  157.         &pass(rmdir($1));
  158.     }
  159.     elsif (m/^([^-=(|]+)([-=(|].*)?$/) {
  160.         &pass(unlink($1));
  161.     }
  162.     else {
  163.         die("Unknown file \"$_\"");
  164.     }
  165.     }
  166.     @left = ();
  167.     &pass(rmdir($A));
  168.     &pass(rmdir($B));
  169.     &pass(rmdir($AB));
  170. }
  171.  
  172.  
  173. sub begin
  174. {
  175.     $tests++;
  176.     print "@_\n";
  177.     if (!$first) {
  178.     &clean();
  179.     }
  180.     $first = 0;
  181.     &pass(mkdir($A,0777));
  182.     &pass(mkdir($B,0777));
  183.     &pass(mkdir($AB,0777));
  184. }
  185.  
  186.  
  187. sub init
  188. {
  189.     local ($dir);
  190.  
  191.     $dir = shift(@_);
  192.     for (@_) {
  193.     if (m,^(.*)/$,) {
  194.         &pass(mkdir($dir."/".$1,0777));
  195.     }
  196.     elsif (m/^([^-=(]+)(=|->|\(|\|)(.*)$/) {
  197.         if ($2 eq "=") { &pass(&create($dir."/".$1,$3)); }
  198.         elsif ($2 eq "->") { &pass(symlink($3,$dir."/".$1)); }
  199.         elsif ($2 eq "|") { die "not yet supported"; }
  200.         elsif ($2 eq "(") { die "not yet supported"; }
  201.         else { die "unknown attribute \"$2\""; }
  202.     }
  203.     else {
  204.         &pass(&touch($dir."/".$_));
  205.     }
  206.     }
  207. }
  208.  
  209. # Must be called before performing any operations on the IFS in a test
  210. # sequence. test implicitly calls commit.
  211.  
  212. sub commit
  213. {
  214.     if (!$mounted) {
  215.     &pass(system("smount -t ifs $A,$B $AB") == 0);
  216.     $mounted = 1;
  217.     }
  218. }
  219.  
  220.  
  221. sub test
  222. {
  223.     local ($dir,$mode,$rdev,@dir,@expect,$file);
  224.  
  225.     $dir = shift(@_);
  226.     &commit();
  227.     if ($dir ne $AB) {
  228.     for (@_) {
  229.         push(@left,$dir."/".$_);
  230.     }
  231.     }
  232.     @dir = &tree($dir);
  233.     for (@dir) {
  234.     ($mode,$rdev) = (lstat($dir."/".$_))[2,6];
  235.     if (&S_ISREG($mode)) { ; }
  236.     elsif (&S_ISDIR($mode)) { $_ .= "/"; }
  237.     elsif (&S_ISLNK($mode)) { $_ .= "->".readlink($dir."/".$_); }
  238.     elsif (&S_ISFIFO($mode)) { $_ .= "|"; }
  239.     elsif (&S_ISCHR($mode) || &S_ISBLK($mode)) {
  240.         $_ .= sprintf("(%d,%d)",$rdev >> 8,$rdev & 0xff);
  241.     }
  242.     else {
  243.         die "unknown mode ".sprintf("0%o",$mode);
  244.     }
  245.     }
  246.     @expect = sort(@_);
  247.     @dir = sort(@dir);
  248.     if ($#_ != $#dir) {
  249.     die "directories \"@expect\" and \"@dir\" differ in size";
  250.     }
  251.     for (0..$#_) {
  252.     if ($expect[$_] =~ /^([^=]*)=(.*)$/) {
  253.         if ($1 ne $dir[$_]) {
  254.         die "directories \"@expect\" and \"@dir\" differ";
  255.         }
  256.         open(FILE,$dir."/".$1) || die "can't open $1: $!";
  257.         $file = join("\n",<FILE>);
  258.         if ($2 ne $file) {
  259.         die "content of file $dir/$1 is \"$file\" instead of \"$2\"";
  260.         }
  261.         close FILE;
  262.     }
  263.     else {
  264.         if ($expect[$_] ne $dir[$_]) {
  265.         die "directories \"@expect\" and \"@dir\" differ";
  266.          }
  267.     }
  268.     }
  269. }
  270.  
  271.  
  272. # INITIALIZATION
  273.  
  274. # system("smount -u /scratch; smount -u $AB; rm -rf $A $B $AB");
  275.  
  276. # READDIR
  277.  
  278. &begin("readdir, no files");
  279. &test($A);
  280. &test($B);
  281. &test($AB);
  282.  
  283. &begin("readdir, on upper layer");
  284. &init($A,"file_a");
  285. &test($A,"file_a");
  286. &test($B);
  287. &test($AB,"file_a");
  288.  
  289. &begin("readdir, on lower layer");
  290. &init($B,"file_b");
  291. &test($A);
  292. &test($B,"file_b");
  293. &test($AB,"file_b");
  294.  
  295. &begin("readdir, on both layers");
  296. &init($A,"file_a","file_c");
  297. &init($B,"file_b","file_c");
  298. &test($A,"file_a","file_c");
  299. &test($B,"file_b","file_c");
  300. &test($AB,"file_a","file_b","file_c");
  301.  
  302. &begin("readdir, on lower layer, whiteout");
  303. &init($A,".../",".../file_b");
  304. &init($B,"file_b");
  305. &test($A,".../",".../file_b");
  306. &test($B,"file_b");
  307. &test($AB);
  308.  
  309. &begin("readdir, no files, whiteout (corrupt)");
  310. &init($A,".../",".../file");
  311. &init($B);
  312. &test($A,".../",".../file");
  313. &test($B);
  314. &test($AB);
  315.  
  316. &begin("readdir, multiple directories");
  317. &init($A,"0/","2/","2/3");
  318. &init($B,"1/","2/","2/4");
  319. &test($A,"0/","2/","2/3");
  320. &test($B,"1/","2/","2/4");
  321. &test($AB,"0/","1/","2/","2/3","2/4");
  322.  
  323. &begin("readdir, lower hidden");
  324. &init($A,"dir/","dir/1=one","dir/2=two",".../",".../dir/");
  325. &init($B,"dir/","dir/3=three");
  326. &test($A,"dir/","dir/1=one","dir/2=two",".../",".../dir/");
  327. &test($B,"dir/","dir/3=three");
  328. &test($AB,"dir/","dir/1=one","dir/2=two");
  329.  
  330. # READ FILE
  331.  
  332. &begin("read file, doesn't exist");
  333. &commit();
  334. &fail(open(DUMMY,"$AB/file"),&ENOENT);
  335.  
  336. &begin("read file, doesn't exist, whiteout (corrupt)");
  337. &init($A,".../",".../file");
  338. &test($A,".../",".../file");
  339. &fail(open(DUMMY,"$AB/file"),&ENOENT);
  340.  
  341. &begin("read file, on upper layer");
  342. &init($A,"file=just_a_file");
  343. &test($A,"file=just_a_file");
  344. &test($AB,"file=just_a_file");
  345.  
  346. &begin("read file, on lower layer");
  347. &init($B,"file=just_a_file");
  348. &test($B,"file=just_a_file");
  349. &test($AB,"file=just_a_file");
  350.  
  351. &begin("read file, on both layers");
  352. &init($A,"file=file_on_A");
  353. &init($B,"file=file_on_B");
  354. &test($A,"file=file_on_A");
  355. &test($B,"file=file_on_B");
  356. &test($AB,"file=file_on_A");
  357.  
  358. &begin("read file, on upper layer, whiteout (corrupt)");
  359. &init($A,"file=just_a_file",".../",".../file");
  360. &test($A,"file=just_a_file",".../",".../file");
  361. &fail(open(DUMMY,"$AB/file"),&ENOENT);
  362.  
  363. &begin("read file, on lower layer, whiteout");
  364. &init($A,".../",".../file");
  365. &init($B,"file=a_file");
  366. &test($A,".../",".../file");
  367. &test($B,"file=a_file");
  368. &fail(open(DUMMY,"$AB/file"),&ENOENT);
  369.  
  370. &begin("read file, on both layers, whiteout (corrupt)");
  371. &init($A,"file=file_on_A",".../",".../file");
  372. &init($B,"file=file_on_B");
  373. &test($A,"file=file_on_A",".../",".../file");
  374. &test($B,"file=file_on_B");
  375. &fail(open(DUMMY,"$AB/file"),&ENOENT);
  376.  
  377. &begin("read file ..., on upper layer (invalid name)");
  378. &init($A,"...");
  379. &commit();
  380. &fail(open(DUMMY,"$AB/..."),&ENOENT);
  381. &test($A,"...");
  382.  
  383. # CREATE FILE
  384.  
  385. &begin("create file, file is new");
  386. &commit();
  387. &pass(&create("$A/file","a_file_..."));
  388. &test($A,"file=a_file_...");
  389. &test($AB,"file=a_file_...");
  390.  
  391. &begin("create file, file is new, whiteout (corrupt)");
  392. &init($A,".../",".../file");
  393. &commit();
  394. &pass(&create("$AB/file","a_file_..."));
  395. &test($A,"file=a_file_...",".../");
  396. &test($AB,"file=a_file_...");
  397.  
  398. &begin("create file, exists on upper layer");
  399. &init($A,"file=on A");
  400. &commit();
  401. &pass(&create("$AB/file","a_file"));
  402. &test($A,"file=a_file");
  403. &test($AB,"file=a_file");
  404.  
  405. &begin("create file, exists on lower layer");
  406. &init($B,"file=on_B");
  407. &commit();
  408. &pass(&create("$AB/file","a_file_..."));
  409. &test($A,"file=a_file_...");
  410. &test($B,"file=on_B");
  411. &test($AB,"file=a_file_...");
  412.  
  413. &begin("create file, exists on upper layer, whiteout (corrupt)");
  414. &init($A,"file=on_A",".../",".../file");
  415. &commit();
  416. &fail(&create("$AB/file","a_file"),&EEXIST);
  417. &test($A,"file=on_A",".../",".../file");
  418. &test($AB);
  419.  
  420. &begin("create file, exists on lower layer, whiteout");
  421. &init($A,".../",".../file");
  422. &init($B,"file=on_B");
  423. &commit();
  424. &pass(&create("$AB/file","a_file_..."));
  425. &test($A,"file=a_file_...",".../");
  426. &test($B,"file=on_B");
  427. &test($AB,"file=a_file_...");
  428.  
  429. &begin("create file ..., new file (invalid name)");
  430. &commit();
  431. &fail(&create("$AB/...",""),&EINVAL);
  432. &test($A);
  433.  
  434. &begin("create file, with entire directory tree");
  435. &init($A,"1/","1/2/","1/2/3/");
  436. &init($B,"1/","1/2/","1/2/3/");
  437. &commit();
  438. &pass(&create("$AB/1/2/3/file",""));
  439. &test($A,"1/","1/2/","1/2/3/","1/2/3/file");
  440. &test($B,"1/","1/2/","1/2/3/");
  441. &test($AB,"1/","1/2/","1/2/3/","1/2/3/file");
  442.  
  443. &begin("create file, with partial directory tree");
  444. &init($A,"1/");
  445. &init($B,"1/","1/2/","1/2/3/");
  446. &commit();
  447. &pass(&create("$AB/1/2/3/file",""));
  448. &test($A,"1/","1/2/","1/2/3/","1/2/3/file");
  449. &test($B,"1/","1/2/","1/2/3/");
  450. &test($AB,"1/","1/2/","1/2/3/","1/2/3/file");
  451.  
  452. &begin("create file, with empty directory tree");
  453. &init($A);
  454. &init($B,"1/","1/2/","1/2/3/");
  455. &commit();
  456. &pass(&create("$AB/1/2/3/file",""));
  457. &test($A,"1/","1/2/","1/2/3/","1/2/3/file");
  458. &test($B,"1/","1/2/","1/2/3/");
  459. &test($AB,"1/","1/2/","1/2/3/","1/2/3/file");
  460.  
  461. # APPEND TO FILE
  462.  
  463. &begin("append to existing file, upper layer");
  464. &init($A,"file=on_A");
  465. &commit();
  466. &pass(&append("$AB/file","_more"));
  467. &test($A,"file=on_A_more");
  468. &test($B);
  469. &test($AB,"file=on_A_more");
  470.  
  471. &begin("append to existing file, lower layer");
  472. &init($B,"file=on_B");
  473. &commit();
  474. &pass(&append("$AB/file","_more"));
  475. &test($A,"file=on_B_more");
  476. &test($B,"file=on_B");
  477. &test($AB,"file=on_B_more");
  478.  
  479. &begin("append to existing file, both layers");
  480. &init($A,"file=on_A");
  481. &init($B,"file=on_B");
  482. &commit();
  483. &pass(&append("$AB/file","_more"));
  484. &test($A,"file=on_A_more");
  485. &test($B,"file=on_B");
  486. &test($AB,"file=on_A_more");
  487.  
  488. &begin("append to file, with entire directory tree");
  489. &init($A,"1/","1/2/","1/2/3/");
  490. &init($B,"1/","1/2/","1/2/3/","1/2/3/file=B");
  491. &commit();
  492. &pass(&append("$AB/1/2/3/file","_more"));
  493. &test($A,"1/","1/2/","1/2/3/","1/2/3/file=B_more");
  494. &test($B,"1/","1/2/","1/2/3/","1/2/3/file=B");
  495. &test($AB,"1/","1/2/","1/2/3/","1/2/3/file=B_more");
  496.  
  497. &begin("append to file, with partial directory tree");
  498. &init($A,"1/");
  499. &init($B,"1/","1/2/","1/2/3/","1/2/3/file=B");
  500. &commit();
  501. &pass(&append("$AB/1/2/3/file","_more"));
  502. &test($A,"1/","1/2/","1/2/3/","1/2/3/file=B_more");
  503. &test($B,"1/","1/2/","1/2/3/","1/2/3/file=B");
  504. &test($AB,"1/","1/2/","1/2/3/","1/2/3/file=B_more");
  505.  
  506. &begin("append to file, with empty directory tree");
  507. &init($A);
  508. &init($B,"1/","1/2/","1/2/3/","1/2/3/file=B");
  509. &commit();
  510. &pass(&append("$AB/1/2/3/file","_more"));
  511. &test($A,"1/","1/2/","1/2/3/","1/2/3/file=B_more");
  512. &test($B,"1/","1/2/","1/2/3/","1/2/3/file=B");
  513. &test($AB,"1/","1/2/","1/2/3/","1/2/3/file=B_more");
  514.  
  515. # TRUNCATE FILE
  516.  
  517. &begin("truncating file, upper layer");
  518. &init($A,"file=abcde");
  519. &commit();
  520. &pass(&truncate("$AB/file",2));
  521. &test($A,"file=ab");
  522. &test($B);
  523. &test($AB,"file=ab");
  524.  
  525. &begin("truncating file, lower layer");
  526. &init($B,"file=abcde");
  527. &commit();
  528. &pass(&truncate("$AB/file",3));
  529. &test($A,"file=abc");
  530. &test($B,"file=abcde");
  531. &test($AB,"file=abc");
  532.  
  533. # UNLINK
  534.  
  535. &begin("unlink, file doesn't exist");
  536. &commit();
  537. &fail(&unlink("$AB/file"),&ENOENT);
  538.  
  539. &begin("unlink, file doesn't exist, whiteout (corrupt)");
  540. &init($A,".../",".../file");
  541. &commit();
  542. &fail(&unlink("$AB/file"),&ENOENT);
  543. &test($A,".../",".../file");
  544. &test($AB);
  545.  
  546. &begin("unlink, exists on upper layer");
  547. &init($A,"file");
  548. &commit();
  549. &pass(&unlink("$AB/file"));
  550. &test($A);
  551. &test($AB);
  552.  
  553. &begin("unlink, exists on lower layer");
  554. &init($B,"file");
  555. &commit();
  556. &pass(&unlink("$AB/file"));
  557. &test($A,".../",".../file");
  558. &test($B,"file");
  559. &test($AB);
  560.  
  561. &begin("unlink, exists on both layers");
  562. &init($A,"file=A");
  563. &init($B,"file=B");
  564. &commit();
  565. &pass(&unlink("$AB/file"));
  566. &test($A,".../",".../file");
  567. &test($B,"file=B");
  568. &test($AB);
  569.  
  570. &begin("unlink, exists on upper layer, whiteout (corrupt)");
  571. &init($A,"file",".../",".../file");
  572. &commit();
  573. &fail(&unlink("$AB/file"),&ENOENT);
  574. &test($A,"file",".../",".../file");
  575. &test($AB);
  576.  
  577. &begin("unlink, exists on lower layer, whiteout");
  578. &init($A,".../",".../file");
  579. &init($B,"file");
  580. &commit();
  581. &fail(&unlink("$AB/file"),&ENOENT);
  582. &test($A,".../",".../file");
  583. &test($B,"file");
  584. &test($AB);
  585.  
  586. &begin("unlink, with entire directory tree");
  587. &init($A,"1/","1/2/","1/2/3/");
  588. &init($B,"1/","1/2/","1/2/3/","1/2/3/file");
  589. &commit();
  590. &pass(&unlink("$AB/1/2/3/file"));
  591. &test($A,"1/","1/2/","1/2/3/","1/2/3/.../","1/2/3/.../file");
  592. &test($B,"1/","1/2/","1/2/3/","1/2/3/file");
  593. &test($AB,"1/","1/2/","1/2/3/");
  594.  
  595. &begin("unlink, with partial directory tree");
  596. &init($A,"1/");
  597. &init($B,"1/","1/2/","1/2/3/","1/2/3/file");
  598. &commit();
  599. &pass(&unlink("$AB/1/2/3/file"));
  600. &test($A,"1/","1/2/","1/2/3/","1/2/3/.../","1/2/3/.../file");
  601. &test($B,"1/","1/2/","1/2/3/","1/2/3/file");
  602. &test($AB,"1/","1/2/","1/2/3/");
  603.  
  604. &begin("unlink, with empty directory tree");
  605. &init($A);
  606. &init($B,"1/","1/2/","1/2/3/","1/2/3/file");
  607. &commit();
  608. &pass(&unlink("$AB/1/2/3/file"));
  609. &test($A,"1/","1/2/","1/2/3/","1/2/3/.../","1/2/3/.../file");
  610. &test($B,"1/","1/2/","1/2/3/","1/2/3/file");
  611. &test($AB,"1/","1/2/","1/2/3/");
  612.  
  613. # MKDIR
  614.  
  615. &begin("mkdir, directory is new");
  616. &commit();
  617. &pass(mkdir("$AB/dir",0777));
  618. &test($A,"dir/");
  619. &test($B);
  620. &test($AB,"dir/");
  621.  
  622. &begin("mkdir, directory is new, whiteout (corrupt)");
  623. &init($A,".../",".../dir");
  624. &commit();
  625. &pass(mkdir("$AB/dir",0777));
  626. &test($A,"dir/",".../");
  627. &test($B);
  628. &test($AB,"dir/");
  629.  
  630. &begin("mkdir, exists on upper layer");
  631. &init($A,"dir/");
  632. &commit();
  633. &fail(mkdir("$AB/dir",0777),&EEXIST);
  634. &test($A,"dir/");
  635. &test($B);
  636. &test($AB,"dir/");
  637.  
  638. &begin("mkdir, exists on lower layer");
  639. &init($B,"dir/");
  640. &commit();
  641. &fail(mkdir("$AB/dir",0777),&EEXIST);
  642. &test($A);
  643. &test($B,"dir/");
  644. &test($AB,"dir/");
  645.  
  646. &begin("mkdir, exists on upper layer, whiteout (corrupt)");
  647. &init($A,"dir/",".../",".../dir");
  648. &commit();
  649. &fail(mkdir("$AB/dir",0777),&EEXIST);
  650. &test($A,"dir/",".../",".../dir");
  651. &test($B);
  652. &test($AB);
  653.  
  654. &begin("mkdir, exists on lower layer, whiteout");
  655. &init($A,".../",".../dir");
  656. &init($B,"dir/");
  657. &commit();
  658. &pass(mkdir("$AB/dir",0777));
  659. &test($A,"dir/",".../",".../dir/");
  660. &test($B,"dir/");
  661. &test($AB,"dir/");
  662.  
  663. # RMDIR
  664.  
  665. &begin("rmdir, directory doesn't exist");
  666. &commit();
  667. &fail(rmdir("$A/dir"),&ENOENT);
  668. &test($AB);
  669.  
  670. &begin("rmdir, directory doesn't exist, whiteout (corrupt)");
  671. &init($A,".../",".../dir");
  672. &commit();
  673. &fail(rmdir("$AB/dir"),&ENOENT);
  674. &test($A,".../",".../dir");
  675. &test($AB);
  676.  
  677. &begin("rmdir, exists on upper layer, empty");
  678. &init($A,"dir/");
  679. &commit();
  680. &pass(rmdir("$AB/dir"));
  681. &test($A);
  682. &test($AB);
  683.  
  684. &begin("rmdir, exists on lower layer, empty");
  685. &init($B,"dir/");
  686. &commit();
  687. &pass(rmdir("$AB/dir"));
  688. &test($A,".../",".../dir");
  689. &test($B,"dir/");
  690. &test($AB);
  691.  
  692. &begin("rmdir, exists on upper layer, empty, whiteout (corrupt)");
  693. &init($A,"dir/",".../",".../dir");
  694. &commit();
  695. &fail(rmdir("$AB/dir"),&ENOENT);
  696. &test($A,"dir/",".../",".../dir");
  697. &test($AB);
  698.  
  699. &begin("rmdir, exists on lower layer, empty, whiteout");
  700. &init($A,".../",".../dir");
  701. &init($B,"dir/");
  702. &commit();
  703. &fail(rmdir("$AB/dir"),&ENOENT);
  704. &test($A,".../",".../dir");
  705. &test($B,"dir/");
  706. &test($AB);
  707.  
  708. &begin("rmdir, exists on upper layer, full");
  709. &init($A,"dir/","dir/1","dir/2");
  710. &commit();
  711. &fail(rmdir("$AB/dir"),&ENOTEMPTY);
  712. &test($A,"dir/","dir/1","dir/2");
  713. &test($AB,"dir/","dir/1","dir/2");
  714.  
  715. &begin("rmdir, exists on both layers, files in lower");
  716. &init($A,"dir/");
  717. &init($B,"dir/","dir/1","dir/2");
  718. &commit();
  719. &fail(rmdir("$AB/dir"),&ENOTEMPTY);
  720. &test($A,"dir/");
  721. &test($B,"dir/","dir/1","dir/2");
  722. &test($AB,"dir/","dir/1","dir/2");
  723.  
  724. &begin("rmdir, exists on lower layer, full");
  725. &init($B,"dir/","dir/1","dir/2");
  726. &commit();
  727. &fail(rmdir("$AB/dir"),&ENOTEMPTY);
  728. &test($A);
  729. &test($B,"dir/","dir/1","dir/2");
  730. &test($AB,"dir/","dir/1","dir/2");
  731.  
  732. &begin("rmdir, exists on both layers, files in lower, all files whited out");
  733. &init($A,"dir/","dir/.../","dir/.../1","dir/.../2");
  734. &init($B,"dir/","dir/1","dir/2");
  735. &commit();
  736. &pass(rmdir("$AB/dir"));
  737. &test($A,".../",".../dir");
  738. &test($B,"dir/","dir/1","dir/2");
  739. &test($AB);
  740.  
  741. &begin("rmdir, exists on both layers, empty, lower hidden");
  742. &init($A,"dir/",".../",".../dir/");
  743. &init($B,"dir/");
  744. &commit();
  745. &pass(rmdir("$AB/dir"));
  746. &test($A,".../",".../dir");
  747. &test($B,"dir/");
  748. &test($AB);
  749.  
  750. # SYMLINK
  751.  
  752. &begin("symlink, file is new");
  753. &commit();
  754. &pass(symlink("dummy","$AB/link"));
  755. &test($A,"link->dummy");
  756. &test($AB,"link->dummy");
  757.  
  758. &begin("symlink, file is new, whiteout (corrupt)");
  759. &init($A,".../",".../link");
  760. &commit();
  761. &pass(symlink("dummy","$AB/link"));
  762. &test($A,"link->dummy",".../");
  763. &test($AB,"link->dummy");
  764.  
  765. &begin("symlink, exists on upper layer");
  766. &init($A,"file");
  767. &commit();
  768. &fail(symlink("dummy","$AB/file"),&EEXIST);
  769. &test($A,"file");
  770. &test($AB,"file");
  771.  
  772. &begin("symlink, exists on lower layer");
  773. &init($B,"file");
  774. &commit();
  775. &fail(symlink("dummy","$AB/file"),&EEXIST);
  776. &test($A);
  777. &test($B,"file");
  778. &test($AB,"file");
  779.  
  780. &begin("symlink, exists on upper layer, whiteout (corrupt)");
  781. &init($A,"link",".../",".../link");
  782. &commit();
  783. &fail(symlink("dummy","$AB/link"),&EEXIST);
  784. &test($A,"link",".../",".../link");
  785. &test($AB);
  786.  
  787. &begin("symlink, exists on lower layer, whiteout");
  788. &init($A,".../",".../link");
  789. &init($B,"link");
  790. &commit();
  791. &pass(symlink("dummy","$AB/link"));
  792. &test($A,"link->dummy",".../");
  793. &test($B,"link");
  794. &test($AB,"link->dummy");
  795.  
  796. # LINK
  797.  
  798. # &begin("link, same FS, file is new");
  799. # &begin("link, same FS, file is new, whiteout");
  800. # &begin("link, same FS, exists on upper layer");
  801. # &begin("link, same FS, exists on lower layer");
  802. # &begin("link, same FS, exists on upper layer, whiteout");
  803. # &begin("link, same FS, exists on lower layer, whiteout");
  804. # &begin("link, different FS");
  805.  
  806. # MKNOD
  807.  
  808. # &begin("mknod, file is new");
  809. # &begin("mknod, file is new, whiteout");
  810. # &begin("mknod, exists on upper layer");
  811. # &begin("mknod, exists on lower layer");
  812. # &begin("mknod, exists on upper layer, whiteout");
  813. # &begin("mknod, exists on lower layer, whiteout");
  814.  
  815. # RENAME
  816.  
  817. &begin("rename file, non-existing source name");
  818. &init($A);
  819. &commit();
  820. &fail(&rename("$AB/src","$AB/dst"),&ENOENT);
  821. &test($A);
  822. &test($AB);
  823.  
  824. &begin("rename file, non-existing source name, whiteout (corrupt)");
  825. &init($A,".../",".../src");
  826. &commit();
  827. &fail(&rename("$AB/src","$AB/dst"),&ENOENT);
  828. &test($A,".../",".../src");
  829. &test($AB);
  830.  
  831. &begin("rename file, src and dst on the same FS, same directory");
  832. &init($A,"src=test");
  833. &commit();
  834. &pass(&rename("$AB/src","$AB/dst"));
  835. &test($A,"dst=test");
  836. &test($AB,"dst=test");
  837.  
  838. &begin("rename file, same FS, same directory, whiteout");
  839. &init($A,"src",".../",".../src");
  840. &commit();
  841. &fail(&rename("$AB/src","$AB/dst"),&ENOENT);
  842. &test($A,"src",".../",".../src");
  843. &test($AB);
  844.  
  845. &begin("rename file, same FS, same directory, dst whiteout");
  846. &init($A,"src=test",".../",".../dst");
  847. &init($B,"dst");
  848. &commit();
  849. &pass(&rename("$AB/src","$AB/dst"));
  850. &test($A,"dst=test",".../");
  851. &test($B,"dst");
  852. &test($AB,"dst=test");
  853.  
  854. &begin("rename file, same FS, different directory");
  855. &init($A,"src=test","dir/");
  856. &commit();
  857. &pass(&rename("$AB/src","$AB/dir/dst"));
  858. &test($A,"dir/","dir/dst=test");
  859. &test($AB,"dir/","dir/dst=test");
  860.  
  861. &begin("rename file, same FS, different directory, src whiteout");
  862. &init($A,"src",".../",".../src","dir/");
  863. &commit();
  864. &fail(&rename("$AB/src","$AB/dir/dst"),&ENOENT);
  865. &test($A,"src",".../",".../src","dir/");
  866. &test($AB,"dir/");
  867.  
  868. &begin("rename file, same FS, different directory, dst whiteout");
  869. &init($A,"src=foo","dir/","dir/.../","dir/.../dst");
  870. &init($B,"dir/","dir/dst=bar");
  871. &commit();
  872. &pass(&rename("$AB/src","$AB/dir/dst"));
  873. &test($A,"dir/","dir/.../","dir/dst=foo");
  874. &test($B,"dir/","dir/dst=bar");
  875. &test($AB,"dir/","dir/dst=foo");
  876.  
  877. &begin("rename file, same FS, diff. directory, dst ex. & whiteout (corrupt)");
  878. &init($A,"src=foo","dir/","dir/.../","dir/.../dst","dir/dst=baz");
  879. &init($B,"dir/","dir/dst=bar");
  880. &commit();
  881. &pass(&rename("$AB/src","$AB/dir/dst"));
  882. &test($A,"dir/","dir/.../","dir/dst=foo");
  883. &test($B,"dir/","dir/dst=bar");
  884. &test($AB,"dir/","dir/dst=foo");
  885.  
  886. &begin("rename file, same FS, different directory, dst dir. whiteout");
  887. &init($A,"src=foo","dir/",".../",".../dir");
  888. &init($B,"dir/");
  889. &commit();
  890. &fail(&rename("$AB/src","$AB/dir/dst"),&ENOENT);
  891. &test($A,"src=foo","dir/",".../",".../dir");
  892. &test($B,"dir/");
  893. &test($AB,"src=foo");
  894.  
  895. &begin("rename file, same FS, different directory, incomplete path");
  896. &init($A,"src=foo");
  897. &init($B,"dir/");
  898. &commit();
  899. &pass(&rename("$AB/src","$AB/dir/dst"));
  900. &test($A,"dir/","dir/dst=foo");
  901. &test($B,"dir/");
  902. &test($AB,"dir/","dir/dst=foo");
  903.  
  904. &begin("rename file, same FS, diff. level, same directory");
  905. &init($A);
  906. &init($B,"src=test");
  907. &commit();
  908. &pass(&rename("$AB/src","$AB/dst"));
  909. &test($A,"dst=test",".../",".../src");
  910. &test($B,"src=test");
  911. &test($AB,"dst=test");
  912.  
  913. &begin("rename file, same FS, diff. level, different directory");
  914. &init($A);
  915. &init($B,"dir/","dir/src=foo");
  916. &commit();
  917. &pass(&rename("$AB/dir/src","$AB/dst"));
  918. &test($A,"dst=foo","dir/","dir/.../","dir/.../src",".../");
  919. &test($B,"dir/","dir/src=foo");
  920. &test($AB,"dst=foo","dir/");
  921.  
  922. &begin("rename file, same FS, diff. level, diff. dir., dst exists on upper");
  923. &init($A,"dst=foo");
  924. &init($B,"dir/","dir/src=bar");
  925. &commit();
  926. &pass(&rename("$AB/dir/src","$AB/dst"));
  927. &test($A,"dst=bar","dir/","dir/.../","dir/.../src",".../");
  928. &test($B,"dir/","dir/src=bar");
  929. &test($AB,"dst=bar","dir/");
  930.  
  931. &begin("rename file, same FS, diff. level, diff. dir., dst exists on lower");
  932. &init($A);
  933. &init($B,"dst=foo","dir/","dir/src=bar");
  934. &commit();
  935. &pass(&rename("$AB/dir/src","$AB/dst"));
  936. &test($A,"dst=bar","dir/","dir/.../","dir/.../src",".../");
  937. &test($B,"dst=foo","dir/","dir/src=bar");
  938. &test($AB,"dst=bar","dir/");
  939.  
  940. &begin("rename file, same FS, diff. level, different directory, whiteout");
  941. &init($A,".../",".../src");
  942. &init($B,"src=test");
  943. &commit();
  944. &fail(&rename("$AB/src","$AB/dir/dst"),&ENOENT);
  945. &test($A,".../",".../src");
  946. &test($B,"src=test");
  947. &test($AB);
  948.  
  949. # &begin("rename file, different FS, top-level");
  950. # &begin("rename file, different FS, top-level, whiteout");
  951. # &begin("rename file, different FS, different levels, 'same' dir.");
  952. # &begin("rename file, different FS, different levels, 'diff.' dir.");
  953. # &begin("rename file, different FS, different levels, dd, whiteout");
  954.  
  955. # UNWHITEOUT
  956.  
  957. &begin("unwhiteout file, does not exist, no whiteout");
  958. &init($A);
  959. &commit();
  960. &fail(&unwhiteout("$AB","file"),&ENOENT);
  961. &test($A);
  962. &test($AB);
  963.  
  964. &begin("unwhiteout file, does not exist, whiteout (corrupt)");
  965. &init($A,".../",".../file");
  966. &commit();
  967. &pass(&unwhiteout("$AB","file"));
  968. &test($A,".../");
  969. &test($AB);
  970.  
  971. &begin("unwhiteout file, exists on upper, no whiteout");
  972. &init($A,"file=foo");
  973. &commit();
  974. &fail(&unwhiteout("$AB","file"),&ENOENT);
  975. &test($A,"file=foo");
  976. &test($AB,"file=foo");
  977.  
  978. &begin("unwhiteout file, exists on upper, whiteout (corrupt)");
  979. &init($A,"file",".../",".../file");
  980. &commit();
  981. &pass(&unwhiteout("$AB","file"));
  982. &test($A,"file",".../");
  983. &test($AB,"file");
  984.  
  985. &begin("unwhiteout file, exists on lower, no whiteout");
  986. &init($A);
  987. &init($B,"file=test");
  988. &commit();
  989. &fail(&unwhiteout("$AB","file"),&ENOENT);
  990. &test($A);
  991. &test($B,"file=test");
  992. &test($AB,"file=test");
  993.  
  994. &begin("unwhiteout file, exists on lower, whiteout");
  995. &init($A,".../",".../file");
  996. &init($B,"file=test");
  997. &commit();
  998. &pass(&unwhiteout("$AB","file"));
  999. &test($A,".../");
  1000. &test($B,"file=test");
  1001. &test($AB,"file=test");
  1002.  
  1003. # Missing test:
  1004. #   create path across file systems
  1005.  
  1006. &clean();
  1007. print "Passed all $tests test sequences.\n";
  1008. exit(0);
  1009.