xref: /netbsd-src/external/apache2/llvm/dist/clang/utils/TestUtils/pch-test.pl (revision e038c9c4676b0f19b1b7dd08a940c6ed64a6d5ae)
1*e038c9c4Sjoerg#!/usr/bin/env perl
27330f729Sjoerg
37330f729Sjoerg# This tiny little script, which should be run from the clang
47330f729Sjoerg# directory (with clang in your patch), tries to take each
57330f729Sjoerg# compilable Clang test and build a PCH file from that test, then read
67330f729Sjoerg# and dump the contents of the PCH file just created.
77330f729Sjoerguse POSIX;
8*e038c9c4Sjoerguse warnings;
97330f729Sjoerg
107330f729Sjoerg$exitcode = 0;
117330f729Sjoergsub testfiles($$) {
127330f729Sjoerg  my $suffix = shift;
137330f729Sjoerg  my $language = shift;
147330f729Sjoerg  my $passed = 0;
157330f729Sjoerg  my $failed = 0;
167330f729Sjoerg  my $skipped = 0;
177330f729Sjoerg
187330f729Sjoerg  @files = `ls test/*/*.$suffix`;
197330f729Sjoerg  foreach $file (@files) {
207330f729Sjoerg    chomp($file);
217330f729Sjoerg    my $code = system("clang -fsyntax-only -x $language $file > /dev/null 2>&1");
227330f729Sjoerg    if ($code == 0) {
237330f729Sjoerg      print(".");
247330f729Sjoerg      $code = system("clang -cc1 -emit-pch -x $language -o $file.pch $file > /dev/null 2>&1");
257330f729Sjoerg      if ($code == 0) {
267330f729Sjoerg        $code = system("clang -cc1 -include-pch $file.pch -x $language -ast-dump /dev/null > /dev/null 2>&1");
277330f729Sjoerg        if ($code == 0) {
287330f729Sjoerg          $passed++;
297330f729Sjoerg        } elsif (($code & 0xFF) == SIGINT) {
307330f729Sjoerg          exit($exitcode);
317330f729Sjoerg        } else {
327330f729Sjoerg          print("\n---Failed to dump AST file for \"$file\"---\n");
337330f729Sjoerg          $exitcode = 1;
347330f729Sjoerg          $failed++;
357330f729Sjoerg        }
367330f729Sjoerg        unlink "$file.pch";
377330f729Sjoerg      } elsif (($code & 0xFF) == SIGINT) {
387330f729Sjoerg        exit($exitcode);
397330f729Sjoerg      } else {
407330f729Sjoerg        print("\n---Failed to build PCH file for \"$file\"---\n");
417330f729Sjoerg        $exitcode = 1;
427330f729Sjoerg          $failed++;
437330f729Sjoerg      }
447330f729Sjoerg    } elsif (($code & 0xFF) == SIGINT) {
457330f729Sjoerg      exit($exitcode);
467330f729Sjoerg    } else {
477330f729Sjoerg      print("x");
487330f729Sjoerg      $skipped++;
497330f729Sjoerg    }
507330f729Sjoerg  }
517330f729Sjoerg
527330f729Sjoerg  print("\n\n$passed tests passed\n");
537330f729Sjoerg  print("$failed tests failed\n");
547330f729Sjoerg  print("$skipped tests skipped ('x')\n")
557330f729Sjoerg}
567330f729Sjoerg
577330f729Sjoergprintf("-----Testing precompiled headers for C-----\n");
587330f729Sjoergtestfiles("c", "c");
597330f729Sjoergprintf("\n-----Testing precompiled headers for Objective-C-----\n");
607330f729Sjoergtestfiles("m", "objective-c");
617330f729Sjoergprint("\n");
627330f729Sjoergexit($exitcode);
63