Skip to content

Commit

Permalink
Restruct P4Tools to easily add new modules.
Browse files Browse the repository at this point in the history
  • Loading branch information
fruffy committed Nov 10, 2022
1 parent c59597f commit 0974b37
Show file tree
Hide file tree
Showing 223 changed files with 686 additions and 1,003 deletions.
19 changes: 17 additions & 2 deletions backends/p4tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,23 @@ set(ENABLE_TESTING ON)

# Include sub projects.
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/common)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/testgen)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/p4check)

file(GLOB tools_modules RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/modules ${CMAKE_CURRENT_SOURCE_DIR}/modules/*)
foreach(ext ${tools_modules})
set (tools_dir ${CMAKE_CURRENT_SOURCE_DIR}/modules/${ext})
if(EXISTS ${tools_dir}/CMakeLists.txt AND IS_DIRECTORY ${tools_dir})
# Generate an option that makes it possible to disable this extension.
string(MAKE_C_IDENTIFIER ${ext} EXT_AS_IDENTIFIER)
string(TOUPPER ${EXT_AS_IDENTIFIER} EXT_AS_OPTION_NAME)
string(CONCAT ENABLE_EXT_OPTION "ENABLE_TOOLS_MODULE_" ${EXT_AS_OPTION_NAME})
string(CONCAT EXT_HELP_TEXT "Build the " ${ext} " module")
option(${ENABLE_EXT_OPTION} ${EXT_HELP_TEXT} ON)
if(${ENABLE_EXT_OPTION})
message("-- Enabling P4Tools module ${ext}")
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/modules/${ext})
endif()
endif()
endforeach(ext)

# Custom IR constructs for P4Tools.
set(IR_DEF_FILES ${IR_DEF_FILES} ${CMAKE_CURRENT_SOURCE_DIR}/common/testgen.def PARENT_SCOPE)
14 changes: 0 additions & 14 deletions backends/p4tools/cmake/common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,3 @@ function(add_p4tools_library target)
PUBLIC "${CMAKE_BINARY_DIR}"
)
endfunction(add_p4tools_library)

# Helper for adding a subproject and configuring it for linting.
function(add_and_lint_subdirectory dir cpplint_dir)
add_subdirectory(${dir})
get_filename_component(basedir ${dir} NAME_WE)
add_test(
NAME "testgen-cpplint-${basedir}"
COMMAND sh -c "find '${dir}' \
-iname \\*.h -o -iname \\*.hpp -o -iname \\*.c -o -iname \\*.cpp \
| xargs python3 ${cpplint_dir}/cpplint.py \
--quiet "
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
endfunction(add_and_lint_subdirectory)
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ set(
options.cpp
testgen.cpp


core/arch_spec.cpp
core/externs.cpp
core/program_info.cpp
Expand Down Expand Up @@ -70,9 +69,10 @@ set(
inja
)

file(GLOB tools_targets RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/targets ${CMAKE_CURRENT_SOURCE_DIR}/targets/*)
foreach(ext ${tools_targets})
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/targets/${ext}/CMakeLists.txt)
file(GLOB testgen_targets RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/targets ${CMAKE_CURRENT_SOURCE_DIR}/targets/*)
foreach(ext ${testgen_targets})
set(testgen_targets_dir ${CMAKE_CURRENT_SOURCE_DIR}/targets/${ext}/)
if(EXISTS ${testgen_targets_dir}/CMakeLists.txt AND IS_DIRECTORY ${testgen_targets_dir})
# Generate an option that makes it possible to disable this extension.
string(MAKE_C_IDENTIFIER ${ext} EXT_AS_IDENTIFIER)
string(TOUPPER ${EXT_AS_IDENTIFIER} EXT_AS_OPTION_NAME)
Expand All @@ -82,9 +82,9 @@ foreach(ext ${tools_targets})
if(${ENABLE_EXT_OPTION})
message("-- Enabling target ${ext}")
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/targets/${ext})
set(include_statements "${include_statements}#include \"backends/p4tools/testgen/targets/${ext}/register.h\"\n")
set(compiler_targets "${compiler_targets} ${ext}_registerCompilerTarget();\n")
set(testgen_targets "${testgen_targets} ${ext}_registerTestgenTarget();\n")
set(include_statements_var "${include_statements_var}#include \"backends/p4tools/modules/testgen/targets/${ext}/register.h\"\n")
set(compiler_targets_var "${compiler_targets_var} ${ext}_registerCompilerTarget();\n")
set(testgen_targets_var "${testgen_targets_var} ${ext}_registerTestgenTarget();\n")
endif()
endif()
endforeach(ext)
Expand All @@ -96,13 +96,29 @@ endforeach()
# Fill the template
configure_file(register.h.in register.h)

add_p4tools_library(p4testgen ${TESTGEN_SOURCES})
add_p4tools_library(testgen ${TESTGEN_SOURCES})

target_link_libraries(
testgen
${TESTGEN_LIBS}
)

add_p4tools_executable(p4testgen main.cpp)

target_link_libraries(
p4testgen
testgen
${TESTGEN_LIBS}
)

add_custom_target(
linkp4testgen
# Add some convenience links for invoking p4testgen.
COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_CURRENT_BINARY_DIR}/p4testgen ${CMAKE_BINARY_DIR}/p4testgen
)

add_dependencies(p4testgen linkp4testgen)

if(ENABLE_GTESTS)
add_executable(testgen-gtest ${TESTGEN_GTEST_SOURCES})
target_include_directories(
Expand All @@ -112,7 +128,7 @@ if(ENABLE_GTESTS)
)
target_link_libraries(
testgen-gtest
PRIVATE p4testgen
PRIVATE testgen
PRIVATE gtest
)

Expand All @@ -139,5 +155,5 @@ if(ENABLE_GTESTS)
endif()

if(ENABLE_IWYU)
set_property(TARGET p4testgen PROPERTY CXX_INCLUDE_WHAT_YOU_USE ${iwyu_path})
set_property(TARGET testgen PROPERTY CXX_INCLUDE_WHAT_YOU_USE ${iwyu_path})
endif()
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "backends/p4tools/testgen/core/arch_spec.h"
#include "backends/p4tools/modules/testgen/core/arch_spec.h"

#include "lib/exceptions.h"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef BACKENDS_P4TOOLS_TESTGEN_CORE_ARCH_SPEC_H_
#define BACKENDS_P4TOOLS_TESTGEN_CORE_ARCH_SPEC_H_
#ifndef BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_ARCH_SPEC_H_
#define BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_ARCH_SPEC_H_

#include <map>
#include <vector>
Expand Down Expand Up @@ -61,4 +61,4 @@ class ArchSpec {

} // namespace P4Tools

#endif /* BACKENDS_P4TOOLS_TESTGEN_CORE_ARCH_SPEC_H_ */
#endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_ARCH_SPEC_H_ */
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef BACKENDS_P4TOOLS_TESTGEN_CORE_CONSTANTS_H_
#define BACKENDS_P4TOOLS_TESTGEN_CORE_CONSTANTS_H_
#ifndef BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_CONSTANTS_H_
#define BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_CONSTANTS_H_

#include "ir/ir.h"

Expand Down Expand Up @@ -37,4 +37,4 @@ class P4Constants {

} // namespace P4Tools

#endif /* BACKENDS_P4TOOLS_TESTGEN_CORE_CONSTANTS_H_ */
#endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_CONSTANTS_H_ */
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "backends/p4tools/testgen/core/exploration_strategy/exploration_strategy.h"
#include "backends/p4tools/modules/testgen/core/exploration_strategy/exploration_strategy.h"

#include <algorithm>
#include <cstdlib>
Expand All @@ -21,10 +21,10 @@
#include "lib/exceptions.h"
#include "lib/log.h"

#include "backends/p4tools/testgen/lib/continuation.h"
#include "backends/p4tools/testgen/lib/exceptions.h"
#include "backends/p4tools/testgen/lib/logging.h"
#include "backends/p4tools/testgen/options.h"
#include "backends/p4tools/modules/testgen/lib/continuation.h"
#include "backends/p4tools/modules/testgen/lib/exceptions.h"
#include "backends/p4tools/modules/testgen/lib/logging.h"
#include "backends/p4tools/modules/testgen/options.h"

namespace P4Tools {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef BACKENDS_P4TOOLS_TESTGEN_CORE_EXPLORATION_STRATEGY_EXPLORATION_STRATEGY_H_
#define BACKENDS_P4TOOLS_TESTGEN_CORE_EXPLORATION_STRATEGY_EXPLORATION_STRATEGY_H_
#ifndef BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_EXPLORATION_STRATEGY_EXPLORATION_STRATEGY_H_
#define BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_EXPLORATION_STRATEGY_EXPLORATION_STRATEGY_H_

#include <cstdint>
#include <ctime>
Expand All @@ -19,10 +19,10 @@
#include "backends/p4tools/common/lib/formulae.h"
#include "gsl/gsl-lite.hpp"

#include "backends/p4tools/testgen/core/program_info.h"
#include "backends/p4tools/testgen/core/small_step/small_step.h"
#include "backends/p4tools/testgen/lib/execution_state.h"
#include "backends/p4tools/testgen/lib/final_state.h"
#include "backends/p4tools/modules/testgen/core/program_info.h"
#include "backends/p4tools/modules/testgen/core/small_step/small_step.h"
#include "backends/p4tools/modules/testgen/lib/execution_state.h"
#include "backends/p4tools/modules/testgen/lib/final_state.h"

namespace P4Tools {

Expand Down Expand Up @@ -102,4 +102,4 @@ class ExplorationStrategy {

} // namespace P4Tools

#endif /* BACKENDS_P4TOOLS_TESTGEN_CORE_EXPLORATION_STRATEGY_EXPLORATION_STRATEGY_H_ */
#endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_EXPLORATION_STRATEGY_EXPLORATION_STRATEGY_H_ */
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "backends/p4tools/testgen/core/exploration_strategy/incremental_max_coverage_stack.h"
#include "backends/p4tools/modules/testgen/core/exploration_strategy/incremental_max_coverage_stack.h"

#include <algorithm>
#include <cstdlib>
Expand All @@ -22,10 +22,10 @@
#include "lib/exceptions.h"
#include "lib/log.h"

#include "backends/p4tools/testgen/core/small_step/small_step.h"
#include "backends/p4tools/testgen/lib/continuation.h"
#include "backends/p4tools/testgen/lib/exceptions.h"
#include "backends/p4tools/testgen/options.h"
#include "backends/p4tools/modules/testgen/core/small_step/small_step.h"
#include "backends/p4tools/modules/testgen/lib/continuation.h"
#include "backends/p4tools/modules/testgen/lib/exceptions.h"
#include "backends/p4tools/modules/testgen/options.h"

namespace P4Tools {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef BACKENDS_P4TOOLS_TESTGEN_CORE_EXPLORATION_STRATEGY_INCREMENTAL_MAX_COVERAGE_STACK_H_
#define BACKENDS_P4TOOLS_TESTGEN_CORE_EXPLORATION_STRATEGY_INCREMENTAL_MAX_COVERAGE_STACK_H_
#ifndef BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_EXPLORATION_STRATEGY_INCREMENTAL_MAX_COVERAGE_STACK_H_
#define BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_EXPLORATION_STRATEGY_INCREMENTAL_MAX_COVERAGE_STACK_H_

#include <cstdint>
#include <ctime>
Expand All @@ -21,11 +21,11 @@
#include "gsl/gsl-lite.hpp"
#include "ir/ir.h"

#include "backends/p4tools/testgen/core/exploration_strategy/exploration_strategy.h"
#include "backends/p4tools/testgen/core/program_info.h"
#include "backends/p4tools/testgen/core/small_step/small_step.h"
#include "backends/p4tools/testgen/lib/execution_state.h"
#include "backends/p4tools/testgen/lib/final_state.h"
#include "backends/p4tools/modules/testgen/core/exploration_strategy/exploration_strategy.h"
#include "backends/p4tools/modules/testgen/core/program_info.h"
#include "backends/p4tools/modules/testgen/core/small_step/small_step.h"
#include "backends/p4tools/modules/testgen/lib/execution_state.h"
#include "backends/p4tools/modules/testgen/lib/final_state.h"

namespace P4Tools {

Expand Down Expand Up @@ -87,4 +87,5 @@ class IncrementalMaxCoverageStack : public ExplorationStrategy {

} // namespace P4Tools

#endif /* BACKENDS_P4TOOLS_TESTGEN_CORE_EXPLORATION_STRATEGY_INCREMENTAL_MAX_COVERAGE_STACK_H_ */
#endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_EXPLORATION_STRATEGY_INCREMENTAL_MAX_COVERAGE_STACK_H_ \
*/
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "backends/p4tools/testgen/core/exploration_strategy/incremental_stack.h"
#include "backends/p4tools/modules/testgen/core/exploration_strategy/incremental_stack.h"

#include <algorithm>
#include <cstdlib>
Expand All @@ -21,9 +21,9 @@
#include "lib/exceptions.h"
#include "lib/log.h"

#include "backends/p4tools/testgen/lib/continuation.h"
#include "backends/p4tools/testgen/lib/exceptions.h"
#include "backends/p4tools/testgen/options.h"
#include "backends/p4tools/modules/testgen/lib/continuation.h"
#include "backends/p4tools/modules/testgen/lib/exceptions.h"
#include "backends/p4tools/modules/testgen/options.h"

namespace P4Tools {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef BACKENDS_P4TOOLS_TESTGEN_CORE_EXPLORATION_STRATEGY_INCREMENTAL_STACK_H_
#define BACKENDS_P4TOOLS_TESTGEN_CORE_EXPLORATION_STRATEGY_INCREMENTAL_STACK_H_
#ifndef BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_EXPLORATION_STRATEGY_INCREMENTAL_STACK_H_
#define BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_EXPLORATION_STRATEGY_INCREMENTAL_STACK_H_

#include <cstdint>
#include <ctime>
Expand All @@ -20,10 +20,10 @@
#include "gsl/gsl-lite.hpp"
#include "ir/ir.h"

#include "backends/p4tools/testgen/core/exploration_strategy/exploration_strategy.h"
#include "backends/p4tools/testgen/core/program_info.h"
#include "backends/p4tools/testgen/lib/execution_state.h"
#include "backends/p4tools/testgen/lib/final_state.h"
#include "backends/p4tools/modules/testgen/core/exploration_strategy/exploration_strategy.h"
#include "backends/p4tools/modules/testgen/core/program_info.h"
#include "backends/p4tools/modules/testgen/lib/execution_state.h"
#include "backends/p4tools/modules/testgen/lib/final_state.h"

namespace P4Tools {

Expand Down Expand Up @@ -94,4 +94,4 @@ class IncrementalStack : public ExplorationStrategy {

} // namespace P4Tools

#endif /* BACKENDS_P4TOOLS_TESTGEN_CORE_EXPLORATION_STRATEGY_INCREMENTAL_STACK_H_ */
#endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_EXPLORATION_STRATEGY_INCREMENTAL_STACK_H_ */
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "backends/p4tools/testgen/core/exploration_strategy/linear_enumeration.h"
#include "backends/p4tools/modules/testgen/core/exploration_strategy/linear_enumeration.h"

#include <algorithm>
#include <cstdlib>
Expand All @@ -21,10 +21,10 @@
#include "lib/exceptions.h"
#include "lib/log.h"

#include "backends/p4tools/testgen/core/small_step/small_step.h"
#include "backends/p4tools/testgen/lib/continuation.h"
#include "backends/p4tools/testgen/lib/exceptions.h"
#include "backends/p4tools/testgen/options.h"
#include "backends/p4tools/modules/testgen/core/small_step/small_step.h"
#include "backends/p4tools/modules/testgen/lib/continuation.h"
#include "backends/p4tools/modules/testgen/lib/exceptions.h"
#include "backends/p4tools/modules/testgen/options.h"

namespace P4Tools {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef BACKENDS_P4TOOLS_TESTGEN_CORE_EXPLORATION_STRATEGY_LINEAR_ENUMERATION_H_
#define BACKENDS_P4TOOLS_TESTGEN_CORE_EXPLORATION_STRATEGY_LINEAR_ENUMERATION_H_
#ifndef BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_EXPLORATION_STRATEGY_LINEAR_ENUMERATION_H_
#define BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_EXPLORATION_STRATEGY_LINEAR_ENUMERATION_H_

#include <cstdint>
#include <ctime>
Expand All @@ -20,11 +20,11 @@
#include "gsl/gsl-lite.hpp"
#include "ir/ir.h"

#include "backends/p4tools/testgen/core/exploration_strategy/exploration_strategy.h"
#include "backends/p4tools/testgen/core/program_info.h"
#include "backends/p4tools/testgen/core/small_step/small_step.h"
#include "backends/p4tools/testgen/lib/execution_state.h"
#include "backends/p4tools/testgen/lib/final_state.h"
#include "backends/p4tools/modules/testgen/core/exploration_strategy/exploration_strategy.h"
#include "backends/p4tools/modules/testgen/core/program_info.h"
#include "backends/p4tools/modules/testgen/core/small_step/small_step.h"
#include "backends/p4tools/modules/testgen/lib/execution_state.h"
#include "backends/p4tools/modules/testgen/lib/final_state.h"

namespace P4Tools {

Expand Down Expand Up @@ -65,4 +65,4 @@ class LinearEnumeration : public ExplorationStrategy {

} // namespace P4Tools

#endif /* BACKENDS_P4TOOLS_TESTGEN_CORE_EXPLORATION_STRATEGY_LINEAR_ENUMERATION_H_ */
#endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_EXPLORATION_STRATEGY_LINEAR_ENUMERATION_H_ */
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "backends/p4tools/testgen/core/exploration_strategy/random_access_max_coverage.h"
#include "backends/p4tools/modules/testgen/core/exploration_strategy/random_access_max_coverage.h"

#include <algorithm>
#include <cstdlib>
Expand All @@ -22,10 +22,10 @@
#include "lib/exceptions.h"
#include "lib/log.h"

#include "backends/p4tools/testgen/core/small_step/small_step.h"
#include "backends/p4tools/testgen/lib/continuation.h"
#include "backends/p4tools/testgen/lib/exceptions.h"
#include "backends/p4tools/testgen/options.h"
#include "backends/p4tools/modules/testgen/core/small_step/small_step.h"
#include "backends/p4tools/modules/testgen/lib/continuation.h"
#include "backends/p4tools/modules/testgen/lib/exceptions.h"
#include "backends/p4tools/modules/testgen/options.h"

namespace P4Tools {

Expand Down
Loading

0 comments on commit 0974b37

Please sign in to comment.