Skip to content

Commit

Permalink
test v6.8
Browse files Browse the repository at this point in the history
  • Loading branch information
whentojump committed Aug 14, 2024
1 parent c322b21 commit 1f2c6aa
Show file tree
Hide file tree
Showing 10 changed files with 1,251 additions and 8 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/llvm-trunk-linux-v5.15.153.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
name: Test workflow with LLVM trunk and Linux v5.15.153

on:
push:
branches:
- llvm-trunk
paths:
- '.github/workflows/**'
- 'ci/**'
- 'patches/**'
- 'scripts/**'
# push:
# branches:
# - llvm-trunk
# paths:
# - '.github/workflows/**'
# - 'ci/**'
# - 'patches/**'
# - 'scripts/**'
workflow_dispatch:

# Allow at most one run from any workflow in this repo at the same time, as most
Expand Down
150 changes: 150 additions & 0 deletions .github/workflows/llvm-trunk-linux-v6.8.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
name: Test workflow with LLVM trunk and Linux v6.8

on:
push:
branches:
- llvm-trunk
paths:
- '.github/workflows/**'
- 'ci/**'
- 'patches/**'
- 'scripts/**'
workflow_dispatch:

# Allow at most one run from any workflow in this repo at the same time, as most
# of them will operate on some shared directories of self-hosted runners and
# interfere with each other. Without this setting, the below could happen:
#
# T1 T2 T3 T4
# runner1 -(R1J1--------------------R1J2)-
# ---------(R2J1----R2J2)---------
#
# Now:
#
# T1 T2 T3 T4 T5 T6
# runner1 -(R1J1----R1J2)--xxxxxxxxxxxxxx--xxxxxxxxxxxxxx-
# -xxxxxxxxxxxxxx--(R2J1----R2J2)--xxxxxxxxxxxxxx-
# runner2 -xxxxxxxxxxxxxx--xxxxxxxxxxxxxx--(R3J1----R3J2)-
#
# Ideally we want a single runner to finish all jobs from a workflow before
# accepting any other job. But I don't know how.
#
# T1 T2 T3 T4 T5 T6
# runner1 -(R1J1----R1J2)--xxxxxxxxxxxxxx-----------------
# -xxxxxxxxxxxxxx--(R3J1----R3J2)-----------------
# runner2 ---------(R2J1----R2J2)--xxxxxxxxxxxxxx---------
# ---------xxxxxxxxxxxxxx--(R4J1----R4J2)---------
#
# Or maybe we should redesign the abstraction: what ought to be workflows? what
# ought to be jobs? and what ought to be steps?

concurrency:
group: xlab-uiuc/linux-mcdc

env:
MCDC_HOME: /home/github-runner/mcdc-workdir

jobs:
find_runner:
name: Find an available self-hosted runner
runs-on: self-hosted
# Enforce this same runner for all later jobs that depend on this one
# FIXME this requires each runner has a label the same as its name
outputs:
runner_name: ${{ runner.name }}
# Dummy, do nothing
steps:
- uses: actions/checkout@v4

install_deps:
name: 1. Install dependencies
needs: find_runner
# Enforce the same runner
runs-on: ${{ needs.find_runner.outputs.runner_name }}
outputs:
runner_name: ${{ runner.name }}
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: ./ci/linux-v6.8/1_install_deps.sh

pull_source:
name: 2. Pull the source code and apply patches
needs: install_deps
# Enforce the same runner
runs-on: ${{ needs.install_deps.outputs.runner_name }}
outputs:
runner_name: ${{ runner.name }}
steps:
- uses: actions/checkout@v4
- name: Create a workspace from clean slate
run: |
rm -rf $MCDC_HOME
mkdir -p $MCDC_HOME
- name: Pull the source code and apply patches
run: ./ci/linux-v6.8/2_pull_source.sh

