test.sh 15.4 KB
Newer Older
Drew's avatar
Drew committed
1 2
#!/bin/bash
set -e
Drew's avatar
Drew committed
3 4
UNAME=`uname`

Drew's avatar
Drew committed
5 6 7

echo "**********THE ATBUILD TEST SCRIPT*************"

8
DIR=`pwd`
Drew's avatar
Drew committed
9 10 11 12
ATBUILD="`pwd`/.atllbuild/products/atbuild"
pwd

echo "****************SELF-HOSTING TEST**************"
Drew's avatar
Drew committed
13

14
$ATBUILD atbuild
Drew's avatar
Drew committed
15

Drew's avatar
Drew committed
16 17 18 19 20 21 22
echo "****************DT TEST**************"
cd $DIR/tests/fixtures/deployment_target

if [ "$UNAME" == "Darwin" ]; then
    $ATBUILD --platform ios-x86_64
fi

23 24 25 26 27 28 29 30 31
echo "****************C TEST**************"
cd $DIR/tests/fixtures/c
$ATBUILD
$ATBUILD --configuration release

if [ "$UNAME" == "Darwin" ]; then
    $ATBUILD --platform ios-arm64
fi

Drew's avatar
Drew committed
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
echo "****************CONFIGURATION TEST**************"

cd $DIR/tests/fixtures/configurations
$ATBUILD > /tmp/configurations.txt
if ! grep "debug 0" /tmp/configurations.txt; then
    echo "Invalid configuration behavior"
    exit 1
fi

$ATBUILD --configuration release > /tmp/configurations.txt
if ! grep "release 1" /tmp/configurations.txt; then
    echo "Invalid configuration behavior"
    exit 1
fi

$ATBUILD --configuration custom tool > /tmp/configurations.txt
if ! grep "\-always some flag --bond james bond" /tmp/configurations.txt; then
    echo "Invalid configuration behavior"
    exit 1
fi

53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
## try atllbuild-level config
$ATBUILD --configuration debug build
bin/conftest > /tmp/configurations.txt
if ! grep "Debug build" /tmp/configurations.txt; then
    echo "Invalid configuration behavior"
    exit 1
fi

$ATBUILD --configuration release build
bin/conftest > /tmp/configurations.txt
if ! grep "Release build" /tmp/configurations.txt; then
    echo "Invalid configuration behavior"
    exit 1
fi

$ATBUILD --configuration test build
bin/conftest > /tmp/configurations.txt
if ! grep "Test build" /tmp/configurations.txt; then
    echo "Invalid configuration behavior"
    exit 1
fi

$ATBUILD --configuration bench build
bin/conftest > /tmp/configurations.txt
if ! grep "Bench build" /tmp/configurations.txt; then
    echo "Invalid configuration behavior"
    exit 1
fi

$ATBUILD --configuration JAMES_BOND build
bin/conftest > /tmp/configurations.txt
if ! grep "James bond build" /tmp/configurations.txt; then
    echo "Invalid configuration behavior"
    exit 1
fi

Drew's avatar
Drew committed
89 90


Drew's avatar
Drew committed
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
echo "****************BITCODE TEST**************"
cd $DIR/tests/fixtures/bitcode

#xcode toolchain is only supported on OSX
#and we only support bitcode on the xcode toolchain
if [ "$UNAME" == "Darwin" ]; then
    $ATBUILD --platform ios --toolchain xcode bitcode 

    # verify bitcode sections exist
    if ! otool -l bin/s.atbin/s.a | grep __LLVM; then
        echo "No bitcode for static library"
        exit 1
    fi
    if ! otool -l bin/d.atbin/d.dylib | grep __LLVM; then
        echo "No bitcode for dynamic library"
        exit 1
    fi

    if ! otool -l bin/e.atbin/e | grep __LLVM; then
        echo "No bitcode for executable"
        exit 1
    fi
fi





Drew's avatar
Drew committed
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
echo "****************ONLY-PLATFORMS TEST**************"
cd $DIR/tests/fixtures/only_platforms
$ATBUILD > /tmp/only.txt

if [ "$UNAME" == "Darwin" ]; then
    EXPECT="hello from osx"
    DONTEXPECT="hello from linux"
else
    EXPECT="hello from linux"
    DONTEXPECT="hello from osx"
fi
if ! grep "$EXPECT" /tmp/only.txt; then
    echo "Didn't find $EXPECT in /tmp/only.txt"
    exit 1
fi

if grep "$DONTEXPECT" /tmp/only.txt; then
    echo "Found $DONTEXPECT in /tmp/only.txt"
    exit 1
fi


