]>
git.saurik.com Git - apple/objc4.git/blob - test/test.pl
10 chomp (my $DIR = `pwd`);
12 my $TESTLIBNAME = "libobjc.A.dylib";
13 my $TESTLIBPATH = "/usr/lib/$TESTLIBNAME";
15 my $BUILDDIR = "/tmp/test-$TESTLIBNAME-build";
18 my $red = "\e[41;37m";
19 my $yellow = "\e[43;37m";
23 if (scalar(@ARGV) == 1) {
25 if ($arg eq "clean") {
26 my $cmd = "rm -rf $BUILDDIR *~";
31 elsif ($arg eq "-h" || $arg eq "-H" || $arg eq "-help" || $arg eq "help") {
33 usage: $0 [options] [testname ...]
38 `testname
` runs a specific test. If no testnames are given, runs all tests.
43 ROOT=/path/to/project.roots/
47 LANGUAGE=c,c++,objective-c,objective-c++,swift
49 STDLIB=libc++,libstdc++
58 test installed library, x86_64, no gc
61 test buildit-built root, i386 and x86_64, MRC and ARC and GC, clang compiler
62 $0 ARCH=i386,x86_64 ROOT=/tmp/libclosure.roots MEM=mrc,arc,gc CC=clang
64 test buildit-built root with iOS simulator
65 $0 ARCH=i386 ROOT=/tmp/libclosure.roots SDK=iphonesimulator
67 test buildit-built root on attached iOS device
68 $0 ARCH=armv7 ROOT=/tmp/libclosure.roots SDK=iphoneos
74 #########################################################################
79 #########################################################################
80 ## Variables for use in complex build and run rules
82 # variable # example value
84 # things you can multiplex on the command line
85 # ARCH=i386,x86_64,armv6,armv7
86 # SDK=macosx,iphoneos,iphonesimulator
87 # LANGUAGE=c,c++,objective-c,objective-c++,swift
88 # CC=clang,gcc-4.2,llvm-gcc-4.2
90 # STDLIB=libc++,libstdc++
93 # things you can set once on the command line
94 # ROOT=/path/to/project.roots
105 my $crashcatch = <<'END';
106 // interpose-able code to catch crashes, print, and exit cleanly
111 // from dyld-interposing.h
112 #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 };
114 static void catchcrash(int sig)
118 case SIGILL: msg = "CRASHED: SIGILL\\n"; break;
119 case SIGBUS: msg = "CRASHED: SIGBUS\\n"; break;
120 case SIGSYS: msg = "CRASHED: SIGSYS\\n"; break;
121 case SIGSEGV: msg = "CRASHED: SIGSEGV\\n"; break;
122 case SIGTRAP: msg = "CRASHED: SIGTRAP\\n"; break;
123 case SIGABRT: msg = "CRASHED: SIGABRT\\n"; break;
124 default: msg = "SIG\?\?\?\?\\n"; break;
126 write(STDERR_FILENO, msg, strlen(msg));
130 static void setupcrash(void) __attribute__((constructor));
131 static void setupcrash(void)
133 signal(SIGILL, &catchcrash);
134 signal(SIGBUS, &catchcrash);
135 signal(SIGSYS, &catchcrash);
136 signal(SIGSEGV, &catchcrash);
137 signal(SIGTRAP, &catchcrash);
138 signal(SIGABRT, &catchcrash);
142 static int hacked = 0;
143 ssize_t hacked_write(int fildes, const void *buf, size_t nbyte)
149 return write(fildes, buf, nbyte);
152 DYLD_INTERPOSE(hacked_write, write);
157 #########################################################################
161 # map language to buildable extensions for that language
162 my %extensions_for_language = (
164 "objective-c" => ["c", "m"],
165 "c++" => ["c", "cc", "cp", "cpp", "cxx", "c++"],
166 "objective-c++" => ["c", "m", "cc", "cp", "cpp", "cxx", "c++", "mm"],
167 "swift" => ["swift"],
169 "any" => ["c", "m", "cc", "cp", "cpp", "cxx", "c++", "mm", "swift"],
172 # map extension to languages
173 my %languages_for_extension = (
174 "c" => ["c", "objective-c", "c++", "objective-c++"],
175 "m" => ["objective-c", "objective-c++"],
176 "mm" => ["objective-c++"],
177 "cc" => ["c++", "objective-c++"],
178 "cp" => ["c++", "objective-c++"],
179 "cpp" => ["c++", "objective-c++"],
180 "cxx" => ["c++", "objective-c++"],
181 "c++" => ["c++", "objective-c++"],
182 "swift" => ["swift"],
185 # Run some newline-separated commands like `make` would, stopping if any fail
186 # run("cmd1 \n cmd2 \n cmd3")
189 my @cmds = split("\n", $_[0]);
190 die if scalar(@cmds) == 0;
192 foreach my $cmd (@cmds) {
194 next if $cmd =~ /^\s*$/;
196 print "$cmd\n" if $VERBOSE;
200 print "$output\n" if $VERBOSE;
207 print "cd $dir\n" if $VERBOSE;
211 # Return test names from the command line.
212 # Returns all tests if no tests were named.
216 foreach my $arg (@ARGV) {
217 push @tests, $arg if ($arg !~ /=/ && $arg !~ /^-/);
220 opendir(my $dir, $DIR) || die;
221 while (my $file = readdir($dir)) {
222 my ($name, $ext) = ($file =~ /^([^.]+)\.([^.]+)$/);
223 next if ! $languages_for_extension{$ext};
225 open(my $in, "< $file") || die "$file";
226 my $contents = join "", <$in>;
227 if (defined $ALL_TESTS{$name}) {
228 print "${yellow}SKIP: multiple tests named '$name'; skipping file '$file'.${def}\n";
230 $ALL_TESTS{$name} = $ext if ($contents =~ m#^[/*\s]*TEST_#m);
236 if (scalar(@tests) == 0) {
237 @tests = keys %ALL_TESTS;
240 @tests = sort @tests;
246 # Turn a C compiler name into a C++ compiler name.
253 return $c . "++"; # e.g. clang => clang++
256 # Turn a C compiler name into a Swift compiler name
259 $c =~ s#[^/]*$#swift#;
263 # Returns an array of all sdks from `xcodebuild
-showsdks
`
267 @sdks_memo = (`xcodebuild
-showsdks
` =~ /-sdk (.+)$/mg);
272 # Returns whether the given sdk supports -lauto
273 sub supportslibauto {
275 return 1 if $sdk =~ /^macosx/;
276 return 0 if $sdk =~ /^iphone/;
280 # print text with a colored prefix on each line
283 while (my @lines = split("\n", shift)) {
284 for my $line (@lines) {
286 print "$color $def$line\n";
295 # parse name=value,value pairs
297 my ($conditionstring) = @_;
300 my @conditions = ($conditionstring =~ /\w+=(?:[^\s,]+,?)+/g);
301 for my $condition (@conditions) {
302 my ($name, $values) = ($condition =~ /(\w+)=(.+)/);
303 $results{$name} = [split ',', $values];
309 # Get the name of the system SDK from sw_vers
311 my @lines = `/usr/bin
/sw_vers
`;
314 for my $line (@lines) {
315 ($name) = ($line =~ /^ProductName:\s+(.*)/) if !$name;
316 ($vers) = ($line =~ /^ProductVersion:\s+(.*)/) if !$vers;
322 if (-d "/usr/local/include/objc") {
323 if ($name eq "macosx") {
324 $internal = "internal";
326 $internal = ".internal";
329 return $name . $vers . $internal;
337 my %T = %{$C{"TEST_$name"}};
339 # Quietly strip MallocScribble before saving the "original" output
340 # because it is distracting.
341 filter_malloc(\@output);
343 my @original_output = @output;
345 # Run result-checking passes, reducing @output each time
349 my $runerror = $T{TEST_RUN_OUTPUT};
350 filter_hax(\@output);
351 filter_verbose(\@output);
352 $warn = filter_warn(\@output);
353 $bad |= filter_guardmalloc(\@output) if ($C{GUARDMALLOC});
354 $bad |= filter_valgrind(\@output) if ($C{VALGRIND});
355 $bad = filter_expected(\@output, \%C, $name) if ($bad eq "");
356 $bad = filter_bad(\@output) if ($bad eq "");
358 # OK line should be the only one left
359 $bad = "(output not 'OK: $name')" if ($bad eq "" && (scalar(@output) != 1 || $output[0] !~ /^OK: $name/));
362 print "${red}FAIL: /// test '$name' \\\\\\$def\n";
363 colorprint($red, @original_output);
364 print "${red}FAIL: \\\\\\ test '$name' ///$def\n";
365 print "${red}FAIL: $name: $bad$def\n";
368 elsif ($warn ne "") {
369 print "${yellow}PASS: /// test '$name' \\\\\\$def\n";
370 colorprint($yellow, @original_output);
371 print "${yellow}PASS: \\\\\\ test '$name' ///$def\n";
372 print "PASS: $name (with warnings)\n";
375 print "PASS: $name\n";
382 my $outputref = shift;
386 my %T = %{$C{"TEST_$name"}};
387 my $runerror = $T{TEST_RUN_OUTPUT} || return "";
391 my $output = join("\n", @$outputref) . "\n";
392 if ($output !~ /$runerror/) {
393 $bad = "(run output does not match TEST_RUN_OUTPUT)";
394 @$outputref = ("FAIL: $name");
396 @$outputref = ("OK: $name"); # pacify later filter
404 my $outputref = shift;
408 for my $line (@$outputref) {
409 if ($line =~ /^BAD: (.*)/) {
412 push @new_output, $line;
416 @$outputref = @new_output;
422 my $outputref = shift;
426 for my $line (@$outputref) {
427 if ($line !~ /^WARN: (.*)/) {
428 push @new_output, $line;
434 @$outputref = @new_output;
440 my $outputref = shift;
443 for my $line (@$outputref) {
444 if ($line !~ /^VERBOSE: (.*)/) {
445 push @new_output, $line;
449 @$outputref = @new_output;
454 my $outputref = shift;
457 for my $line (@$outputref) {
458 if ($line !~ /Class OS_tcp_/) {
459 push @new_output, $line;
463 @$outputref = @new_output;
468 my $outputref = shift;
473 for my $line (@$outputref) {
474 if ($line =~ /^Approx: do_origins_Dirty\([RW]\): missed \d bytes$/) {
475 # --track-origins warning (harmless)
478 if ($line =~ /^UNKNOWN __disable_threadsignal is unsupported. This warning will not be repeated.$/) {
479 # signals unsupported (harmless)
482 if ($line =~ /^UNKNOWN __pthread_sigmask is unsupported. This warning will not be repeated.$/) {
483 # signals unsupported (harmless)
486 if ($line !~ /^^\.*==\d+==/) {
487 # not valgrind output
488 push @new_output, $line;
492 my ($errcount) = ($line =~ /==\d+== ERROR SUMMARY: (\d+) errors/);
493 if (defined $errcount && $errcount > 0) {
497 (my $leakcount) = ($line =~ /==\d+==\s+(?:definitely|possibly) lost:\s+([0-9,]+)/);
498 if (defined $leakcount && $leakcount > 0) {
503 @$outputref = @new_output;
506 $bad .= "(valgrind errors)" if ($errors);
507 $bad .= "(valgrind leaks)" if ($leaks);
515 my $outputref = shift;
520 for my $line (@$outputref) {
521 # Ignore MallocScribble prologue.
522 # Ignore MallocStackLogging prologue.
523 if ($line =~ /malloc: enabling scribbling to detect mods to free/ ||
524 $line =~ /Deleted objects will be dirtied by the collector/ ||
525 $line =~ /malloc: stack logs being written into/ ||
526 $line =~ /malloc: recording malloc and VM allocation stacks/)
532 push @new_output, $line;
536 @$outputref = @new_output;
539 sub filter_guardmalloc
541 my $outputref = shift;
546 for my $line (@$outputref) {
547 if ($line !~ /^GuardMalloc\[[^\]]+\]: /) {
548 # not guardmalloc output
549 push @new_output, $line;
553 # Ignore 4 lines of guardmalloc prologue.
554 # Anything further is a guardmalloc error.
560 @$outputref = @new_output;
563 $bad .= "(guardmalloc errors)" if ($errors);
571 sub extract_multiline {
572 my ($flag, $contents, $name) = @_;
573 if ($contents =~ /$flag\n/) {
574 my ($output) = ($contents =~ /$flag\n(.*?\n)END[ *\/]*\n/s);
575 die "$name used $flag without END\n" if !defined($output);
587 sub extract_multiple_multiline {
588 my ($flag, $contents, $name) = @_;
589 if ($contents =~ /$flag\n/) {
590 my ($output) = ($contents =~ /$flag\n(.*?\n)END[ *\/]*\n/s);
591 die "$name used $flag without END\n" if !defined($output);
593 $output =~ s/\nOR\n/\n|/sg;
594 $output = "^(" . $output . ")\$";
607 my $ext = $ALL_TESTS{$name};
608 my $file = "$name.$ext";
611 # search file for 'TEST_CONFIG' or '#include "test.h"'
612 # also collect other values:
613 # TEST_CONFIG test conditions
614 # TEST_ENV environment prefix
615 # TEST_CFLAGS compile flags
616 # TEST_BUILD build instructions
617 # TEST_BUILD_OUTPUT expected build stdout/stderr
618 # TEST_RUN_OUTPUT expected run stdout/stderr
619 open(my $in, "< $file") || die;
620 my $contents = join "", <$in>;
622 my $test_h = ($contents =~ /^\s*#\s*(include|import)\s*"test\.h"/m);
623 my $disabled = ($contents =~ /\bTEST_DISABLED\b/m);
624 my $crashes = ($contents =~ /\bTEST_CRASHES\b/m);
625 my ($conditionstring) = ($contents =~ /\bTEST_CONFIG\b(.*)$/m);
626 my ($envstring) = ($contents =~ /\bTEST_ENV\b(.*)$/m);
627 my ($cflags) = ($contents =~ /\bTEST_CFLAGS\b(.*)$/m);
628 my ($buildcmd) = extract_multiline("TEST_BUILD", $contents, $name);
629 my ($builderror) = extract_multiple_multiline("TEST_BUILD_OUTPUT", $contents, $name);
630 my ($runerror) = extract_multiple_multiline("TEST_RUN_OUTPUT", $contents, $name);
632 return 0 if !$test_h && !$disabled && !$crashes && !defined($conditionstring) && !defined($envstring) && !defined($cflags) && !defined($buildcmd) && !defined($builderror) && !defined($runerror);
635 print "${yellow}SKIP: $name (disabled by TEST_DISABLED)$def\n";
639 # check test conditions
642 my %conditions = readconditions($conditionstring);
643 if (! $conditions{LANGUAGE}) {
644 # implicit language restriction from file extension
645 $conditions{LANGUAGE} = $languages_for_extension{$ext};
647 for my $condkey (keys %conditions) {
648 my @condvalues = @{$conditions{$condkey}};
650 # special case: RUN=0 does not affect build
651 if ($condkey eq "RUN" && @condvalues == 1 && $condvalues[0] == 0) {
656 my $testvalue = $C{$condkey};
657 next if !defined($testvalue);
658 # testvalue is the configuration being run now
659 # condvalues are the allowed values for this test
662 for my $condvalue (@condvalues) {
664 # special case: objc and objc++
665 if ($condkey eq "LANGUAGE") {
666 $condvalue = "objective-c" if $condvalue eq "objc";
667 $condvalue = "objective-c++" if $condvalue eq "objc++";
670 $ok = 1 if ($testvalue eq $condvalue);
672 # special case: SDK allows prefixes
673 if ($condkey eq "SDK") {
674 $ok = 1 if ($testvalue =~ /^$condvalue/);
677 # special case: CC and CXX allow substring matches
678 if ($condkey eq "CC" || $condkey eq "CXX") {
679 $ok = 1 if ($testvalue =~ /$condvalue/);
686 my $plural = (@condvalues > 1) ? "one of: " : "";
687 print "SKIP: $name ($condkey=$testvalue, but test requires $plural", join(' ', @condvalues), ")\n";
692 # save some results for build and run phases
693 $$CREF{"TEST_$name"} = {
694 TEST_BUILD => $buildcmd,
695 TEST_BUILD_OUTPUT => $builderror,
696 TEST_CRASHES => $crashes,
697 TEST_RUN_OUTPUT => $runerror,
698 TEST_CFLAGS => $cflags,
699 TEST_ENV => $envstring,
706 # Builds a simple test
710 my %T = %{$C{"TEST_$name"}};
711 chdir_verbose "$C{DIR}/$name.build";
713 my $ext = $ALL_TESTS{$name};
714 my $file = "$DIR/$name.$ext";
716 if ($T{TEST_CRASHES}) {
717 `echo
'$crashcatch' > crashcatch
.c
`;
718 make("$C{COMPILE_C} -dynamiclib -o libcrashcatch.dylib -x c crashcatch.c");
722 my $cmd = $T{TEST_BUILD} ? eval "return \"$T{TEST_BUILD}\"" : "$C{COMPILE} $T{TEST_CFLAGS} $file -o $name.out";
724 my $output = make($cmd);
727 $output =~ s/ld: warning: could not create compact unwind for [^\n]+: does not use standard frame\n//g;
730 if (my $builderror = $T{TEST_BUILD_OUTPUT}) {
731 # check for expected output and ignore $?
732 if ($output =~ /$builderror/) {
735 print "${red}FAIL: /// test '$name' \\\\\\$def\n";
736 colorprint $red, $output;
737 print "${red}FAIL: \\\\\\ test '$name' ///$def\n";
738 print "${red}FAIL: $name (build output does not match TEST_BUILD_OUTPUT)$def\n";
742 print "${red}FAIL: /// test '$name' \\\\\\$def\n";
743 colorprint $red, $output;
744 print "${red}FAIL: \\\\\\ test '$name' ///$def\n";
745 print "${red}FAIL: $name (build failed)$def\n";
747 } elsif ($output ne "") {
748 print "${red}FAIL: /// test '$name' \\\\\\$def\n";
749 colorprint $red, $output;
750 print "${red}FAIL: \\\\\\ test '$name' ///$def\n";
751 print "${red}FAIL: $name (unexpected build output)$def\n";
759 foreach my $file (glob("*.out *.dylib *.bundle")) {
760 make("dsymutil $file");
767 # Run a simple test (testname.out, with error checking of stdout and stderr)
771 my %T = %{$C{"TEST_$name"}};
773 if (! $T{TEST_RUN}) {
774 print "PASS: $name (build only)\n";
778 chdir_verbose "$C{DIR}/$name.build";
781 my $env = "$C{ENV} $T{TEST_ENV}";
782 if ($T{TEST_CRASHES}) {
783 $env .= " DYLD_INSERT_LIBRARIES=libcrashcatch.dylib";
788 if ($C{ARCH} =~ /^arm/ && `unamep
-p
` !~ /^arm/) {
791 my $remotedir = "/var/root/test/" . basename($C{DIR}) . "/$name.build";
793 $remotedyld .= " DYLD_LIBRARY_PATH=$remotedir";
794 $remotedyld .= ":/var/root/test/" if ($C{TESTLIB} ne $TESTLIBPATH);
796 # elide host-specific paths
797 $env =~ s/DYLD_LIBRARY_PATH=\S+//;
798 $env =~ s/DYLD_ROOT_PATH=\S+//;
800 my $cmd = "ssh iphone 'cd $remotedir && env $env $remotedyld ./$name.out'";
801 $output = make("$cmd");
806 my $cmd = "env $env ./$name.out";
807 $output = make("sh -c '$cmd 2>&1' 2>&1");
808 # need extra sh level to capture "sh: Illegal instruction" after crash
809 # fixme fail if $? except tests that expect to crash
812 return check_output(\%C, $name, split("\n", $output));
818 my ($cc, $sdk, $sdk_path) = @_;
821 my $key = $cc . ':' . $sdk;
822 my $result = $compiler_memo{$key};
823 return $result if defined $result;
825 $result = `xcrun
-sdk
$sdk -find
$cc 2>/dev/null
`;
828 $compiler_memo{$key} = $result;
832 sub make_one_config {
833 my $configref = shift;
835 my %C = %{$configref};
838 $C{LANGUAGE} = "objective-c" if $C{LANGUAGE} eq "objc";
839 $C{LANGUAGE} = "objective-c++" if $C{LANGUAGE} eq "objc++";
842 # Try exact match first.
843 # Then try lexically-last prefix match (so "macosx" => "macosx10.7internal").
844 my @sdks = getsdks();
846 print "Installed SDKs: @sdks\n";
848 my $exactsdk = undef;
849 my $prefixsdk = undef;
850 foreach my $sdk (@sdks) {
852 $exactsdk = $sdk if ($sdk eq $SDK);
853 # check for digits to prevent e.g. "iphone" => "iphonesimulator4.2"
854 $prefixsdk = $sdk if ($sdk =~ /^$SDK[0-9]/ && $sdk gt $prefixsdk);
858 } elsif ($prefixsdk) {
859 $C{SDK} = $prefixsdk;
861 die "unknown SDK '$C{SDK}'\nInstalled SDKs: @sdks\n";
864 # set the config name now, after massaging the language and sdk,
865 # but before adding other settings
866 my $configname = config_name(%C);
867 die if ($configname =~ /'/);
868 die if ($configname =~ / /);
869 ($C{NAME} = $configname) =~ s/~/ /g;
870 (my $configdir = $configname) =~ s#/##g;
871 $C{DIR} = "$BUILDDIR/$configdir";
873 ($C{SDK_PATH}) = (`xcodebuild
-version
-sdk
$C{SDK
} Path
` =~ /^\s*(.+?)\s*$/);
875 # Look up test library (possible in root or SDK_PATH)
879 my @sympaths = ( (glob "$root/*~sym")[0],
880 (glob "$root/BuildRecords/*_install/Symbols")[0],
882 my @dstpaths = ( (glob "$root/*~dst")[0],
883 (glob "$root/BuildRecords/*_install/Root")[0],
885 for(my $i = 0; $i < scalar(@sympaths); $i++) {
886 if (-e $sympaths[$i] && -e $dstpaths[$i]) {
887 $symroot = $sympaths[$i];
888 $root = $dstpaths[$i];
893 if ($root ne "" && -e "$root$C{SDK_PATH}$TESTLIBPATH") {
894 $C{TESTLIB} = "$root$C{SDK_PATH}$TESTLIBPATH";
895 } elsif (-e "$root$TESTLIBPATH") {
896 $C{TESTLIB} = "$root$TESTLIBPATH";
897 } elsif (-e "$root/$TESTLIBNAME") {
898 $C{TESTLIB} = "$root/$TESTLIBNAME";
900 die "No $TESTLIBNAME in root '$rootarg' for sdk '$C{SDK_PATH}'\n"
901 # . join("\n", @dstpaths) . "\n"
905 if (-e "$symroot/$TESTLIBNAME.dSYM") {
906 $C{TESTDSYM} = "$symroot/$TESTLIBNAME.dSYM";
910 my @uuids = `/usr/bin
/dwarfdump
-u
'$C{TESTLIB}'`;
911 while (my $uuid = shift @uuids) {
918 my $cxx = cplusplus($C{CC});
919 my $swift = swift($C{CC});
925 $C{CC} = find_compiler($cc, $C{SDK}, $C{SDK_PATH});
926 $C{CXX} = find_compiler($cxx, $C{SDK}, $C{SDK_PATH});
927 $C{SWIFT} = find_compiler($swift, $C{SDK}, $C{SDK_PATH});
929 die "No compiler '$cc' ('$C{CC}') in SDK '$C{SDK}'\n" if !-e $C{CC};
930 die "No compiler '$cxx' ('$C{CXX}') in SDK '$C{SDK}'\n" if !-e $C{CXX};
931 die "No compiler '$swift' ('$C{SWIFT}') in SDK '$C{SDK}'\n" if !-e $C{SWIFT};
936 # save-temps so dsymutil works so debug info works
937 my $cflags = "-I$DIR -W -Wall -Wno-deprecated-declarations -Wshorten-64-to-32 -g -save-temps -Os -arch $C{ARCH} ";
939 my $swiftflags = "-g ";
941 $cflags .= " -isysroot '$C{SDK_PATH}'";
942 $cflags .= " '-Wl,-syslibroot,$C{SDK_PATH}'";
943 $swiftflags .= " -sdk '$C{SDK_PATH}'";
946 if ($C{SDK} =~ /^iphoneos[0-9]/ && $cflags !~ /-mios-version-min/) {
947 my ($vers) = ($C{SDK} =~ /^iphoneos([0-9]+\.[0-9]+)/);
948 $cflags .= " -mios-version-min=$vers";
949 $target = "$C{ARCH}-apple-ios$vers";
951 elsif ($C{SDK} =~ /^iphonesimulator[0-9]/ && $cflags !~ /-mios-simulator-version-min/) {
952 my ($vers) = ($C{SDK} =~ /^iphonesimulator([0-9]+\.[0-9]+)/);
953 $cflags .= " -mios-simulator-version-min=$vers";
954 $target = "$C{ARCH}-apple-ios$vers";
957 my ($vers) = ($C{SDK} =~ /^macosx([0-9]+\.[0-9]+)/);
958 $vers = "" if !defined($vers);
959 $target = "$C{ARCH}-apple-macosx$vers";
961 $swiftflags .= " -target $target";
963 if ($C{SDK} =~ /^iphonesimulator/ && $C{ARCH} eq "i386") {
964 $objcflags .= " -fobjc-abi-version=2 -fobjc-legacy-dispatch";
968 my $library_path = dirname($C{TESTLIB});
969 $cflags .= " -L$library_path";
970 $cflags .= " -I '$root/usr/include'";
971 $cflags .= " -I '$root/usr/local/include'";
973 if ($C{SDK_PATH} ne "/") {
974 $cflags .= " -I '$root$C{SDK_PATH}/usr/include'";
975 $cflags .= " -I '$root$C{SDK_PATH}/usr/local/include'";
979 if ($C{CC} =~ /clang/) {
980 $cflags .= " -Qunused-arguments -fno-caret-diagnostics";
981 $cflags .= " -stdlib=$C{STDLIB}"; # fixme -fno-objc-link-runtime"
982 $cflags .= " -Wl,-segalign,0x4000 ";
988 $objcflags .= " -lobjc";
989 if ($C{MEM} eq "gc") {
990 $objcflags .= " -fobjc-gc";
992 elsif ($C{MEM} eq "arc") {
993 $objcflags .= " -fobjc-arc";
995 elsif ($C{MEM} eq "mrc") {
999 die "unrecognized MEM '$C{MEM}'\n";
1002 if (supportslibauto($C{SDK})) {
1003 # do this even for non-GC tests
1004 $objcflags .= " -lauto";
1007 # Populate ENV_PREFIX
1008 $C{ENV} = "LANG=C MallocScribble=1";
1009 $C{ENV} .= " VERBOSE=1" if $VERBOSE;
1011 my $library_path = dirname($C{TESTLIB});
1012 die "no spaces allowed in root" if $library_path =~ /\s+/;
1013 $C{ENV} .= " DYLD_LIBRARY_PATH=$library_path" if ($library_path ne "/usr/lib");
1015 if ($C{SDK_PATH} ne "/") {
1016 die "no spaces allowed in sdk" if $C{SDK_PATH} =~ /\s+/;
1017 $C{ENV} .= " DYLD_ROOT_PATH=$C{SDK_PATH}";
1019 if ($C{GUARDMALLOC}) {
1020 $ENV{GUARDMALLOC} = "1"; # checked by tests and errcheck.pl
1021 $C{ENV} .= " DYLD_INSERT_LIBRARIES=/usr/lib/libgmalloc.dylib";
1023 if ($C{SDK} =~ /^iphonesimulator[0-9]/) {
1024 my ($vers) = ($C{SDK} =~ /^iphonesimulator([0-9]+\.[0-9+])/);
1026 " CFFIXED_USER_HOME=$ENV{HOME}/Library/Application\\ Support/iPhone\\ Simulator/$vers" .
1027 " IPHONE_SIMULATOR_ROOT=$C{SDK_PATH}" .
1028 " IPHONE_SHARED_RESOURCES_DIRECTORY=$ENV{HOME}/Library/Application\\ Support/iPhone\\ Simulator/$vers";
1031 # Populate compiler commands
1032 $C{COMPILE_C} = "env LANG=C '$C{CC}' $cflags -x c -std=gnu99";
1033 $C{COMPILE_CXX} = "env LANG=C '$C{CXX}' $cflags -x c++";
1034 $C{COMPILE_M} = "env LANG=C '$C{CC}' $cflags $objcflags -x objective-c -std=gnu99";
1035 $C{COMPILE_MM} = "env LANG=C '$C{CXX}' $cflags $objcflags -x objective-c++";
1036 $C{COMPILE_SWIFT} = "env LANG=C '$C{SWIFT}' $swiftflags";
1038 $C{COMPILE} = $C{COMPILE_C} if $C{LANGUAGE} eq "c";
1039 $C{COMPILE} = $C{COMPILE_CXX} if $C{LANGUAGE} eq "c++";
1040 $C{COMPILE} = $C{COMPILE_M} if $C{LANGUAGE} eq "objective-c";
1041 $C{COMPILE} = $C{COMPILE_MM} if $C{LANGUAGE} eq "objective-c++";
1042 $C{COMPILE} = $C{COMPILE_SWIFT} if $C{LANGUAGE} eq "swift";
1043 die "unknown language '$C{LANGUAGE}'\n" if !defined $C{COMPILE};
1045 ($C{COMPILE_NOMEM} = $C{COMPILE}) =~ s/ -fobjc-(?:gc|arc)\S*//g;
1046 ($C{COMPILE_NOLINK} = $C{COMPILE}) =~ s/ '?-(?:Wl,|l)\S*//g;
1047 ($C{COMPILE_NOLINK_NOMEM} = $C{COMPILE_NOMEM}) =~ s/ '?-(?:Wl,|l)\S*//g;
1050 # Reject some self-inconsistent configurations
1051 if ($C{MEM} !~ /^(mrc|arc|gc)$/) {
1052 die "unknown MEM=$C{MEM} (expected one of mrc arc gc)\n";
1055 if ($C{MEM} eq "gc" && $C{SDK} =~ /^iphone/) {
1056 print "note: skipping configuration $C{NAME}\n";
1057 print "note: because SDK=$C{SDK} does not support MEM=$C{MEM}\n";
1060 if ($C{MEM} eq "arc" && $C{SDK} !~ /^iphone/ && $C{ARCH} eq "i386") {
1061 print "note: skipping configuration $C{NAME}\n";
1062 print "note: because 32-bit Mac does not support MEM=$C{MEM}\n";
1065 if ($C{MEM} eq "arc" && $C{CC} !~ /clang/) {
1066 print "note: skipping configuration $C{NAME}\n";
1067 print "note: because CC=$C{CC} does not support MEM=$C{MEM}\n";
1071 if ($C{STDLIB} ne "libstdc++" && $C{CC} !~ /clang/) {
1072 print "note: skipping configuration $C{NAME}\n";
1073 print "note: because CC=$C{CC} does not support STDLIB=$C{STDLIB}\n";
1078 if ($C{LANGUAGE} eq "swift" && $C{ARCH} =~ /^arm/) {
1079 print "note: skipping configuration $C{NAME}\n";
1080 print "note: because ARCH=$C{ARCH} does not support LANGAUGE=SWIFT\n";
1088 my ($root, %args) = @_;
1090 my @results = ({}); # start with one empty config
1092 for my $key (keys %args) {
1094 my @values = @{$args{$key}};
1095 for my $configref (@results) {
1096 my %config = %{$configref};
1097 for my $value (@values) {
1098 my %newconfig = %config;
1099 $newconfig{$key} = $value;
1100 push @newresults, \%newconfig;
1103 @results = @newresults;
1107 for my $configref(@results) {
1108 if (make_one_config($configref, $root)) {
1109 push @newresults, $configref;
1119 for my $key (sort keys %config) {
1120 $name .= '~' if $name ne "";
1121 $name .= "$key=$config{$key}";
1126 sub run_one_config {
1135 foreach my $test (@tests) {
1137 print "\nGATHER $test\n";
1140 if ($ALL_TESTS{$test}) {
1141 gather_simple(\%C, $test) || next; # not pass, not fail
1142 push @gathertests, $test;
1144 die "No test named '$test'\n";
1150 @builttests = @gathertests;
1151 $testcount = scalar(@gathertests);
1153 my $configdir = $C{DIR};
1154 print $configdir, "\n" if $VERBOSE;
1155 mkdir $configdir || die;
1157 foreach my $test (@gathertests) {
1159 print "\nBUILD $test\n";
1161 mkdir "$configdir/$test.build" || die;
1163 if ($ALL_TESTS{$test}) {
1165 if (!build_simple(\%C, $test)) {
1168 push @builttests, $test;
1171 die "No test named '$test'\n";
1176 if (!$RUN || !scalar(@builttests)) {
1180 if ($C{ARCH} =~ /^arm/ && `unamep
-p
` !~ /^arm/) {
1181 # upload all tests to iOS device
1182 make("RSYNC_PASSWORD=alpine rsync -av $C{DIR} rsync://root\@localhost:10873/root/var/root/test/");
1183 die "Couldn't rsync tests to device\n" if ($?);
1185 # upload library to iOS device
1186 if ($C{TESTLIB} ne $TESTLIBPATH) {
1187 make("RSYNC_PASSWORD=alpine rsync -av $C{TESTLIB} rsync://root\@localhost:10873/root/var/root/test/");
1188 die "Couldn't rsync $C{TESTLIB} to device\n" if ($?);
1189 make("RSYNC_PASSWORD=alpine rsync -av $C{TESTDSYM} rsync://root\@localhost:10873/root/var/root/test/");
1193 foreach my $test (@builttests) {
1194 print "\nRUN $test\n" if ($VERBOSE);
1196 if ($ALL_TESTS{$test})
1198 if (!run_simple(\%C, $test)) {
1202 die "No test named '$test'\n";
1207 return ($testcount, $failcount);
1212 # Return value if set by "$argname=value" on the command line
1213 # Return $default if not set.
1215 my ($argname, $default) = @_;
1217 foreach my $arg (@ARGV) {
1218 my ($value) = ($arg =~ /^$argname=(.+)$/);
1219 return [split ',', $value] if defined $value;
1222 return [split ',', $default];
1225 # Return 1 or 0 if set by "$argname=1" or "$argname=0" on the
1226 # command line. Return $default if not set.
1228 my ($argname, $default) = @_;
1230 my @values = @{getargs($argname, $default)};
1231 return [( map { ($_ eq "0") ? 0 : 1 } @values )];
1235 my ($argname, $default) = @_;
1236 my @values = @{getargs($argname, $default)};
1237 die "Only one value allowed for $argname\n" if @values > 1;
1242 my ($argname, $default) = @_;
1243 my @values = @{getbools($argname, $default)};
1244 die "Only one value allowed for $argname\n" if @values > 1;
1253 my $default_arch = (`/usr/sbin
/sysctl hw
.optional
.x86_64
` eq "hw.optional.x86_64: 1\n") ? "x86_64" : "i386";
1254 $args{ARCH} = getargs("ARCH", 0);
1255 $args{ARCH} = getargs("ARCHS", $default_arch) if !@{$args{ARCH}}[0];
1257 $args{SDK} = getargs("SDK", "macosx");
1259 $args{MEM} = getargs("MEM", "mrc");
1260 $args{LANGUAGE} = [ map { lc($_) } @{getargs("LANGUAGE", "objective-c,swift")} ];
1261 $args{STDLIB} = getargs("STDLIB", "libstdc++");
1263 $args{CC} = getargs("CC", "clang");
1265 $args{GUARDMALLOC} = getbools("GUARDMALLOC", 0);
1267 $BUILD = getbool("BUILD", 1);
1268 $RUN = getbool("RUN", 1);
1269 $VERBOSE = getbool("VERBOSE", 0);
1271 my $root = getarg("ROOT", "");
1274 my @tests = gettests();
1276 print "note: -----\n";
1277 print "note: testing root '$root'\n";
1279 my @configs = make_configs($root, %args);
1281 print "note: -----\n";
1282 print "note: testing ", scalar(@configs), " configurations:\n";
1283 for my $configref (@configs) {
1284 my $configname = $$configref{NAME};
1285 print "note: configuration $configname\n";
1289 `rm
-rf
'$BUILDDIR'`;
1290 mkdir "$BUILDDIR" || die;
1295 my $testconfigs = @configs;
1296 my $failconfigs = 0;
1299 for my $configref (@configs) {
1300 my $configname = $$configref{NAME};
1301 print "note: -----\n";
1302 print "note: \nnote: $configname\nnote: \n";
1304 (my $t, my $f) = eval { run_one_config($configref, @tests); };
1307 print "${red}FAIL: $configname${def}\n";
1308 print "${red}FAIL: $@${def}\n";
1311 my $color = ($f ? $red : "");
1313 print "${color}note: $configname$def\n";
1314 print "${color}note: $t tests, $f failures$def\n";
1317 $failconfigs++ if ($f);
1321 print "note: -----\n";
1322 my $color = ($failconfigs ? $red : "");
1323 print "${color}note: $testconfigs configurations, $failconfigs with failures$def\n";
1324 print "${color}note: $testcount tests, $failcount failures$def\n";
1326 $failed = ($failconfigs ? 1 : 0);
1328 exit ($failed ? 1 : 0);