get_llvm:
name: 3. Get LLVM
needs: pull_source
# Enforce the same runner
runs-on: ${{ needs.pull_source.outputs.runner_name }}
outputs:
runner_name: ${{ runner.name }}
steps:
- uses: actions/checkout@v4
- name: Build from source
run: ./ci/linux-v6.8/3_get_llvm.sh
- name: Print LLVM build resource usage
run: |
cat /tmp/time.log
du -sh $MCDC_HOME/llvm-project
build_kernel:
name: 4. Build the kernel
needs: get_llvm
# Enforce the same runner
runs-on: ${{ needs.get_llvm.outputs.runner_name }}
outputs:
runner_name: ${{ runner.name }}
steps:
- uses: actions/checkout@v4
- name: Set up LLVM path
run: echo "$MCDC_HOME/llvm-project/build/bin" >> $GITHUB_PATH
- name: Print toolchain version
run: |
clang -v
llc --version
- name: Build the kernel
run: ./ci/linux-v6.8/4_build_kernel.sh
- name: Print full kernel build log
run: cat /tmp/make.log
- name: Print kernel build resource usage
run: |
cat /tmp/time.log
du -sh $MCDC_HOME/linux
- name: Print kernel binary layout
run: |
llvm-readelf --sections -W $MCDC_HOME/linux/vmlinux
boot_kernel_and_collect_coverage:
name: 5. Boot the kernel and collect coverage
needs: build_kernel
# Enforce the same runner
runs-on: ${{ needs.build_kernel.outputs.runner_name }}
outputs:
runner_name: ${{ runner.name }}
steps:
- uses: actions/checkout@v4
- name: Set up LLVM path
run: echo "$MCDC_HOME/llvm-project/build/bin" >> $GITHUB_PATH
- name: Print toolchain version
run: |
clang -v
llc --version
- name: Boot the kernel and collect coverage
run: ./ci/linux-v6.8/5_boot_kernel_and_collect_coverage.sh
- name: Print the index of coverage report (immediately after reset)
run: cat $MCDC_HOME/analysis_reset/text-coverage-reports/index.txt
- name: Print the index of coverage report
run: cat $MCDC_HOME/analysis/text-coverage-reports/index.txt
11 changes: 11 additions & 0 deletions ci/linux-v6.8/1_install_deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

# For building LLVM from source (optional)
sudo apt-get -yq install cmake ninja-build mold

# For building the kernel
sudo apt-get -yq install git bc libncurses-dev wget busybox \
libssl-dev libelf-dev dwarves flex bison build-essential

# For booting the kernel
sudo apt-get -yq install qemu-system-x86
17 changes: 17 additions & 0 deletions ci/linux-v6.8/2_pull_source.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

cd $MCDC_HOME

# This meta repository
git clone https://github.com/whentojump/linux-mcdc.git --branch llvm-trunk
# LLVM if we want to build it from source (optional)
git clone https://github.com/llvm/llvm-project.git --depth 5
# Linux kernel
git clone https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git

# Apply kernel patches
cd $MCDC_HOME/linux
git checkout 70293240c5ce675a67bfc48f419b093023b862b3
git apply $MCDC_HOME/linux-mcdc/patches/v0.6-linux-v6.8/0001-llvm-cov-add-Clang-s-Source-based-Code-Coverage-supp.patch
git apply $MCDC_HOME/linux-mcdc/patches/v0.6-linux-v6.8/0002-kbuild-llvm-cov-disable-instrumentation-in-odd-or-se.patch
git apply $MCDC_HOME/linux-mcdc/patches/v0.6-linux-v6.8/0003-llvm-cov-add-Clang-s-MC-DC-support.patch
51 changes: 51 additions & 0 deletions ci/linux-v6.8/3_get_llvm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash

cd $MCDC_HOME/llvm-project

# Patches that improve llvm-cov text output