141 142 143 144
echo "****************EXECUTABLE-NAME TEST**************"
cd $DIR/tests/fixtures/executable_name
$ATBUILD check

Drew's avatar
Drew committed
145 146 147
echo "****************ATBIN TEST**************"
cd $DIR/tests/fixtures/atbin

Drew's avatar
Drew committed
148 149
$ATBUILD use

Drew's avatar
Drew committed
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
$ATBUILD
#did we build all the things we were supposed to?

if [ "$UNAME" == "Darwin" ]; then
    if [ ! -f "bin/dynamicatbin.atbin/osx.swiftmodule" ]; then
        echo "Missing swiftmodule"
        exit 1
    fi
    if [ ! -f "bin/dynamicatbin.atbin/osx.swiftdoc" ]; then
        echo "Missing swiftdoc"
        exit 1
    fi

    if [ ! -f "bin/dynamicatbin.atbin/dlib.dylib" ]; then
        echo "Missing dylib"
        exit 1
    fi

    if [ ! -f "bin/staticatbin.atbin/osx.swiftmodule" ]; then
        echo "Missing swiftmodule"
        exit 1
    fi
    if [ ! -f "bin/staticatbin.atbin/osx.swiftdoc" ]; then
        echo "Missing swiftdoc"
        exit 1
    fi
176 177 178 179 180 181

    if [ ! -f "bin/dynamicatbin-1.0-osx.atbin.tar.xz" ]; then
        echo "Missing compressed atbin"
        exit 1
    fi
    tar xf bin/dynamicatbin-1.0-osx.atbin.tar.xz
Drew's avatar
Drew committed
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
else
    if [ ! -f "bin/dynamicatbin.atbin/linux.swiftmodule" ]; then
        echo "Missing swiftmodule"
        exit 1
    fi
    if [ ! -f "bin/dynamicatbin.atbin/linux.swiftdoc" ]; then
        echo "Missing swiftdoc"
        exit 1
    fi

    if [ ! -f "bin/dynamicatbin.atbin/dlib.so" ]; then
        echo "Missing dylib"
        exit 1
    fi

    if [ ! -f "bin/staticatbin.atbin/linux.swiftmodule" ]; then
        echo "Missing swiftmodule"
        exit 1
    fi
    if [ ! -f "bin/staticatbin.atbin/linux.swiftdoc" ]; then
        echo "Missing swiftdoc"
        exit 1
    fi
205 206 207 208 209 210

    if [ ! -f "bin/dynamicatbin-1.0-linux.atbin.tar.xz" ]; then
        echo "Missing compressed atbin"
        exit 1
    fi
    tar xf bin/dynamicatbin-1.0-linux.atbin.tar.xz
Drew's avatar
Drew committed
211 212 213 214 215 216 217 218 219 220 221 222
fi

# check non-platform-specific-things
if [ ! -f "bin/staticatbin.atbin/module.modulemap" ]; then
    echo "Missing modulemap"
    exit 1
fi
if [ ! -f "bin/dynamicatbin.atbin/module.modulemap" ]; then
    echo "Missing modulemap"
    exit 1
fi

Drew's avatar
Drew committed
223 224
if [ ! -f "bin/staticatbin.atbin/compiled.atpkg" ]; then
    echo "Missing compiled.atpkg"
Drew's avatar
Drew committed
225 226
    exit 1
fi
Drew's avatar
Drew committed
227 228
if [ ! -f "bin/dynamicatbin.atbin/compiled.atpkg" ]; then
    echo "Missing compiled.atpkg"
Drew's avatar
Drew committed
229 230 231
    exit 1
fi

Drew's avatar
Drew committed
232 233
if [ ! -f "bin/executableatbin.atbin/compiled.atpkg" ]; then
    echo "Missing compiled.atpkg"
Drew's avatar
Drew committed
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
    exit 1
fi

if [ ! -f "bin/executableatbin.atbin/exec" ]; then
    echo "Missing payload"
    exit 1
fi

if [ ! -f "bin/staticatbin.atbin/slib.a" ]; then
    echo "Missing payload"
    exit 1
fi


if [ "$UNAME" == "Darwin" ]; then
    $ATBUILD --platform ios

    #check archs
    FILE=`file bin/staticatbin.atbin/slib.a | wc -l | bc`
    if [ "$FILE" != "5" ]; then
        echo "Architecture mismatch (static iOS) $FILE"
        exit 1
    fi 

    FILE=`file bin/executableatbin.atbin/exec | wc -l | bc`
    if [ "$FILE" != "5" ]; then
        echo "Architecture mismatch (executable iOS) $FILE"
        exit 1
    fi 

    FILE=`file bin/dynamicatbin.atbin/dlib.dylib | wc -l | bc`
    if [ "$FILE" != "5" ]; then
        echo "Architecture mismatch (dynamic library iOS) $FILE"
        exit 1
    fi 

    FILE=`file bin/sim.atbin/slib.a | wc -l | bc`
    if [ "$FILE" != "3" ]; then
        echo "Architecture mismatch (sim iOS) $FILE"
        exit 1
    fi 

