Skip to content

Commit

Permalink
Merge branch 'main' into statement-splitter
Browse files Browse the repository at this point in the history
  • Loading branch information
vlstill authored Mar 6, 2025
2 parents 702bbe8 + 126f849 commit 88274c2
Show file tree
Hide file tree
Showing 509 changed files with 7,372 additions and 6,653 deletions.
8 changes: 7 additions & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@ common --enable_workspace
# Enable once #5066 is resolved.
common --noenable_bzlmod

build --action_env=BAZEL_CXXOPTS="-std=c++17"
# Use C++17.
build --cxxopt=-std=c++17
build --host_cxxopt=-std=c++17

# Force the use of Clang for all builds.
build --action_env=CC=clang
build --action_env=CXX=clang++
47 changes: 23 additions & 24 deletions .github/workflows/ci-bazel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,28 @@ concurrency:
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}

jobs:

format_bazel_files:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: tools/format-bazel-files.sh
- name: Check formatting diff
run: |
CHANGED_FILES="$(git diff-index --name-only HEAD --)"
if [[ -z "${CHANGED_FILES}" ]]; then
echo "Success: no formatting changes needed."
exit 0
fi
echo "Found formatting changes in the following files:"
echo "${CHANGED_FILES}"
echo ""
echo "Please run `tools/format-bazel-files.sh` to apply the changes."
exit 1
build_direct: # Build p4c directly.
needs: format_bazel_files
runs-on: ubuntu-latest
env:
BAZEL: bazelisk-linux-amd64
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -34,25 +52,15 @@ jobs:
restore-keys: |
${{ runner.os }}-build-direct-
- name: Install bazelisk
run: |
curl -LO "https://github.com/bazelbuild/bazelisk/releases/download/v1.18.0/$BAZEL"
chmod +x $BAZEL
sudo mv $BAZEL /usr/local/bin/bazel
- name: First, pass the lint test
run: bazel run //:buildifier_check

- name: Install Flex and Bison
run: sudo apt-get update && sudo apt-get install bison flex libfl-dev
run: sudo apt install bison flex libfl-dev

- name: Build p4c
run: bazel build //... --verbose_failures

build_indirect: # Build 3rd party Bazel project depending on p4c as a subproject.
needs: format_bazel_files
runs-on: ubuntu-latest
env:
BAZEL: bazelisk-linux-amd64
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -69,17 +77,8 @@ jobs:
restore-keys: |
${{ runner.os }}-build-indirect-
- name: First, pass the lint test
run: bazel run //:buildifier_check

- name: Install bazelisk
run: |
curl -LO "https://github.com/bazelbuild/bazelisk/releases/download/v1.18.0/$BAZEL"
chmod +x $BAZEL
sudo mv $BAZEL /usr/local/bin/bazel
- name: Install Flex and Bison
run: sudo apt-get update && sudo apt-get install bison flex libfl-dev
run: sudo apt install bison flex libfl-dev

- name: Build bazel/example
run: cd ./bazel/example && bazel build //... --verbose_failures
8 changes: 4 additions & 4 deletions .github/workflows/ci-test-debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ jobs:
tools/ci-build.sh
- name: Run tests (Ubuntu 22.04)
# Need to use sudo for the eBPF kernel tests.
run: sudo -E ctest --output-on-failure --schedule-random
# Need to use sudo for the eBPF kernel tests and need to avoid p4tc_stf tests.
run: sudo -E ctest --output-on-failure --schedule-random -E "p4tc_samples_stf|p4tc_cleanup|p4tc_setup"
working-directory: ./build

# Build with GCC and test Tofino backend on Ubuntu 22.04.
Expand Down Expand Up @@ -116,7 +116,7 @@ jobs:
tools/ci-build.sh
- name: Run tests (Ubuntu 20.04)
# Need to use sudo for the eBPF kernel tests.
run: sudo -E ctest --output-on-failure --schedule-random
# Need to use sudo for the eBPF kernel tests and need to avoid p4tc_stf tests.
run: sudo -E ctest --output-on-failure --schedule-random -E "p4tc_samples_stf|p4tc_cleanup|p4tc_setup"
working-directory: ./build
if: matrix.unity == 'ON' && matrix.gtest == 'ON'
3 changes: 2 additions & 1 deletion .github/workflows/ci-test-fedora.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@ jobs:
- name: Run p4c tests (Fedora Linux)
run: |
export PATH="$HOME/.local/bin:$PATH"; ctest --output-on-failure --schedule-random
# Avoid running p4tc stf tests for now
export PATH="$HOME/.local/bin:$PATH"; ctest --output-on-failure --schedule-random -E "p4tc_samples_stf|p4tc_cleanup|p4tc_setup"
working-directory: ./build
4 changes: 2 additions & 2 deletions .github/workflows/ci-test-mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
- name: Run tests (MacOS)
run: |
source ~/.bash_profile
ctest --output-on-failure --schedule-random -E "bpf|ubpf|testgen|smith"
ctest --output-on-failure --schedule-random -E "bpf|ubpf|testgen|smith|p4tc"
working-directory: ./build

