]>
git.saurik.com Git - apple/objc4.git/blob - test/test.pl
9 # We use encode_json() to write BATS plist files.
10 # JSON::PP does not exist on iOS devices, but we need not write plists there.
11 # So we simply load JSON:PP if it exists.
12 if ( eval { require JSON
:: PP
; 1 ; }) {
18 chomp ( my $DIR = `pwd` );
20 if ( scalar ( @ARGV ) == 1 ) {
22 if ( $arg eq "-h" || $arg eq "-H" || $arg eq "-help" || $arg eq "help" ) {
24 usage: $0 [options] [testname ...]
28 `testname` runs a specific test. If no testnames are given, runs all tests.
32 OS=<sdk name>[sdk version][-<deployment target>[-<run target>]]
33 ROOT=/path/to/project.roots/
37 LANGUAGE=c,c++,objective-c,objective-c++,swift
39 GUARDMALLOC=0|1|before|after
41 BUILD=0|1 (build the tests?)
42 RUN=0|1 (run the tests?)
43 VERBOSE=0|1|2 (0=quieter 1=print commands executed 2=full test output)
44 BATS=0|1 (build for and/or run in BATS?)
48 test installed library, x86_64
51 test buildit-built root, i386 and x86_64, MRC and ARC, clang compiler
52 $0 ARCH=i386,x86_64 ROOT=/tmp/objc4.roots MEM=mrc,arc CC=clang
54 test buildit-built root with iOS simulator, deploy to iOS 7, run on iOS 8
55 $0 ARCH=x86_64 ROOT=/tmp/objc4.roots OS=iphonesimulator-7.0-8.0
57 test buildit-built root on attached iOS device
58 $0 ARCH=arm64 ROOT=/tmp/objc4.roots OS=iphoneos
64 #########################################################################
67 # Maps test name => test's filename extension.
68 # ex: "msgSend" => "m"
69 # `keys %ALL_TESTS` is also used as the list of all tests found on disk.
72 #########################################################################
73 ## Variables for use in complex build and run rules
75 # variable # example value
77 # things you can multiplex on the command line
78 # ARCH=i386,x86_64,armv6,armv7
79 # OS=macosx,iphoneos,iphonesimulator (plus sdk/deployment/run versions)
80 # LANGUAGE=c,c++,objective-c,objective-c++,swift
83 # GUARDMALLOC=0,1,before,after
85 # things you can set once on the command line
86 # ROOT=/path/to/project.roots
92 # environment variables from the command line
95 # (SRCROOT is ignored; test sources are assumed to
96 # be in the same directory as the test script itself.)
97 # fixme SYMROOT for dsymutil output?
100 # Some arguments as read from the command line.
110 my @TESTLIBNAMES = ( "libobjc.A.dylib" , "libobjc-trampolines.dylib" );
111 my $TESTLIBDIR = "/usr/lib" ;
113 # Top level directory for intermediate and final build products.
114 # Intermediate files must be kept separate for XBS BATS builds.
115 my $OBJROOT = $ENV { OBJROOT
} || "" ;
116 my $DSTROOT = $ENV { DSTROOT
} || "" ;
118 # Build product directory inside DSTROOT and OBJROOT.
119 # Each test config gets its own build directory inside this.
122 # Local top-level directory.
123 # This is the default value for $BUILDDIR.
124 my $LOCALBASE = "/tmp/test- $TESTLIBNAMES [0]-build" ;
126 # Device-side top-level directory.
127 # This replaces $DSTROOT$BUILDDIR/ for on-device execution.
128 my $REMOTEBASE = "/AppleInternal/objctest" ;
130 # BATS top-level directory.
131 # This replaces $DSTROOT$BUILDDIR/ for BATS execution.
132 my $BATSBASE = "/AppleInternal/CoreOS/tests/objc4" ;
135 my $crashcatch = <<'END';
136 // interpose-able code to catch crashes, print, and exit cleanly
141 // from dyld-interposing.h
142 #define DYLD_INTERPOSE(_replacement,_replacee) __attribute__((used)) static struct{ const void* replacement; const void* replacee; } _interpose_##_replacee __attribute__ ((section ("__DATA,__interpose"))) = { (const void*)(unsigned long)&_replacement, (const void*)(unsigned long)&_replacee };
144 static void catchcrash(int sig)
148 case SIGILL: msg = "CRASHED: SIGILL"; break;
149 case SIGBUS: msg = "CRASHED: SIGBUS"; break;
150 case SIGSYS: msg = "CRASHED: SIGSYS"; break;
151 case SIGSEGV: msg = "CRASHED: SIGSEGV"; break;
152 case SIGTRAP: msg = "CRASHED: SIGTRAP"; break;
153 case SIGABRT: msg = "CRASHED: SIGABRT"; break;
154 default: msg = "unknown signal"; break;
156 write(STDERR_FILENO, msg, strlen(msg));
158 // avoid backslash-n newline due to escaping differences somewhere
159 // in BATS versus local execution (perhaps different perl versions?)
161 write(STDERR_FILENO, &newline, 1);
166 static void setupcrash(void) __attribute__((constructor));
167 static void setupcrash(void)
169 signal(SIGILL, &catchcrash);
170 signal(SIGBUS, &catchcrash);
171 signal(SIGSYS, &catchcrash);
172 signal(SIGSEGV, &catchcrash);
173 signal(SIGTRAP, &catchcrash);
174 signal(SIGABRT, &catchcrash);
178 static int hacked = 0;
179 ssize_t hacked_write(int fildes, const void *buf, size_t nbyte)
185 return write(fildes, buf, nbyte);
188 DYLD_INTERPOSE(hacked_write, write);
193 #########################################################################
197 # map language to buildable extensions for that language
198 my %extensions_for_language = (
200 "objective-c" => [ "c" , "m" ],
201 "c++" => [ "c" , "cc" , "cp" , "cpp" , "cxx" , "c++" ],
202 "objective-c++" => [ "c" , "m" , "cc" , "cp" , "cpp" , "cxx" , "c++" , "mm" ],
203 "swift" => [ "swift" ],
205 "any" => [ "c" , "m" , "cc" , "cp" , "cpp" , "cxx" , "c++" , "mm" , "swift" ],
208 # map extension to languages
209 my %languages_for_extension = (
210 "c" => [ "c" , "objective-c" , "c++" , "objective-c++" ],
211 "m" => [ "objective-c" , "objective-c++" ],
212 "mm" => [ "objective-c++" ],
213 "cc" => [ "c++" , "objective-c++" ],
214 "cp" => [ "c++" , "objective-c++" ],
215 "cpp" => [ "c++" , "objective-c++" ],
216 "cxx" => [ "c++" , "objective-c++" ],
217 "c++" => [ "c++" , "objective-c++" ],
218 "swift" => [ "swift" ],
221 # Run some newline-separated commands like `make` would, stopping if any fail
222 # run("cmd1 \n cmd2 \n cmd3")
225 my @cmds = split ( " \n " , $_ [ 0 ]);
226 die if scalar ( @cmds ) == 0 ;
228 foreach my $cmd ( @cmds ) {
230 next if $cmd =~ /^\s*$/ ;
232 print " $cmd \n " if $VERBOSE ;
236 print " $output \n " if $VERBOSE ;
241 my $dir = shift || die;
242 print "cd $dir \n " if $VERBOSE ;
243 chdir $dir || die "couldn't cd $dir ";
247 my $dir = shift || die;
248 print "mkdir -p $dir \n " if $VERBOSE ;
250 die "couldn't rm -rf $dir " if $? ;
254 my $dir = shift || die;
255 print "mkdir -p $dir \n " if $VERBOSE ;
257 die "couldn't mkdir $dir " if $? ;
262 my $red = "\e[41;37m";
263 my $yellow = "\e[43;30m";
264 my $nocolor = "\e[0m";
266 # Not isatty. Don't use colors.
272 # print text with a colored prefix on each line
273 # fixme some callers pass an array of lines and some don't
276 while (defined(my $lines = shift)) {
277 $lines = " \n " if ( $lines eq "");
278 for my $line (split(/^/, $lines )) {
280 print " $color $nocolor$line \n ";
286 # fixme some callers pass an array of lines and some don't
289 while (defined(my $lines = shift)) {
290 $lines = " \n " if ( $lines eq "");
291 for my $line (split(/^/, $lines )) {
293 print " $color$line$nocolor \n ";
298 # Return test names from the command line.
299 # Returns all tests if no tests were named.
303 foreach my $arg ( @ARGV ) {
304 push @tests , $arg if ( $arg !~ /=/ && $arg !~ /^-/);
307 opendir(my $dir , $DIR ) || die;
308 while (my $file = readdir( $dir )) {
309 my ( $name , $ext ) = ( $file =~ /^([^.]+)\.([^.]+) $/ );
310 next if ! $languages_for_extension { $ext };
312 open(my $in , "< $file ") || die " $file ";
313 my $contents = join "", < $in >;
314 if (defined $ALL_TESTS { $name }) {
315 colorprint $yellow , "SKIP: multiple tests named ' $name '; skipping file ' $file '.";
317 $ALL_TESTS { $name } = $ext if ( $contents =~ m#^[/*\s]*TEST_#m);
323 if (scalar( @tests ) == 0) {
324 @tests = keys %ALL_TESTS ;
327 @tests = sort @tests ;
333 # Turn a C compiler name into a C++ compiler name.
340 return $c . "++"; # e.g. clang => clang++
343 # Turn a C compiler name into a Swift compiler name
346 $c =~ s#[^/]* $#swift# ;
350 # Returns an array of all sdks from ` xcodebuild
- showsdks
`
354 @sdks_memo = (` xcodebuild
- showsdks
` =~ /-sdk (.+) $/mg );
359 my %sdk_path_memo = {};
362 if (!defined $sdk_path_memo { $sdk }) {
363 ( $sdk_path_memo { $sdk }) = (` xcodebuild
- version
- sdk
' $sdk ' Path
` =~ /^\s*(.+?)\s* $/ );
365 return $sdk_path_memo { $sdk };
368 # Extract a version number from a string.
369 # Ignore trailing "internal".
372 my ( $vers ) = ( $str =~ /([0-9]+\.[0-9]+)(?:\.?internal)? $/ );
375 sub majorversionsuffix {
377 my ( $vers ) = ( $str =~ /([0-9]+)\.[0-9]+(?:\.?internal)? $/ );
380 sub minorversionsuffix {
382 my ( $vers ) = ( $str =~ /[0-9]+\.([0-9]+)(?:\.?internal)? $/ );
386 # Compares two SDK names and returns the newer one.
387 # Assumes the two SDKs are the same OS.
389 my ( $lhs , $rhs ) = @_ ;
391 # Major version wins.
392 my $lhsMajor = majorversionsuffix( $lhs );
393 my $rhsMajor = majorversionsuffix( $rhs );
394 if ( $lhsMajor > $rhsMajor ) { return $lhs ; }
395 if ( $lhsMajor < $rhsMajor ) { return $rhs ; }
397 # Minor version wins.
398 my $lhsMinor = minorversionsuffix( $lhs );
399 my $rhsMinor = minorversionsuffix( $rhs );
400 if ( $lhsMinor > $rhsMinor ) { return $lhs ; }
401 if ( $lhsMinor < $rhsMinor ) { return $rhs ; }
403 # Lexically-last wins (i.e. internal is better than not internal)
404 if ( $lhs gt $rhs ) { return $lhs ; }
412 # parse name=value,value pairs
414 my ( $conditionstring ) = @_ ;
417 my @conditions = ( $conditionstring =~ /\w+=(?:[^\s,]+,?)+/g);
418 for my $condition ( @conditions ) {
419 my ( $name , $values ) = ( $condition =~ /(\w+)=(.+)/);
420 $results { $name } = [split ',', $values ];
431 my %T = %{ $C {"TEST_ $name "}};
433 # Quietly strip MallocScribble before saving the "original" output
434 # because it is distracting.
435 filter_malloc(\ @output );
437 my @original_output = @output ;
439 # Run result-checking passes, reducing @output each time
443 my $runerror = $T {TEST_RUN_OUTPUT};
444 filter_hax(\ @output );
445 filter_verbose(\ @output );
446 filter_simulator(\ @output );
447 $warn = filter_warn(\ @output );
448 $bad |= filter_guardmalloc(\ @output ) if ( $C {GUARDMALLOC});
449 $bad |= filter_valgrind(\ @output ) if ( $C {VALGRIND});
450 $bad = filter_expected(\ @output , \ %C , $name ) if ( $bad eq "");
451 $bad = filter_bad(\ @output ) if ( $bad eq "");
453 # OK line should be the only one left
454 $bad = "(output not 'OK: $name ')" if ( $bad eq "" && (scalar( @output ) != 1 || $output [0] !~ /^OK: $name/ ));
457 colorprint $red , "FAIL: /// test ' $name ' \\\\\\ ";
458 colorprefix $red , @original_output ;
459 colorprint $red , "FAIL: \\\\\\ test ' $name ' ///";
460 colorprint $red , "FAIL: $name : $bad ";
463 elsif ( $warn ne "") {
464 colorprint $yellow , "PASS: /// test ' $name ' \\\\\\ ";
465 colorprefix $yellow , @original_output ;
466 colorprint $yellow , "PASS: \\\\\\ test ' $name ' ///";
467 print "PASS: $name (with warnings) \n ";
470 print "PASS: $name \n ";
477 my $outputref = shift;
481 my %T = %{ $C {"TEST_ $name "}};
482 my $runerror = $T {TEST_RUN_OUTPUT} || return "";
486 my $output = join(" \n ", @$outputref ) . " \n ";
487 if ( $output !~ / $runerror/ ) {
488 $bad = "(run output does not match TEST_RUN_OUTPUT)";
489 @$outputref = ("FAIL: $name ");
491 @$outputref = ("OK: $name "); # pacify later filter
499 my $outputref = shift;
503 for my $line ( @$outputref ) {
504 if ( $line =~ /^BAD: (.*)/) {
507 push @new_output , $line ;
511 @$outputref = @new_output ;
517 my $outputref = shift;
521 for my $line ( @$outputref ) {
522 if ( $line !~ /^WARN: (.*)/) {
523 push @new_output , $line ;
529 @$outputref = @new_output ;
535 my $outputref = shift;
538 for my $line ( @$outputref ) {
539 if ( $line !~ /^VERBOSE: (.*)/) {
540 push @new_output , $line ;
544 @$outputref = @new_output ;
549 my $outputref = shift;
552 for my $line ( @$outputref ) {
553 if (( $line !~ /No simulator devices appear to be running/) &&
554 ( $line !~ /CoreSimulator is attempting to unload a stale CoreSimulatorService job/) &&
555 ( $line !~ /Failed to locate a valid instance of CoreSimulatorService/))
557 push @new_output , $line ;
561 @$outputref = @new_output ;
566 my $outputref = shift;
569 for my $line ( @$outputref ) {
570 if ( $line !~ /Class OS_tcp_/) {
571 push @new_output , $line ;
575 @$outputref = @new_output ;
580 my $outputref = shift;
585 for my $line ( @$outputref ) {
586 if ( $line =~ /^Approx: do_origins_Dirty\([RW]\): missed \d bytes $/ ) {
587 # --track-origins warning (harmless)
590 if ( $line =~ /^UNKNOWN __disable_threadsignal is unsupported. This warning will not be repeated. $/ ) {
591 # signals unsupported (harmless)
594 if ( $line =~ /^UNKNOWN __pthread_sigmask is unsupported. This warning will not be repeated. $/ ) {
595 # signals unsupported (harmless)
598 if ( $line !~ /^^\.*==\d+==/) {
599 # not valgrind output
600 push @new_output , $line ;
604 my ( $errcount ) = ( $line =~ /==\d+== ERROR SUMMARY: (\d+) errors/);
605 if (defined $errcount && $errcount > 0) {
609 (my $leakcount ) = ( $line =~ /==\d+==\s+(?:definitely|possibly) lost:\s+([0-9,]+)/);
610 if (defined $leakcount && $leakcount > 0) {
615 @$outputref = @new_output ;
618 $bad .= "(valgrind errors)" if ( $errors );
619 $bad .= "(valgrind leaks)" if ( $leaks );
627 my $outputref = shift;
632 for my $line ( @$outputref ) {
633 # Ignore MallocScribble prologue.
634 # Ignore MallocStackLogging prologue.
635 if ( $line =~ /malloc: enabling scribbling to detect mods to free/ ||
636 $line =~ /Deleted objects will be dirtied by the collector/ ||
637 $line =~ /malloc: stack logs being written into/ ||
638 $line =~ /malloc: stack logs deleted from/ ||
639 $line =~ /malloc: process \d+ no longer exists/ ||
640 $line =~ /malloc: recording malloc and VM allocation stacks/)
646 push @new_output , $line ;
650 @$outputref = @new_output ;
653 sub filter_guardmalloc
655 my $outputref = shift;
660 for my $line ( @$outputref ) {
661 if ( $line !~ /^GuardMalloc\[[^\]]+\]: /) {
662 # not guardmalloc output
663 push @new_output , $line ;
667 # Ignore 4 lines of guardmalloc prologue.
668 # Anything further is a guardmalloc error.
674 @$outputref = @new_output ;
677 $bad .= "(guardmalloc errors)" if ( $errors );
685 sub extract_multiline {
686 my ( $flag , $contents , $name ) = @_ ;
687 if ( $contents =~ / $flag \n /) {
688 my ( $output ) = ( $contents =~ / $flag \n (.*? \n )END[ *\/]* \n /s);
689 die " $name used $flag without END \n " if !defined( $output );
701 sub extract_multiple_multiline {
702 my ( $flag , $contents , $name ) = @_ ;
703 if ( $contents =~ / $flag \n /) {
704 my ( $output ) = ( $contents =~ / $flag \n (.*? \n )END[ *\/]* \n /s);
705 die " $name used $flag without END \n " if !defined( $output );
707 $output =~ s/\nOR\n/\n|/sg;
708 $output = "^(" . $output . ")\$";
721 my $ext = $ALL_TESTS { $name };
722 my $file = " $name . $ext ";
725 # search file for 'TEST_CONFIG' or '#include "test.h"'
726 # also collect other values:
727 # TEST_DISABLED disable test with an optional message
728 # TEST_CRASHES test is expected to crash
729 # TEST_CONFIG test conditions
730 # TEST_ENV environment prefix
731 # TEST_CFLAGS compile flags
732 # TEST_BUILD build instructions
733 # TEST_BUILD_OUTPUT expected build stdout/stderr
734 # TEST_RUN_OUTPUT expected run stdout/stderr
735 open(my $in , "< $file ") || die;
736 my $contents = join "", < $in >;
738 my $test_h = ( $contents =~ /^\s*#\s*(include|import)\s*"test\.h"/m);
739 my ( $disabled ) = ( $contents =~ / \b (TEST_DISABLED \b .*) $/m );
740 my $crashes = ( $contents =~ / \b TEST_CRASHES \b /m);
741 my ( $conditionstring ) = ( $contents =~ / \b TEST_CONFIG \b (.*) $/m );
742 my ( $envstring ) = ( $contents =~ / \b TEST_ENV \b (.*) $/m );
743 my ( $cflags ) = ( $contents =~ / \b TEST_CFLAGS \b (.*) $/m );
744 my ( $buildcmd ) = extract_multiline("TEST_BUILD", $contents , $name );
745 my ( $builderror ) = extract_multiple_multiline("TEST_BUILD_OUTPUT", $contents , $name );
746 my ( $runerror ) = extract_multiple_multiline("TEST_RUN_OUTPUT", $contents , $name );
748 return 0 if ! $test_h && ! $disabled && ! $crashes && !defined( $conditionstring ) && !defined( $envstring ) && !defined( $cflags ) && !defined( $buildcmd ) && !defined( $builderror ) && !defined( $runerror );
751 colorprint $yellow , "SKIP: $name (disabled by $disabled )";
755 # check test conditions
758 my %conditions = readconditions( $conditionstring );
759 if (! $conditions {LANGUAGE}) {
760 # implicit language restriction from file extension
761 $conditions {LANGUAGE} = $languages_for_extension { $ext };
763 for my $condkey (keys %conditions ) {
764 my @condvalues = @{ $conditions { $condkey }};
766 # special case: RUN=0 does not affect build
767 if ( $condkey eq "RUN" && @condvalues == 1 && $condvalues [0] == 0) {
772 my $testvalue = $C { $condkey };
773 next if !defined( $testvalue );
774 # testvalue is the configuration being run now
775 # condvalues are the allowed values for this test
778 for my $condvalue ( @condvalues ) {
780 # special case: objc and objc++
781 if ( $condkey eq "LANGUAGE") {
782 $condvalue = "objective-c" if $condvalue eq "objc";
783 $condvalue = "objective-c++" if $condvalue eq "objc++";
786 $ok = 1 if ( $testvalue eq $condvalue );
788 # special case: CC and CXX allow substring matches
789 if ( $condkey eq "CC" || $condkey eq "CXX") {
790 $ok = 1 if ( $testvalue =~ / $condvalue/ );
797 my $plural = ( @condvalues > 1) ? "one of: " : "";
798 print "SKIP: $name ( $condkey = $testvalue , but test requires $plural ", join(' ', @condvalues ), ") \n ";
803 # save some results for build and run phases
804 $$CREF {"TEST_ $name "} = {
805 TEST_BUILD => $buildcmd ,
806 TEST_BUILD_OUTPUT => $builderror ,
807 TEST_CRASHES => $crashes ,
808 TEST_RUN_OUTPUT => $runerror ,
809 TEST_CFLAGS => $cflags ,
810 TEST_ENV => $envstring ,
812 DSTDIR => " $C {DSTDIR}/ $name .build",
813 OBJDIR => " $C {OBJDIR}/ $name .build",
820 # Test description plist to write when building for BATS execution.
822 $bats_plist {'Project'} = "objc4";
823 $bats_plist {'Tests'} = []; # populated by append_bats_test()
825 # Saves run instructions for a single test in all configurations as a BATS test.
826 sub append_bats_test {
829 my $arch = join(',', @{ $args {ARCH}});
830 my $os = join(',', @{ $args {OSVERSION}});
831 my $mem = join(',', @{ $args {MEM}});
832 my $language = join(',', @{ $args {LANGUAGE}});
834 push @{ $bats_plist {'Tests'}}, {
835 "TestName" => " $name ",
838 " $BATSBASE/test/test .pl",
843 "LANGUAGE= $language ",
853 # Builds a simple test
857 my %T = %{ $C {"TEST_ $name "}};
859 mkdir_verbose $T {DSTDIR};
860 chdir_verbose $T {DSTDIR};
861 # we don't mkdir $T {OBJDIR} because most tests don't use it
863 my $ext = $ALL_TESTS { $name };
864 my $file = " $DIR/$name . $ext ";
866 if ( $T {TEST_CRASHES}) {
867 ` echo
' $crashcatch ' > crashcatch
. c
`;
868 make(" $C {COMPILE_C} -dynamiclib -o libcrashcatch.dylib -x c crashcatch.c");
872 my $cmd = $T {TEST_BUILD} ? eval "return \" $T {TEST_BUILD} \" " : " $C {COMPILE} $T {TEST_CFLAGS} $file -o $name .exe";
874 my $output = make( $cmd );
876 # ignore out-of-date text-based stubs (caused by ditto into SDK)
877 $output =~ s/ld: warning: text-based stub file.*\n//g;
879 $output =~ s/ld: warning: could not create compact unwind for [^\n]+: does not use standard frame\n//g;
881 $output =~ s/^warning: Cannot lower [^\n]+\n//g;
882 $output =~ s/^warning: key: [^\n]+\n//g;
883 $output =~ s/^warning: discriminator: [^\n]+\n//g;
884 $output =~ s/^warning: callee: [^\n]+\n//g;
886 $output =~ s/ld: warning: ignoring file [^\n]*libclang_rt\.bridgeos\.a[^\n]*\n//g;
887 # ignore compiler logging of CCC_OVERRIDE_OPTIONS effects
888 if (defined $ENV {CCC_OVERRIDE_OPTIONS}) {
889 $output =~ s/### (CCC_OVERRIDE_OPTIONS:|Adding argument|Deleting argument|Replacing) [^\n]*\n//g;
893 if (my $builderror = $T {TEST_BUILD_OUTPUT}) {
894 # check for expected output and ignore $?
895 if ( $output =~ / $builderror/ ) {
897 } elsif (defined $ENV {CCC_OVERRIDE_OPTIONS} && $builderror =~ /warning:/) {
898 # CCC_OVERRIDE_OPTIONS manipulates compiler diagnostics.
899 # Don't enforce any TEST_BUILD_OUTPUT that looks for warnings.
900 colorprint $yellow , "WARN: /// test ' $name ' \\\\\\ ";
901 colorprefix $yellow , $output ;
902 colorprint $yellow , "WARN: \\\\\\ test ' $name ' ///";
903 colorprint $yellow , "WARN: $name (build output does not match TEST_BUILD_OUTPUT; not fatal because CCC_OVERRIDE_OPTIONS is set)";
906 colorprint $red , "FAIL: /// test ' $name ' \\\\\\ ";
907 colorprefix $red , $output ;
908 colorprint $red , "FAIL: \\\\\\ test ' $name ' ///";
909 colorprint $red , "FAIL: $name (build output does not match TEST_BUILD_OUTPUT)";
913 colorprint $red , "FAIL: /// test ' $name ' \\\\\\ ";
914 colorprefix $red , $output ;
915 colorprint $red , "FAIL: \\\\\\ test ' $name ' ///";
916 colorprint $red , "FAIL: $name (build failed)";
918 } elsif ( $output ne "") {
919 colorprint $red , "FAIL: /// test ' $name ' \\\\\\ ";
920 colorprefix $red , $output ;
921 colorprint $red , "FAIL: \\\\\\ test ' $name ' ///";
922 colorprint $red , "FAIL: $name (unexpected build output)";
929 foreach my $file (glob("*.exe *.dylib *.bundle")) {
931 # not for BATS to save space and build time
933 make("xcrun dsymutil $file ");
935 if ( $C {OS} eq "macosx" || $C {OS} =~ /simulator/) {
936 # setting any entitlements disables dyld environment variables
938 # get-task-allow entitlement is required
939 # to enable dyld environment variables
940 make("xcrun codesign -s - --entitlements $DIR/get_task_allow_entitlement .plist $file ");
949 # Run a simple test (testname.exe, with error checking of stdout and stderr)
953 my %T = %{ $C {"TEST_ $name "}};
955 if (! $T {TEST_RUN}) {
956 print "PASS: $name (build only) \n ";
960 my $testdir = $T {DSTDIR};
961 chdir_verbose $testdir ;
963 my $env = " $C {ENV} $T {TEST_ENV}";
965 if ( $T {TEST_CRASHES}) {
966 $env .= " OBJC_DEBUG_DONT_CRASH=YES";
971 if ( $C {ARCH} =~ /^arm/ && ` uname
- p
` !~ /^arm/) {
972 # run on iOS or watchos or tvos device
973 # fixme device selection and verification
974 my $remotedir = " $REMOTEBASE/ " . basename( $C {DSTDIR}) . "/ $name .build";
976 # Add test dir and libobjc's dir to DYLD_LIBRARY_PATH.
977 # Insert libcrashcatch.dylib if necessary.
978 $env .= " DYLD_LIBRARY_PATH= $remotedir ";
979 $env .= ": $REMOTEBASE " if ( $C {TESTLIBDIR} ne $TESTLIBDIR );
980 if ( $T {TEST_CRASHES}) {
981 $env .= " DYLD_INSERT_LIBRARIES= $remotedir/libcrashcatch .dylib";
984 my $cmd = "ssh -p $PORT $HOST 'cd $remotedir && env $env ./ $name .exe'";
985 $output = make(" $cmd ");
987 elsif ( $C {OS} =~ /simulator/) {
988 # run locally in a simulator
989 # fixme selection of simulated OS version
991 if ( $C {OS} =~ /iphonesimulator/) {
992 $simdevice = 'iPhone X';
993 } elsif ( $C {OS} =~ /watchsimulator/) {
994 $simdevice = 'Apple Watch Series 4 - 40mm';
995 } elsif ( $C {OS} =~ /tvsimulator/) {
996 $simdevice = 'Apple TV 1080p';
998 die "unknown simulator $C {OS} \n ";
1000 my $sim = "xcrun -sdk iphonesimulator simctl spawn ' $simdevice '";
1001 # Add test dir and libobjc's dir to DYLD_LIBRARY_PATH.
1002 # Insert libcrashcatch.dylib if necessary.
1003 $env .= " DYLD_LIBRARY_PATH= $testdir ";
1004 $env .= ":" . $C {TESTLIBDIR} if ( $C {TESTLIBDIR} ne $TESTLIBDIR );
1005 if ( $T {TEST_CRASHES}) {
1006 $env .= " DYLD_INSERT_LIBRARIES= $testdir/libcrashcatch .dylib";
1010 foreach my $keyvalue (split(' ', $env )) {
1011 $simenv .= "SIMCTL_CHILD_ $keyvalue ";
1013 # Use the full path here so hack_cwd in test.h works.
1014 $output = make("env $simenv $sim $testdir/$name .exe");
1019 # Add test dir and libobjc's dir to DYLD_LIBRARY_PATH.
1020 # Insert libcrashcatch.dylib if necessary.
1021 $env .= " DYLD_LIBRARY_PATH= $testdir ";
1022 $env .= ":" . $C {TESTLIBDIR} if ( $C {TESTLIBDIR} ne $TESTLIBDIR );
1023 if ( $T {TEST_CRASHES}) {
1024 $env .= " DYLD_INSERT_LIBRARIES= $testdir/libcrashcatch .dylib";
1027 $output = make("sh -c ' $env ./ $name .exe'");
1030 return check_output(\ %C , $name , split(" \n ", $output ));
1036 my ( $cc , $toolchain , $sdk_path ) = @_ ;
1039 my $key = $cc . ':' . $toolchain ;
1040 my $result = $compiler_memo { $key };
1041 return $result if defined $result ;
1043 $result = make("xcrun -toolchain $toolchain -find $cc 2>/dev/null");
1046 $compiler_memo { $key } = $result ;
1050 sub dirContainsAllTestLibs {
1053 foreach my $testlib ( @TESTLIBNAMES ) {
1054 my $found = (-e " $dir/$testlib ");
1055 my $foundstr = ( $found ? "found" : "didn't find");
1056 print "note: $foundstr $testlib in $dir \n " if ( $VERBOSE );
1057 return 0 if (! $found );
1063 sub make_one_config {
1064 my $configref = shift;
1066 my %C = %{ $configref };
1069 $C {LANGUAGE} = "objective-c" if $C {LANGUAGE} eq "objc";
1070 $C {LANGUAGE} = "objective-c++" if $C {LANGUAGE} eq "objc++";
1072 # Interpret OS version string from command line.
1073 my ( $sdk_arg , $deployment_arg , $run_arg , undef) = split('-', $C {OSVERSION});
1074 delete $C {OSVERSION};
1075 my ( $os_arg ) = ( $sdk_arg =~ /^([^\.0-9]+)/);
1076 $deployment_arg = "default" if !defined( $deployment_arg );
1077 $run_arg = "default" if !defined( $run_arg );
1079 my %allowed_os_args = (
1080 "macosx" => "macosx", "osx" => "macosx", "macos" => "macosx",
1081 "iphoneos" => "iphoneos", "ios" => "iphoneos",
1082 "iphonesimulator" => "iphonesimulator", "iossimulator" => "iphonesimulator",
1083 "watchos" => "watchos",
1084 "watchsimulator" => "watchsimulator", "watchossimulator" => "watchsimulator",
1085 "appletvos" => "appletvos", "tvos" => "appletvos",
1086 "appletvsimulator" => "appletvsimulator", "tvsimulator" => "appletvsimulator",
1087 "bridgeos" => "bridgeos",
1090 $C {OS} = $allowed_os_args { $os_arg } || die "unknown OS ' $os_arg ' (expected " . join(', ', sort keys %allowed_os_args ) . ") \n ";
1092 # set the config name now, after massaging the language and OS versions,
1093 # but before adding other settings
1094 my $configname = config_name( %C );
1095 die if ( $configname =~ /'/);
1096 die if ( $configname =~ / /);
1097 ( $C {NAME} = $configname ) =~ s/~/ /g;
1098 (my $configdir = $configname ) =~ s#/##g;
1099 $C {DSTDIR} = " $DSTROOT$BUILDDIR/$configdir ";
1100 $C {OBJDIR} = " $OBJROOT$BUILDDIR/$configdir ";
1102 # Allow tests to see BATS-edness in TEST_CONFIG.
1105 if ( $C {OS} eq "iphoneos" || $C {OS} eq "iphonesimulator") {
1106 $C {TOOLCHAIN} = "ios";
1107 } elsif ( $C {OS} eq "watchos" || $C {OS} eq "watchsimulator") {
1108 $C {TOOLCHAIN} = "watchos";
1109 } elsif ( $C {OS} eq "appletvos" || $C {OS} eq "appletvsimulator") {
1110 $C {TOOLCHAIN} = "appletvos";
1111 } elsif ( $C {OS} eq "bridgeos") {
1112 $C {TOOLCHAIN} = "bridgeos";
1113 } elsif ( $C {OS} eq "macosx") {
1114 $C {TOOLCHAIN} = "osx";
1116 colorprint $yellow , "WARN: don't know toolchain for OS $C {OS}";
1117 $C {TOOLCHAIN} = "default";
1122 # Try exact match first.
1123 # Then try lexically-last prefix match
1124 # (so "macosx" => "macosx10.7internal")
1126 $sdk_arg =~ s/$os_arg/$C{OS}/;
1128 my @sdks = getsdks();
1130 print "note: Installed SDKs: @sdks \n ";
1132 my $exactsdk = undef;
1133 my $prefixsdk = undef;
1134 foreach my $sdk ( @sdks ) {
1135 $exactsdk = $sdk if ( $sdk eq $sdk_arg );
1136 $prefixsdk = newersdk( $sdk , $prefixsdk ) if ( $sdk =~ /^ $sdk_arg/ );
1142 } elsif ( $prefixsdk ) {
1145 die "unknown SDK ' $sdk_arg ' \n Installed SDKs: @sdks \n ";
1148 # Set deployment target.
1149 # fixme can't enforce version when run_arg eq "default"
1150 # because we don't know it yet
1151 $deployment_arg = versionsuffix( $sdk ) if $deployment_arg eq "default";
1152 if ( $run_arg ne "default") {
1153 die "Deployment target ' $deployment_arg ' is newer than run target ' $run_arg ' \n " if $deployment_arg > $run_arg ;
1155 $C {DEPLOYMENT_TARGET} = $deployment_arg ;
1156 $C {SDK_PATH} = getsdkpath( $sdk );
1159 $C {DEPLOYMENT_TARGET} = "unknown_deployment_target";
1160 $C {SDK_PATH} = "/unknown/sdk";
1164 $C {RUN_TARGET} = $run_arg ;
1166 # Look up test library (possible in root or SDK_PATH)
1168 my $rootarg = $root ;
1170 my @sympaths = ( (glob " $root/*~sym ")[0],
1171 (glob " $root/BuildRecords/*_install/Symbols ")[0],
1173 my @dstpaths = ( (glob " $root/*~dst ")[0],
1174 (glob " $root/BuildRecords/*_install/Root ")[0],
1176 for(my $i = 0; $i < scalar( @sympaths ); $i++ ) {
1177 if (-e $sympaths [ $i ] && -e $dstpaths [ $i ]) {
1178 $symroot = $sympaths [ $i ];
1179 $root = $dstpaths [ $i ];
1185 # Root specified. Require that it contain our dylibs.
1186 if (dirContainsAllTestLibs(" $root$C {SDK_PATH} $TESTLIBDIR ")) {
1187 $C {TESTLIBDIR} = " $root$C {SDK_PATH} $TESTLIBDIR ";
1188 } elsif (dirContainsAllTestLibs(" $root$TESTLIBDIR ")) {
1189 $C {TESTLIBDIR} = " $root$TESTLIBDIR ";
1190 } elsif (dirContainsAllTestLibs( $root )) {
1191 $C {TESTLIBDIR} = " $root ";
1193 die "Didn't find some libs in root ' $rootarg ' for sdk ' $C {SDK_PATH}' \n ";
1197 # No root specified. Use the SDK or / for our dylibs.
1198 if (dirContainsAllTestLibs(" $C {SDK_PATH} $TESTLIBDIR ")) {
1199 $C {TESTLIBDIR} = " $C {SDK_PATH} $TESTLIBDIR ";
1201 # We don't actually check in / because on devices
1202 # there are no dylib files there.
1203 $C {TESTLIBDIR} = $TESTLIBDIR ;
1207 @{ $C {TESTLIBS}} = map { " $C {TESTLIBDIR}/ $_ " } @TESTLIBNAMES ;
1208 # convenience for tests that want libobjc.dylib's path
1209 $C {TESTLIB} = @{ $C {TESTLIBS}}[0];
1211 foreach my $testlibname ( @TESTLIBNAMES ) {
1212 if (-e " $symroot/$testlibname .dSYM") {
1213 push(@{ $C {TESTDSYMS}}, " $symroot/$testlibname .dSYM");
1218 foreach my $testlib (@{ $C {TESTLIBS}}) {
1219 my @uuids = ` /usr/ bin
/ dwarfdump
- u
' $testlib ' `;
1220 while (my $uuid = shift @uuids ) {
1221 print "note: $uuid ";
1228 my $cxx = cplusplus( $C {CC});
1229 my $swift = swift( $C {CC});
1235 $C {CC} = find_compiler( $cc , $C {TOOLCHAIN}, $C {SDK_PATH});
1236 $C {CXX} = find_compiler( $cxx , $C {TOOLCHAIN}, $C {SDK_PATH});
1237 $C {SWIFT} = find_compiler( $swift , $C {TOOLCHAIN}, $C {SDK_PATH});
1239 die "No C compiler ' $cc ' (' $C {CC}') in toolchain ' $C {TOOLCHAIN}' \n " if !-e $C {CC};
1240 die "No C++ compiler ' $cxx ' (' $C {CXX}') in toolchain ' $C {TOOLCHAIN}' \n " if !-e $C {CXX};
1241 die "No Swift compiler ' $swift ' (' $C {SWIFT}') in toolchain ' $C {TOOLCHAIN}' \n " if !-e $C {SWIFT};
1244 if ( $C {ARCH} eq "i386" && $C {OS} eq "macosx") {
1245 # libarclite no longer available on i386
1246 # fixme need an archived copy for bincompat testing
1247 $C {FORCE_LOAD_ARCLITE} = "";
1248 } elsif ( $C {OS} eq "bridgeos") {
1249 # no libarclite on bridgeOS
1250 $C {FORCE_LOAD_ARCLITE} = "";
1252 $C {FORCE_LOAD_ARCLITE} = "-Xlinker -force_load -Xlinker " . dirname( $C {CC}) . "/../lib/arc/libarclite_ $C {OS}.a";
1257 my $cflags = "-I $DIR -W -Wall -Wno-objc-weak-compat -Wno-arc-bridge-casts-disallowed-in-nonarc -Wshorten-64-to-32 -Qunused-arguments -fno-caret-diagnostics -Os -arch $C {ARCH} ";
1259 # save-temps so dsymutil works so debug info works.
1260 # Disabled in BATS to save disk space.
1261 # rdar://45656803 -save-temps causes bad -Wstdlibcxx-not-found warnings
1262 $cflags .= "-g -save-temps -Wno-stdlibcxx-not-found";
1265 my $swiftflags = "-g ";
1267 $cflags .= " -isysroot ' $C {SDK_PATH}'";
1268 $cflags .= " '-Wl,-syslibroot, $C {SDK_PATH}'";
1269 $swiftflags .= " -sdk ' $C {SDK_PATH}'";
1271 # Set deployment target cflags
1273 die "No deployment target" if $C {DEPLOYMENT_TARGET} eq "";
1274 if ( $C {OS} eq "iphoneos") {
1275 $cflags .= " -mios-version-min= $C {DEPLOYMENT_TARGET}";
1276 $target = " $C {ARCH}-apple-ios $C {DEPLOYMENT_TARGET}";
1278 elsif ( $C {OS} eq "iphonesimulator") {
1279 $cflags .= " -mios-simulator-version-min= $C {DEPLOYMENT_TARGET}";
1280 $target = " $C {ARCH}-apple-ios $C {DEPLOYMENT_TARGET}";
1282 elsif ( $C {OS} eq "watchos") {
1283 $cflags .= " -mwatchos-version-min= $C {DEPLOYMENT_TARGET}";
1284 $target = " $C {ARCH}-apple-watchos $C {DEPLOYMENT_TARGET}";
1286 elsif ( $C {OS} eq "watchsimulator") {
1287 $cflags .= " -mwatchos-simulator-version-min= $C {DEPLOYMENT_TARGET}";
1288 $target = " $C {ARCH}-apple-watchos $C {DEPLOYMENT_TARGET}";
1290 elsif ( $C {OS} eq "appletvos") {
1291 $cflags .= " -mtvos-version-min= $C {DEPLOYMENT_TARGET}";
1292 $target = " $C {ARCH}-apple-tvos $C {DEPLOYMENT_TARGET}";
1294 elsif ( $C {OS} eq "appletvsimulator") {
1295 $cflags .= " -mtvos-simulator-version-min= $C {DEPLOYMENT_TARGET}";
1296 $target = " $C {ARCH}-apple-tvos $C {DEPLOYMENT_TARGET}";
1298 elsif ( $C {OS} eq "bridgeos") {
1299 $cflags .= " -mbridgeos-version-min= $C {DEPLOYMENT_TARGET}";
1300 $target = " $C {ARCH}-apple-bridgeos $C {DEPLOYMENT_TARGET}";
1303 $cflags .= " -mmacosx-version-min= $C {DEPLOYMENT_TARGET}";
1304 $target = " $C {ARCH}-apple-macosx $C {DEPLOYMENT_TARGET}";
1306 $swiftflags .= " -target $target ";
1308 $C {TESTINCLUDEDIR} = " $C {SDK_PATH}/usr/include";
1309 $C {TESTLOCALINCLUDEDIR} = " $C {SDK_PATH}/usr/local/include";
1311 if ( $C {SDK_PATH} ne "/") {
1312 $cflags .= " -isystem ' $root$C {SDK_PATH}/usr/include'";
1313 $cflags .= " -isystem ' $root$C {SDK_PATH}/usr/local/include'";
1316 my $library_path = $C {TESTLIBDIR};
1317 $cflags .= " -L $library_path ";
1318 # fixme Root vs SDKContentRoot
1319 $C {TESTINCLUDEDIR} = " $root/ ../SDKContentRoot/usr/include";
1320 $C {TESTLOCALINCLUDEDIR} = " $root/ ../SDKContentRoot/usr/local/include";
1321 $cflags .= " -isystem ' $C {TESTINCLUDEDIR}'";
1322 $cflags .= " -isystem ' $C {TESTLOCALINCLUDEDIR}'";
1326 # Populate objcflags
1328 $objcflags .= " -lobjc";
1329 if ( $C {MEM} eq "arc") {
1330 $objcflags .= " -fobjc-arc";
1332 elsif ( $C {MEM} eq "mrc") {
1336 die "unrecognized MEM ' $C {MEM}' \n ";
1339 # Populate ENV_PREFIX
1340 $C {ENV} = "LANG=C MallocScribble=1";
1341 $C {ENV} .= " VERBOSE= $VERBOSE " if $VERBOSE ;
1343 die "no spaces allowed in root" if $C {TESTLIBDIR} =~ /\s+/;
1345 if ( $C {GUARDMALLOC}) {
1346 $C {ENV} .= " GUARDMALLOC=1"; # checked by tests and errcheck.pl
1347 $C {ENV} .= " DYLD_INSERT_LIBRARIES=/usr/lib/libgmalloc.dylib";
1348 if ( $C {GUARDMALLOC} eq "before") {
1349 $C {ENV} .= " MALLOC_PROTECT_BEFORE=1";
1350 } elsif ( $C {GUARDMALLOC} eq "after") {
1351 # protect after is the default
1353 die "Unknown guard malloc mode ' $C {GUARDMALLOC}' \n ";
1357 # Populate compiler commands
1358 $C {XCRUN} = "env LANG=C /usr/bin/xcrun -toolchain ' $C {TOOLCHAIN}'";
1360 $C {COMPILE_C} = " $C {XCRUN} ' $C {CC}' $cflags -x c -std=gnu99";
1361 $C {COMPILE_CXX} = " $C {XCRUN} ' $C {CXX}' $cflags -x c++";
1362 $C {COMPILE_M} = " $C {XCRUN} ' $C {CC}' $cflags $objcflags -x objective-c -std=gnu99";
1363 $C {COMPILE_MM} = " $C {XCRUN} ' $C {CXX}' $cflags $objcflags -x objective-c++";
1364 $C {COMPILE_SWIFT} = " $C {XCRUN} ' $C {SWIFT}' $swiftflags ";
1366 $C {COMPILE} = $C {COMPILE_C} if $C {LANGUAGE} eq "c";
1367 $C {COMPILE} = $C {COMPILE_CXX} if $C {LANGUAGE} eq "c++";
1368 $C {COMPILE} = $C {COMPILE_M} if $C {LANGUAGE} eq "objective-c";
1369 $C {COMPILE} = $C {COMPILE_MM} if $C {LANGUAGE} eq "objective-c++";
1370 $C {COMPILE} = $C {COMPILE_SWIFT} if $C {LANGUAGE} eq "swift";
1371 die "unknown language ' $C {LANGUAGE}' \n " if !defined $C {COMPILE};
1373 ( $C {COMPILE_NOMEM} = $C {COMPILE}) =~ s/ -fobjc-arc\S*//g;
1374 ( $C {COMPILE_NOLINK} = $C {COMPILE}) =~ s/ '?-(?:Wl,|l)\S*//g;
1375 ( $C {COMPILE_NOLINK_NOMEM} = $C {COMPILE_NOMEM}) =~ s/ '?-(?:Wl,|l)\S*//g;
1378 # Reject some self-inconsistent and disallowed configurations
1379 if ( $C {MEM} !~ /^(mrc|arc) $/ ) {
1380 die "unknown MEM= $C {MEM} (expected one of mrc arc) \n ";
1383 if ( $C {MEM} eq "arc" && $C {CC} !~ /clang/) {
1384 print "note: skipping configuration $C {NAME} \n ";
1385 print "note: because CC= $C {CC} does not support MEM= $C {MEM} \n ";
1389 if ( $C {ARCH} eq "i386" && $C {OS} eq "macosx") {
1390 colorprint $yellow , "WARN: skipping configuration $C {NAME} \n ";
1391 colorprint $yellow , "WARN: because 32-bit Mac is dead \n ";
1396 if ( $C {LANGUAGE} eq "swift" && $C {ARCH} =~ /^arm/) {
1397 print "note: skipping configuration $C {NAME} \n ";
1398 print "note: because ARCH= $C {ARCH} does not support LANGUAGE=SWIFT \n ";
1402 # fixme unimplemented run targets
1403 if ( $C {RUN_TARGET} ne "default" && $C {OS} !~ /simulator/) {
1404 colorprint $yellow , "WARN: skipping configuration $C {NAME}";
1405 colorprint $yellow , "WARN: because OS= $C {OS} does not yet implement RUN_TARGET= $C {RUN_TARGET}";
1412 my ( $root , %args ) = @_ ;
1414 my @results = ({}); # start with one empty config
1416 for my $key (keys %args ) {
1418 my @values = @{ $args { $key }};
1419 for my $configref ( @results ) {
1420 my %config = %{ $configref };
1421 for my $value ( @values ) {
1422 my %newconfig = %config ;
1423 $newconfig { $key } = $value ;
1424 push @newresults , \ %newconfig ;
1427 @results = @newresults ;
1431 for my $configref ( @results ) {
1432 if (make_one_config( $configref , $root )) {
1433 push @newresults , $configref ;
1443 for my $key (sort keys %config ) {
1444 $name .= '~' if $name ne "";
1445 $name .= " $key = $config { $key }";
1451 my ( $src , $timeout ) = @_ ;
1452 for (my $i = 0; $i < 10; $i++ ) {
1453 make(" $DIR/timeout .pl $timeout rsync -e 'ssh -p $PORT ' -av $src $HOST :/ $REMOTEBASE/ ");
1455 colorprint $yellow , "WARN: RETRY \n " if $VERBOSE ;
1457 die "Couldn't rsync tests to device. Check: device is connected; tcprelay is running; device trusts your Mac; device is unlocked; filesystem is mounted r/w \n ";
1460 sub build_and_run_one_config {
1470 foreach my $test ( @tests ) {
1472 print " \n GATHER $test \n ";
1475 if ( $ALL_TESTS { $test }) {
1476 gather_simple(\ %C , $test ) || next; # not pass, not fail
1477 push @gathertests , $test ;
1479 die "No test named ' $test ' \n ";
1485 @builttests = @gathertests ;
1486 $testcount = scalar( @gathertests );
1488 foreach my $test ( @gathertests ) {
1490 print " \n BUILD $test \n ";
1493 if ( $ALL_TESTS { $test }) {
1495 if (!build_simple(\ %C , $test )) {
1498 push @builttests , $test ;
1501 die "No test named ' $test ' \n ";
1506 if (! $RUN || !scalar( @builttests )) {
1510 if ( $C {ARCH} =~ /^arm/ && ` uname
- p
` !~ /^arm/) {
1511 # upload timeout - longer for slow watch devices
1512 my $timeout = ( $C {OS} =~ /watch/) ? 120 : 20;
1514 # upload all tests to iOS device
1515 rsync_ios( $C {DSTDIR}, $timeout );
1517 # upload library to iOS device
1518 if ( $C {TESTLIBDIR} ne $TESTLIBDIR ) {
1519 foreach my $thing (@{ $C {TESTLIBS}}, @{ $C {TESTDSYMS}}) {
1520 rsync_ios( $thing , $timeout );
1524 elsif ( $C {OS} =~ /simulator/) {
1525 # run locally in a simulator
1530 # BATS execution tries to run architectures that
1531 # aren't supported by the device. Skip those configs here.
1532 my $machine = ` machine
`;
1535 # running arm64e on non-arm64e device
1536 # running arm64 on non-arm64* device
1537 # running armv7k on non-armv7k device
1538 # running arm64_32 on armv7k device
1539 # We don't need to handle all mismatches here,
1540 # only mismatches that arise within a single OS.
1542 (( $C {ARCH} eq "arm64e" && $machine ne "arm64e") ||
1543 ( $C {ARCH} eq "arm64" && $machine !~ /^arm64/) ||
1544 ( $C {ARCH} eq "armv7k" && $machine ne "armv7k") ||
1545 ( $C {ARCH} eq "arm64_32" && $machine eq "armv7k"));
1547 print "note: skipping configuration $C {NAME} \n ";
1548 print "note: because test arch $C {ARCH} is not " .
1549 "supported on device arch $machine \n ";
1556 foreach my $test ( @builttests ) {
1557 print " \n RUN $test \n " if ( $VERBOSE );
1559 if ( $ALL_TESTS { $test }) {
1560 if (!run_simple(\ %C , $test )) {
1564 die "No test named ' $test ' \n ";
1570 return ( $testcount , $failcount , $skipconfig );
1575 # Return value if set by " $argname =value" on the command line
1576 # Return $default if not set.
1578 my ( $argname , $default ) = @_ ;
1580 foreach my $arg ( @ARGV ) {
1581 my ( $value ) = ( $arg =~ /^ $argname =(.+) $/ );
1582 return [split ',', $value ] if defined $value ;
1585 return [split ',', $default ];
1588 # Return 1 or 0 if set by " $argname =1" or " $argname =0" on the
1589 # command line. Return $default if not set.
1591 my ( $argname , $default ) = @_ ;
1593 my @values = @{getargs( $argname , $default )};
1594 return [( map { ( $_ eq "0") ? 0 : 1 } @values )];
1597 # Return an integer if set by " $argname =value" on the
1598 # command line. Return $default if not set.
1600 my ( $argname , $default ) = @_ ;
1602 my @values = @{getargs( $argname , $default )};
1603 return [( map { int( $_ ) } @values )];
1607 my ( $argname , $default ) = @_ ;
1608 my @values = @{getargs( $argname , $default )};
1609 die "Only one value allowed for $argname \n " if @values > 1;
1614 my ( $argname , $default ) = @_ ;
1615 my @values = @{getbools( $argname , $default )};
1616 die "Only one value allowed for $argname \n " if @values > 1;
1621 my ( $argname , $default ) = @_ ;
1622 my @values = @{getints( $argname , $default )};
1623 die "Only one value allowed for $argname \n " if @values > 1;
1628 my $default_arch = "x86_64";
1629 $args {ARCH} = getargs("ARCH", 0);
1630 $args {ARCH} = getargs("ARCHS", $default_arch ) if !@{ $args {ARCH}}[0];
1632 $args {OSVERSION} = getargs("OS", "macosx-default-default");
1634 $args {MEM} = getargs("MEM", "mrc,arc");
1635 $args {LANGUAGE} = [ map { lc( $_ ) } @{getargs("LANGUAGE", "c,objective-c,c++,objective-c++")} ];
1637 $args {CC} = getargs("CC", "clang");
1639 $HOST = getarg("HOST", "iphone");
1640 $PORT = getarg("PORT", "10022");
1643 my $guardmalloc = getargs("GUARDMALLOC", 0);
1644 # GUARDMALLOC=1 is the same as GUARDMALLOC=before,after
1645 my @guardmalloc2 = ();
1646 for my $arg ( @$guardmalloc ) {
1647 if ( $arg == 1) { push @guardmalloc2 , "before";
1648 push @guardmalloc2 , "after"; }
1649 else { push @guardmalloc2 , $arg }
1651 $args {GUARDMALLOC} = \ @guardmalloc2 ;
1654 $BUILD = getbool("BUILD", 1);
1655 $RUN = getbool("RUN", 1);
1656 $VERBOSE = getint("VERBOSE", 0);
1657 $BATS = getbool("BATS", 0);
1658 $BUILDDIR = getarg("BUILDDIR", $BATS ? $BATSBASE : $LOCALBASE );
1660 my $root = getarg("ROOT", "");
1663 my @tests = gettests();
1666 rm_rf_verbose " $DSTROOT$BUILDDIR ";
1667 rm_rf_verbose " $OBJROOT$BUILDDIR ";
1670 print "note: ----- \n ";
1671 print "note: testing root ' $root ' \n ";
1673 my @configs = make_configs( $root , %args );
1675 print "note: ----- \n ";
1676 print "note: testing ", scalar( @configs ), " configurations: \n ";
1677 for my $configref ( @configs ) {
1678 my $configname = $$configref {NAME};
1679 print "note: configuration $configname \n ";
1684 my $testconfigs = @configs ;
1685 my $failconfigs = 0;
1686 my $skipconfigs = 0;
1689 for my $configref ( @configs ) {
1690 my $configname = $$configref {NAME};
1691 print "note: ----- \n ";
1692 print "note: \n note: $configname \n note: \n ";
1694 (my $t , my $f , my $skipconfig ) =
1695 eval { build_and_run_one_config( $configref , @tests ); };
1696 $skipconfigs += $skipconfig ;
1699 colorprint $red , "FAIL: $configname ";
1700 colorprint $red , "FAIL: $@ ";
1703 my $color = ( $f ? $red : "");
1705 colorprint $color , "note: $configname \n ";
1706 colorprint $color , "note: $t tests, $f failures";
1709 $failconfigs++ if ( $f );
1713 print "note: ----- \n ";
1714 my $color = ( $failconfigs ? $red : "");
1715 colorprint $color , "note: $testconfigs configurations, " .
1716 " $failconfigs with failures, $skipconfigs skipped";
1717 colorprint $color , "note: $testcount tests, $failcount failures";
1719 $failed = ( $failconfigs ? 1 : 0);
1722 if ( $BUILD && $BATS && ! $failed ) {
1723 # Collect BATS execution instructions for all tests.
1724 # Each BATS "test" is all configurations together of one of our tests.
1725 for my $testname ( @tests ) {
1726 append_bats_test( $testname );
1729 # Write the BATS plist to disk.
1730 my $json = encode_json(\ %bats_plist );
1731 my $filename = " $DSTROOT$BATSBASE/objc4 .plist";
1732 print "note: writing BATS config to $filename \n ";
1733 open(my $file , '>', $filename );
1738 exit ( $failed ? 1 : 0);