fi


Drew's avatar
Drew committed
279 280 281 282 283 284 285 286 287
echo "****************USAGE TEST**************"
cd $DIR/tests/fixtures/nonstandard_package_file
$ATBUILD --help > /tmp/usage.txt || true
if ! grep "Usage:" /tmp/usage.txt; then
    echo "Didn't print usage"
    exit 1
fi


Drew's avatar
Drew committed
288
echo "****************PLUGIN TEST**************"
Drew's avatar
Drew committed
289
cd $DIR/tests/fixtures/attool
Drew's avatar
Drew committed
290
$ATBUILD > /tmp/plugin.txt
Drew's avatar
Drew committed
291
if [ "$UNAME" == "Darwin" ]; then
Drew's avatar
Drew committed
292
    SEARCHTEXT="\-bindir .*tests/fixtures/attool/bin --key value --platform osx --test test_substitution --userpath .*tests/fixtures/attool/user --version 1.0"
Drew's avatar
Drew committed
293
else
Drew's avatar
Drew committed
294
    SEARCHTEXT="\-bindir .*tests/fixtures/attool/bin --key value --platform linux --test test_substitution --userpath .*tests/fixtures/attool/user --version 1.0"
Drew's avatar
Drew committed
295 296 297
fi

if ! grep "$SEARCHTEXT" /tmp/plugin.txt; then
Drew's avatar
Drew committed
298 299
    cat /tmp/plugin.txt
    echo "Did not find key print in plugin test"
Drew's avatar
Drew committed
300
    echo $SEARCHTEXT
Drew's avatar
Drew committed
301 302 303
    exit 1
fi

Drew's avatar
Drew committed
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383
echo "****************IOS TEST**************"
cd $DIR/tests/fixtures/ios
if [ "$UNAME" == "Darwin" ]; then
    $ATBUILD --platform ios-x86_64 ##FIXME
    INFO=`lipo -info .atllbuild/products/static.a`
    if [[ "$INFO" != *"architecture: x86_64"* ]]; then
        echo "bad architecture $INFO"
        exit 1
    fi
    INFO=`lipo -info .atllbuild/products/dynamic.dylib`
    if [[ "$INFO" != *"architecture: x86_64"* ]]; then
        echo "bad architecture $INFO"
        exit 1
    fi

    INFO=`lipo -info .atllbuild/products/executable`
    if [[ "$INFO" != *"architecture: x86_64"* ]]; then
        echo "bad architecture $INFO"
        exit 1
    fi


    $ATBUILD --platform ios-i386
    INFO=`lipo -info .atllbuild/products/static.a`
    if [[ "$INFO" != *"architecture: i386"* ]]; then
        echo "bad architecture $INFO"
        exit 1
    fi
    INFO=`lipo -info .atllbuild/products/dynamic.dylib`
    if [[ "$INFO" != *"architecture: i386"* ]]; then
        echo "bad architecture $INFO"
        exit 1
    fi

    INFO=`lipo -info .atllbuild/products/executable`
    if [[ "$INFO" != *"architecture: i386"* ]]; then
        echo "bad architecture $INFO"
        exit 1
    fi

    $ATBUILD --platform ios-arm64
    INFO=`lipo -info .atllbuild/products/static.a`
    if [[ "$INFO" != *"architecture: arm64"* ]]; then
        echo "bad architecture $INFO"
        exit 1
    fi
    INFO=`lipo -info .atllbuild/products/dynamic.dylib`
    if [[ "$INFO" != *"architecture: arm64"* ]]; then
        echo "bad architecture $INFO"
        exit 1
    fi

    INFO=`lipo -info .atllbuild/products/executable`
    if [[ "$INFO" != *"architecture: arm64"* ]]; then
        echo "bad architecture $INFO"
        exit 1
    fi

    $ATBUILD --platform ios-armv7
    INFO=`lipo -info .atllbuild/products/static.a`
    if [[ "$INFO" != *"architecture: armv7"* ]]; then
        echo "bad architecture $INFO"
        exit 1
    fi
    INFO=`lipo -info .atllbuild/products/dynamic.dylib`
    if [[ "$INFO" != *"architecture: armv7"* ]]; then
        echo "bad architecture $INFO"
        exit 1
    fi

    INFO=`lipo -info .atllbuild/products/executable`
    if [[ "$INFO" != *"architecture: armv7"* ]]; then
        echo "bad architecture $INFO"
        exit 1
    fi

