build: CMake refactoring and fixes

Includes:
- fix int64x64 parsing order, remove cached entries in macros-and-definitions and in the docs
- update launch.json scratch names
- add a ctest entry per executable
- forward POSIX signal in ns3 (to get segmentation fault)
- prioritize Ninja generator instead of Makefiles
- add tests for unused utils source files
- remove dummy file and add tests to check for unused source files
- add missing examples and clean up unnecessary definitions
- missing feature entry for LTE used by pybindgen
- refactor CMake related filenames
- fix python libraries and include directories bindings
- fix brite example name
- Keep C++ compiler and flags when refreshing
- Disable precompiled headers when Ccache is found
- Mark find_external_library headers as advanced
- consolidate auxiliary files: build-status.py, _cache.py and .lock-waf_sys.platform_build files are merged into .lock-ns3_sys.platform_build
- scan .cc sources used in bindings and update docs
This commit is contained in:
Gabriel Ferreira
2022-01-31 20:02:10 -03:00
parent e32c177e45
commit 4aedba2f00
51 changed files with 526 additions and 464 deletions

2
.gitignore vendored
View File

@@ -39,7 +39,7 @@ build/
version.cache
.idea/
cmake_cache/
cmake-cache/
cmake-build-debug/
cmake-build-relwithdebinfo/
cmake-build-minsizerel/

4
.vscode/launch.json vendored
View File

@@ -8,7 +8,7 @@
"name": "(gdb) Launch from scratch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/scratch/${fileBasenameNoExtension}",
"program": "${workspaceFolder}/build/scratch/ns3-dev-${fileBasenameNoExtension}-debug",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
@@ -33,7 +33,7 @@
"name": "(lldb) Launch from scratch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/scratch/${fileBasenameNoExtension}",
"program": "${workspaceFolder}/build/scratch/ns3-dev-${fileBasenameNoExtension}-debug",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",

View File

@@ -11,9 +11,9 @@ if(CCACHE_FOUND)
message(
STATUS "CCache is enabled. Precompiled headers are disabled by default."
)
set(NS3_PRECOMPILE_HEADERS OFF CACHE BOOL "")
else()
set(NS3_PRECOMPILE_HEADERS ON CACHE BOOL "")
set(NS3_PRECOMPILE_HEADERS OFF
CACHE BOOL "Precompile module headers to speed up compilation" FORCE
)
endif()
# ##############################################################################
@@ -102,7 +102,7 @@ set(NS3_DISABLED_MODULES ""
)
# Include macros used below
include(buildsupport/macros_and_definitions.cmake)
include(build-support/macros-and-definitions.cmake)
# Scan module libraries
subdirlist(libs_to_build ${CMAKE_SOURCE_DIR}/src)
@@ -139,11 +139,8 @@ add_subdirectory(scratch)
# Build test utils
add_subdirectory(utils)
# Workaround for missing waf files used by test.py
generate_c4che_cachepy()
generate_buildstatus()
generate_fakewaflock()
write_fakewaf_config()
write_lock()
write_configtable()
write_header_to_modules_map()
# Export package targets when installing

View File

@@ -88,7 +88,7 @@ function(pkgconfig_module libname)
# Configure pkgconfig file for the module using pkgconfig variables
set(pkgconfig_file ${CMAKE_BINARY_DIR}/pkgconfig/ns3-${module_name}.pc)
configure_file(
${PROJECT_SOURCE_DIR}/buildsupport/pkgconfig_template.pc.in
${PROJECT_SOURCE_DIR}/build-support/pkgconfig-template.pc.in
${pkgconfig_file} @ONLY
)
@@ -125,7 +125,7 @@ function(ns3_cmake_package)
include(CMakePackageConfigHelpers)
configure_package_config_file(
"buildsupport/Config.cmake.in" "ns3Config.cmake"
"build-support/Config.cmake.in" "ns3Config.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ns3
PATH_VARS CMAKE_INSTALL_LIBDIR
)

View File

