]>
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.
107 my @TESTLIBNAMES = ( "libobjc.A.dylib" , "libobjc-trampolines.dylib" );
108 my $TESTLIBDIR = "/usr/lib" ;
110 # Top level directory for intermediate and final build products.
111 # Intermediate files must be kept separate for XBS BATS builds.
112 my $OBJROOT = $ENV { OBJROOT
} || "" ;
113 my $DSTROOT = $ENV { DSTROOT
} || "" ;
115 # Build product directory inside DSTROOT and OBJROOT.
116 # Each test config gets its own build directory inside this.
119 # Local top-level directory.
120 # This is the default value for $BUILDDIR.
121 my $LOCALBASE = "/tmp/test- $TESTLIBNAMES [0]-build" ;
123 # Device-side top-level directory.
124 # This replaces $DSTROOT$BUILDDIR/ for on-device execution.
125 my $REMOTEBASE = "/AppleInternal/objctest" ;
127 # BATS top-level directory.
128 # This replaces $DSTROOT$BUILDDIR/ for BATS execution.
129 my $BATSBASE = "/AppleInternal/CoreOS/tests/objc4" ;
132 my $crashcatch = <<'END';
133 // interpose-able code to catch crashes, print, and exit cleanly
138 // from dyld-interposing.h
139 #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 };
141 static void catchcrash(int sig)
145 case SIGILL: msg = "CRASHED: SIGILL"; break;
146 case SIGBUS: msg = "CRASHED: SIGBUS"; break;
147 case SIGSYS: msg = "CRASHED: SIGSYS"; break;
148 case SIGSEGV: msg = "CRASHED: SIGSEGV"; break;
149 case SIGTRAP: msg = "CRASHED: SIGTRAP"; break;
150 case SIGABRT: msg = "CRASHED: SIGABRT"; break;
151 default: msg = "unknown signal"; break;
153 write(STDERR_FILENO, msg, strlen(msg));
155 // avoid backslash-n newline due to escaping differences somewhere
156 // in BATS versus local execution (perhaps different perl versions?)
158 write(STDERR_FILENO, &newline, 1);
163 static void setupcrash(void) __attribute__((constructor));
164 static void setupcrash(void)
166 signal(SIGILL, &catchcrash);
167 signal(SIGBUS, &catchcrash);
168 signal(SIGSYS, &catchcrash);
169 signal(SIGSEGV, &catchcrash);
170 signal(SIGTRAP, &catchcrash);
171 signal(SIGABRT, &catchcrash);
175 static int hacked = 0;
176 ssize_t hacked_write(int fildes, const void *buf, size_t nbyte)
182 return write(fildes, buf, nbyte);
185 DYLD_INTERPOSE(hacked_write, write);
190 #########################################################################
194 # map language to buildable extensions for that language
195 my %extensions_for_language = (
197 "objective-c" => [ "c" , "m" ],
198 "c++" => [ "c" , "cc" , "cp" , "cpp" , "cxx" , "c++" ],
199 "objective-c++" => [ "c" , "m" , "cc" , "cp" , "cpp" , "cxx" , "c++" , "mm" ],
200 "swift" => [ "swift" ],
202 "any" => [ "c" , "m" , "cc" , "cp" , "cpp" , "cxx" , "c++" , "mm" , "swift" ],
205 # map extension to languages
206 my %languages_for_extension = (
207 "c" => [ "c" , "objective-c" , "c++" , "objective-c++" ],
208 "m" => [ "objective-c" , "objective-c++" ],
209 "mm" => [ "objective-c++" ],
210 "cc" => [ "c++" , "objective-c++" ],
211 "cp" => [ "c++" , "objective-c++" ],
212 "cpp" => [ "c++" , "objective-c++" ],
213 "cxx" => [ "c++" , "objective-c++" ],
214 "c++" => [ "c++" , "objective-c++" ],
215 "swift" => [ "swift" ],
218 # Run some newline-separated commands like `make` would, stopping if any fail
219 # run("cmd1 \n cmd2 \n cmd3")
222 my @cmds = split ( " \n " , $_ [ 0 ]);
223 die if scalar ( @cmds ) == 0 ;
225 foreach my $cmd ( @cmds ) {
227 next if $cmd =~ /^\s*$/ ;
229 print " $cmd \n " if $VERBOSE ;
233 print " $output \n " if $VERBOSE ;
238 my $dir = shift || die;
239 print "cd $dir \n " if $VERBOSE ;
240 chdir $dir || die "couldn't cd $dir ";
244 my $dir = shift || die;
245 print "mkdir -p $dir \n " if $VERBOSE ;
247 die "couldn't rm -rf $dir " if $? ;
251 my $dir = shift || die;
252 print "mkdir -p $dir \n " if $VERBOSE ;
254 die "couldn't mkdir $dir " if $? ;
259 my $red = "\e[41;37m";
260 my $yellow = "\e[43;30m";
261 my $nocolor = "\e[0m";
263 # Not isatty. Don't use colors.
269 # print text with a colored prefix on each line
270 # fixme some callers pass an array of lines and some don't
273 while (defined(my $lines = shift)) {
274 $lines = " \n " if ( $lines eq "");
275 for my $line (split(/^/, $lines )) {
277 print " $color $nocolor$line \n ";
283 # fixme some callers pass an array of lines and some don't
286 while (defined(my $lines = shift)) {
287 $lines = " \n " if ( $lines eq "");
288 for my $line (split(/^/, $lines )) {
290 print " $color$line$nocolor \n ";
295 # Return test names from the command line.
296 # Returns all tests if no tests were named.
300 foreach my $arg ( @ARGV ) {
301 push @tests , $arg if ( $arg !~ /=/ && $arg !~ /^-/);
304 opendir(my $dir , $DIR ) || die;
305 while (my $file = readdir( $dir )) {
306 my ( $name , $ext ) = ( $file =~ /^([^.]+)\.([^.]+) $/ );
307 next if ! $languages_for_extension { $ext };
309 open(my $in , "< $file ") || die " $file ";
310 my $contents = join "", < $in >;
311 if (defined $ALL_TESTS { $name }) {
312 colorprint $yellow , "SKIP: multiple tests named ' $name '; skipping file ' $file '.";
314 $ALL_TESTS { $name } = $ext if ( $contents =~ m#^[/*\s]*TEST_#m);
320 if (scalar( @tests ) == 0) {
321 @tests = keys %ALL_TESTS ;
324 @tests = sort @tests ;
330 # Turn a C compiler name into a C++ compiler name.
337 return $c . "++"; # e.g. clang => clang++
340 # Turn a C compiler name into a Swift compiler name
343 $c =~ s#[^/]* $#swift# ;
347 # Returns an array of all sdks from ` xcodebuild
- showsdks
`
351 @sdks_memo = (` xcodebuild
- showsdks
` =~ /-sdk (.+) $/mg );
356 my %sdk_path_memo = {};
359 if (!defined $sdk_path_memo { $sdk }) {
360 ( $sdk_path_memo { $sdk }) = (` xcodebuild
- version
- sdk
' $sdk ' Path
` =~ /^\s*(.+?)\s* $/ );
362 return $sdk_path_memo { $sdk };
365 # Extract a version number from a string.
366 # Ignore trailing "internal".
369 my ( $vers ) = ( $str =~ /([0-9]+\.[0-9]+)(?:\.?internal)? $/ );
372 sub majorversionsuffix {
374 my ( $vers ) = ( $str =~ /([0-9]+)\.[0-9]+(?:\.?internal)? $/ );
377 sub minorversionsuffix {
379 my ( $vers ) = ( $str =~ /[0-9]+\.([0-9]+)(?:\.?internal)? $/ );
383 # Compares two SDK names and returns the newer one.
384 # Assumes the two SDKs are the same OS.
386 my ( $lhs , $rhs ) = @_ ;
388 # Major version wins.
389 my $lhsMajor = majorversionsuffix( $lhs );
390 my $rhsMajor = majorversionsuffix( $rhs );
391 if ( $lhsMajor > $rhsMajor ) { return $lhs ; }
392 if ( $lhsMajor < $rhsMajor ) { return $rhs ; }
394 # Minor version wins.
395 my $lhsMinor = minorversionsuffix( $lhs );
396 my $rhsMinor = minorversionsuffix( $rhs );
397 if ( $lhsMinor > $rhsMinor ) { return $lhs ; }
398 if ( $lhsMinor < $rhsMinor ) { return $rhs ; }
400 # Lexically-last wins (i.e. internal is better than not internal)
401 if ( $lhs gt $rhs ) { return $lhs ; }
409 # parse name=value,value pairs
411 my ( $conditionstring ) = @_ ;
414 my @conditions = ( $conditionstring =~ /\w+=(?:[^\s,]+,?)+/g);
415 for my $condition ( @conditions ) {
416 my ( $name , $values ) = ( $condition =~ /(\w+)=(.+)/);
417 $results { $name } = [split ',', $values ];
428 my %T = %{ $C {"TEST_ $name "}};
430 # Quietly strip MallocScribble before saving the "original" output
431 # because it is distracting.
432 filter_malloc(\ @output );
434 my @original_output = @output ;
436 # Run result-checking passes, reducing @output each time
440 my $runerror = $T {TEST_RUN_OUTPUT};
441 filter_hax(\ @output );
442 filter_verbose(\ @output );
443 filter_simulator(\ @output );
444 $warn = filter_warn(\ @output );
445 $bad |= filter_guardmalloc(\ @output ) if ( $C {GUARDMALLOC});
446 $bad |= filter_valgrind(\ @output ) if ( $C {VALGRIND});
447 $bad = filter_expected(\ @output , \ %C , $name ) if ( $bad eq "");
448 $bad = filter_bad(\ @output ) if ( $bad eq "");
450 # OK line should be the only one left
451 $bad = "(output not 'OK: $name ')" if ( $bad eq "" && (scalar( @output ) != 1 || $output [0] !~ /^OK: $name/ ));
454 colorprint $red , "FAIL: /// test ' $name ' \\\\\\ ";
455 colorprefix $red , @original_output ;
456 colorprint $red , "FAIL: \\\\\\ test ' $name ' ///";
457 colorprint $red , "FAIL: $name : $bad ";
460 elsif ( $warn ne "") {
461 colorprint $yellow , "PASS: /// test ' $name ' \\\\\\ ";
462 colorprefix $yellow , @original_output ;
463 colorprint $yellow , "PASS: \\\\\\ test ' $name ' ///";
464 print "PASS: $name (with warnings) \n ";
467 print "PASS: $name \n ";
474 my $outputref = shift;
478 my %T = %{ $C {"TEST_ $name "}};
479 my $runerror = $T {TEST_RUN_OUTPUT} || return "";
483 my $output = join(" \n ", @$outputref ) . " \n ";
484 if ( $output !~ / $runerror/ ) {
485 $bad = "(run output does not match TEST_RUN_OUTPUT)";
486 @$outputref = ("FAIL: $name ");
488 @$outputref = ("OK: $name "); # pacify later filter
496 my $outputref = shift;
500 for my $line ( @$outputref ) {
501 if ( $line =~ /^BAD: (.*)/) {
504 push @new_output , $line ;
508 @$outputref = @new_output ;
514 my $outputref = shift;
518 for my $line ( @$outputref ) {
519 if ( $line !~ /^WARN: (.*)/) {
520 push @new_output , $line ;
526 @$outputref = @new_output ;
532 my $outputref = shift;
535 for my $line ( @$outputref ) {
536 if ( $line !~ /^VERBOSE: (.*)/) {
537 push @new_output , $line ;
541 @$outputref = @new_output ;
546 my $outputref = shift;
549 for my $line ( @$outputref ) {
550 if (( $line !~ /No simulator devices appear to be running/) &&
551 ( $line !~ /CoreSimulator is attempting to unload a stale CoreSimulatorService job/) &&
552 ( $line !~ /Failed to locate a valid instance of CoreSimulatorService/))
554 push @new_output , $line ;
558 @$outputref = @new_output ;
563 my $outputref = shift;
566 for my $line ( @$outputref ) {
567 if ( $line !~ /Class OS_tcp_/) {
568 push @new_output , $line ;
572 @$outputref = @new_output ;
577 my $outputref = shift;
582 for my $line ( @$outputref ) {
583 if ( $line =~ /^Approx: do_origins_Dirty\([RW]\): missed \d bytes $/ ) {
584 # --track-origins warning (harmless)
587 if ( $line =~ /^UNKNOWN __disable_threadsignal is unsupported. This warning will not be repeated. $/ ) {
588 # signals unsupported (harmless)
591 if ( $line =~ /^UNKNOWN __pthread_sigmask is unsupported. This warning will not be repeated. $/ ) {
592 # signals unsupported (harmless)
595 if ( $line !~ /^^\.*==\d+==/) {
596 # not valgrind output
597 push @new_output , $line ;
601 my ( $errcount ) = ( $line =~ /==\d+== ERROR SUMMARY: (\d+) errors/);
602 if (defined $errcount && $errcount > 0) {
606 (my $leakcount ) = ( $line =~ /==\d+==\s+(?:definitely|possibly) lost:\s+([0-9,]+)/);
607 if (defined $leakcount && $leakcount > 0) {
612 @$outputref = @new_output ;
615 $bad .= "(valgrind errors)" if ( $errors );
616 $bad .= "(valgrind leaks)" if ( $leaks );
624 my $outputref = shift;
629 for my $line ( @$outputref ) {
630 # Ignore MallocScribble prologue.
631 # Ignore MallocStackLogging prologue.
632 if ( $line =~ /malloc: enabling scribbling to detect mods to free/ ||
633 $line =~ /Deleted objects will be dirtied by the collector/ ||
634 $line =~ /malloc: stack logs being written into/ ||
635 $line =~ /malloc: stack logs deleted from/ ||
636 $line =~ /malloc: process \d+ no longer exists/ ||
637 $line =~ /malloc: recording malloc and VM allocation stacks/)
643 push @new_output , $line ;
647 @$outputref = @new_output ;
650 sub filter_guardmalloc
652 my $outputref = shift;
657 for my $line ( @$outputref ) {
658 if ( $line !~ /^GuardMalloc\[[^\]]+\]: /) {
659 # not guardmalloc output
660 push @new_output , $line ;
664 # Ignore 4 lines of guardmalloc prologue.
665 # Anything further is a guardmalloc error.
671 @$outputref = @new_output ;
674 $bad .= "(guardmalloc errors)" if ( $errors );
682 sub extract_multiline {
683 my ( $flag , $contents , $name ) = @_ ;
684 if ( $contents =~ / $flag \n /) {
685 my ( $output ) = ( $contents =~ / $flag \n (.*? \n )END[ *\/]* \n /s);
686 die " $name used $flag without END \n " if !defined( $output );
698 sub extract_multiple_multiline {
699 my ( $flag , $contents , $name ) = @_ ;
700 if ( $contents =~ / $flag \n /) {
701 my ( $output ) = ( $contents =~ / $flag \n (.*? \n )END[ *\/]* \n /s);
702 die " $name used $flag without END \n " if !defined( $output );
704 $output =~ s/\nOR\n/\n|/sg;
705 $output = "^(" . $output . ")\$";
718 my $ext = $ALL_TESTS { $name };
719 my $file = " $name . $ext ";
722 # search file for 'TEST_CONFIG' or '#include "test.h"'
723 # also collect other values:
724 # TEST_DISABLED disable test with an optional message
725 # TEST_CRASHES test is expected to crash
726 # TEST_CONFIG test conditions
727 # TEST_ENV environment prefix
728 # TEST_CFLAGS compile flags
729 # TEST_BUILD build instructions
730 # TEST_BUILD_OUTPUT expected build stdout/stderr
731 # TEST_RUN_OUTPUT expected run stdout/stderr
732 open(my $in , "< $file ") || die;
733 my $contents = join "", < $in >;
735 my $test_h = ( $contents =~ /^\s*#\s*(include|import)\s*"test\.h"/m);
736 my ( $disabled ) = ( $contents =~ / \b (TEST_DISABLED \b .*) $/m );
737 my $crashes = ( $contents =~ / \b TEST_CRASHES \b /m);
738 my ( $conditionstring ) = ( $contents =~ / \b TEST_CONFIG \b (.*) $/m );
739 my ( $envstring ) = ( $contents =~ / \b TEST_ENV \b (.*) $/m );
740 my ( $cflags ) = ( $contents =~ / \b TEST_CFLAGS \b (.*) $/m );
741 my ( $buildcmd ) = extract_multiline("TEST_BUILD", $contents , $name );
742 my ( $builderror ) = extract_multiple_multiline("TEST_BUILD_OUTPUT", $contents , $name );
743 my ( $runerror ) = extract_multiple_multiline("TEST_RUN_OUTPUT", $contents , $name );
745 return 0 if ! $test_h && ! $disabled && ! $crashes && !defined( $conditionstring ) && !defined( $envstring ) && !defined( $cflags ) && !defined( $buildcmd ) && !defined( $builderror ) && !defined( $runerror );
748 colorprint $yellow , "SKIP: $name (disabled by $disabled )";
752 # check test conditions
755 my %conditions = readconditions( $conditionstring );
756 if (! $conditions {LANGUAGE}) {
757 # implicit language restriction from file extension
758 $conditions {LANGUAGE} = $languages_for_extension { $ext };
760 for my $condkey (keys %conditions ) {
761 my @condvalues = @{ $conditions { $condkey }};
763 # special case: RUN=0 does not affect build
764 if ( $condkey eq "RUN" && @condvalues == 1 && $condvalues [0] == 0) {
769 my $testvalue = $C { $condkey };
770 next if !defined( $testvalue );
771 # testvalue is the configuration being run now
772 # condvalues are the allowed values for this test
775 for my $condvalue ( @condvalues ) {
777 # special case: objc and objc++
778 if ( $condkey eq "LANGUAGE") {
779 $condvalue = "objective-c" if $condvalue eq "objc";
780 $condvalue = "objective-c++" if $condvalue eq "objc++";
783 $ok = 1 if ( $testvalue eq $condvalue );
785 # special case: CC and CXX allow substring matches
786 if ( $condkey eq "CC" || $condkey eq "CXX") {
787 $ok = 1 if ( $testvalue =~ / $condvalue/ );
794 my $plural = ( @condvalues > 1) ? "one of: " : "";
795 print "SKIP: $name ( $condkey = $testvalue , but test requires $plural ", join(' ', @condvalues ), ") \n ";
800 # save some results for build and run phases
801 $$CREF {"TEST_ $name "} = {
802 TEST_BUILD => $buildcmd ,
803 TEST_BUILD_OUTPUT => $builderror ,
804 TEST_CRASHES => $crashes ,
805 TEST_RUN_OUTPUT => $runerror ,
806 TEST_CFLAGS => $cflags ,
807 TEST_ENV => $envstring ,
809 DSTDIR => " $C {DSTDIR}/ $name .build",
810 OBJDIR => " $C {OBJDIR}/ $name .build",
817 # Test description plist to write when building for BATS execution.
819 $bats_plist {'Project'} = "objc4";
820 $bats_plist {'Tests'} = []; # populated by append_bats_test()
822 # Saves run instructions for a single test in all configurations as a BATS test.
823 sub append_bats_test {
826 my $arch = join(',', @{ $args {ARCH}});
827 my $os = join(',', @{ $args {OSVERSION}});
828 my $mem = join(',', @{ $args {MEM}});
829 my $language = join(',', @{ $args {LANGUAGE}});
831 push @{ $bats_plist {'Tests'}}, {
832 "TestName" => " $name ",
835 " $BATSBASE/test/test .pl",
840 "LANGUAGE= $language ",
850 # Builds a simple test
854 my %T = %{ $C {"TEST_ $name "}};
856 mkdir_verbose $T {DSTDIR};
857 chdir_verbose $T {DSTDIR};
858 # we don't mkdir $T {OBJDIR} because most tests don't use it
860 my $ext = $ALL_TESTS { $name };
861 my $file = " $DIR/$name . $ext ";
863 if ( $T {TEST_CRASHES}) {
864 ` echo
' $crashcatch ' > crashcatch
. c
`;
865 make(" $C {COMPILE_C} -dynamiclib -o libcrashcatch.dylib -x c crashcatch.c");
869 my $cmd = $T {TEST_BUILD} ? eval "return \" $T {TEST_BUILD} \" " : " $C {COMPILE} $T {TEST_CFLAGS} $file -o $name .exe";
871 my $output = make( $cmd );
873 # ignore out-of-date text-based stubs (caused by ditto into SDK)
874 $output =~ s/ld: warning: text-based stub file.*\n//g;
876 $output =~ s/ld: warning: could not create compact unwind for [^\n]+: does not use standard frame\n//g;
878 $output =~ s/^warning: Cannot lower [^\n]+\n//g;
879 $output =~ s/^warning: key: [^\n]+\n//g;
880 $output =~ s/^warning: discriminator: [^\n]+\n//g;
881 $output =~ s/^warning: callee: [^\n]+\n//g;
884 if (my $builderror = $T {TEST_BUILD_OUTPUT}) {
885 # check for expected output and ignore $?
886 if ( $output =~ / $builderror/ ) {
889 colorprint $red , "FAIL: /// test ' $name ' \\\\\\ ";
890 colorprefix $red , $output ;
891 colorprint $red , "FAIL: \\\\\\ test ' $name ' ///";
892 colorprint $red , "FAIL: $name (build output does not match TEST_BUILD_OUTPUT)";
896 colorprint $red , "FAIL: /// test ' $name ' \\\\\\ ";
897 colorprefix $red , $output ;
898 colorprint $red , "FAIL: \\\\\\ test ' $name ' ///";
899 colorprint $red , "FAIL: $name (build failed)";
901 } elsif ( $output ne "") {
902 colorprint $red , "FAIL: /// test ' $name ' \\\\\\ ";
903 colorprefix $red , $output ;
904 colorprint $red , "FAIL: \\\\\\ test ' $name ' ///";
905 colorprint $red , "FAIL: $name (unexpected build output)";
912 foreach my $file (glob("*.exe *.dylib *.bundle")) {
914 # not for BATS to save space and build time
916 make("xcrun dsymutil $file ");
918 if ( $C {OS} eq "macosx" || $C {OS} =~ /simulator/) {
919 # setting any entitlements disables dyld environment variables
921 # get-task-allow entitlement is required
922 # to enable dyld environment variables
923 make("xcrun codesign -s - --entitlements $DIR/get_task_allow_entitlement .plist $file ");
932 # Run a simple test (testname.exe, with error checking of stdout and stderr)
936 my %T = %{ $C {"TEST_ $name "}};
938 if (! $T {TEST_RUN}) {
939 print "PASS: $name (build only) \n ";
943 my $testdir = $T {DSTDIR};
944 chdir_verbose $testdir ;
946 my $env = " $C {ENV} $T {TEST_ENV}";
948 if ( $T {TEST_CRASHES}) {
949 $env .= " OBJC_DEBUG_DONT_CRASH=YES";
954 if ( $C {ARCH} =~ /^arm/ && ` uname
- p
` !~ /^arm/) {
955 # run on iOS or watchos or tvos device
956 # fixme device selection and verification
957 my $remotedir = " $REMOTEBASE/ " . basename( $C {DSTDIR}) . "/ $name .build";
959 # Add test dir and libobjc's dir to DYLD_LIBRARY_PATH.
960 # Insert libcrashcatch.dylib if necessary.
961 $env .= " DYLD_LIBRARY_PATH= $remotedir ";
962 $env .= ": $REMOTEBASE " if ( $C {TESTLIBDIR} ne $TESTLIBDIR );
963 if ( $T {TEST_CRASHES}) {
964 $env .= " DYLD_INSERT_LIBRARIES= $remotedir/libcrashcatch .dylib";
967 my $cmd = "ssh iphone 'cd $remotedir && env $env ./ $name .exe'";
968 $output = make(" $cmd ");
970 elsif ( $C {OS} =~ /simulator/) {
971 # run locally in a simulator
972 # fixme selection of simulated OS version
974 if ( $C {OS} =~ /iphonesimulator/) {
975 $simdevice = 'iPhone 6';
976 } elsif ( $C {OS} =~ /watchsimulator/) {
977 $simdevice = 'Apple Watch Series 4 - 40mm';
978 } elsif ( $C {OS} =~ /tvsimulator/) {
979 $simdevice = 'Apple TV 1080p';
981 die "unknown simulator $C {OS} \n ";
983 my $sim = "xcrun -sdk iphonesimulator simctl spawn ' $simdevice '";
984 # Add test dir and libobjc's dir to DYLD_LIBRARY_PATH.
985 # Insert libcrashcatch.dylib if necessary.
986 $env .= " DYLD_LIBRARY_PATH= $testdir ";
987 $env .= ":" . $C {TESTLIBDIR} if ( $C {TESTLIBDIR} ne $TESTLIBDIR );
988 if ( $T {TEST_CRASHES}) {
989 $env .= " DYLD_INSERT_LIBRARIES= $testdir/libcrashcatch .dylib";
993 foreach my $keyvalue (split(' ', $env )) {
994 $simenv .= "SIMCTL_CHILD_ $keyvalue ";
996 # Use the full path here so hack_cwd in test.h works.
997 $output = make("env $simenv $sim $testdir/$name .exe");
1002 # Add test dir and libobjc's dir to DYLD_LIBRARY_PATH.
1003 # Insert libcrashcatch.dylib if necessary.
1004 $env .= " DYLD_LIBRARY_PATH= $testdir ";
1005 $env .= ":" . $C {TESTLIBDIR} if ( $C {TESTLIBDIR} ne $TESTLIBDIR );
1006 if ( $T {TEST_CRASHES}) {
1007 $env .= " DYLD_INSERT_LIBRARIES= $testdir/libcrashcatch .dylib";
1010 $output = make("sh -c ' $env ./ $name .exe'");
1013 return check_output(\ %C , $name , split(" \n ", $output ));
1019 my ( $cc , $toolchain , $sdk_path ) = @_ ;
1022 my $key = $cc . ':' . $toolchain ;
1023 my $result = $compiler_memo { $key };
1024 return $result if defined $result ;
1026 $result = make("xcrun -toolchain $toolchain -find $cc 2>/dev/null");
1029 $compiler_memo { $key } = $result ;
1033 sub dirContainsAllTestLibs {
1036 foreach my $testlib ( @TESTLIBNAMES ) {
1037 my $found = (-e " $dir/$testlib ");
1038 my $foundstr = ( $found ? "found" : "didn't find");
1039 print "note: $foundstr $testlib in $dir \n " if ( $VERBOSE );
1040 return 0 if (! $found );
1046 sub make_one_config {
1047 my $configref = shift;
1049 my %C = %{ $configref };
1052 $C {LANGUAGE} = "objective-c" if $C {LANGUAGE} eq "objc";
1053 $C {LANGUAGE} = "objective-c++" if $C {LANGUAGE} eq "objc++";
1055 # Interpret OS version string from command line.
1056 my ( $sdk_arg , $deployment_arg , $run_arg , undef) = split('-', $C {OSVERSION});
1057 delete $C {OSVERSION};
1058 my ( $os_arg ) = ( $sdk_arg =~ /^([^\.0-9]+)/);
1059 $deployment_arg = "default" if !defined( $deployment_arg );
1060 $run_arg = "default" if !defined( $run_arg );
1062 my %allowed_os_args = (
1063 "macosx" => "macosx", "osx" => "macosx", "macos" => "macosx",
1064 "iphoneos" => "iphoneos", "ios" => "iphoneos",
1065 "iphonesimulator" => "iphonesimulator", "iossimulator" => "iphonesimulator",
1066 "watchos" => "watchos",
1067 "watchsimulator" => "watchsimulator", "watchossimulator" => "watchsimulator",
1068 "appletvos" => "appletvos", "tvos" => "appletvos",
1069 "appletvsimulator" => "appletvsimulator", "tvsimulator" => "appletvsimulator",
1070 "bridgeos" => "bridgeos",
1073 $C {OS} = $allowed_os_args { $os_arg } || die "unknown OS ' $os_arg ' (expected " . join(', ', sort keys %allowed_os_args ) . ") \n ";
1075 # set the config name now, after massaging the language and OS versions,
1076 # but before adding other settings
1077 my $configname = config_name( %C );
1078 die if ( $configname =~ /'/);
1079 die if ( $configname =~ / /);
1080 ( $C {NAME} = $configname ) =~ s/~/ /g;
1081 (my $configdir = $configname ) =~ s#/##g;
1082 $C {DSTDIR} = " $DSTROOT$BUILDDIR/$configdir ";
1083 $C {OBJDIR} = " $OBJROOT$BUILDDIR/$configdir ";
1085 # Allow tests to see BATS-edness in TEST_CONFIG.
1088 if ( $C {OS} eq "iphoneos" || $C {OS} eq "iphonesimulator") {
1089 $C {TOOLCHAIN} = "ios";
1090 } elsif ( $C {OS} eq "watchos" || $C {OS} eq "watchsimulator") {
1091 $C {TOOLCHAIN} = "watchos";
1092 } elsif ( $C {OS} eq "appletvos" || $C {OS} eq "appletvsimulator") {
1093 $C {TOOLCHAIN} = "appletvos";
1094 } elsif ( $C {OS} eq "bridgeos") {
1095 $C {TOOLCHAIN} = "bridgeos";
1096 } elsif ( $C {OS} eq "macosx") {
1097 $C {TOOLCHAIN} = "osx";
1099 colorprint $yellow , "WARN: don't know toolchain for OS $C {OS}";
1100 $C {TOOLCHAIN} = "default";
1105 # Try exact match first.
1106 # Then try lexically-last prefix match
1107 # (so "macosx" => "macosx10.7internal")
1109 $sdk_arg =~ s/$os_arg/$C{OS}/;
1111 my @sdks = getsdks();
1113 print "note: Installed SDKs: @sdks \n ";
1115 my $exactsdk = undef;
1116 my $prefixsdk = undef;
1117 foreach my $sdk ( @sdks ) {
1118 $exactsdk = $sdk if ( $sdk eq $sdk_arg );
1119 $prefixsdk = newersdk( $sdk , $prefixsdk ) if ( $sdk =~ /^ $sdk_arg/ );
1125 } elsif ( $prefixsdk ) {
1128 die "unknown SDK ' $sdk_arg ' \n Installed SDKs: @sdks \n ";
1131 # Set deployment target.
1132 # fixme can't enforce version when run_arg eq "default"
1133 # because we don't know it yet
1134 $deployment_arg = versionsuffix( $sdk ) if $deployment_arg eq "default";
1135 if ( $run_arg ne "default") {
1136 die "Deployment target ' $deployment_arg ' is newer than run target ' $run_arg ' \n " if $deployment_arg > $run_arg ;
1138 $C {DEPLOYMENT_TARGET} = $deployment_arg ;
1139 $C {SDK_PATH} = getsdkpath( $sdk );
1142 $C {DEPLOYMENT_TARGET} = "unknown_deployment_target";
1143 $C {SDK_PATH} = "/unknown/sdk";
1147 $C {RUN_TARGET} = $run_arg ;
1149 # Look up test library (possible in root or SDK_PATH)
1151 my $rootarg = $root ;
1153 my @sympaths = ( (glob " $root/*~sym ")[0],
1154 (glob " $root/BuildRecords/*_install/Symbols ")[0],
1156 my @dstpaths = ( (glob " $root/*~dst ")[0],
1157 (glob " $root/BuildRecords/*_install/Root ")[0],
1159 for(my $i = 0; $i < scalar( @sympaths ); $i++ ) {
1160 if (-e $sympaths [ $i ] && -e $dstpaths [ $i ]) {
1161 $symroot = $sympaths [ $i ];
1162 $root = $dstpaths [ $i ];
1168 # Root specified. Require that it contain our dylibs.
1169 if (dirContainsAllTestLibs(" $root$C {SDK_PATH} $TESTLIBDIR ")) {
1170 $C {TESTLIBDIR} = " $root$C {SDK_PATH} $TESTLIBDIR ";
1171 } elsif (dirContainsAllTestLibs(" $root$TESTLIBDIR ")) {
1172 $C {TESTLIBDIR} = " $root$TESTLIBDIR ";
1173 } elsif (dirContainsAllTestLibs( $root )) {
1174 $C {TESTLIBDIR} = " $root ";
1176 die "Didn't find some libs in root ' $rootarg ' for sdk ' $C {SDK_PATH}' \n ";
1180 # No root specified. Use the SDK or / for our dylibs.
1181 if (dirContainsAllTestLibs(" $C {SDK_PATH} $TESTLIBDIR ")) {
1182 $C {TESTLIBDIR} = " $C {SDK_PATH} $TESTLIBDIR ";
1184 # We don't actually check in / because on devices
1185 # there are no dylib files there.
1186 $C {TESTLIBDIR} = $TESTLIBDIR ;
1190 @{ $C {TESTLIBS}} = map { " $C {TESTLIBDIR}/ $_ " } @TESTLIBNAMES ;
1191 # convenience for tests that want libobjc.dylib's path
1192 $C {TESTLIB} = @{ $C {TESTLIBS}}[0];
1194 foreach my $testlibname ( @TESTLIBNAMES ) {
1195 if (-e " $symroot/$testlibname .dSYM") {
1196 push(@{ $C {TESTDSYMS}}, " $symroot/$testlibname .dSYM");
1201 foreach my $testlib (@{ $C {TESTLIBS}}) {
1202 my @uuids = ` /usr/ bin
/ dwarfdump
- u
' $testlib ' `;
1203 while (my $uuid = shift @uuids ) {
1204 print "note: $uuid ";
1211 my $cxx = cplusplus( $C {CC});
1212 my $swift = swift( $C {CC});
1218 $C {CC} = find_compiler( $cc , $C {TOOLCHAIN}, $C {SDK_PATH});
1219 $C {CXX} = find_compiler( $cxx , $C {TOOLCHAIN}, $C {SDK_PATH});
1220 $C {SWIFT} = find_compiler( $swift , $C {TOOLCHAIN}, $C {SDK_PATH});
1222 die "No C compiler ' $cc ' (' $C {CC}') in toolchain ' $C {TOOLCHAIN}' \n " if !-e $C {CC};
1223 die "No C++ compiler ' $cxx ' (' $C {CXX}') in toolchain ' $C {TOOLCHAIN}' \n " if !-e $C {CXX};
1224 die "No Swift compiler ' $swift ' (' $C {SWIFT}') in toolchain ' $C {TOOLCHAIN}' \n " if !-e $C {SWIFT};
1227 if ( $C {ARCH} eq "i386" && $C {OS} eq "macosx") {
1228 # libarclite no longer available on i386
1229 # fixme need an archived copy for bincompat testing
1230 $C {FORCE_LOAD_ARCLITE} = "";
1232 $C {FORCE_LOAD_ARCLITE} = "-Xlinker -force_load -Xlinker " . dirname( $C {CC}) . "/../lib/arc/libarclite_ $C {OS}.a";
1237 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} ";
1239 # save-temps so dsymutil works so debug info works.
1240 # Disabled in BATS to save disk space.
1241 # rdar://45656803 -save-temps causes bad -Wstdlibcxx-not-found warnings
1242 $cflags .= "-g -save-temps -Wno-stdlibcxx-not-found";
1245 my $swiftflags = "-g ";
1247 $cflags .= " -isysroot ' $C {SDK_PATH}'";
1248 $cflags .= " '-Wl,-syslibroot, $C {SDK_PATH}'";
1249 $swiftflags .= " -sdk ' $C {SDK_PATH}'";
1251 # Set deployment target cflags
1253 die "No deployment target" if $C {DEPLOYMENT_TARGET} eq "";
1254 if ( $C {OS} eq "iphoneos") {
1255 $cflags .= " -mios-version-min= $C {DEPLOYMENT_TARGET}";
1256 $target = " $C {ARCH}-apple-ios $C {DEPLOYMENT_TARGET}";
1258 elsif ( $C {OS} eq "iphonesimulator") {
1259 $cflags .= " -mios-simulator-version-min= $C {DEPLOYMENT_TARGET}";
1260 $target = " $C {ARCH}-apple-ios $C {DEPLOYMENT_TARGET}";
1262 elsif ( $C {OS} eq "watchos") {
1263 $cflags .= " -mwatchos-version-min= $C {DEPLOYMENT_TARGET}";
1264 $target = " $C {ARCH}-apple-watchos $C {DEPLOYMENT_TARGET}";
1266 elsif ( $C {OS} eq "watchsimulator") {
1267 $cflags .= " -mwatchos-simulator-version-min= $C {DEPLOYMENT_TARGET}";
1268 $target = " $C {ARCH}-apple-watchos $C {DEPLOYMENT_TARGET}";
1270 elsif ( $C {OS} eq "appletvos") {
1271 $cflags .= " -mtvos-version-min= $C {DEPLOYMENT_TARGET}";
1272 $target = " $C {ARCH}-apple-tvos $C {DEPLOYMENT_TARGET}";
1274 elsif ( $C {OS} eq "appletvsimulator") {
1275 $cflags .= " -mtvos-simulator-version-min= $C {DEPLOYMENT_TARGET}";
1276 $target = " $C {ARCH}-apple-tvos $C {DEPLOYMENT_TARGET}";
1278 elsif ( $C {OS} eq "bridgeos") {
1279 $cflags .= " -mbridgeos-version-min= $C {DEPLOYMENT_TARGET}";
1280 $target = " $C {ARCH}-apple-bridgeos $C {DEPLOYMENT_TARGET}";
1283 $cflags .= " -mmacosx-version-min= $C {DEPLOYMENT_TARGET}";
1284 $target = " $C {ARCH}-apple-macosx $C {DEPLOYMENT_TARGET}";
1286 $swiftflags .= " -target $target ";
1288 $C {TESTINCLUDEDIR} = " $C {SDK_PATH}/usr/include";
1289 $C {TESTLOCALINCLUDEDIR} = " $C {SDK_PATH}/usr/local/include";
1291 if ( $C {SDK_PATH} ne "/") {
1292 $cflags .= " -isystem ' $root$C {SDK_PATH}/usr/include'";
1293 $cflags .= " -isystem ' $root$C {SDK_PATH}/usr/local/include'";
1296 my $library_path = $C {TESTLIBDIR};
1297 $cflags .= " -L $library_path ";
1298 # fixme Root vs SDKContentRoot
1299 $C {TESTINCLUDEDIR} = " $root/ ../SDKContentRoot/usr/include";
1300 $C {TESTLOCALINCLUDEDIR} = " $root/ ../SDKContentRoot/usr/local/include";
1301 $cflags .= " -isystem ' $C {TESTINCLUDEDIR}'";
1302 $cflags .= " -isystem ' $C {TESTLOCALINCLUDEDIR}'";
1306 # Populate objcflags
1308 $objcflags .= " -lobjc";
1309 if ( $C {MEM} eq "arc") {
1310 $objcflags .= " -fobjc-arc";
1312 elsif ( $C {MEM} eq "mrc") {
1316 die "unrecognized MEM ' $C {MEM}' \n ";
1319 # Populate ENV_PREFIX
1320 $C {ENV} = "LANG=C MallocScribble=1";
1321 $C {ENV} .= " VERBOSE= $VERBOSE " if $VERBOSE ;
1323 die "no spaces allowed in root" if $C {TESTLIBDIR} =~ /\s+/;
1325 if ( $C {GUARDMALLOC}) {
1326 $C {ENV} .= " GUARDMALLOC=1"; # checked by tests and errcheck.pl
1327 $C {ENV} .= " DYLD_INSERT_LIBRARIES=/usr/lib/libgmalloc.dylib";
1328 if ( $C {GUARDMALLOC} eq "before") {
1329 $C {ENV} .= " MALLOC_PROTECT_BEFORE=1";
1330 } elsif ( $C {GUARDMALLOC} eq "after") {
1331 # protect after is the default
1333 die "Unknown guard malloc mode ' $C {GUARDMALLOC}' \n ";
1337 # Populate compiler commands
1338 $C {XCRUN} = "env LANG=C /usr/bin/xcrun -toolchain ' $C {TOOLCHAIN}'";
1340 $C {COMPILE_C} = " $C {XCRUN} ' $C {CC}' $cflags -x c -std=gnu99";
1341 $C {COMPILE_CXX} = " $C {XCRUN} ' $C {CXX}' $cflags -x c++";
1342 $C {COMPILE_M} = " $C {XCRUN} ' $C {CC}' $cflags $objcflags -x objective-c -std=gnu99";
1343 $C {COMPILE_MM} = " $C {XCRUN} ' $C {CXX}' $cflags $objcflags -x objective-c++";
1344 $C {COMPILE_SWIFT} = " $C {XCRUN} ' $C {SWIFT}' $swiftflags ";
1346 $C {COMPILE} = $C {COMPILE_C} if $C {LANGUAGE} eq "c";
1347 $C {COMPILE} = $C {COMPILE_CXX} if $C {LANGUAGE} eq "c++";
1348 $C {COMPILE} = $C {COMPILE_M} if $C {LANGUAGE} eq "objective-c";
1349 $C {COMPILE} = $C {COMPILE_MM} if $C {LANGUAGE} eq "objective-c++";
1350 $C {COMPILE} = $C {COMPILE_SWIFT} if $C {LANGUAGE} eq "swift";
1351 die "unknown language ' $C {LANGUAGE}' \n " if !defined $C {COMPILE};
1353 ( $C {COMPILE_NOMEM} = $C {COMPILE}) =~ s/ -fobjc-arc\S*//g;
1354 ( $C {COMPILE_NOLINK} = $C {COMPILE}) =~ s/ '?-(?:Wl,|l)\S*//g;
1355 ( $C {COMPILE_NOLINK_NOMEM} = $C {COMPILE_NOMEM}) =~ s/ '?-(?:Wl,|l)\S*//g;
1358 # Reject some self-inconsistent and disallowed configurations
1359 if ( $C {MEM} !~ /^(mrc|arc) $/ ) {
1360 die "unknown MEM= $C {MEM} (expected one of mrc arc) \n ";
1363 if ( $C {MEM} eq "arc" && $C {CC} !~ /clang/) {
1364 print "note: skipping configuration $C {NAME} \n ";
1365 print "note: because CC= $C {CC} does not support MEM= $C {MEM} \n ";
1369 if ( $C {ARCH} eq "i386" && $C {OS} eq "macosx") {
1370 colorprint $yellow , "WARN: skipping configuration $C {NAME} \n ";
1371 colorprint $yellow , "WARN: because 32-bit Mac is dead \n ";
1376 if ( $C {LANGUAGE} eq "swift" && $C {ARCH} =~ /^arm/) {
1377 print "note: skipping configuration $C {NAME} \n ";
1378 print "note: because ARCH= $C {ARCH} does not support LANGUAGE=SWIFT \n ";
1382 # fixme unimplemented run targets
1383 if ( $C {RUN_TARGET} ne "default" && $C {OS} !~ /simulator/) {
1384 colorprint $yellow , "WARN: skipping configuration $C {NAME}";
1385 colorprint $yellow , "WARN: because OS= $C {OS} does not yet implement RUN_TARGET= $C {RUN_TARGET}";
1392 my ( $root , %args ) = @_ ;
1394 my @results = ({}); # start with one empty config
1396 for my $key (keys %args ) {
1398 my @values = @{ $args { $key }};
1399 for my $configref ( @results ) {
1400 my %config = %{ $configref };
1401 for my $value ( @values ) {
1402 my %newconfig = %config ;
1403 $newconfig { $key } = $value ;
1404 push @newresults , \ %newconfig ;
1407 @results = @newresults ;
1411 for my $configref ( @results ) {
1412 if (make_one_config( $configref , $root )) {
1413 push @newresults , $configref ;
1423 for my $key (sort keys %config ) {
1424 $name .= '~' if $name ne "";
1425 $name .= " $key = $config { $key }";
1431 my ( $src , $timeout ) = @_ ;
1432 for (my $i = 0; $i < 10; $i++ ) {
1433 make(" $DIR/timeout .pl $timeout env RSYNC_PASSWORD=alpine rsync -av $src rsync://root\ @localhost :10873/root/ $REMOTEBASE/ ");
1435 colorprint $yellow , "WARN: RETRY \n " if $VERBOSE ;
1437 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 ";
1440 sub build_and_run_one_config {
1450 foreach my $test ( @tests ) {
1452 print " \n GATHER $test \n ";
1455 if ( $ALL_TESTS { $test }) {
1456 gather_simple(\ %C , $test ) || next; # not pass, not fail
1457 push @gathertests , $test ;
1459 die "No test named ' $test ' \n ";
1465 @builttests = @gathertests ;
1466 $testcount = scalar( @gathertests );
1468 foreach my $test ( @gathertests ) {
1470 print " \n BUILD $test \n ";
1473 if ( $ALL_TESTS { $test }) {
1475 if (!build_simple(\ %C , $test )) {
1478 push @builttests , $test ;
1481 die "No test named ' $test ' \n ";
1486 if (! $RUN || !scalar( @builttests )) {
1490 if ( $C {ARCH} =~ /^arm/ && ` uname
- p
` !~ /^arm/) {
1491 # upload timeout - longer for slow watch devices
1492 my $timeout = ( $C {OS} =~ /watch/) ? 120 : 20;
1494 # upload all tests to iOS device
1495 rsync_ios( $C {DSTDIR}, $timeout );
1497 # upload library to iOS device
1498 if ( $C {TESTLIBDIR} ne $TESTLIBDIR ) {
1499 foreach my $thing (@{ $C {TESTLIBS}}, @{ $C {TESTDSYMS}}) {
1500 rsync_ios( $thing , $timeout );
1504 elsif ( $C {OS} =~ /simulator/) {
1505 # run locally in a simulator
1510 # BATS execution tries to run architectures that
1511 # aren't supported by the device. Skip those configs here.
1512 my $machine = ` machine
`;
1515 # running arm64e on non-arm64e device
1516 # running arm64 on non-arm64* device
1517 # running armv7k on non-armv7k device
1518 # running arm64_32 on armv7k device
1519 # We don't need to handle all mismatches here,
1520 # only mismatches that arise within a single OS.
1522 (( $C {ARCH} eq "arm64e" && $machine ne "arm64e") ||
1523 ( $C {ARCH} eq "arm64" && $machine !~ /^arm64/) ||
1524 ( $C {ARCH} eq "armv7k" && $machine ne "armv7k") ||
1525 ( $C {ARCH} eq "arm64_32" && $machine eq "armv7k"));
1527 print "note: skipping configuration $C {NAME} \n ";
1528 print "note: because test arch $C {ARCH} is not " .
1529 "supported on device arch $machine \n ";
1536 foreach my $test ( @builttests ) {
1537 print " \n RUN $test \n " if ( $VERBOSE );
1539 if ( $ALL_TESTS { $test }) {
1540 if (!run_simple(\ %C , $test )) {
1544 die "No test named ' $test ' \n ";
1550 return ( $testcount , $failcount , $skipconfig );
1555 # Return value if set by " $argname =value" on the command line
1556 # Return $default if not set.
1558 my ( $argname , $default ) = @_ ;
1560 foreach my $arg ( @ARGV ) {
1561 my ( $value ) = ( $arg =~ /^ $argname =(.+) $/ );
1562 return [split ',', $value ] if defined $value ;
1565 return [split ',', $default ];
1568 # Return 1 or 0 if set by " $argname =1" or " $argname =0" on the
1569 # command line. Return $default if not set.
1571 my ( $argname , $default ) = @_ ;
1573 my @values = @{getargs( $argname , $default )};
1574 return [( map { ( $_ eq "0") ? 0 : 1 } @values )];
1577 # Return an integer if set by " $argname =value" on the
1578 # command line. Return $default if not set.
1580 my ( $argname , $default ) = @_ ;
1582 my @values = @{getargs( $argname , $default )};
1583 return [( map { int( $_ ) } @values )];
1587 my ( $argname , $default ) = @_ ;
1588 my @values = @{getargs( $argname , $default )};
1589 die "Only one value allowed for $argname \n " if @values > 1;
1594 my ( $argname , $default ) = @_ ;
1595 my @values = @{getbools( $argname , $default )};
1596 die "Only one value allowed for $argname \n " if @values > 1;
1601 my ( $argname , $default ) = @_ ;
1602 my @values = @{getints( $argname , $default )};
1603 die "Only one value allowed for $argname \n " if @values > 1;
1608 my $default_arch = "x86_64";
1609 $args {ARCH} = getargs("ARCH", 0);
1610 $args {ARCH} = getargs("ARCHS", $default_arch ) if !@{ $args {ARCH}}[0];
1612 $args {OSVERSION} = getargs("OS", "macosx-default-default");
1614 $args {MEM} = getargs("MEM", "mrc");
1615 $args {LANGUAGE} = [ map { lc( $_ ) } @{getargs("LANGUAGE", "objective-c")} ];
1617 $args {CC} = getargs("CC", "clang");
1620 my $guardmalloc = getargs("GUARDMALLOC", 0);
1621 # GUARDMALLOC=1 is the same as GUARDMALLOC=before,after
1622 my @guardmalloc2 = ();
1623 for my $arg ( @$guardmalloc ) {
1624 if ( $arg == 1) { push @guardmalloc2 , "before";
1625 push @guardmalloc2 , "after"; }
1626 else { push @guardmalloc2 , $arg }
1628 $args {GUARDMALLOC} = \ @guardmalloc2 ;
1631 $BUILD = getbool("BUILD", 1);
1632 $RUN = getbool("RUN", 1);
1633 $VERBOSE = getint("VERBOSE", 0);
1634 $BATS = getbool("BATS", 0);
1635 $BUILDDIR = getarg("BUILDDIR", $BATS ? $BATSBASE : $LOCALBASE );
1637 my $root = getarg("ROOT", "");
1640 my @tests = gettests();
1643 rm_rf_verbose " $DSTROOT$BUILDDIR ";
1644 rm_rf_verbose " $OBJROOT$BUILDDIR ";
1647 print "note: ----- \n ";
1648 print "note: testing root ' $root ' \n ";
1650 my @configs = make_configs( $root , %args );
1652 print "note: ----- \n ";
1653 print "note: testing ", scalar( @configs ), " configurations: \n ";
1654 for my $configref ( @configs ) {
1655 my $configname = $$configref {NAME};
1656 print "note: configuration $configname \n ";
1661 my $testconfigs = @configs ;
1662 my $failconfigs = 0;
1663 my $skipconfigs = 0;
1666 for my $configref ( @configs ) {
1667 my $configname = $$configref {NAME};
1668 print "note: ----- \n ";
1669 print "note: \n note: $configname \n note: \n ";
1671 (my $t , my $f , my $skipconfig ) =
1672 eval { build_and_run_one_config( $configref , @tests ); };
1673 $skipconfigs += $skipconfig ;
1676 colorprint $red , "FAIL: $configname ";
1677 colorprint $red , "FAIL: $@ ";
1680 my $color = ( $f ? $red : "");
1682 colorprint $color , "note: $configname \n ";
1683 colorprint $color , "note: $t tests, $f failures";
1686 $failconfigs++ if ( $f );
1690 print "note: ----- \n ";
1691 my $color = ( $failconfigs ? $red : "");
1692 colorprint $color , "note: $testconfigs configurations, " .
1693 " $failconfigs with failures, $skipconfigs skipped";
1694 colorprint $color , "note: $testcount tests, $failcount failures";
1696 $failed = ( $failconfigs ? 1 : 0);
1699 if ( $BUILD && $BATS && ! $failed ) {
1700 # Collect BATS execution instructions for all tests.
1701 # Each BATS "test" is all configurations together of one of our tests.
1702 for my $testname ( @tests ) {
1703 append_bats_test( $testname );
1706 # Write the BATS plist to disk.
1707 my $json = encode_json(\ %bats_plist );
1708 my $filename = " $DSTROOT$BATSBASE/objc4 .plist";
1709 print "note: writing BATS config to $filename \n ";
1710 open(my $file , '>', $filename );
1715 exit ( $failed ? 1 : 0);