else
    echo "Skipping iOS tests on non-Darwin platform"
fi

Drew's avatar
Drew committed
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413
echo "****************PLATFORMS TEST**************"
cd $DIR/tests/fixtures/platforms
UNAME=`uname`
$ATBUILD check 2&> /tmp/platforms.txt
if [ "$UNAME" == "Darwin" ]; then
    STR="Hello from OSX!"
else
    STR="Hello from LINUX!"
fi
if ! grep "$STR" /tmp/platforms.txt; then
    cat /tmp/platforms.txt
    echo "Did not find platform print in platform test"
    exit 1
fi

#check bootstrapping case
$ATBUILD build --use-overlay bootstrap-only --platform linux
if ! cmp --silent bin/bootstrap-platform.yaml known-linux-bootstrap.yaml; then
    echo "Linux bootstrap was unexpected"
    exit 1
fi

$ATBUILD build --use-overlay bootstrap-only --platform osx
if ! cmp --silent bin/bootstrap-platform.yaml known-osx-bootstrap.yaml; then
    echo "OSX bootstrap was unexpected"
    exit 1
fi



Drew's avatar
Drew committed
414 415 416 417
echo "****************XCODE TOOLCHAIN TEST**************"

if [ -e "/Applications/Xcode.app" ]; then
    cd $DIR/tests/fixtures/xcode_toolchain
418
    $ATBUILD --toolchain xcode
Drew's avatar
Drew committed
419 420 421 422
else
    echo "Xcode is not installed; skipping test"
fi

Drew's avatar
Drew committed
423 424 425 426 427 428 429
if [ -e "/Applications/Xcode-beta.app" ]; then
    cd $DIR/tests/fixtures/xcode_toolchain
    $ATBUILD swiftthree --toolchain xcode-beta
else
    echo "Xcode beta toolchain is not installed; skipping test"
fi

430 431 432 433 434 435 436 437
echo "****************PACKAGE FRAMEWORK TESTS**************"
UNAME=`uname`
if [ "$UNAME" == "Darwin" ]; then
    cd $DIR/tests/fixtures/package_framework
    $ATBUILD check
else
    echo "Skipping framework tests on this platform"
fi
438 439 440 441
echo "****************COLLECT SOURCES TEST**************"
cd $DIR/tests/fixtures/collect_sources
$ATBUILD collect-sources 2&> /tmp/sources.txt
if ! grep "sources src/a.swift src/b.swift" /tmp/sources.txt; then
442 443 444
    if ! grep "sources src/b.swift src/a.swift" /tmp/sources.txt; then
        exit 1
    fi
445 446
fi

Drew's avatar
Drew committed
447 448 449 450 451
echo "****************DYNAMIC LIBRARY TEST**************"
cd $DIR/tests/fixtures/dynamic_library
$ATBUILD
.atllbuild/products/dynamic_library_tester

Drew's avatar
Drew committed
452 453
echo "****************WMO TEST**************"
cd $DIR/tests/fixtures/wmo
454
$ATBUILD --configuration release
Drew's avatar
Drew committed
455

456 457
echo "****************UMBRELLA TEST**************"
cd $DIR/tests/fixtures/umbrella_header
Drew's avatar
Drew committed
458
$ATBUILD check
459

Drew's avatar
Drew committed
460 461 462 463 464 465 466 467 468 469 470 471
echo "****************USER PATH TEST**************"
cd $DIR/tests/fixtures/user_paths

$ATBUILD third
RESULT=`cat user/test`
RESULT2="FIRST
SECOND
THIRD"
if [ "$RESULT" != "$RESULT2" ]; then
    echo "Unusual user path concoction $RESULT $RESULT2"
    exit 1
fi
Drew's avatar
Drew committed
472 473 474 475 476
RESULT=`cat bin/test`
if [ "$RESULT" != "$RESULT2" ]; then
    echo "Unusual bin path concoction $RESULT $RESULT2"
    exit 1
fi
Drew's avatar
Drew committed
477 478 479 480

$ATBUILD compile


Drew's avatar
Drew committed
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504
echo "****************PUBLISHPRODUCT TEST**************"
cd $DIR/tests/fixtures/publish_product
$ATBUILD

if [ ! -f "bin/executable" ]; then
    echo "No executable"
    exit 1
fi

