From 5a4cc333fbd3757b5f51f6cb140e8955d26f683c Mon Sep 17 00:00:00 2001 From: Geza Lore Date: Mon, 22 Jun 2020 10:13:54 +0100 Subject: [PATCH] Travis: Add OS X build (#2440) --- .travis.yml | 7 ++ ci/travis-install.bash | 11 ++- ci/travis-script.bash | 130 +++++++++++++------------ configure.ac | 6 -- examples/make_protect_lib/Makefile | 2 +- src/Makefile_obj.in | 1 - test_regress/t/t_case_huge_prof.pl | 62 +++++++----- test_regress/t/t_flag_ldflags.pl | 13 +++ test_regress/t/t_prot_lib.pl | 2 +- test_regress/t/t_prot_lib_clk_gated.pl | 2 +- 10 files changed, 137 insertions(+), 99 deletions(-) diff --git a/.travis.yml b/.travis.yml index aeb2146eb..4eba3d177 100644 --- a/.travis.yml +++ b/.travis.yml @@ -70,6 +70,8 @@ jobs: - {stage: build, os: linux, dist: focal, compiler: clang, workspaces: {create: {name: focal-clang, paths: .}}} # Coverage build - {stage: build, if: type = cron, os: linux, dist: focal, compiler: gcc, workspaces: {create: {name: coverage, paths: .}}, env: COVERAGE=1} + # OS X build + - {stage: build, if: type = cron, os: osx, osx_image: xcode11.6, compiler: clang, workspaces: {create: {name: osx-xcode11.6, paths: .}}} ############################################################################ # Jobs in the 'test' stage ############################################################################ @@ -109,6 +111,11 @@ jobs: - {stage: test, if: type = cron, os: linux, dist: focal, compiler: gcc, workspaces: {use: coverage}, git: {clone: false}, env: TESTS=coverage-vltmt-1} - {stage: test, if: type = cron, os: linux, dist: focal, compiler: gcc, workspaces: {use: coverage}, git: {clone: false}, env: TESTS=coverage-vltmt-2} - {stage: test, if: type = cron, os: linux, dist: focal, compiler: gcc, workspaces: {use: coverage}, git: {clone: false}, env: TESTS=coverage-vltmt-3} + # OS X tests + - {stage: test, if: type = cron, os: osx, osx_image: xcode11.6, compiler: clang, workspaces: {use: osx-xcode11.6}, git: {clone: false}, env: TESTS=dist-vlt-0} + - {stage: test, if: type = cron, os: osx, osx_image: xcode11.6, compiler: clang, workspaces: {use: osx-xcode11.6}, git: {clone: false}, env: TESTS=dist-vlt-1} + - {stage: test, if: type = cron, os: osx, osx_image: xcode11.6, compiler: clang, workspaces: {use: osx-xcode11.6}, git: {clone: false}, env: TESTS=vltmt-0} + - {stage: test, if: type = cron, os: osx, osx_image: xcode11.6, compiler: clang, workspaces: {use: osx-xcode11.6}, git: {clone: false}, env: TESTS=vltmt-1} notifications: email: diff --git a/ci/travis-install.bash b/ci/travis-install.bash index 6fb552ca5..038e91b91 100755 --- a/ci/travis-install.bash +++ b/ci/travis-install.bash @@ -39,12 +39,15 @@ if [ "$TRAVIS_BUILD_STAGE_NAME" = "build" ]; then # build Verilator if [ "$TRAVIS_OS_NAME" = "linux" ]; then - time sudo apt-get update + sudo apt-get update sudo apt-get install libfl-dev sudo apt-get install libgoogle-perftools-dev if [ "$COVERAGE" = 1 ]; then yes yes | sudo cpan -fi Unix::Processors Parallel::Forker fi + elif [ "$TRAVIS_OS_NAME" = "osx" ]; then + brew update + brew install ccache perl gperftools else fatal "Unknown os: '$TRAVIS_OS_NAME'" fi @@ -62,6 +65,12 @@ elif [ "$TRAVIS_BUILD_STAGE_NAME" = "test" ]; then yes yes | sudo cpan -fi Unix::Processors Parallel::Forker # Not listing Bit::Vector as slow to install, and only skips one test install-vcddiff + elif [ "$TRAVIS_OS_NAME" = "osx" ]; then + brew update + # brew cask install gtkwave # fst2vcd hangs at launch, so don't bother + brew install ccache perl + yes yes | sudo cpan -fi Unix::Processors Parallel::Forker + install-vcddiff else fatal "Unknown os: '$TRAVIS_OS_NAME'" fi diff --git a/ci/travis-script.bash b/ci/travis-script.bash index e87e62429..0a3c26778 100755 --- a/ci/travis-script.bash +++ b/ci/travis-script.bash @@ -22,77 +22,85 @@ fatal() { echo "ERROR: $(basename "$0"): $1" >&2; exit 1; } +if [ "$TRAVIS_OS_NAME" = "linux" ]; then + NPROC=$(nproc) +elif [ "$TRAVIS_OS_NAME" = "osx" ]; then + NPROC=$(sysctl -n hw.logicalcpu) +else + fatal "Unknown os: '$TRAVIS_OS_NAME'" +fi + if [ "$TRAVIS_BUILD_STAGE_NAME" = "build" ]; then ############################################################################## # Build verilator - if [ "$TRAVIS_OS_NAME" = "linux" ]; then - if [ "$COVERAGE" != 1 ]; then - autoconf - ./configure --enable-longtests --enable-ccwarn - make -j $(nproc) - else - nodist/code_coverage --stages 1-2 - fi + if [ "$COVERAGE" != 1 ]; then + autoconf + ./configure --enable-longtests --enable-ccwarn + make -j "$NPROC" + file bin/verilator_bin + file bin/verilator_bin_dbg else - fatal "Unknown os: '$TRAVIS_OS_NAME'" + nodist/code_coverage --stages 1-2 fi elif [ "$TRAVIS_BUILD_STAGE_NAME" = "test" ]; then ############################################################################## # Run tests - if [ "$TRAVIS_OS_NAME" = "linux" ]; then - # Run the specified test - case $TESTS in - dist-vlt-0) - make -C test_regress SCENARIOS="--dist --vlt" DRIVER_HASHSET=--hashset=0/2 - ;; - dist-vlt-1) - make -C test_regress SCENARIOS="--dist --vlt" DRIVER_HASHSET=--hashset=1/2 - ;; - vltmt-0) - make -C test_regress SCENARIOS=--vltmt DRIVER_HASHSET=--hashset=0/2 - ;; - vltmt-1) - make -C test_regress SCENARIOS=--vltmt DRIVER_HASHSET=--hashset=1/2 - ;; - coverage-dist) - nodist/code_coverage --stages 3- --scenarios=--dist - ;; - coverage-vlt-0) - nodist/code_coverage --stages 3- --scenarios=--vlt --hashset=0/4 - ;; - coverage-vlt-1) - nodist/code_coverage --stages 3- --scenarios=--vlt --hashset=1/4 - ;; - coverage-vlt-2) - nodist/code_coverage --stages 3- --scenarios=--vlt --hashset=2/4 - ;; - coverage-vlt-3) - nodist/code_coverage --stages 3- --scenarios=--vlt --hashset=3/4 - ;; - coverage-vltmt-0) - nodist/code_coverage --stages 3- --scenarios=--vltmt --hashset=0/4 - ;; - coverage-vltmt-1) - nodist/code_coverage --stages 3- --scenarios=--vltmt --hashset=1/4 - ;; - coverage-vltmt-2) - nodist/code_coverage --stages 3- --scenarios=--vltmt --hashset=2/4 - ;; - coverage-vltmt-3) - nodist/code_coverage --stages 3- --scenarios=--vltmt --hashset=3/4 - ;; - *) - fatal "Unknown test: $TESTS" - ;; - esac - # Upload coverage data to codecov.io - if [[ $TESTS == coverage-* ]]; then - bash <(curl -s https://codecov.io/bash) -f nodist/obj_dir/coverage/app_total.info - fi - else - fatal "Unknown os: '$TRAVIS_OS_NAME'" + if [ "$TRAVIS_OS_NAME" = "osx" ]; then + export VERILATOR_TEST_NO_GDB=1 # Pain to get GDB to work on OS X + export VERILATOR_TEST_NO_GPROF=1 # Apple Clang has no -pg + # export PATH="/Applications/gtkwave.app/Contents/Resources/bin:$PATH" # fst2vcd + fi + + # Run the specified test + case $TESTS in + dist-vlt-0) + make -C test_regress SCENARIOS="--dist --vlt" DRIVER_HASHSET=--hashset=0/2 + ;; + dist-vlt-1) + make -C test_regress SCENARIOS="--dist --vlt" DRIVER_HASHSET=--hashset=1/2 + ;; + vltmt-0) + make -C test_regress SCENARIOS=--vltmt DRIVER_HASHSET=--hashset=0/2 + ;; + vltmt-1) + make -C test_regress SCENARIOS=--vltmt DRIVER_HASHSET=--hashset=1/2 + ;; + coverage-dist) + nodist/code_coverage --stages 3- --scenarios=--dist + ;; + coverage-vlt-0) + nodist/code_coverage --stages 3- --scenarios=--vlt --hashset=0/4 + ;; + coverage-vlt-1) + nodist/code_coverage --stages 3- --scenarios=--vlt --hashset=1/4 + ;; + coverage-vlt-2) + nodist/code_coverage --stages 3- --scenarios=--vlt --hashset=2/4 + ;; + coverage-vlt-3) + nodist/code_coverage --stages 3- --scenarios=--vlt --hashset=3/4 + ;; + coverage-vltmt-0) + nodist/code_coverage --stages 3- --scenarios=--vltmt --hashset=0/4 + ;; + coverage-vltmt-1) + nodist/code_coverage --stages 3- --scenarios=--vltmt --hashset=1/4 + ;; + coverage-vltmt-2) + nodist/code_coverage --stages 3- --scenarios=--vltmt --hashset=2/4 + ;; + coverage-vltmt-3) + nodist/code_coverage --stages 3- --scenarios=--vltmt --hashset=3/4 + ;; + *) + fatal "Unknown test: $TESTS" + ;; + esac + # Upload coverage data to codecov.io + if [[ $TESTS == coverage-* ]]; then + bash <(curl -s https://codecov.io/bash) -f nodist/obj_dir/coverage/app_total.info fi else ############################################################################## diff --git a/configure.ac b/configure.ac index 7ecdd2e24..36530dd92 100644 --- a/configure.ac +++ b/configure.ac @@ -128,12 +128,6 @@ AC_ARG_ENABLE([prec11], AC_SUBST(CFG_WITH_PREC11) AC_MSG_RESULT($CFG_WITH_PREC11) -# Compiler flags -CFLAGS+=" -I${includedir}" -CPPFLAGS+=" -I${includedir}" -CXXFLAGS+=" -I${includedir}" -LDFLAGS+=" -L${libdir}" - # Checks for programs. AC_PROG_CC AC_PROG_CXX diff --git a/examples/make_protect_lib/Makefile b/examples/make_protect_lib/Makefile index 8a82d9372..319ce5c4a 100644 --- a/examples/make_protect_lib/Makefile +++ b/examples/make_protect_lib/Makefile @@ -68,7 +68,7 @@ run: @echo " library (libverilated_secret.a) generated from the previous" @echo " step" @echo "---------------------------------------------------------------" - $(VERILATOR) $(TOP_VERILATOR_FLAGS) --exe -LDFLAGS '-L../obj_dir_secret -lverilated_secret -static' top.v obj_dir_secret/verilated_secret.sv sim_main.cpp + $(VERILATOR) $(TOP_VERILATOR_FLAGS) --exe -LDFLAGS '../obj_dir_secret/libverilated_secret.a' top.v obj_dir_secret/verilated_secret.sv sim_main.cpp @echo @echo "-- COMPILE entire design --------------------------------------" diff --git a/src/Makefile_obj.in b/src/Makefile_obj.in index 0cd331087..0c2ed579c 100644 --- a/src/Makefile_obj.in +++ b/src/Makefile_obj.in @@ -278,7 +278,6 @@ V3__CONCAT.cpp: $(addsuffix .cpp, $(basename $(RAW_OBJS))) $(TGT): $(PREDEP_H) $(OBJS) @echo " Linking $@..." - -rm -rf $@ $@.exe ${LINK} ${LDFLAGS} -o $@ $(OBJS) $(CCMALLOC) ${LIBS} V3Number_test: V3Number_test.o diff --git a/test_regress/t/t_case_huge_prof.pl b/test_regress/t/t_case_huge_prof.pl index 2514ab53e..9e75c590c 100755 --- a/test_regress/t/t_case_huge_prof.pl +++ b/test_regress/t/t_case_huge_prof.pl @@ -9,35 +9,43 @@ if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); di # SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0 scenarios(vlt_all => 1); - top_filename("t/t_case_huge.v"); -compile( - verilator_flags2 => ["--stats --prof-cfuncs -CFLAGS '-pg' -LDFLAGS '-pg'"], - ); - -file_grep($Self->{stats}, qr/Optimizations, Tables created\s+(\d+)/i, 10); -file_grep($Self->{stats}, qr/Optimizations, Combined CFuncs\s+(\d+)/i, 10); - -unlink $_ foreach (glob "$Self->{obj_dir}/gmon.out.*"); -setenv('GMON_OUT_PREFIX', "$Self->{obj_dir}/gmon.out"); - -execute( - check_finished => 1, - ); - -my $gmon_path; -$gmon_path = $_ foreach (glob "$Self->{obj_dir}/gmon.out.*"); -$gmon_path or error("Profiler did not create a gmon.out"); -(my $gmon_base = $gmon_path) =~ s!.*[/\\]!!; - -run(cmd => ["cd $Self->{obj_dir} && gprof $Self->{VM_PREFIX} $gmon_base > gprof.out"], - check_finished => 0); - -run(cmd => ["cd $Self->{obj_dir} && $ENV{VERILATOR_ROOT}/bin/verilator_profcfunc gprof.out > cfuncs.out"], - check_finished => 0); - -file_grep("$Self->{obj_dir}/cfuncs.out", qr/Overall summary by/); +if ($ENV{VERILATOR_TEST_NO_GPROF}) { + skip("Skipping due to VERILATOR_TEST_NO_GPROF"); +} else { + dotest(); +} ok(1); + +sub dotest { + compile( + verilator_flags2 => ["--stats --prof-cfuncs -CFLAGS '-pg' -LDFLAGS '-pg'"], + ); + + file_grep($Self->{stats}, qr/Optimizations, Tables created\s+(\d+)/i, 10); + file_grep($Self->{stats}, qr/Optimizations, Combined CFuncs\s+(\d+)/i, 10); + + unlink $_ foreach (glob "$Self->{obj_dir}/gmon.out.*"); + setenv('GMON_OUT_PREFIX', "$Self->{obj_dir}/gmon.out"); + + execute( + check_finished => 1, + ); + + my $gmon_path; + $gmon_path = $_ foreach (glob "$Self->{obj_dir}/gmon.out.*"); + $gmon_path or error("Profiler did not create a gmon.out"); + (my $gmon_base = $gmon_path) =~ s!.*[/\\]!!; + + run(cmd => ["cd $Self->{obj_dir} && gprof $Self->{VM_PREFIX} $gmon_base > gprof.out"], + check_finished => 0); + + run(cmd => ["cd $Self->{obj_dir} && $ENV{VERILATOR_ROOT}/bin/verilator_profcfunc gprof.out > cfuncs.out"], + check_finished => 0); + + file_grep("$Self->{obj_dir}/cfuncs.out", qr/Overall summary by/); +} + 1; diff --git a/test_regress/t/t_flag_ldflags.pl b/test_regress/t/t_flag_ldflags.pl index afb1ad462..e1feb205b 100755 --- a/test_regress/t/t_flag_ldflags.pl +++ b/test_regress/t/t_flag_ldflags.pl @@ -28,6 +28,19 @@ compile( "t_flag_ldflags_so.so",], ); + +# On OS X, LD_LIBRARY_PATH is ignored, so set rpath of the exe to find the .so +if ($^O eq "darwin") { + run(cmd => ["cd $Self->{obj_dir}" + ." && install_name_tool -add_rpath \@executable_path/." + ." $Self->{VM_PREFIX}"], + check_finished => 0); + run(cmd => ["cd $Self->{obj_dir}" + ." && install_name_tool -change t_flag_ldflags_so.so" + ." \@rpath/t_flag_ldflags_so.so $Self->{VM_PREFIX}"], + check_finished => 0); +} + execute( check_finished => 1, run_env => "LD_LIBRARY_PATH=$Self->{obj_dir}", diff --git a/test_regress/t/t_prot_lib.pl b/test_regress/t/t_prot_lib.pl index 993d8fb75..7f2b9b352 100755 --- a/test_regress/t/t_prot_lib.pl +++ b/test_regress/t/t_prot_lib.pl @@ -51,7 +51,7 @@ while (1) { compile( verilator_flags2 => ["$secret_dir/secret.sv", "-LDFLAGS", - "'-L$secret_prefix -lsecret -static'"], + "$secret_prefix/libsecret.a"], xsim_flags2 => ["$secret_dir/secret.sv"], ); diff --git a/test_regress/t/t_prot_lib_clk_gated.pl b/test_regress/t/t_prot_lib_clk_gated.pl index 69b9e9ccc..8bb14ba16 100755 --- a/test_regress/t/t_prot_lib_clk_gated.pl +++ b/test_regress/t/t_prot_lib_clk_gated.pl @@ -54,7 +54,7 @@ while (1) { verilator_flags2 => ["$secret_dir/secret.sv", "-GGATED_CLK=1", "-LDFLAGS", - "'-L$secret_prefix -lsecret -static'"], + "$secret_prefix/libsecret.a"], xsim_flags2 => ["$secret_dir/secret.sv"], );