cat > /tmp/llvm_cov_final_new_line.patch << EOF
diff --git a/llvm/tools/llvm-cov/SourceCoverageViewText.cpp b/llvm/tools/llvm-cov/SourceCoverageViewText.cpp
index cab60c2d9..2aa588e6d 100644
--- a/llvm/tools/llvm-cov/SourceCoverageViewText.cpp
+++ b/llvm/tools/llvm-cov/SourceCoverageViewText.cpp
@@ -43,7 +43,8 @@ Error CoveragePrinterText::createIndexFile(
Report.renderFileReports(OSRef, SourceFiles, Filters);
Opts.colored_ostream(OSRef, raw_ostream::CYAN) << "\n"
- << Opts.getLLVMVersionString();
+ << Opts.getLLVMVersionString()
+ << "\n";
return Error::success();
}
@@ -84,7 +85,8 @@ struct CoveragePrinterTextDirectory::Reporter : public DirectoryCoverageReport {
Options.colored_ostream(OSRef, raw_ostream::CYAN)
<< "\n"
- << Options.getLLVMVersionString();
+ << Options.getLLVMVersionString()
+ << "\n";
return Error::success();
}
EOF
git apply /tmp/llvm_cov_final_new_line.patch
cat > /tmp/llvm_cov_trim_abs_path.patch << EOF
diff --git a/llvm/tools/llvm-cov/CoverageReport.cpp b/llvm/tools/llvm-cov/CoverageReport.cpp
index 49a35f2a9..dc9f2f9c5 100644
--- a/llvm/tools/llvm-cov/CoverageReport.cpp
+++ b/llvm/tools/llvm-cov/CoverageReport.cpp
@@ -216,7 +216,7 @@ void CoverageReport::render(const FileCoverageSummary &File,
if (IsDir)
FileName += sys::path::get_separator();
- OS << column(FileName, FileReportColumns[0], Column::NoTrim);
+ OS << column(FileName, FileReportColumns[0], Column::RightTrim);
if (Options.ShowRegionSummary) {
OS << format("%*u", FileReportColumns[1],
EOF
git apply /tmp/llvm_cov_trim_abs_path.patch

/usr/bin/time -v -o /tmp/time.log $MCDC_HOME/linux-mcdc/scripts/build-llvm.sh
32 changes: 32 additions & 0 deletions ci/linux-v6.8/4_build_kernel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

cd $MCDC_HOME/linux
make LLVM=1 defconfig

./scripts/config -e CONFIG_9P_FS_POSIX_ACL
./scripts/config -e CONFIG_9P_FS
./scripts/config -e CONFIG_NET_9P_VIRTIO
./scripts/config -e CONFIG_NET_9P
./scripts/config -e CONFIG_PCI
./scripts/config -e CONFIG_VIRTIO_PCI
./scripts/config -e CONFIG_OVERLAY_FS
./scripts/config -e CONFIG_DEBUG_FS
./scripts/config -e CONFIG_CONFIGFS_FS
./scripts/config -e CONFIG_MAGIC_SYSRQ
make LLVM=1 olddefconfig

./scripts/config -e CONFIG_KUNIT
./scripts/config -e CONFIG_KUNIT_ALL_TESTS
make LLVM=1 olddefconfig

./scripts/config -e CONFIG_LLVM_COV_KERNEL
./scripts/config -e CONFIG_LLVM_COV_KERNEL_MCDC
./scripts/config --set-val LLVM_COV_KERNEL_MCDC_MAX_CONDITIONS 44
make LLVM=1 olddefconfig

cat << EOF
Building the kernel with output suppressed. The log tail will be displayed once
the process finishes. See the full log in the next step.
EOF
/usr/bin/time -v -o /tmp/time.log make LLVM=1 -j$(nproc) >& /tmp/make.log
tail -n 200 /tmp/make.log
70 changes: 70 additions & 0 deletions ci/linux-v6.8/5_boot_kernel_and_collect_coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/bash

#
# Test the functionality of reset
#

GUEST_COMMANDS="true"
GUEST_COMMANDS="$GUEST_COMMANDS; uname -a"
GUEST_COMMANDS="$GUEST_COMMANDS; ls /sys/kernel/debug/llvm-cov"
GUEST_COMMANDS="$GUEST_COMMANDS; echo 1 > /sys/kernel/debug/llvm-cov/reset"
GUEST_COMMANDS="$GUEST_COMMANDS; cp /sys/kernel/debug/llvm-cov/profraw ."

cd $MCDC_HOME/linux
$MCDC_HOME/linux-mcdc/scripts/q -c "$GUEST_COMMANDS"

file profraw |& tee /tmp/file.log
if ! grep "LLVM raw profile data, version 10" /tmp/file.log > /dev/null; then
printf "\nUnexpected profraw\n"
exit 1
fi

mkdir -p $MCDC_HOME/analysis_reset
mv profraw $MCDC_HOME/analysis_reset
cd $MCDC_HOME/analysis_reset

llvm-profdata merge profraw -o profdata
llvm-cov show --show-mcdc \
--show-mcdc-summary \
--show-region-summary=false \
--show-branch-summary=false \
--format=text \
-use-color \
-show-directory-coverage \
-output-dir=text-coverage-reports \
-instr-profile profdata \
$MCDC_HOME/linux/vmlinux

#
# Actual coverage of KUnit + boot
#

GUEST_COMMANDS="true"
GUEST_COMMANDS="$GUEST_COMMANDS; uname -a"
GUEST_COMMANDS="$GUEST_COMMANDS; ls /sys/kernel/debug/llvm-cov"
GUEST_COMMANDS="$GUEST_COMMANDS; cp /sys/kernel/debug/llvm-cov/profraw ."

cd $MCDC_HOME/linux
$MCDC_HOME/linux-mcdc/scripts/q -c "$GUEST_COMMANDS"

file profraw |& tee /tmp/file.log
if ! grep "LLVM raw profile data, version 10" /tmp/file.log > /dev/null; then
printf "\nUnexpected profraw\n"
exit 1
fi

mkdir -p $MCDC_HOME/analysis
mv profraw $MCDC_HOME/analysis
cd $MCDC_HOME/analysis

llvm-profdata merge profraw -o profdata
llvm-cov show --show-mcdc \
--show-mcdc-summary \
--show-region-summary=false \
--show-branch-summary=false \
--format=text \
-use-color \
-show-directory-coverage \
-output-dir=text-coverage-reports \
-instr-profile profdata \
$MCDC_HOME/linux/vmlinux
Loading

0 comments on commit 1f2c6aa

Please sign in to comment.