# Build and test p4c on MacOS 13 on x86.
Expand Down Expand Up @@ -105,5 +105,5 @@ jobs:
- name: Run tests (MacOS)
run: |
source ~/.bash_profile
ctest --output-on-failure --schedule-random -E "bpf|ubpf|testgen|smith"
ctest --output-on-failure --schedule-random -E "bpf|ubpf|testgen|smith|p4tc"
working-directory: ./build
43 changes: 43 additions & 0 deletions .github/workflows/ci-ubuntu-18-nightly-p4tc-stf.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: "test-p4c-ubuntu-18.04"

on:
schedule:
# Every day on midnight UTC
- cron: "0 0 * * *"
pull_request:
branches: [main]
push:
branches: [main]

jobs:
# Run p4tc stf tests
test-ubuntu18-p4tc-stf:
# Only run on pull requests with the "p4tc" label.
if: ${{ github.event_name == 'schedule' || contains(github.event.pull_request.labels.*.name, 'p4tc') }}
runs-on: ubuntu-20.04
env:
CTEST_PARALLEL_LEVEL: 4
IMAGE_TYPE: test
ENABLE_GTESTS: ${{ matrix.gtest }}
CMAKE_UNITY_BUILD: ${{ matrix.unity }}
BUILD_GENERATOR: Ninja
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0

- name: ccache
uses: hendrikmuhs/ccache-action@v1
with:
key: test-${{ matrix.unity }}-${{ runner.os }}-gcc
max-size: 1000M

- name: Build (Ubuntu 20.04, GCC)
run: |
tools/ci-build.sh
- name: Run tests (Ubuntu 20.04)
# Need to use sudo for the eBPF kernel tests.
run: sudo -E ctest --output-on-failure --schedule-random -R "p4tc_samples_stf|p4tc_cleanup|p4tc_setup"
working-directory: ./build
3 changes: 2 additions & 1 deletion .github/workflows/ci-ubuntu-18-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ jobs:
# this is needed to create network namespaces for the ebpf tests.
- name: Run tests (Ubuntu 18.04)
run: |
sudo -E docker run --privileged -w /p4c/build -e $CTEST_PARALLEL_LEVEL p4c ctest --output-on-failure --schedule-random
sudo -E docker run --privileged -w /p4c/build -e $CTEST_PARALLEL_LEVEL p4c ctest --output-on-failure --schedule-random \
-E "p4tc_samples_stf|p4tc_cleanup|p4tc_setup"
2 changes: 1 addition & 1 deletion .github/workflows/ci-ubuntu-20-sanitizer-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ jobs:
- name: Run tests (Ubuntu 20.04)
# Need to use sudo for the eBPF kernel tests.
run: sudo -E ctest --output-on-failure --schedule-random
run: sudo -E ctest --output-on-failure --schedule-random -E "p4tc_samples_stf|p4tc_cleanup|p4tc_setup"
working-directory: ./build
31 changes: 6 additions & 25 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
load("@rules_license//rules:license.bzl", "license")
load("//:bazel/flex.bzl", "genlex")
load("//:bazel/bison.bzl", "genyacc")
load("@com_github_bazelbuild_buildtools//buildifier:def.bzl", "buildifier")
load("//:bazel/flex.bzl", "genlex")

package(
default_applicable_licenses = ["//:license"],
Expand Down Expand Up @@ -212,14 +211,14 @@ cc_library(
"midend/**/*.cpp",
"control-plane/**/*.cpp",
]) + [
"frontends/parsers/p4/p4parser.cc",
"frontends/parsers/v1/v1parser.cc",
"backends/dpdk/dbprint-dpdk.cpp",
"backends/dpdk/printUtils.cpp",
"backends/dpdk/spec.cpp",
"frontends/parsers/p4/p4lexer.cc",
"frontends/parsers/p4/p4parser.cc",
"frontends/parsers/v1/v1lexer.cc",
"frontends/parsers/v1/v1parser.cc",
"ir/ir-generated.cpp",
"backends/dpdk/spec.cpp",
"backends/dpdk/dbprint-dpdk.cpp",
"backends/dpdk/printUtils.cpp",
],
textual_hdrs = glob([
"ir/**/*.h",
Expand Down Expand Up @@ -484,21 +483,3 @@ cc_library(
"@boost//:graph",
],
)

buildifier(
name = "buildifier_check",
diff_command = "diff -u",
exclude_patterns = [
"./build/*",
],
lint_mode = "warn",
mode = "diff",
)

buildifier(
name = "buildifier_fix",
exclude_patterns = [
"./build/*",
],
lint_mode = "fix",
)
2 changes: 1 addition & 1 deletion Version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.5.3
1.2.5.4
66 changes: 38 additions & 28 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
@@ -1,37 +1,30 @@
workspace(name = "com_github_p4lang_p4c")

# -- Load Buildifier -----------------------------------------------------
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
# -- Direct dependencies. ------------------------------------------------------

# buildifier is written in Go and hence needs rules_go to be built.
# See https://github.com/bazelbuild/rules_go for the up to date setup instructions.
http_archive(
name = "io_bazel_rules_go",
sha256 = "6dc2da7ab4cf5d7bfc7c949776b1b7c733f05e56edc4bcd9022bb249d2e2a996",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.39.1/rules_go-v0.39.1.zip",
"https://github.com/bazelbuild/rules_go/releases/download/v0.39.1/rules_go-v0.39.1.zip",
],
)
load("//:bazel/p4c_deps.bzl", "p4c_deps")