@@ -112,7 +112,7 @@ function(print_formatted_table_with_modules table_name modules output)
set(${output} ${${output}}${temp} PARENT_SCOPE)
endfunction()
macro(write_fakewaf_config)
macro(write_configtable)
set(out "---- Summary of optional NS-3 features:\n")
string(APPEND out "Build profile : ${build_profile}\n")
string(APPEND out

View File

@@ -34,7 +34,7 @@ if(${NS3_COVERAGE})
endif()
# The following target will run test.py --no-build to generate the code
# coverage files .gcno and .gcda output will be in ${CMAKE_BINARY_DIR} a.k.a.
# cmake_cache or cmake-build-${build_suffix}
# cmake-cache or cmake-build-${build_suffix}
# Create output directory for coverage info and html
file(MAKE_DIRECTORY ${CMAKE_OUTPUT_DIRECTORY}/coverage)

View File

@@ -0,0 +1,122 @@
# Copyright (c) 2017-2021 Universidade de Brasília
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License version 2 as published by the Free
# Software Foundation;
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307 USA
#
# Author: Gabriel Ferreira <gabrielcarvfer@gmail.com>
function(cache_cmake_flag cmake_flag cache_entry output_string)
if(${${cmake_flag}})
set(${output_string} "${${output_string}}${cache_entry} = True\n"
PARENT_SCOPE
)
else()
set(${output_string} "${${output_string}}${cache_entry} = False\n"
PARENT_SCOPE
)
endif()
endfunction(cache_cmake_flag)
function(write_lock)
set(lock_contents "#! /usr/bin/env python3\n\n")
# Contents previously in ns-3-dev/.lock-waf_sys.platform_build
string(APPEND lock_contents "launch_dir = '${PROJECT_SOURCE_DIR}'\n")
string(APPEND lock_contents "run_dir = '${PROJECT_SOURCE_DIR}'\n")
string(APPEND lock_contents "top_dir = '${PROJECT_SOURCE_DIR}'\n")
string(APPEND lock_contents "out_dir = '${CMAKE_OUTPUT_DIRECTORY}'\n")
string(APPEND lock_contents "\n\n")
# Contents previously in ns-3-dev/build/c4che/_cache.py
string(APPEND lock_contents "NS3_ENABLED_MODULES = [")
foreach(module_library ${ns3-libs}) # fetch core module libraries
string(APPEND lock_contents "'")
string(REPLACE "lib" "" module_name ${module_library}) # lib${libname} into
# libname
string(APPEND lock_contents "ns3-${module_name}', ")
endforeach()
string(APPEND lock_contents "]\n")
string(APPEND lock_contents "NS3_ENABLED_CONTRIBUTED_MODULES = [")
foreach(module_library ${ns3-contrib-libs}) # fetch core module libraries
string(APPEND lock_contents "'")
string(REPLACE "lib" "" module_name ${module_library}) # lib${libname} into
# libname
string(APPEND lock_contents "ns3-${module_name}', ")
endforeach()
string(APPEND lock_contents "]\n")
string(REPLACE ":" "', '" PATH_LIST $ENV{PATH})
string(
APPEND
lock_contents
"NS3_MODULE_PATH = ['${PATH_LIST}', '${CMAKE_OUTPUT_DIRECTORY}', '${CMAKE_LIBRARY_OUTPUT_DIRECTORY}']\n"
)
cache_cmake_flag(ENABLE_REALTIME "ENABLE_REAL_TIME" lock_contents)
cache_cmake_flag(NS3_PTHREAD "ENABLE_THREADING" lock_contents)
cache_cmake_flag(ENABLE_EXAMPLES "ENABLE_EXAMPLES" lock_contents)
cache_cmake_flag(ENABLE_TESTS "ENABLE_TESTS" lock_contents)
cache_cmake_flag(NS3_OPENFLOW "ENABLE_OPENFLOW" lock_contents)
cache_cmake_flag(NS3_CLICK "NSCLICK" lock_contents)
cache_cmake_flag(NS3_BRITE "ENABLE_BRITE" lock_contents)
cache_cmake_flag(NS3_ENABLE_SUDO "ENABLE_SUDO" lock_contents)
cache_cmake_flag(NS3_PYTHON_BINDINGS "ENABLE_PYTHON_BINDINGS" lock_contents)
cache_cmake_flag(
NS3_SCAN_PYTHON_BINDINGS "ENABLE_SCAN_PYTHON_BINDINGS" lock_contents
)
string(APPEND lock_contents "EXAMPLE_DIRECTORIES = [")
foreach(example_folder ${ns3-example-folders})
string(APPEND lock_contents "'${example_folder}', ")
endforeach()
string(APPEND lock_contents "]\n")
string(APPEND lock_contents "APPNAME = 'ns'\n")
string(APPEND lock_contents "BUILD_PROFILE = '${build_profile}'\n")
string(APPEND lock_contents "VERSION = '${NS3_VER}' \n")
string(APPEND lock_contents "PYTHON = ['${Python_EXECUTABLE}']\n")
mark_as_advanced(VALGRIND)
find_program(VALGRIND valgrind)
if("${VALGRIND}" STREQUAL "VALGRIND-NOTFOUND")
string(APPEND lock_contents "VALGRIND_FOUND = False \n")
else()
string(APPEND lock_contents "VALGRIND_FOUND = True \n")
endif()
# Contents previously in ns-3-dev/build/build-status.py
string(APPEND lock_contents "\n\n")
string(APPEND lock_contents "ns3_runnable_programs = [")
foreach(executable ${ns3-execs})
string(APPEND lock_contents "'${executable}', ")
endforeach()
string(APPEND lock_contents "]\n\n")
string(APPEND lock_contents "ns3_runnable_scripts = [")
foreach(executable ${ns3-execs-py})
string(APPEND lock_contents "'${executable}', ")
endforeach()
string(APPEND lock_contents "]\n\n")
if(LINUX)
set(lock_filename .lock-ns3_linux_build)
elseif(APPLE)
set(lock_filename .lock-ns3_darwin_build)
elseif(WIN32)
set(lock_filename .lock-ns3_win32_build)
else()
message(FATAL_ERROR "Platform not supported")
endif()
file(WRITE ${PROJECT_SOURCE_DIR}/${lock_filename} ${lock_contents})
endfunction(write_lock)

View File

@@ -306,7 +306,7 @@ function(build_lib)
set(module_to_generate_api ${module_api_LP64})
set(LP64toILP32
${Python_EXECUTABLE}
${PROJECT_SOURCE_DIR}/buildsupport/pybindings_LP64_to_ILP32.py
${PROJECT_SOURCE_DIR}/build-support/pybindings-LP64-to-ILP32.py
${module_api_LP64} ${module_api_ILP32}
)
endif()
@@ -386,16 +386,15 @@ function(build_lib)
# Add core module helper sources
set(python_module_files ${module_hdr} ${module_src})
if(${BLIB_LIBNAME} STREQUAL "core")
list(APPEND python_module_files
${CMAKE_CURRENT_SOURCE_DIR}/bindings/module_helpers.cc
${CMAKE_CURRENT_SOURCE_DIR}/bindings/scan-header.h
)
endif()
file(GLOB custom_python_module_files
${CMAKE_CURRENT_SOURCE_DIR}/bindings/*.cc
${CMAKE_CURRENT_SOURCE_DIR}/bindings/*.h
)
list(APPEND python_module_files ${custom_python_module_files})
set(bindings-name lib${BLIB_LIBNAME}-bindings)
add_library(${bindings-name} SHARED "${python_module_files}")
target_include_directories(
${bindings-name} PUBLIC ${Python_INCLUDE_DIRS} ${bindings_output_folder}
${bindings-name} PUBLIC ${PYTHON_INCLUDE_DIRS} ${bindings_output_folder}
)
target_compile_options(${bindings-name} PRIVATE -Wno-error)

View File

@@ -91,7 +91,7 @@ function(configure_embedded_version)
check_git_repo_has_ns3_tags(HAS_NS3_TAGS NS3_VERSION_TAG)
set(version_cache_file_template
${PROJECT_SOURCE_DIR}/buildsupport/version.cache.in
${PROJECT_SOURCE_DIR}/build-support/version.cache.in
)
set(version_cache_file ${PROJECT_SOURCE_DIR}/src/core/model/version.cache)
@@ -199,7 +199,7 @@ function(configure_embedded_version)
# Enable embedding build version
add_definitions(-DENABLE_BUILD_VERSION=1)
configure_file(
buildsupport/version-defines-template.h
build-support/version-defines-template.h
${CMAKE_HEADER_OUTPUT_DIRECTORY}/version-defines.h
)
set(ENABLE_BUILD_VERSION True PARENT_SCOPE)

View File

@@ -18,23 +18,20 @@
# Export compile time variable setting the directory to the NS3 root folder
add_definitions(-DPROJECT_SOURCE_PATH="${PROJECT_SOURCE_DIR}")
# Cache options for NS3_INT64X64
# Set INT128 as the default option for INT64X64 and register alternative
# implementations
set(NS3_INT64X64 "INT128" CACHE STRING "Int64x64 implementation")
set(NS3_INT64X64 "CAIRO" CACHE STRING "Int64x64 implementation")
set(NS3_INT64X64 "DOUBLE" CACHE STRING "Int64x64 implementation")
set_property(CACHE NS3_INT64X64 PROPERTY STRINGS INT128 CAIRO DOUBLE)
# Purposefully hidden options:
# for ease of use, export all libraries and include directories to ns-3 module
# consumers by default
mark_as_advanced(NS3_REEXPORT_THIRD_PARTY_LIBRARIES)
option(NS3_REEXPORT_THIRD_PARTY_LIBRARIES "Export all third-party libraries
and include directories to ns-3 module consumers" ON
)
# since we can't really do that safely from the CMake side
mark_as_advanced(NS3_ENABLE_SUDO)
option(NS3_ENABLE_SUDO
"Set executables ownership to root and enable the SUID flag" OFF
)
@@ -125,7 +122,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Get installation folder default values for each platform and include package
# configuration macro
include(GNUInstallDirs)
include(buildsupport/custom_modules/ns3_cmake_package.cmake)
include(build-support/custom-modules/ns3-cmake-package.cmake)
if(${XCODE})
# Is that so hard not to break people's CI, AAPL? Why would you output the
@@ -318,6 +315,7 @@ macro(process_options)
set(ENABLE_TESTS OFF)
if(${NS3_TESTS} OR ${ns3rc_tests_enabled})
set(ENABLE_TESTS ON)
enable_testing()
endif()
set(profiles_without_suffixes release)
@@ -341,7 +339,7 @@ macro(process_options)
endif()
endif()
include(buildsupport/custom_modules/ns3_versioning.cmake)
include(build-support/custom-modules/ns3-versioning.cmake)
set(ENABLE_BUILD_VERSION False)
configure_embedded_version()
@@ -424,18 +422,18 @@ macro(process_options)
CMakeLists.txt
utils/**/CMakeLists.txt
src/CMakeLists.txt
buildsupport/**/*.cmake
buildsupport/*.cmake
build-support/**/*.cmake
build-support/*.cmake
)
add_custom_target(
cmake-format
COMMAND
${CMAKE_FORMAT_PROGRAM} -c
${PROJECT_SOURCE_DIR}/buildsupport/cmake-format.txt -i
${PROJECT_SOURCE_DIR}/build-support/cmake-format.txt -i
${INTERNAL_CMAKE_FILES}
COMMAND
${CMAKE_FORMAT_PROGRAM} -c
${PROJECT_SOURCE_DIR}/buildsupport/cmake-format-modules.txt -i
${PROJECT_SOURCE_DIR}/build-support/cmake-format-modules.txt -i
${MODULES_CMAKE_FILES}
)
unset(MODULES_CMAKE_FILES)
@@ -548,7 +546,7 @@ macro(process_options)
endif()
message(STATUS "iwyu is enabled")
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE
${PROJECT_SOURCE_DIR}/buildsupport/iwyu_wrapper.sh;${PROJECT_SOURCE_DIR}
${PROJECT_SOURCE_DIR}/build-support/iwyu-wrapper.sh;${PROJECT_SOURCE_DIR}
)
else()
unset(CMAKE_CXX_INCLUDE_WHAT_YOU_USE)
@@ -577,9 +575,9 @@ macro(process_options)
# find required dependencies
list(APPEND CMAKE_MODULE_PATH
"${PROJECT_SOURCE_DIR}/buildsupport/custom_modules"
"${PROJECT_SOURCE_DIR}/build-support/custom-modules"
)
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/buildsupport/3rd_party")
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/build-support/3rd-party")
# GTK3 Don't search for it if you don't have it installed, as it take an
# insane amount of time
@@ -757,13 +755,13 @@ macro(process_options)
DEPENDS all-test-targets
)
if(${ENABLE_EXAMPLES})
include(buildsupport/custom_modules/ns3_coverage.cmake)
include(build-support/custom-modules/ns3-coverage.cmake)
endif()
endif()
# Process config-store-config
configure_file(
buildsupport/config-store-config-template.h
build-support/config-store-config-template.h
${CMAKE_HEADER_OUTPUT_DIRECTORY}/config-store-config.h
)
@@ -958,9 +956,9 @@ macro(process_options)
endif()
# end of checking for documentation dependencies and creating targets
# Process core-config
# Process core-config If INT128 is not found, fallback to CAIRO
if(${NS3_INT64X64} MATCHES "INT128")
include(buildsupport/3rd_party/FindInt128.cmake)
include(build-support/3rd-party/FindInt128.cmake)
find_int128_types()
if(UINT128_FOUND)
set(HAVE___UINT128_T TRUE)
@@ -971,10 +969,7 @@ macro(process_options)
endif()
endif()
if(${NS3_INT64X64} MATCHES "CAIRO")
set(INT64X64_USE_CAIRO TRUE)
endif()
# If long double and double have different sizes, fallback to CAIRO
if(${NS3_INT64X64} MATCHES "DOUBLE")
# WSLv1 has a long double issue that will result in a few tests failing
# https://github.com/microsoft/WSL/issues/830
@@ -993,6 +988,11 @@ macro(process_options)
endif()
endif()
# Fallback option
if(${NS3_INT64X64} MATCHES "CAIRO")
set(INT64X64_USE_CAIRO TRUE)
endif()
include(CheckIncludeFileCXX)
include(CheckFunctionExists)
@@ -1010,7 +1010,7 @@ macro(process_options)
check_function_exists("getenv" "HAVE_GETENV")
configure_file(
buildsupport/core-config-template.h
build-support/core-config-template.h
${CMAKE_HEADER_OUTPUT_DIRECTORY}/core-config.h
)
@@ -1124,13 +1124,13 @@ macro(process_options)
<limits>
<math.h>
)
add_library(stdlib_pch OBJECT ${PROJECT_SOURCE_DIR}/buildsupport/empty.cc)
add_library(stdlib_pch OBJECT ${PROJECT_SOURCE_DIR}/build-support/empty.cc)
target_precompile_headers(
stdlib_pch PUBLIC "${precompiled_header_libraries}"
)
add_executable(
stdlib_pch_exec ${PROJECT_SOURCE_DIR}/buildsupport/empty_main.cc
stdlib_pch_exec ${PROJECT_SOURCE_DIR}/build-support/empty-main.cc
)
target_precompile_headers(
stdlib_pch_exec PUBLIC "${precompiled_header_libraries}"
@@ -1156,10 +1156,10 @@ macro(process_options)
GIT_TAG netanim-3.108
)
FetchContent_Populate(netanim)
file(COPY buildsupport/3rd_party/netanim_cmakelists.cmake
file(COPY build-support/3rd-party/netanim-cmakelists.cmake
DESTINATION ${netanim_SOURCE_DIR}
)
file(RENAME ${netanim_SOURCE_DIR}/netanim_cmakelists.cmake
file(RENAME ${netanim_SOURCE_DIR}/netanim-cmakelists.cmake
${netanim_SOURCE_DIR}/CMakeLists.txt
)
add_subdirectory(${netanim_SOURCE_DIR})
@@ -1192,6 +1192,23 @@ function(set_runtime_outputdirectory target_name output_directory target_prefix)
if(${ENABLE_TESTS})
add_dependencies(all-test-targets ${target_prefix}${target_name})
# Create a CTest entry for each executable
if(WIN32)
# Windows require this workaround to make sure the DLL files are located
add_test(
NAME ctest-${target_prefix}${target_name}
COMMAND
${CMAKE_COMMAND} -E env
"PATH=$ENV{PATH};${CMAKE_RUNTIME_OUTPUT_DIRECTORY};${CMAKE_LIBRARY_OUTPUT_DIRECTORY}"
${ns3-exec-outputname}
WORKING_DIRECTORY ${output_directory}
)
else()
add_test(NAME ctest-${target_prefix}${target_name}
COMMAND ${ns3-exec-outputname}
WORKING_DIRECTORY ${output_directory}
)
endif()
endif()
if(${NS3_CLANG_TIMETRACE})
@@ -1221,10 +1238,10 @@ function(copy_headers_before_building_lib libname outputdir headers visibility)
endfunction(copy_headers_before_building_lib)
# Import macros used for modules and define specialized versions for src modules
include(buildsupport/custom_modules/ns3_module_macros.cmake)
include(build-support/custom-modules/ns3-module-macros.cmake)
# Contrib modules counterparts of macros above
include(buildsupport/custom_modules/ns3_contributions.cmake)
include(build-support/custom-modules/ns3-contributions.cmake)
# Macro to build examples in ns-3-dev/examples/
macro(build_example)
@@ -1589,6 +1606,7 @@ function(find_external_library)
set(not_found_headers)
set(include_dirs)
foreach(header ${header_names})
mark_as_advanced(${name}_header_internal_${header})
find_file(
${name}_header_internal_${header} ${header}
HINTS ${search_paths}
@@ -1682,8 +1700,5 @@ function(check_python_packages packages missing_packages)
set(${missing_packages} "${missing}" PARENT_SCOPE)
endfunction()
# Waf workaround scripts
include(buildsupport/custom_modules/waf_workaround_c4cache.cmake)
include(buildsupport/custom_modules/waf_workaround_buildstatus.cmake)
include(buildsupport/custom_modules/waf_workaround_lock.cmake)
include(buildsupport/custom_modules/waf_workaround_fakeconfig.cmake)
include(build-support/custom-modules/ns3-lock.cmake)
include(build-support/custom-modules/ns3-configtable.cmake)

View File

@@ -1,37 +0,0 @@
# Copyright (c) 2017-2021 Universidade de Brasília
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License version 2 as published by the Free
# Software Foundation;
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307 USA
#
# Author: Gabriel Ferreira <gabrielcarvfer@gmail.com>
function(generate_buildstatus)
# Build build-status.py file consumed by test.py
set(buildstatus_contents "#! /usr/bin/env python3\n\n")
string(APPEND buildstatus_contents "ns3_runnable_programs = [")
foreach(executable ${ns3-execs})
string(APPEND buildstatus_contents "'${executable}',\n")
endforeach()
string(APPEND buildstatus_contents "]\n\n")
string(APPEND buildstatus_contents "ns3_runnable_scripts = [")
foreach(executable ${ns3-execs-py})
string(APPEND buildstatus_contents "'${executable}',\n")
endforeach()
string(APPEND buildstatus_contents "]\n\n")
file(WRITE ${CMAKE_OUTPUT_DIRECTORY}/build-status.py
"${buildstatus_contents}"
)
endfunction(generate_buildstatus)

View File

@@ -1,91 +0,0 @@
# Copyright (c) 2017-2021 Universidade de Brasília
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License version 2 as published by the Free
# Software Foundation;
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307 USA
#
# Author: Gabriel Ferreira <gabrielcarvfer@gmail.com>
function(cache_cmake_flag cmake_flag cache_entry output_string)
if(${${cmake_flag}})
set(${output_string} "${${output_string}}${cache_entry} = True\n"
PARENT_SCOPE
)
else()
set(${output_string} "${${output_string}}${cache_entry} = False\n"
PARENT_SCOPE
)
endif()
endfunction(cache_cmake_flag)
function(generate_c4che_cachepy)
# Build _cache.py file consumed by test.py
set(cache_contents "")
string(APPEND cache_contents "NS3_ENABLED_MODULES = [")
foreach(module_library ${ns3-libs}) # fetch core module libraries
string(APPEND cache_contents "'")
string(REPLACE "lib" "" module_name ${module_library}) # lib${libname} into
# libname
string(APPEND cache_contents "ns3-${module_name}', ")
endforeach()
string(APPEND cache_contents "]\n")
string(APPEND cache_contents "NS3_ENABLED_CONTRIBUTED_MODULES = [")
foreach(module_library ${ns3-contrib-libs}) # fetch core module libraries
string(APPEND cache_contents "'")
string(REPLACE "lib" "" module_name ${module_library}) # lib${libname} into
# libname
string(APPEND cache_contents "ns3-${module_name}', ")
endforeach()
string(APPEND cache_contents "]\n")
string(REPLACE ":" "', '" PATH_LIST $ENV{PATH})
string(
APPEND
cache_contents
"NS3_MODULE_PATH = ['${PATH_LIST}', '${CMAKE_OUTPUT_DIRECTORY}', '${CMAKE_LIBRARY_OUTPUT_DIRECTORY}']\n"
)
cache_cmake_flag(ENABLE_REALTIME "ENABLE_REAL_TIME" cache_contents)
cache_cmake_flag(NS3_PTHREAD "ENABLE_THREADING" cache_contents)
cache_cmake_flag(ENABLE_EXAMPLES "ENABLE_EXAMPLES" cache_contents)
cache_cmake_flag(ENABLE_TESTS "ENABLE_TESTS" cache_contents)
cache_cmake_flag(NS3_OPENFLOW "ENABLE_OPENFLOW" cache_contents)
cache_cmake_flag(NS3_CLICK "NSCLICK" cache_contents)
cache_cmake_flag(NS3_BRITE "ENABLE_BRITE" cache_contents)
cache_cmake_flag(NS3_ENABLE_SUDO "ENABLE_SUDO" cache_contents)
cache_cmake_flag(NS3_PYTHON_BINDINGS "ENABLE_PYTHON_BINDINGS" cache_contents)
cache_cmake_flag(
NS3_SCAN_PYTHON_BINDINGS "ENABLE_SCAN_PYTHON_BINDINGS" cache_contents
)
string(APPEND cache_contents "EXAMPLE_DIRECTORIES = [")
foreach(example_folder ${ns3-example-folders})
string(APPEND cache_contents "'${example_folder}', ")
endforeach()
string(APPEND cache_contents "]\n")
string(APPEND cache_contents "APPNAME = 'ns'\n")
string(APPEND cache_contents "BUILD_PROFILE = '${build_profile}'\n")
string(APPEND cache_contents "VERSION = '${NS3_VER}' \n")
string(APPEND cache_contents "PYTHON = ['${Python_EXECUTABLE}']\n")
mark_as_advanced(VALGRIND)
find_program(VALGRIND valgrind)
if("${VALGRIND}" STREQUAL "VALGRIND-NOTFOUND")
string(APPEND cache_contents "VALGRIND_FOUND = False \n")
else()
string(APPEND cache_contents "VALGRIND_FOUND = True \n")
endif()
file(WRITE ${CMAKE_OUTPUT_DIRECTORY}/c4che/_cache.py "${cache_contents}")
endfunction(generate_c4che_cachepy)

View File

@@ -1,37 +0,0 @@
# Copyright (c) 2017-2021 Universidade de Brasília
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License version 2 as published by the Free
# Software Foundation;
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307 USA
#
# Author: Gabriel Ferreira <gabrielcarvfer@gmail.com>
function(generate_fakewaflock)
set(fakewaflock_contents "")
string(APPEND fakewaflock_contents "launch_dir = '${PROJECT_SOURCE_DIR}'\n")
string(APPEND fakewaflock_contents "run_dir = '${PROJECT_SOURCE_DIR}'\n")
string(APPEND fakewaflock_contents "top_dir = '${PROJECT_SOURCE_DIR}'\n")
string(APPEND fakewaflock_contents "out_dir = '${CMAKE_OUTPUT_DIRECTORY}'\n")
set(fakewaflock_filename)
if(LINUX)
set(fakewaflock_filename .lock-waf_linux_build)
elseif(APPLE)
set(fakewaflock_filename .lock-waf_darwin_build)
else()
message(FATAL_ERROR "Platform not supported")
endif()
file(WRITE ${PROJECT_SOURCE_DIR}/${fakewaflock_filename}
${fakewaflock_contents}
)
endfunction(generate_fakewaflock)

View File

@@ -96,6 +96,12 @@ Here is some example code that is written in Python and that runs |ns3|, which i
Running Python Scripts
**********************
First, we need to enable the build of python bindings:
.. sourcecode:: bash
$ ./ns3 configure --enable-python-bindings
ns3 contains some options that automatically update the python path to find the ns3 module. To run example programs, there are two ways to use ns3 to take care of this. One is to run a ns3 shell; e.g.:
.. sourcecode:: bash
@@ -103,17 +109,15 @@ ns3 contains some options that automatically update the python path to find the
$ ./ns3 shell
$ python examples/wireless/mixed-wireless.py
and the other is to use the --pyrun option to ns3:
and the other is to use the 'run' option to ns3:
.. sourcecode:: bash
$ ./ns3 run examples/wireless/mixed-wireless.py
As of ns-3.30, a --pyrun-no-build option was added to allow the running of
a program without invoking a project rebuild. This option may be useful
to improve execution time when running the same program repeatedly but with
different arguments, such as from scripts. It can be used in place of
--pyrun such as:
Use the ``--no-build`` option to run the program without invoking a project rebuild.
This option may be useful to improve execution time when running the same program
repeatedly but with different arguments, such as from scripts.
.. sourcecode:: bash
@@ -251,13 +255,7 @@ If something goes wrong with compiling Python bindings and you just want to igno
.. sourcecode:: bash
$ ./ns3 configure --disable-python ...
To add support for modular bindings to an existing or new |ns3| module, simply add the following line to its wscript build() function:
::
bld.ns3_python_bindings()
$ ./ns3 configure --disable-python-bindings ...
One must also provide the bindings files (usually by running the scanning
framework).
@@ -494,14 +492,14 @@ To re-scan a module:
.. sourcecode:: bash
$ cd source/ns-3-dev
$ ./ns3 --apiscan=wifi
$ ./ns3 build wifi-apiscan
To re-scan all modules:
.. sourcecode:: bash
$ cd source/ns-3-dev
$ ./ns3 --apiscan=all
$ ./ns3 apiscan-all
Generating bindings on MacOS
############################
@@ -520,7 +518,7 @@ The ``src/<module>/bindings`` directory may contain the following files, some of
* ``modulegen__gcc_ILP32.py``: this is a scanned file, DO NOT TOUCH. Scanned API definitions for the GCC, ILP32 architecture (32-bit)
* ``modulegen_customizations.py``: you may optionally add this file in order to customize the pybindgen code generation
* ``scan-header.h``: you may optionally add this file to customize what header file is scanned for the module. Basically this file is scanned instead of ns3/<module>-module.h. Typically, the first statement is #include "ns3/<module>-module.h", plus some other stuff to force template instantiations;
* ``module_helpers.cc``: you may add additional files, such as this, to be linked to python extension module, but they have to be registered in the wscript. Look at src/core/wscript for an example of how to do so;
* ``module_helpers.cc``: you may add additional files, such as this, to be linked to python extension module. They will be automatically scanned;
* ``<module>.py``: if this file exists, it becomes the "frontend" python module for the ns3 module, and the extension module (.so file) becomes _<module>.so instead of <module>.so. The <module>.py file has to import all symbols from the module _<module> (this is more tricky than it sounds, see src/core/bindings/core.py for an example), and then can add some additional pure-python definitions.
Historical Information

View File

@@ -104,8 +104,8 @@ To check what underlying commands dare being executed, add the
~/ns-3-dev$ ./ns3 --dry-run configure -d release --enable-examples --enable-tests
The following commands would be executed:
mkdir cmake_cache
cd cmake_cache; /usr/bin/cmake -DCMAKE_BUILD_TYPE=release -DNS3_NATIVE_OPTIMIZATIONS=OFF -DNS3_EXAMPLES=ON -DNS3_TESTS=ON -G Unix Makefiles .. ; cd ..
mkdir cmake-cache
cd cmake-cache; /usr/bin/cmake -DCMAKE_BUILD_TYPE=release -DNS3_NATIVE_OPTIMIZATIONS=OFF -DNS3_EXAMPLES=ON -DNS3_TESTS=ON -G Unix Makefiles .. ; cd ..
Now we run it for real:
@@ -147,10 +147,10 @@ Now we run it for real:
-- Configuring done
-- Generating done
-- Build files have been written to: /mnt/dev/tools/source/ns-3-dev/cmake_cache
-- Build files have been written to: /mnt/dev/tools/source/ns-3-dev/cmake-cache
Finished executing the following commands:
mkdir cmake_cache
cd cmake_cache; /usr/bin/cmake -DCMAKE_BUILD_TYPE=release -DNS3_NATIVE_OPTIMIZATIONS=OFF -DNS3_EXAMPLES=ON -DNS3_TESTS=ON -G Unix Makefiles .. ; cd ..
mkdir cmake-cache
cd cmake-cache; /usr/bin/cmake -DCMAKE_BUILD_TYPE=release -DNS3_NATIVE_OPTIMIZATIONS=OFF -DNS3_EXAMPLES=ON -DNS3_TESTS=ON -G Unix Makefiles .. ; cd ..
Notice that CCache is automatically used (if installed) for your convenience.
@@ -194,9 +194,9 @@ navigate to it and run `CMake`_ pointing to the ns-3-dev folder.
.. sourcecode:: console
~$ cd ns-3-dev
~/ns-3-dev$ mkdir cmake_cache
~/ns-3-dev$ cd cmake_cache
~/ns-3-dev/cmake_cache$ cmake ..
~/ns-3-dev$ mkdir cmake-cache
~/ns-3-dev$ cd cmake-cache
~/ns-3-dev/cmake-cache$ cmake ..
You can pass additional arguments to the CMake command, to configure it. To change variable values,
you should use the -D option followed by the variable name.
@@ -222,7 +222,7 @@ created previously.
.. sourcecode:: console
~/ns-3-dev/cmake_cache$ cmake -DCMAKE_BUILD_TYPE=DEBUG ..
~/ns-3-dev/cmake-cache$ cmake -DCMAKE_BUILD_TYPE=DEBUG ..
Another common option to change is the `generator`_, which is the real underlying build system called by CMake.
There are many generators supported by CMake, including the ones listed in the table below.
@@ -250,23 +250,23 @@ prefer Ninja to Makefiles, which are the default, we need to run the following c
.. sourcecode:: console
~/ns-3-dev/cmake_cache$ cmake -G Ninja ..
~/ns-3-dev/cmake-cache$ cmake -G Ninja ..
This command may fail if there are different generator files in the same CMake cache folder. It is recommended to clean up
the CMake cache folder, then recreate it and reconfigure setting the generator in the first run.
.. sourcecode:: console
~/ns-3-dev/cmake_cache$ cd ..
~/ns-3-dev$ rm -R cmake_cache && mkdir cmake_cache && cd cmake_cache
~/ns-3-dev/cmake_cache$ cmake -DCMAKE_BUILD_TYPE=release -G Ninja ..
~/ns-3-dev/cmake-cache$ cd ..
~/ns-3-dev$ rm -R cmake-cache && mkdir cmake-cache && cd cmake-cache
~/ns-3-dev/cmake-cache$ cmake -DCMAKE_BUILD_TYPE=release -G Ninja ..
After configuring for the first time, settings will be initialized to their
default values, and then you can use the ``ccmake`` command to manually change them:
.. sourcecode:: console
~/ns-3-dev/cmake_cache$ ccmake .
~/ns-3-dev/cmake-cache$ ccmake .
CMAKE_BUILD_TYPE release
CMAKE_INSTALL_PREFIX /usr/local
NS3_ASSERT OFF
@@ -292,7 +292,7 @@ To enable both examples and tests, run:
.. sourcecode:: console
~/ns-3-dev/cmake_cache$ cmake -DNS3_EXAMPLES=ON -DNS3_TESTS=ON ..
~/ns-3-dev/cmake-cache$ cmake -DNS3_EXAMPLES=ON -DNS3_TESTS=ON ..
.. _Manually refresh the CMake cache:
@@ -309,7 +309,7 @@ The refresh is done by running the CMake command from the CMake cache folder.
.. sourcecode:: console
~/ns-3-dev/cmake_cache$ cmake ..
~/ns-3-dev/cmake-cache$ cmake ..
Previous settings stored in the CMakeCache.txt will be preserved, while new modules will be
scanned and targets will be added.
@@ -357,9 +357,9 @@ invoking CMake build. To build all the targets, run:
.. sourcecode:: console
~/ns-3-dev/cmake_cache$ cmake --build .
~/ns-3-dev/cmake-cache$ cmake --build .
Notice the single dot now refers to the ``cmake_cache`` directory, where the underlying
Notice the single dot now refers to the ``cmake-cache`` directory, where the underlying
build system files are stored (referred inside CMake as ``PROJECT_BINARY_DIR`` or
``CMAKE_BINARY_DIR``, which have slightly different uses if working with sub-projects).
@@ -370,7 +370,7 @@ To build specific targets, run:
.. sourcecode:: console
~/ns-3-dev/cmake_cache$ cmake --build . --target target_name
~/ns-3-dev/cmake-cache$ cmake --build . --target target_name
Where target_name is a valid target name. Module libraries are prefixed with ``lib`` (e.g. libcore),
executables from the scratch folder are prefixed with ``scratch_`` (e.g. scratch_scratch-simulator).
@@ -540,7 +540,7 @@ produces the following:
~/ns-3-dev$ ./ns3 --dry-run run scratch-simulator
The following commands would be executed:
cd cmake_cache; cmake --build . -j 15 --target scratch_scratch-simulator ; cd ..
cd cmake-cache; cmake --build . -j 15 --target scratch_scratch-simulator ; cd ..
export PATH=$PATH:~/ns-3-dev/build/lib
export PYTHONPATH=~/ns-3-dev/build/bindings/python
export LD_LIBRARY_PATH=~/ns-3-dev/build/lib
@@ -572,10 +572,10 @@ Or directly:
.. sourcecode:: console
~/ns-3-dev/cmake_cache$ export PATH=$PATH:~/ns-3-dev/build/lib
~/ns-3-dev/cmake_cache$ export PYTHONPATH=~/ns-3-dev/build/bindings/python
~/ns-3-dev/cmake_cache$ export LD_LIBRARY_PATH=~/ns-3-dev/build/lib
~/ns-3-dev/cmake_cache$ gdb ../build/scratch/ns3-dev-scratch-simulator
~/ns-3-dev/cmake-cache$ export PATH=$PATH:~/ns-3-dev/build/lib
~/ns-3-dev/cmake-cache$ export PYTHONPATH=~/ns-3-dev/build/bindings/python
~/ns-3-dev/cmake-cache$ export LD_LIBRARY_PATH=~/ns-3-dev/build/lib
~/ns-3-dev/cmake-cache$ gdb ../build/scratch/ns3-dev-scratch-simulator
Modifying files
@@ -802,7 +802,7 @@ Linking third-party libraries using CMake's find_package
Assume we have a module with optional features that rely on a third-party library
that provides a FindThirdPartyPackage.cmake. This Find.cmake file can be distributed
by `CMake itself`_, via library/package managers (APT, Pacman,
`VcPkg`_), or included to the project tree in the buildsupport/3rd_party directory.
`VcPkg`_), or included to the project tree in the build-support/3rd-party directory.
.. _CMake itself: https://github.com/Kitware/CMake/tree/master/Modules
.. _Vcpkg: https://github.com/Microsoft/vcpkg#using-vcpkg-with-cmake
@@ -959,7 +959,7 @@ Inclusion of options
There are two ways of managing module options: option switches or cached variables.
Both are present in the main CMakeLists.txt in the ns-3-dev directory and the
buildsupport/macros_and_definitions.cmake file.
build-support/macros-and-definitions.cmake file.
.. sourcecode:: cmake
@@ -984,10 +984,8 @@ buildsupport/macros_and_definitions.cmake file.
set(NS3_OUTPUT_DIRECTORY "" CACHE PATH "Directory to store built artifacts")
# The last case are options that can only assume predefined values
# First we cache different values for that variable
# First we cache the default option
set(NS3_INT64X64 "INT128" CACHE STRING "Int64x64 implementation")
set(NS3_INT64X64 "CAIRO" CACHE STRING "Int64x64 implementation")
set(NS3_INT64X64 "DOUBLE" CACHE STRING "Int64x64 implementation")
# Then set a cache property for the variable indicating it can assume
# specific values
@@ -1009,7 +1007,7 @@ In order for CMake to feel more familiar to Waf users, a few macros and function
were created.
The most frequently used macros them can be found in
``buildsupport/macros_and_definitions.cmake``. This file includes build type checking,
``build-support/macros-and-definitions.cmake``. This file includes build type checking,
compiler family and version checking, enabling and disabling features based
on user options, checking for dependencies of enabled features,
pre-compiling headers, filtering enabled/disabled modules and dependencies,
@@ -1018,7 +1016,7 @@ and more.
Module macros
=============
Module macros are located in ``buildsupport/custom_modules/ns3_module_macros.cmake``.
Module macros are located in ``build-support/custom-modules/ns3-module-macros.cmake``.
This file contains macros defining a library (``build_lib``), the associated test library,
examples (``build_lib_example``) and more. It also contains the macro that builds the
module header (``write_module_header``) that includes all headers from the module
@@ -1449,7 +1447,7 @@ bindings for the module using pybindgen.
set(module_to_generate_api ${module_api_LP64})
set(LP64toILP32
${Python_EXECUTABLE}
${PROJECT_SOURCE_DIR}/buildsupport/pybindings_LP64_to_ILP32.py
${PROJECT_SOURCE_DIR}/build-support/pybindings_LP64_to_ILP32.py
${module_api_LP64} ${module_api_ILP32}
)
endif()
@@ -1474,7 +1472,7 @@ The targets can be built to execute the scanning using one of the following comm
.. sourcecode:: console
~/cmake_cache$ cmake --build . --target libcore-apiscan
~/cmake-cache$ cmake --build . --target libcore-apiscan
~/ns-3-dev/$ ./ns3 build core-apiscan
To re-scan all bindings, use ``./ns3 build apiscan-all``.
@@ -1859,7 +1857,7 @@ followed by a header configuration:
# CMake variables and save the resulting file to the target destination
# (in the second argument)
configure_file(
buildsupport/core-config-template.h
build-support/core-config-template.h
${CMAKE_HEADER_OUTPUT_DIRECTORY}/core-config.h
)
@@ -2027,7 +2025,7 @@ handled directly by CMake:
Other flags need to be handled manually and change based on
the compiler used. The most commonly used are handled in
``buildsupport/macros_and_definitions.cmake``.
``build-support/macros-and-definitions.cmake``.
.. sourcecode:: cmake

View File

@@ -887,7 +887,7 @@ most of our *repositories* will look:
drwxr-xr-x [up]
-rwxrwxrwx 12507 nov 23 23:12 AUTHORS
drwxrwxrwx 0 dez 30 2020 bindings
drwxrwxrwx 4096 nov 28 11:25 buildsupport
drwxrwxrwx 4096 nov 28 11:25 build-support
-rwxrwxrwx 189870 nov 28 10:13 CHANGES.html
-rwxrwxrwx 1490 nov 22 10:56 .clang-format
-rwxrwxrwx 5079 nov 28 10:50 CMakeLists.txt

View File

@@ -677,10 +677,10 @@ output that looks similar to the following::
-- Configuring done
-- Generating done
-- Build files have been written to: /mnt/dev/tools/source/ns-3-dev/cmake_cache
-- Build files have been written to: /mnt/dev/tools/source/ns-3-dev/cmake-cache
Finished executing the following commands:
mkdir cmake_cache
cd cmake_cache; /usr/bin/cmake -DCMAKE_BUILD_TYPE=release -DNS3_NATIVE_OPTIMIZATIONS=ON -DNS3_EXAMPLES=ON -DNS3_TESTS=ON -G Unix Makefiles .. ; cd ..
mkdir cmake-cache
cd cmake-cache; /usr/bin/cmake -DCMAKE_BUILD_TYPE=release -DNS3_NATIVE_OPTIMIZATIONS=ON -DNS3_EXAMPLES=ON -DNS3_TESTS=ON -G Unix Makefiles .. ; cd ..
Note the last part of the above output. Some |ns3| options are not enabled by
@@ -1011,7 +1011,7 @@ Corresponds to
.. sourcecode:: console
$ cd /ns-3-dev/cmake_cache/
$ cd /ns-3-dev/cmake-cache/
$ cmake -DCMAKE_BUILD_TYPE=release -DNS3_NATIVE_OPTIMIZATIONS=ON -DNS3_ASSERT=OFF -DNS3_LOG=OFF -DNS3_TESTS=ON -DNS3_EXAMPLES=ON ..
Build command
@@ -1027,7 +1027,7 @@ Which corresponds to the following commands:
.. sourcecode:: console
$ cd /ns-3-dev/cmake_cache/
$ cd /ns-3-dev/cmake-cache/
$ cmake --build . -j 16 --target test-runner # This command builds the test-runner target with the underlying build system
@@ -1041,7 +1041,7 @@ Which corresponds to:
.. sourcecode:: console
$ cd /ns-3-dev/cmake_cache/
$ cd /ns-3-dev/cmake-cache/
$ cmake --build . -j 16 # This command builds all the targets with the underlying build system
Run command
@@ -1055,7 +1055,7 @@ Corresponds to:
.. sourcecode:: console
$ cd /ns-3-dev/cmake_cache/
$ cd /ns-3-dev/cmake-cache/
$ cmake --build . -j 16 --target test-runner # This command builds the test-runner target calling the underlying build system
$ export PATH=$PATH:/ns-3-dev/build/:/ns-3-dev/build/lib:/ns-3-dev/build/bindings/python # export library paths
$ export LD_LIBRARY_PATH=/ns-3-dev/build/:/ns-3-dev/build/lib:/ns-3-dev/build/bindings/python
@@ -1161,10 +1161,10 @@ system and underlying build system. https://cmake.org/cmake/help/latest/generato
...
$ -- Build files have been written to: /ns-3-dev/cmake_cache
$ -- Build files have been written to: /ns-3-dev/cmake-cache
There will be a NS3.cbp file inside the cache folder used during configuration (in this case cmake_cache).
There will be a NS3.cbp file inside the cache folder used during configuration (in this case cmake-cache).
This is a Code::Blocks project file that can be opened by the IDE.
When you first open the IDE, you will be greeted by a window asking you to select the compiler you want.
@@ -1217,11 +1217,11 @@ system and underlying build system. https://cmake.org/cmake/help/latest/generato
...
$ -- Build files have been written to: /ns-3-dev/cmake_cache
$ -- Build files have been written to: /ns-3-dev/cmake-cache
There will be a NS3.xcodeproj file inside the cache folder used during configuration
(in this case cmake_cache). This is a XCode project file that can be opened by the IDE.
(in this case cmake-cache). This is a XCode project file that can be opened by the IDE.
Loading the project will take a while, and you will be greeted with the following prompt.
Select to automatically create the schemes.
@@ -1288,7 +1288,7 @@ executing each test, which will actually look something like:
-- Configuring done
-- Generating done
-- Build files have been written to: /ns-3-dev/cmake_cache
-- Build files have been written to: /ns-3-dev/cmake-cache
...
Scanning dependencies of target tap-creator

68
ns3
View File

@@ -11,7 +11,7 @@ import sys
ns3_path = os.path.dirname(os.path.abspath(__file__))
out_dir = os.sep.join([ns3_path, "build"])
lock_file = os.sep.join([ns3_path, ".lock-waf_%s_build" % sys.platform])
lock_file = os.sep.join([ns3_path, ".lock-ns3_%s_build" % sys.platform])
print_buffer = ""
verbose = True
@@ -284,33 +284,31 @@ def parse_args(argv):
return args
def check_c4che_data(output_directory):
# Check the c4cache for the build type (in case there are multiple cmake cache folders
c4che_path = os.sep.join([output_directory, "c4che", "_cache.py"])
def check_lock_data(output_directory):
# Check the .lock-ns3 for the build type (in case there are multiple cmake cache folders
ns3_modules_tests = []
ns3_modules_apiscan = []
ns3_modules_bindings = []
ns3_modules = None
c4che_info = {"BUILD_PROFILE": None,
build_info = {"BUILD_PROFILE": None,
"VERSION": None,
"ENABLE_EXAMPLES": False,
"ENABLE_SUDO": False,
"ENABLE_TESTS": False,
}
if output_directory and os.path.exists(c4che_path):
exec(open(c4che_path).read(), globals(), c4che_info)
ns3_modules = c4che_info["NS3_ENABLED_MODULES"]
if output_directory and os.path.exists(lock_file):
exec(open(lock_file).read(), globals(), build_info)
ns3_modules = build_info["NS3_ENABLED_MODULES"]
if ns3_modules:
if c4che_info["ENABLE_TESTS"]:
if build_info["ENABLE_TESTS"]:
ns3_modules_tests = [x + "-test" for x in ns3_modules]
if c4che_info["ENABLE_PYTHON_BINDINGS"]:
if build_info["ENABLE_PYTHON_BINDINGS"]:
ns3_modules_bindings = [x + "-bindings" for x in ns3_modules]
if "ENABLE_SCAN_PYTHON_BINDINGS" in c4che_info and c4che_info["ENABLE_SCAN_PYTHON_BINDINGS"]:
if "ENABLE_SCAN_PYTHON_BINDINGS" in build_info and build_info["ENABLE_SCAN_PYTHON_BINDINGS"]:
ns3_modules_apiscan = [x + "-apiscan" for x in ns3_modules]
ns3_modules = ns3_modules + ns3_modules_tests + ns3_modules_apiscan + ns3_modules_bindings
return c4che_info, ns3_modules
return build_info, ns3_modules
def print_and_buffer(message):
@@ -379,8 +377,8 @@ def search_cmake_cache(build_profile):
if not current_cmake_generator:
# Search for available generators
cmake_generator_map = {"make": "Unix Makefiles",
"ninja": "Ninja",
cmake_generator_map = {"ninja": "Ninja",
"make": "Unix Makefiles",
"xcodebuild": "Xcode"
}
available_generators = []
@@ -428,7 +426,7 @@ def configure_cmake(cmake, args, current_cmake_cache_folder, current_cmake_gener
if not project_configured(current_cmake_cache_folder):
# Create a new cmake_cache folder if one does not exist
current_cmake_cache_folder = os.sep.join([ns3_path, "cmake_cache"])
current_cmake_cache_folder = os.sep.join([ns3_path, "cmake-cache"])
if not os.path.exists(current_cmake_cache_folder):
print_and_buffer("mkdir %s" % os.path.relpath(current_cmake_cache_folder, ns3_path))
if not dry_run:
@@ -549,11 +547,9 @@ def refresh_cmake(current_cmake_cache_folder, output):
def get_program_shortcuts(build_profile, ns3_version):
build_status_file = os.sep.join([out_dir, "build-status.py"])
# Import programs from build-status.py
# Import programs from .lock-ns3
programs_dict = {}
exec(open(build_status_file).read(), globals(), programs_dict)
exec(open(lock_file).read(), globals(), programs_dict)
# We can now build a map to simplify things for users (at this point we could remove versioning prefix/suffix)
ns3_program_map = {}
@@ -689,8 +685,18 @@ def extract_cmakecache_settings(current_cmake_cache_folder):
current_settings = re.findall("(NS3_.*):.*=(.*)", contents) # extract NS3 specific settings
current_settings.extend(re.findall("(CMAKE_BUILD_TYPE):.*=(.*)", contents)) # extract build type
current_settings.extend(re.findall("(CMAKE_GENERATOR):.*=(.*)", contents)) # extract generator
current_settings.extend(re.findall("(CMAKE_CXX_COMPILER):.*=(.*)", contents)) # C++ compiler
current_settings.extend(re.findall("(CMAKE_CXX_FLAGS):.*=(.*)", contents)) # C++ flags
current_settings.extend(re.findall("(CMAKE_C_COMPILER):.*=(.*)", contents)) # C compiler
current_settings.extend(re.findall("(CMAKE_C_FLAGS):.*=(.*)", contents)) # C flags
current_settings.extend(re.findall("(CMAKE_INSTALL_PREFIX):.*=(.*)", contents)) # installation directory
return dict(current_settings)
# Transform list into dictionary
settings_dictionary = dict(current_settings)
del settings_dictionary["NS3_INT64X64-STRINGS"] # remove cached options or CMake will warn you
# Return dictionary with NS3-related CMake settings
return settings_dictionary
def reconfigure_cmake_to_force_refresh(cmake, current_cmake_cache_folder, output, dry_run=False):
@@ -938,6 +944,12 @@ def run_step(args, target_to_run, target_args):
if not args.dry_run:
try:
ret = subprocess.run(program_arguments, env=proc_env, cwd=working_dir, shell=use_shell)
# Forward POSIX signal error codes
if ret.returncode < 0:
os.kill(os.getpid(), -ret.returncode)
# Return in case of a positive error number
exit(ret.returncode)
except KeyboardInterrupt:
print("Process was interrupted by the user")
@@ -1052,15 +1064,15 @@ def main():
args.build = ['uninstall']
# Get build profile and other settings
c4che_info, ns3_modules = check_c4che_data(out_dir)
build_profile = c4che_info["BUILD_PROFILE"]
enable_sudo = c4che_info["ENABLE_SUDO"]
ns3_version = c4che_info["VERSION"]
build_info, ns3_modules = check_lock_data(out_dir)
build_profile = build_info["BUILD_PROFILE"]
enable_sudo = build_info["ENABLE_SUDO"]
ns3_version = build_info["VERSION"]
# Docs options become cmake targets
if args.docs:
args.build = [args.docs] if args.docs != "all" else ["sphinx", "doxygen"]
if "doxygen" in args.build and (not c4che_info["ENABLE_EXAMPLES"] or not c4che_info["ENABLE_TESTS"]):
if "doxygen" in args.build and (not build_info["ENABLE_EXAMPLES"] or not build_info["ENABLE_TESTS"]):
print('The "./ns3 docs doxygen" and "./ns3 docs all" commands,\n'
'require examples and tests to generate introspected documentation.\n'
'Try "./ns3 docs doxygen-no-build" or enable examples and tests.')
@@ -1140,10 +1152,10 @@ def main():
if ns3_modules is None:
project_not_configured()
# We could also replace the "ns3-" prefix used in c4che with the "lib" prefix currently used in cmake
# We could also replace the "ns3-" prefix used in .lock-ns3 with the "lib" prefix currently used in cmake
ns3_modules = [module.replace("ns3-", "") for module in ns3_modules]
# Now that CMake is configured, we can look for c++ targets in build-status.py
# Now that CMake is configured, we can look for c++ targets in .lock-ns3
ns3_programs = get_program_shortcuts(build_profile, ns3_version)
def check_ambiguous_target(target_type, target_to_check, programs):

View File

@@ -25,7 +25,7 @@ endforeach()
# Build the lib-ns3-static (ns3.x-static-buildtype.a/.lib) with all sublibraries
if(${NS3_STATIC})
add_library(
${lib-ns3-static} STATIC ${PROJECT_SOURCE_DIR}/buildsupport/empty.cc
${lib-ns3-static} STATIC ${PROJECT_SOURCE_DIR}/build-support/empty.cc
"${lib-ns3-static-objs}"
)
@@ -65,7 +65,7 @@ endif()
# sublibraries
if(${NS3_MONOLIB})
add_library(
${lib-ns3-monolib} SHARED ${PROJECT_SOURCE_DIR}/buildsupport/empty.cc
${lib-ns3-monolib} SHARED ${PROJECT_SOURCE_DIR}/build-support/empty.cc
"${lib-ns3-static-objs}"
)
set_target_properties(

View File

@@ -23,7 +23,7 @@ if(${ENABLE_MPI})
${MPI_CXX_LIBRARIES}
)
target_include_directories(
${name}
brite-MPI-example
PUBLIC ${MPI_CXX_INCLUDE_DIRS}
)
endif()

View File

@@ -1,5 +1,3 @@
set(name)
set(source_files
helper/internet-stack-helper.cc
helper/internet-trace-helper.cc
@@ -130,8 +128,6 @@ set(source_files
model/udp-socket.cc
)
set(private_header_files)
set(header_files
${header_files}
helper/internet-stack-helper.h

View File

@@ -1,5 +1,6 @@
set(base_examples
lr-wpan-data
lr-wpan-mlme
lr-wpan-packet-print
lr-wpan-phy-test
)

View File

@@ -1,3 +1,7 @@
set(emu_sources)
set(emu_headers)
set(emu_features)
set(emu_libraries)
if(${ENABLE_EMU})
set(emu_sources
helper/emu-epc-helper.cc
@@ -5,6 +9,9 @@ if(${ENABLE_EMU})
set(emu_headers
helper/emu-epc-helper.h
)
set(emu_features
EmuFdNetDevice
)
set(emu_libraries
${libfd-net-device}
)
@@ -349,4 +356,5 @@ build_lib(
${libinternet}
${libcsma}
TEST_SOURCES ${test_sources}
MODULE_ENABLED_FEATURES ${emu_features}
)

View File

@@ -1,25 +1,27 @@
set(base_examples
lena-cc-helper
lena-cqi-threshold
lena-deactivate-bearer
lena-distributed-ffr
lena-dual-stripe
lena-fading
lena-frequency-reuse
lena-intercell-interference
lena-ipv6-addr-conf
lena-ipv6-ue-rh
lena-ipv6-ue-ue
lena-pathloss-traces
lena-profiling
lena-radio-link-failure
lena-rem
lena-rem-sector-antenna
lena-rlc-traces
lena-simple
lena-simple-epc
lena-deactivate-bearer
lena-simple-epc-backhaul
lena-uplink-power-control
lena-x2-handover
lena-x2-handover-measures
lena-frequency-reuse
lena-distributed-ffr
lena-uplink-power-control
lena-ipv6-addr-conf
lena-ipv6-ue-rh
lena-ipv6-ue-ue
lena-radio-link-failure
)
foreach(

View File

@@ -1,5 +1,3 @@
set(name)
set(source_files
helper/application-container.cc
helper/delay-jitter-estimation.cc

View File

@@ -1,19 +1,3 @@
set(name)
set(source_files)
set(header_files)
set(deprecated_header_files)
set(libraries_to_link
${libinternet}
)
set(test_sources
test/nix-test.cc
)
build_lib(
LIBNAME nix-vector-routing
SOURCE_FILES helper/nix-vector-helper.cc

View File

@@ -18,3 +18,14 @@ foreach(
${libnix-vector-routing}
)
endforeach()
build_lib_example(
NAME nix-double-wifi
SOURCE_FILES nix-double-wifi.cc
LIBRARIES_TO_LINK
${libpoint-to-point}
${libwifi}
${libapplications}
${libinternet}
${libnix-vector-routing}
)

View File

@@ -1,11 +1,3 @@
set(name)
set(source_files)
set(header_files)
set(libraries_to_link)
build_lib(
LIBNAME point-to-point-layout
SOURCE_FILES

View File

@@ -93,8 +93,8 @@ endif()
add_library(
${lib${name}}
OBJECT
${PROJECT_SOURCE_DIR}/buildsupport/empty.cc # empty source file if only
# libcore is enabled
${PROJECT_SOURCE_DIR}/build-support/empty.cc # empty source file if only
# libcore is enabled
${applications_sources}
${csma_sources}
${dsr_sources}

View File

@@ -1,4 +1,4 @@
include_directories(${Python_INCLUDE_DIRS})
include_directories(${PYTHON_INCLUDE_DIRS})
build_lib(
LIBNAME visualizer
@@ -6,7 +6,7 @@ build_lib(
model/visual-simulator-impl.cc
HEADER_FILES model/pyviz.h
LIBRARIES_TO_LINK
${Python_LIBRARIES}
${PYTHON_LIBRARIES}
${libcore}
${libinternet}
${libwifi}

View File

@@ -1,21 +0,0 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright 2011 University of Washington
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Mitch Watrous (watrous@u.washington.edu)
*/
// This file does nothing.

22
test.py
View File

@@ -50,7 +50,7 @@ except ImportError:
# XXX This should really be part of a ns3 command to list the configuration
# items relative to optional ns-3 pieces.
#
# A list of interesting configuration items in the waf configuration
# A list of interesting configuration items in the ns3 configuration
# cache which we may be interested in when deciding on which examples
# to run and how to run them. These are set by ns3 during the
# configuration phase and the corresponding assignments are usually
@@ -593,16 +593,14 @@ def sigint_hook(signal, frame):
# and use that result.
#
def read_ns3_config():
lock_filename = ".lock-ns3_%s_build" % sys.platform
f = None
try:
# sys.platform reports linux2 for python2 and linux for python3
f = open(".lock-waf_" + sys.platform + "_build", "rt")
f = open(lock_filename, "rt")
except FileNotFoundError:
try:
f = open(".lock-waf_linux2_build", "rt")
except FileNotFoundError:
print('The .lock-waf ... directory was not found. You must do waf build before running test.py.', file=sys.stderr)
sys.exit(2)
print('The .lock-ns3 file was not found. You must configure before running test.py.', file=sys.stderr)
sys.exit(2)
for line in f:
if line.startswith("top_dir ="):
@@ -619,7 +617,7 @@ def read_ns3_config():
global NS3_BUILDDIR
NS3_BUILDDIR = out_dir
with open("%s/c4che/_cache.py" % out_dir) as f:
with open(lock_filename) as f:
for line in f.readlines():
for item in interesting_config_items:
if line.startswith(item):
@@ -1116,10 +1114,10 @@ def run_tests():
#
# Get the information from the build status file.
#
build_status_file = os.path.join(NS3_BUILDDIR, 'build-status.py')
if os.path.exists(build_status_file):
ns3_runnable_programs = get_list_from_file(build_status_file, "ns3_runnable_programs")
ns3_runnable_scripts = get_list_from_file(build_status_file, "ns3_runnable_scripts")
lock_filename = ".lock-ns3_%s_build" % sys.platform
if os.path.exists(lock_filename):
ns3_runnable_programs = get_list_from_file(lock_filename, "ns3_runnable_programs")
ns3_runnable_scripts = get_list_from_file(lock_filename, "ns3_runnable_scripts")
ns3_runnable_scripts = [os.path.basename(script) for script in ns3_runnable_scripts]
else:
print('The build status file was not found. You must configure before running test.py.', file=sys.stderr)

View File

@@ -33,11 +33,10 @@ from functools import partial
# Get path containing ns3
ns3_path = os.path.dirname(os.path.abspath(os.sep.join([__file__, "../../"])))
ns3_lock_filename = os.path.join(ns3_path, ".lock-ns3_%s_build" % sys.platform)
ns3_script = os.sep.join([ns3_path, "ns3"])
ns3rc_script = os.sep.join([ns3_path, ".ns3rc"])
usual_outdir = os.sep.join([ns3_path, "build"])
usual_build_status_script = os.sep.join([usual_outdir, "build-status.py"])
usual_c4che_script = os.sep.join([usual_outdir, "c4che", "_cache.py"])
usual_lib_outdir = os.sep.join([usual_outdir, "lib"])
# Move the current working directory to the ns-3-dev folder
@@ -106,14 +105,13 @@ def run_program(program, args, python=False, cwd=ns3_path, env=None):
return ret.returncode, ret.stdout.decode(sys.stdout.encoding), ret.stderr.decode(sys.stderr.encoding)
def get_programs_list(build_status_script_path=usual_build_status_script):
def get_programs_list():
"""!
Extracts the programs list from build-status.py
@param build_status_script_path: path containing build-status.py
Extracts the programs list from .lock-ns3
@return list of programs.
"""
values = {}
with open(build_status_script_path) as f:
with open(ns3_lock_filename) as f:
exec(f.read(), globals(), values)
return values["ns3_runnable_programs"]
@@ -136,35 +134,151 @@ def get_headers_list(outdir=usual_outdir):
return glob.glob(outdir + '/**/*.h', recursive=True)
def read_c4che_entry(entry, c4che_script_path=usual_c4che_script):
def read_buildstatus_entry(entry):
"""!
Read interesting entries from the c4che/_cache.py file
@param entry: entry to read from c4che/_cache.py
@param c4che_script_path: path containing _cache.py
Read interesting entries from the .lock-ns3 file
@param entry: entry to read from .lock-ns3
@return value of the requested entry.
"""
values = {}
with open(c4che_script_path) as f:
with open(ns3_lock_filename) as f:
exec(f.read(), globals(), values)
return values.get(entry, None)
def get_test_enabled():
"""!
Check if tests are enabled in the c4che/_cache.py
Check if tests are enabled in the .lock-ns3
@return bool.
"""
return read_c4che_entry("ENABLE_TESTS")
return read_buildstatus_entry("ENABLE_TESTS")
def get_enabled_modules():
"""
Check if tests are enabled in the c4che/_cache.py
Check if tests are enabled in the .lock-ns3
@return list of enabled modules (prefixed with 'ns3-').
"""
return read_c4che_entry("NS3_ENABLED_MODULES")
return read_buildstatus_entry("NS3_ENABLED_MODULES")
class NS3UnusedSourcesTestCase(unittest.TestCase):
"""!
ns-3 tests related to checking if source files were left behind, not being used by CMake
"""
## dictionary containing directories with .cc source files
directory_and_files = {}
def setUp(self):
"""!
Scan all C++ source files and add them to a list based on their path
@return None
"""
for root, dirs, files in os.walk(ns3_path):
for name in files:
if name.endswith(".cc"):
path = os.path.join(root, name)
directory = os.path.dirname(path)
if directory not in self.directory_and_files:
self.directory_and_files[directory] = []
self.directory_and_files[directory].append(path)
def test_01_UnusedExampleSources(self):
"""!
Test if all example source files are being used in their respective CMakeLists.txt
@return None
"""
unused_sources = set()
for example_directory in self.directory_and_files.keys():
# Skip non-example directories
if os.sep+"examples" not in example_directory:
continue
# Open the examples CMakeLists.txt and read it
with open(os.path.join(example_directory, "CMakeLists.txt"), "r") as f:
cmake_contents = f.read()
# For each file, check if it is in the CMake contents
for file in self.directory_and_files[example_directory]:
# We remove the .cc because some examples sources can be written as ${example_name}.cc
if os.path.basename(file).replace(".cc", "") not in cmake_contents:
unused_sources.add(file)
self.assertListEqual([], list(unused_sources))
def test_02_UnusedModuleSources(self):
"""!
Test if all module source files are being used in their respective CMakeLists.txt
@return None
"""
unused_sources = set()
for directory in self.directory_and_files.keys():
# Skip examples and bindings directories
is_not_module = not ("src" in directory or "contrib" in directory)
is_example = os.sep + "examples" in directory
is_bindings = os.sep + "bindings" in directory
if is_not_module or is_bindings or is_example:
continue
# We can be in one of the module subdirectories (helper, model, test, bindings, etc)
# Navigate upwards until we hit a CMakeLists.txt
cmake_path = os.path.join(directory, "CMakeLists.txt")
while not os.path.exists(cmake_path):
parent_directory = os.path.dirname(os.path.dirname(cmake_path))
cmake_path = os.path.join(parent_directory, os.path.basename(cmake_path))
# Open the module CMakeLists.txt and read it
with open(cmake_path, "r") as f:
cmake_contents = f.read()
# For each file, check if it is in the CMake contents
for file in self.directory_and_files[directory]:
if os.path.basename(file) not in cmake_contents:
unused_sources.add(file)
# Remove temporary exceptions
exceptions = ["win32-system-wall-clock-ms.cc", # Should be removed with MR784
]
for exception in exceptions:
for unused_source in unused_sources:
if os.path.basename(unused_source) == exception:
unused_sources.remove(unused_source)
break
self.assertListEqual([], list(unused_sources))
def test_03_UnusedUtilsSources(self):
"""!
Test if all utils source files are being used in their respective CMakeLists.txt
@return None
"""
unused_sources = set()
for directory in self.directory_and_files.keys():
# Skip directories that are not utils
is_module = "src" in directory or "contrib" in directory
if os.sep+"utils" not in directory or is_module:
continue
# We can be in one of the module subdirectories (helper, model, test, bindings, etc)
# Navigate upwards until we hit a CMakeLists.txt
cmake_path = os.path.join(directory, "CMakeLists.txt")
while not os.path.exists(cmake_path):
parent_directory = os.path.dirname(os.path.dirname(cmake_path))
cmake_path = os.path.join(parent_directory, os.path.basename(cmake_path))
# Open the module CMakeLists.txt and read it
with open(cmake_path, "r") as f:
cmake_contents = f.read()
# For each file, check if it is in the CMake contents
for file in self.directory_and_files[directory]:
if os.path.basename(file) not in cmake_contents:
unused_sources.add(file)
self.assertListEqual([], list(unused_sources))
class NS3CommonSettingsTestCase(unittest.TestCase):
"""!
ns3 tests related to generic options
@@ -244,7 +358,7 @@ class NS3ConfigureBuildProfileTestCase(unittest.TestCase):
Test the debug build
@return None
"""
return_code, stdout, stderr = run_ns3("configure -d debug --enable-verbose")
return_code, stdout, stderr = run_ns3("configure -G \"Unix Makefiles\" -d debug --enable-verbose")
self.assertEqual(return_code, 0)
self.assertIn("Build profile : debug", stdout)
self.assertIn("Build files have been written to", stdout)
@@ -263,7 +377,7 @@ class NS3ConfigureBuildProfileTestCase(unittest.TestCase):
Test the release build
@return None
"""
return_code, stdout, stderr = run_ns3("configure -d release")
return_code, stdout, stderr = run_ns3("configure -G \"Unix Makefiles\" -d release")
self.assertEqual(return_code, 0)
self.assertIn("Build profile : release", stdout)
self.assertIn("Build files have been written to", stdout)
@@ -273,7 +387,7 @@ class NS3ConfigureBuildProfileTestCase(unittest.TestCase):
Test the optimized build
@return None
"""
return_code, stdout, stderr = run_ns3("configure -d optimized --enable-verbose")
return_code, stdout, stderr = run_ns3("configure -G \"Unix Makefiles\" -d optimized --enable-verbose")
self.assertEqual(return_code, 0)
self.assertIn("Build profile : optimized", stdout)
self.assertIn("Build files have been written to", stdout)
@@ -292,7 +406,7 @@ class NS3ConfigureBuildProfileTestCase(unittest.TestCase):
Test a build type with a typo
@return None
"""
return_code, stdout, stderr = run_ns3("configure -d Optimized")
return_code, stdout, stderr = run_ns3("configure -G \"Unix Makefiles\" -d Optimized")
self.assertEqual(return_code, 2)
self.assertIn("invalid choice: 'Optimized'", stderr)
@@ -301,7 +415,7 @@ class NS3ConfigureBuildProfileTestCase(unittest.TestCase):
Test a build type with another typo
@return None
"""
return_code, stdout, stderr = run_ns3("configure -d OPTIMIZED")
return_code, stdout, stderr = run_ns3("configure -G \"Unix Makefiles\" -d OPTIMIZED")
self.assertEqual(return_code, 2)
self.assertIn("invalid choice: 'OPTIMIZED'", stderr)
@@ -341,17 +455,17 @@ class NS3BaseTestCase(unittest.TestCase):
if not NS3BaseTestCase.cleaned_once:
NS3BaseTestCase.cleaned_once = True
run_ns3("clean")
return_code, stdout, stderr = run_ns3("configure -d release --enable-verbose")
return_code, stdout, stderr = run_ns3("configure -G \"Unix Makefiles\" -d release --enable-verbose")
self.config_ok(return_code, stdout)
# Check if build-status.py exists, then read to get list of executables.
self.assertTrue(os.path.exists(usual_build_status_script))
## ns3_executables holds a list of executables in build-status.py
# Check if .lock-ns3 exists, then read to get list of executables.
self.assertTrue(os.path.exists(ns3_lock_filename))
## ns3_executables holds a list of executables in .lock-ns3
self.ns3_executables = get_programs_list()
# Check if c4che.py exists than read to get the list of enabled modules.
self.assertTrue(os.path.exists(usual_c4che_script))
## ns3_modules holds a list to the modules enabled stored in c4che.py
# Check if .lock-ns3 exists than read to get the list of enabled modules.
self.assertTrue(os.path.exists(ns3_lock_filename))
## ns3_modules holds a list to the modules enabled stored in .lock-ns3
self.ns3_modules = get_enabled_modules()
@@ -378,7 +492,7 @@ class NS3ConfigureTestCase(NS3BaseTestCase):
Test enabling and disabling examples
@return None
"""
return_code, stdout, stderr = run_ns3("configure --enable-examples")
return_code, stdout, stderr = run_ns3("configure -G \"Unix Makefiles\" --enable-examples")
# This just tests if we didn't break anything, not that we actually have enabled anything.
self.config_ok(return_code, stdout)
@@ -387,7 +501,7 @@ class NS3ConfigureTestCase(NS3BaseTestCase):
self.assertGreater(len(get_programs_list()), len(self.ns3_executables))
# Now we disabled them back.
return_code, stdout, stderr = run_ns3("configure --disable-examples")
return_code, stdout, stderr = run_ns3("configure -G \"Unix Makefiles\" --disable-examples")
# This just tests if we didn't break anything, not that we actually have enabled anything.
self.config_ok(return_code, stdout)
@@ -401,7 +515,7 @@ class NS3ConfigureTestCase(NS3BaseTestCase):
@return None
"""
# Try enabling tests
return_code, stdout, stderr = run_ns3("configure --enable-tests")
return_code, stdout, stderr = run_ns3("configure -G \"Unix Makefiles\" --enable-tests")
self.config_ok(return_code, stdout)
# Then try building the libcore test
@@ -412,7 +526,7 @@ class NS3ConfigureTestCase(NS3BaseTestCase):
self.assertIn("Built target libcore-test", stdout)
# Now we disabled the tests
return_code, stdout, stderr = run_ns3("configure --disable-tests")
return_code, stdout, stderr = run_ns3("configure -G \"Unix Makefiles\" --disable-tests")
self.config_ok(return_code, stdout)
# Now building the library test should fail
@@ -428,7 +542,7 @@ class NS3ConfigureTestCase(NS3BaseTestCase):
@return None
"""
# Try filtering enabled modules to network+Wi-Fi and their dependencies
return_code, stdout, stderr = run_ns3("configure --enable-modules='network;wifi'")
return_code, stdout, stderr = run_ns3("configure -G \"Unix Makefiles\" --enable-modules='network;wifi'")
self.config_ok(return_code, stdout)
# At this point we should have fewer modules
@@ -438,12 +552,12 @@ class NS3ConfigureTestCase(NS3BaseTestCase):
self.assertIn("ns3-wifi", enabled_modules)
# Try enabling only core
return_code, stdout, stderr = run_ns3("configure --enable-modules='core' --enable-python-bindings")
return_code, stdout, stderr = run_ns3("configure -G \"Unix Makefiles\" --enable-modules='core' --enable-python-bindings")
self.config_ok(return_code, stdout)
self.assertIn("ns3-core", get_enabled_modules())
# Try cleaning the list of enabled modules to reset to the normal configuration.
return_code, stdout, stderr = run_ns3("configure --enable-modules='' --disable-python-bindings")
return_code, stdout, stderr = run_ns3("configure -G \"Unix Makefiles\" --enable-modules='' --disable-python-bindings")
self.config_ok(return_code, stdout)
# At this point we should have the same amount of modules that we had when we started.
@@ -455,7 +569,7 @@ class NS3ConfigureTestCase(NS3BaseTestCase):
@return None
"""
# Try filtering disabled modules to disable lte and modules that depend on it.
return_code, stdout, stderr = run_ns3("configure --disable-modules='lte;wimax'")
return_code, stdout, stderr = run_ns3("configure -G \"Unix Makefiles\" --disable-modules='lte;wimax'")
self.config_ok(return_code, stdout)
# At this point we should have fewer modules.
@@ -465,7 +579,7 @@ class NS3ConfigureTestCase(NS3BaseTestCase):
self.assertNotIn("ns3-wimax", enabled_modules)
# Try cleaning the list of enabled modules to reset to the normal configuration.
return_code, stdout, stderr = run_ns3("configure --disable-modules=''")
return_code, stdout, stderr = run_ns3("configure -G \"Unix Makefiles\" --disable-modules=''")
self.config_ok(return_code, stdout)
# At this point we should have the same amount of modules that we had when we started.
@@ -477,7 +591,7 @@ class NS3ConfigureTestCase(NS3BaseTestCase):
@return None
"""
# Try filtering enabled modules to network+Wi-Fi and their dependencies.
return_code, stdout, stderr = run_ns3("configure --enable-modules='network,wifi'")
return_code, stdout, stderr = run_ns3("configure -G \"Unix Makefiles\" --enable-modules='network,wifi'")
self.config_ok(return_code, stdout)
# At this point we should have fewer modules.
@@ -487,7 +601,7 @@ class NS3ConfigureTestCase(NS3BaseTestCase):
self.assertIn("ns3-wifi", enabled_modules)
# Try cleaning the list of enabled modules to reset to the normal configuration.
return_code, stdout, stderr = run_ns3("configure --enable-modules=''")
return_code, stdout, stderr = run_ns3("configure -G \"Unix Makefiles\" --enable-modules=''")
self.config_ok(return_code, stdout)
# At this point we should have the same amount of modules that we had when we started.
@@ -499,7 +613,7 @@ class NS3ConfigureTestCase(NS3BaseTestCase):
@return None
"""
# Try filtering disabled modules to disable lte and modules that depend on it.
return_code, stdout, stderr = run_ns3("configure --disable-modules='lte,mpi'")
return_code, stdout, stderr = run_ns3("configure -G \"Unix Makefiles\" --disable-modules='lte,mpi'")
self.config_ok(return_code, stdout)
# At this point we should have fewer modules.
@@ -509,7 +623,7 @@ class NS3ConfigureTestCase(NS3BaseTestCase):
self.assertNotIn("ns3-mpi", enabled_modules)
# Try cleaning the list of enabled modules to reset to the normal configuration.
return_code, stdout, stderr = run_ns3("configure --disable-modules=''")
return_code, stdout, stderr = run_ns3("configure -G \"Unix Makefiles\" --disable-modules=''")
self.config_ok(return_code, stdout)
# At this point we should have the same amount of modules that we had when we started.
@@ -540,7 +654,7 @@ class NS3ConfigureTestCase(NS3BaseTestCase):
f.write(ns3rc_template.format(modules="'lte'", examples="False", tests="True"))
# Reconfigure.
return_code, stdout, stderr = run_ns3("configure")
return_code, stdout, stderr = run_ns3("configure -G \"Unix Makefiles\"")
self.config_ok(return_code, stdout)
# Check.
@@ -555,7 +669,7 @@ class NS3ConfigureTestCase(NS3BaseTestCase):
f.write(ns3rc_template.format(modules="'wifi'", examples="True", tests="False"))
# Reconfigure
return_code, stdout, stderr = run_ns3("configure")
return_code, stdout, stderr = run_ns3("configure -G \"Unix Makefiles\"")
self.config_ok(return_code, stdout)
# Check
@@ -569,7 +683,7 @@ class NS3ConfigureTestCase(NS3BaseTestCase):
os.remove(ns3rc_script)
# Reconfigure
return_code, stdout, stderr = run_ns3("configure")
return_code, stdout, stderr = run_ns3("configure -G \"Unix Makefiles\"")
self.config_ok(return_code, stdout)
# Check
@@ -593,8 +707,10 @@ class NS3ConfigureTestCase(NS3BaseTestCase):
self.assertEqual(stdout, stdout1)
self.assertEqual(stderr, stderr1)
run_ns3("clean")
# Build target before using below
run_ns3("configure -d release --enable-verbose")
run_ns3("configure -G \"Unix Makefiles\" -d release --enable-verbose")
run_ns3("build scratch-simulator")
# Run all cases and then check outputs
@@ -638,7 +754,7 @@ class NS3ConfigureTestCase(NS3BaseTestCase):
return_code, _, _ = run_ns3("clean")
self.assertEqual(return_code, 0)
return_code, _, _ = run_ns3("configure --enable-examples --enable-tests")
return_code, _, _ = run_ns3("configure -G \"Unix Makefiles\" --enable-examples --enable-tests")
self.assertEqual(return_code, 0)
# Build necessary executables
@@ -678,7 +794,7 @@ class NS3ConfigureTestCase(NS3BaseTestCase):
Test passing --check-version argument to ns3 to get the build version
@return None
"""
return_code, _, _ = run_ns3("configure --enable-build-version")
return_code, _, _ = run_ns3("configure -G \"Unix Makefiles\" --enable-build-version")
self.assertEqual(return_code, 0)
return_code, stdout, stderr = run_ns3("--check-version")
@@ -711,7 +827,7 @@ class NS3ConfigureTestCase(NS3BaseTestCase):
f.write("")
# Reload the cmake cache to pick them up
return_code, stdout, stderr = run_ns3("configure")
return_code, stdout, stderr = run_ns3("configure -G \"Unix Makefiles\"")
self.assertEqual(return_code, 0)
# Try to build them with ns3 and cmake
@@ -719,7 +835,7 @@ class NS3ConfigureTestCase(NS3BaseTestCase):
path = path.replace(".cc", "")
return_code1, stdout1, stderr1 = run_program("cmake", "--build . --target %s"
% path.replace("/", "_"),
cwd=os.path.join(ns3_path, "cmake_cache"))
cwd=os.path.join(ns3_path, "cmake-cache"))
return_code2, stdout2, stderr2 = run_ns3("build %s" % path)
if "main" in path:
self.assertEqual(return_code1, 0)
@@ -754,7 +870,7 @@ class NS3ConfigureTestCase(NS3BaseTestCase):
if path not in ["scratch/main.cc", "scratch/empty.cc"]:
os.rmdir(os.path.dirname(source_absolute_path))
return_code, stdout, stderr = run_ns3("configure")
return_code, stdout, stderr = run_ns3("configure -G \"Unix Makefiles\"")
self.assertEqual(return_code, 0)
def test_14_MpiCommandTemplate(self):
@@ -891,7 +1007,7 @@ class NS3BuildBaseTestCase(NS3BaseTestCase):
f.write("3-00\n")
# Reconfigure.
return_code, stdout, stderr = run_ns3("configure")
return_code, stdout, stderr = run_ns3("configure -G \"Unix Makefiles\"")
self.config_ok(return_code, stdout)
# Build.
@@ -937,7 +1053,7 @@ class NS3BuildBaseTestCase(NS3BaseTestCase):
## ns3_libraries holds a list of built module libraries
self.ns3_libraries = get_libraries_list()
## ns3_executables holds a list of executables in build-status.py
## ns3_executables holds a list of executables in .lock-ns3
self.ns3_executables = get_programs_list()
# Delete built programs and libraries to check if they were restored later.
@@ -950,7 +1066,7 @@ class NS3BuildBaseTestCase(NS3BaseTestCase):
absolute_path = os.sep.join([ns3_path, "build", "release"])
relative_path = os.sep.join(["build", "release"])
for different_out_dir in [absolute_path, relative_path]:
return_code, stdout, stderr = run_ns3("configure --out=%s" % different_out_dir)
return_code, stdout, stderr = run_ns3("configure -G \"Unix Makefiles\" --out=%s" % different_out_dir)
self.config_ok(return_code, stdout)
self.assertIn("Build directory : %s" % absolute_path, stdout)
@@ -958,7 +1074,7 @@ class NS3BuildBaseTestCase(NS3BaseTestCase):
run_ns3("build")
# Check if we have the same number of binaries and that they were built correctly.
new_programs = get_programs_list(os.sep.join([absolute_path, "build-status.py"]))
new_programs = get_programs_list()
self.assertEqual(len(new_programs), len(self.ns3_executables))
for program in new_programs:
self.assertTrue(os.path.exists(program))
@@ -974,7 +1090,7 @@ class NS3BuildBaseTestCase(NS3BaseTestCase):
shutil.rmtree(absolute_path)
# Restore original output directory.
return_code, stdout, stderr = run_ns3("configure --out=''")
return_code, stdout, stderr = run_ns3("configure -G \"Unix Makefiles\" --out=''")
self.config_ok(return_code, stdout)
self.assertIn("Build directory : %s" % usual_outdir, stdout)
@@ -1012,7 +1128,7 @@ class NS3BuildBaseTestCase(NS3BaseTestCase):
# Reconfigure setting the installation folder to ns-3-dev/build/install.
install_prefix = os.sep.join([ns3_path, "build", "install"])
return_code, stdout, stderr = run_ns3("configure --prefix=%s" % install_prefix)
return_code, stdout, stderr = run_ns3("configure -G \"Unix Makefiles\" --prefix=%s" % install_prefix)
self.config_ok(return_code, stdout)
# Build.
@@ -1172,7 +1288,7 @@ class NS3BuildBaseTestCase(NS3BaseTestCase):
self.skipTest("Pybindgen is not available")
# First we enable python bindings
return_code, stdout, stderr = run_ns3("configure --enable-examples --enable-tests --enable-python-bindings")
return_code, stdout, stderr = run_ns3("configure -G \"Unix Makefiles\" --enable-examples --enable-tests --enable-python-bindings")
self.assertEqual(return_code, 0)
# Then look for python bindings sources
@@ -1192,7 +1308,7 @@ class NS3BuildBaseTestCase(NS3BaseTestCase):
self.assertGreater(len(list(filter(lambda x: "_core" in x, os.listdir(core_bindings_path)))), 0)
# Now enable python bindings scanning
return_code, stdout, stderr = run_ns3("configure -- -DNS3_SCAN_PYTHON_BINDINGS=ON")
return_code, stdout, stderr = run_ns3("configure -G \"Unix Makefiles\" -- -DNS3_SCAN_PYTHON_BINDINGS=ON")
self.assertEqual(return_code, 0)
# Get the file status for the current scanned bindings
@@ -1219,7 +1335,7 @@ class NS3BuildBaseTestCase(NS3BaseTestCase):
os.remove(os.path.join(core_bindings_generated_sources_path, f))
# Reconfigure to recreate the source files
return_code, stdout, stderr = run_ns3("configure")
return_code, stdout, stderr = run_ns3("configure -G \"Unix Makefiles\"")
self.assertEqual(return_code, 0)
# Check again if they exist
@@ -1257,7 +1373,7 @@ class NS3BuildBaseTestCase(NS3BaseTestCase):
shutil.copy("./examples/tutorial/second.cc", "./scratch/second.cc")
# Reconfigure to re-scan the scratches
return_code, stdout, stderr = run_ns3("configure --enable-examples")
return_code, stdout, stderr = run_ns3("configure -G \"Unix Makefiles\" --enable-examples")
self.assertEqual(return_code, 0)
# Try to run second and collide
@@ -1318,19 +1434,19 @@ class NS3ExpectedUseTestCase(NS3BaseTestCase):
super().setUp()
# On top of the release build configured by NS3ConfigureTestCase, also enable examples, tests and docs.
return_code, stdout, stderr = run_ns3("configure --enable-examples --enable-tests")
return_code, stdout, stderr = run_ns3("configure -G \"Unix Makefiles\" --enable-examples --enable-tests")
self.config_ok(return_code, stdout)
# Check if build-status.py exists, then read to get list of executables.
self.assertTrue(os.path.exists(usual_build_status_script))
# Check if .lock-ns3 exists, then read to get list of executables.
self.assertTrue(os.path.exists(ns3_lock_filename))
## ns3_executables holds a list of executables in build-status.py
## ns3_executables holds a list of executables in .lock-ns3
self.ns3_executables = get_programs_list()
# Check if c4che.py exists than read to get the list of enabled modules.
self.assertTrue(os.path.exists(usual_c4che_script))
# Check if .lock-ns3 exists than read to get the list of enabled modules.
self.assertTrue(os.path.exists(ns3_lock_filename))
## ns3_modules holds a list to the modules enabled stored in c4che.py
## ns3_modules holds a list to the modules enabled stored in .lock-ns3
self.ns3_modules = get_enabled_modules()
def test_01_BuildProject(self):
@@ -1563,7 +1679,7 @@ class NS3ExpectedUseTestCase(NS3BaseTestCase):
if sudo_password is None:
self.skipTest("SUDO_PASSWORD environment variable was not specified")
enable_sudo = read_c4che_entry("ENABLE_SUDO")
enable_sudo = read_buildstatus_entry("ENABLE_SUDO")
self.assertFalse(enable_sudo is True)
# First we run to ensure the program was built
@@ -1602,8 +1718,8 @@ class NS3ExpectedUseTestCase(NS3BaseTestCase):
return_code, stdout, stderr = run_ns3('configure --enable-sudo')
self.assertEqual(return_code, 0)
# Check if it was properly set in the c4che file
enable_sudo = read_c4che_entry("ENABLE_SUDO")
# Check if it was properly set in the buildstatus file
enable_sudo = read_buildstatus_entry("ENABLE_SUDO")
self.assertTrue(enable_sudo)
# Remove old executables
@@ -1728,6 +1844,7 @@ if __name__ == '__main__':
suite = unittest.TestSuite()
# Put tests cases in order
suite.addTests(loader.loadTestsFromTestCase(NS3UnusedSourcesTestCase))
suite.addTests(loader.loadTestsFromTestCase(NS3CommonSettingsTestCase))
suite.addTests(loader.loadTestsFromTestCase(NS3ConfigureBuildProfileTestCase))
suite.addTests(loader.loadTestsFromTestCase(NS3ConfigureTestCase))