if [ ! -f "bin/executable.swiftmodule" ]; then
    echo "No module (executable)"
    exit 1
fi

if [ ! -f "bin/library.swiftmodule" ]; then
    echo "No module (library)"
    exit 1
fi

if [ ! -f "bin/library.a" ]; then
    echo "No library"
    exit 1
fi

505 506 507 508
echo "****************NONSTANDARD TEST**************"
cd $DIR/tests/fixtures/nonstandard_package_file
$ATBUILD -f nonstandard.atpkg

509 510 511 512 513 514
echo "****************AGRESSIVE TEST**************"
cd $DIR/tests/fixtures/agressive
if $ATBUILD 2&> /tmp/warnings.txt; then
    echo "No tool specified but passed anyway?"
    exit 1
fi
Drew's avatar
Drew committed
515
if ! grep "No tool for task agressive.default; did you forget to specify it?" /tmp/warnings.txt; then
516 517 518 519
    echo "Got an error other than one prompting for the correct tool"
    exit 1
fi

520 521 522 523 524 525 526
echo "****************SHADOW TEST*********************"
cd $DIR/tests/fixtures/depend_default
if $ATBUILD build-tests; then
    echo "default task was shadowed; expected a failure but got a pass"
    exit 1
fi

527 528 529 530 531 532 533 534
echo "****************WARNING TEST*********************"
cd $DIR/tests/fixtures/warnings
$ATBUILD > /tmp/warnings.txt
if ! grep "germany" /tmp/warnings.txt; then
    echo "Was not warned about invalid task key"
    exit 1
fi

Drew's avatar
Drew committed
535 536 537 538 539
if ! grep "poland" /tmp/warnings.txt; then
    echo "Was not warmed about invalid package key"
    exit 1
fi

540 541
cd $DIR/tests/fixtures/overlay
$ATBUILD --use-overlay got-overlay > /tmp/warnings.txt
Drew's avatar
Drew committed
542
if grep "Warning: Can't apply overlay no-such-overlay to task chained_overlays.child" /tmp/warnings.txt; then
543 544 545 546
    echo "Got a warning when building the overlay fixture"
    exit 1
fi

Drew's avatar
Drew committed
547 548 549 550 551 552
cd $DIR/tests/fixtures/chained_overlays
$ATBUILD --use-overlay no-such-overlay > /tmp/warnings.txt
if grep "Warning: Can't apply overlay no-such-overlay to task chained_overlays.child" /tmp/warnings.txt; then
    echo "Got a warning when building the chained_overlays fixture"
    exit 1
fi
553

Drew's avatar
Drew committed
554
echo "****************HELP TEST*********************"
555 556

if $ATBUILD atbuild --help; then
Drew's avatar
Drew committed
557 558 559 560
    echo "Unusual help exit code"
    exit 1
fi

Drew's avatar
Drew committed
561
echo "*****************XCS TEST**********************"
562
cd $DIR/tests/fixtures/xcs && $ATBUILD run-tests
Drew's avatar
Drew committed
563

564 565 566 567 568 569 570 571 572 573 574 575 576
echo "*****************STRICT CHECKS**********************"
if [ `uname` != "Darwin" ]; then
    echo "Not checking STRICT for non-Darwin platform"
else
    cd $DIR/tests/fixtures/xcs_strict
    if $ATBUILD run-tests; then
        echo "Expected a failure in xcs_strict"
        exit 1
    else
        echo "Strict failed as expected"
    fi
fi

Drew's avatar
Drew committed
577 578 579
echo "*****************OVERLAY CHECKS**********************"

cd $DIR/tests/fixtures/overlay
Drew's avatar
Drew committed
580 581 582 583
if $ATBUILD; then
    echo "Expected a failure in overlay"
    exit 1
fi
Drew's avatar
Drew committed
584

585
$ATBUILD --use-overlay got-overlay
Drew's avatar
Drew committed
586

587
cd $DIR/tests/fixtures/overlay_default
588
if $ATBUILD --use-overlay foo; then
589 590 591 592
    echo "Expected a failure in overlay"
    exit 1
fi

593 594 595 596 597 598 599 600 601 602 603 604
printf "\e[1m\e[32m***ATBUILD TESTS PASSED SUCCESSFULLY*****\e[0m\n"

echo "*****************PACKAGING**********************"
cd $DIR
if ! $ATBUILD package --use-overlay static --configuration release;  then
    echo "Self-host failed; maybe you're not running CaffeinatedSwift?"
    echo "Retrying with non-static build"
    $ATBUILD package --configuration release
fi


printf "\e[1m\e[32m***ATBUILD BUILT SUCCESSFULLY*****\e[0m\n"