load("@io_bazel_rules_go//go:deps.bzl", "go_rules_dependencies")
p4c_deps()

go_rules_dependencies()
# -- Load Rules Foreign CC -----------------------------------------------------

http_archive(
name = "com_github_bazelbuild_buildtools",
sha256 = "ae34c344514e08c23e90da0e2d6cb700fcd28e80c02e23e4d5715dddcb42f7b3",
strip_prefix = "buildtools-4.2.2",
urls = [
"https://github.com/bazelbuild/buildtools/archive/refs/tags/4.2.2.tar.gz",
],
)
load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies")

# -- Direct dependencies. ------------------------------------------------------
# This sets up some common toolchains for building targets. For more details, please see
# https://bazel-contrib.github.io/rules_foreign_cc/0.14.0/flatten.html#rules_foreign_cc_dependencies
rules_foreign_cc_dependencies()

load("//:bazel/p4c_deps.bzl", "p4c_deps")
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

p4c_deps()
bazel_skylib_workspace()

load("@bazel_features//:deps.bzl", "bazel_features_deps")

bazel_features_deps()

load("@rules_python//python:repositories.bzl", "py_repositories")

py_repositories()

# -- Dependencies of dependencies. ---------------------------------------------

Expand Down Expand Up @@ -65,8 +58,25 @@ load("@com_github_grpc_grpc//bazel:grpc_extra_deps.bzl", "grpc_extra_deps")

grpc_extra_deps()

# -- Load Rules Foreign CC -----------------------------------------------------
# -- Load Buildifier (for formatting) ------------------------------------------

load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

rules_foreign_cc_dependencies()
http_archive(
name = "buildifier_prebuilt",
integrity = "sha256-f4W2iKS1WOLZCZNAz7UQunF5+ClFT7qEI3C8z/tn1sw=",
# Newer versions of Buildifier enforce the use of Starlark versions of
# `proto_library`, `cc_{executable, library, proto_library, test}`, etc.
# We're not ready to make that migration yet, and use an older Buildifier
# version as a workaround.
strip_prefix = "buildifier-prebuilt-7.3.1",
urls = ["https://github.com/keith/buildifier-prebuilt/archive/7.3.1.tar.gz"],
)

load("@buildifier_prebuilt//:deps.bzl", "buildifier_prebuilt_deps")

buildifier_prebuilt_deps()

load("@buildifier_prebuilt//:defs.bzl", "buildifier_prebuilt_register_toolchains")

buildifier_prebuilt_register_toolchains()
15 changes: 6 additions & 9 deletions backends/bmv2/bmv2stf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
# Copyright 2013-present Barefoot Networks, Inc.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,11 +30,7 @@
from pathlib import Path
from typing import Dict, List, Optional, Tuple

try:
import scapy.utils as scapy_util
from scapy.layers.all import *
except ImportError:
pass
from ptf.pcap_writer import LINKTYPE_ETHERNET, PcapWriter, rdpcap

FILE_DIR = Path(__file__).resolve().parent
# Append the root to the import path.
Expand Down Expand Up @@ -577,7 +574,7 @@ def execute_stf_command(self, stf_entry):
data = stf_entry[2]
time.sleep(self.packetDelay)
try:
self.interfaces[interface]._write_packet(bytes.fromhex(data))
self.interfaces[interface].write(bytes.fromhex(data))
except ValueError:
testutils.log.error("Invalid packet data %s", data)
return testutils.FAILURE
Expand Down Expand Up @@ -772,8 +769,8 @@ def run(self, stf_map: Dict[str, str]) -> int:
sw = subprocess.Popen(runswitch, cwd=self.folder)

def openInterface(ifname):
fp = self.interfaces[interface] = scapy_util.RawPcapWriter(str(ifname), linktype=0)
fp._write_header(None)
self.interfaces[interface] = PcapWriter(str(ifname), linktype=LINKTYPE_ETHERNET)
self.interfaces[interface].flush()

# Try to open input interfaces. Each time, we set a 2 second
# timeout. If the timeout expires we check if the bmv2 process is
Expand Down Expand Up @@ -875,7 +872,7 @@ def checkOutputs(self) -> int:
packets = []
else:
try:
packets = scapy_util.rdpcap(file)
packets = rdpcap(file)
except Exception as e:
testutils.log.error("Corrupt pcap file %s\n%s", file, e)
return testutils.FAILURE
Expand Down
Loading

0 comments on commit 88274c2

Please sign in to comment.