Skip to content

Commit 2ec43fc

Browse files
committed
[TEST]: Add CT-LLVM
Signed-off-by: Matthias J. Kannwischer <[email protected]>
1 parent 5d79846 commit 2ec43fc

File tree

5 files changed

+1533
-17
lines changed

5 files changed

+1533
-17
lines changed

.github/actions/ct-test/action.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ inputs:
1010
valgrind_flags:
1111
description: Extra flags to pass to valgrind
1212
default: ""
13+
ctllvm:
14+
description: whether to run CT-LLVM or not (requires LLVM)
15+
default: "false"
1316

1417
runs:
1518
using: composite
@@ -40,3 +43,8 @@ runs:
4043
run: |
4144
make clean
4245
tests func --exec-wrapper="valgrind --error-exitcode=1 --track-origins=yes ${{ inputs.valgrind_flags }}" --cflags="-DMLK_CT_TESTING_ENABLED -DNTESTS=50 ${{ inputs.cflags }}"
46+
- shell: ${{ env.SHELL }}
47+
if: ${{ inputs.ctllvm == 'true' }}
48+
run: |
49+
make clean
50+
tests func --cflags="-fpass-plugin=test/ctllvm/ctllvm.so"-g ${{ inputs.cflags }}"

.github/workflows/ct-tests.yml

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,77 +12,103 @@ jobs:
1212
# Using the patched Valgrind from the KyberSlash paper to detect divisions
1313
# In case the patch no longer applies after an update, we may want to switch back
1414
# to stock valgrind added in https://github.com/pq-code-package/mlkem-native/pull/687
15-
name: CT test ${{ matrix.nix-shell }} ${{ matrix.system }}
15+
name: CT test ${{ matrix.nix-shell.shell }} ${{ matrix.system }}
1616
strategy:
1717
fail-fast: false
1818
max-parallel: 10
1919
matrix:
2020
system: [ubuntu-latest, pqcp-arm64]
2121
nix-shell:
22-
- ci_valgrind-varlat_clang14
23-
- ci_valgrind-varlat_clang15
24-
- ci_valgrind-varlat_clang16
25-
- ci_valgrind-varlat_clang17
26-
- ci_valgrind-varlat_clang18
27-
- ci_valgrind-varlat_clang19
28-
- ci_valgrind-varlat_clang20
29-
- ci_valgrind-varlat_gcc48
30-
- ci_valgrind-varlat_gcc49
31-
- ci_valgrind-varlat_gcc7
32-
- ci_valgrind-varlat_gcc11
33-
- ci_valgrind-varlat_gcc12
34-
- ci_valgrind-varlat_gcc13
35-
- ci_valgrind-varlat_gcc14
22+
- shell: ci_valgrind-varlat_clang14
23+
ctllvm: True
24+
- shell: ci_valgrind-varlat_clang15
25+
ctllvm: True
26+
- shell: ci_valgrind-varlat_clang16
27+
ctllvm: True
28+
- shell: ci_valgrind-varlat_clang17
29+
ctllvm: True
30+
- shell: ci_valgrind-varlat_clang18
31+
ctllvm: True
32+
- shell: ci_valgrind-varlat_clang19
33+
ctllvm: True
34+
- shell: ci_valgrind-varlat_clang20
35+
ctllvm: True
36+
- shell: ci_valgrind-varlat_gcc48
37+
ctllvm: False
38+
- shell: ci_valgrind-varlat_gcc49
39+
ctllvm: False
40+
- shell: ci_valgrind-varlat_gcc7
41+
ctllvm: False
42+
- shell: ci_valgrind-varlat_gcc11
43+
ctllvm: False
44+
- shell: ci_valgrind-varlat_gcc12
45+
ctllvm: False
46+
- shell: ci_valgrind-varlat_gcc13
47+
ctllvm: False
48+
- shell: ci_valgrind-varlat_gcc14
49+
ctllvm: False
3650
runs-on: ${{ matrix.system }}
3751
steps:
3852
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3953
- name: Setup nix
4054
uses: ./.github/actions/setup-shell
4155
with:
4256
gh_token: ${{ secrets.GITHUB_TOKEN }}
43-
nix-shell: ${{ matrix.nix-shell }}
57+
nix-shell: ${{ matrix.nix-shell.name }}
4458
nix-cache: true
59+
- name: Build CT-LLVM Plugin
60+
if: ${{ matrix.nix-shell.ctllvm }}
61+
run: |
62+
make -C test/ctllvm
4563
- name: Build and run test (-Oz)
4664
# -Oz got introduced in gcc12
4765
if: ${{ matrix.nix-shell != 'ci_valgrind-varlat_gcc48' && matrix.nix-shell != 'ci_valgrind-varlat_gcc49' && matrix.nix-shell != 'ci_valgrind-varlat_gcc7' && matrix.nix-shell != 'ci_valgrind-varlat_gcc11'}}
4866
uses: ./.github/actions/ct-test
4967
with:
5068
cflags: -Oz -DMLK_KEYGEN_PCT
5169
valgrind_flags: --variable-latency-errors=yes
70+
ctllvm: ${{ matrix.nix-shell.ctllvm }}
5271
- name: Build and run test (-Os)
5372
uses: ./.github/actions/ct-test
5473
with:
5574
cflags: -Os -DMLK_KEYGEN_PCT
5675
valgrind_flags: --variable-latency-errors=yes
76+
ctllvm: ${{ matrix.nix-shell.ctllvm }}
5777
- name: Build and run test (-O3)
5878
uses: ./.github/actions/ct-test
5979
with:
6080
cflags: -O3 -DMLK_KEYGEN_PCT
6181
valgrind_flags: --variable-latency-errors=yes
82+
ctllvm: ${{ matrix.nix-shell.ctllvm }}
6283
- name: Build and run test (-Ofast)
6384
# -Ofast got deprecated in clang19; -O3 -ffast-math should be used instead
6485
if: ${{ matrix.nix-shell != 'ci_valgrind-varlat_clang19' && matrix.nix-shell != 'ci_valgrind-varlat_clang20' }}
6586
uses: ./.github/actions/ct-test
6687
with:
6788
cflags: -Ofast -DMLK_KEYGEN_PCT
6889
valgrind_flags: --variable-latency-errors=yes
90+
ctllvm: ${{ matrix.nix-shell.ctllvm }}
6991
- name: Build and run test (-O3 -ffast-math)
7092
uses: ./.github/actions/ct-test
7193
with:
7294
cflags: -O3 -ffast-math -DMLK_KEYGEN_PCT
7395
valgrind_flags: --variable-latency-errors=yes
96+
ctllvm: ${{ matrix.nix-shell.ctllvm }}
7497
- name: Build and run test (-O2)
7598
uses: ./.github/actions/ct-test
7699
with:
77100
cflags: -O2 -DMLK_KEYGEN_PCT
78101
valgrind_flags: --variable-latency-errors=yes
102+
ctllvm: ${{ matrix.nix-shell.ctllvm }}
79103
- name: Build and run test (-O1)
80104
uses: ./.github/actions/ct-test
81105
with:
82106
cflags: -O1 -DMLK_KEYGEN_PCT
83107
valgrind_flags: --variable-latency-errors=yes
108+
ctllvm: ${{ matrix.nix-shell.ctllvm }}
84109
- name: Build and run test (-O0)
85110
uses: ./.github/actions/ct-test
86111
with:
87112
cflags: -O0 -DMLK_KEYGEN_PCT
88113
valgrind_flags: --variable-latency-errors=yes
114+
ctllvm: ${{ matrix.nix-shell.ctllvm }}

nix/util.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ rec {
6565
};
6666
mkShellWithCC_valgrind' = cc:
6767
mkShellWithCC cc {
68-
packages = [ pkgs.python3 ] ++ pkgs.lib.optionals (!pkgs.stdenv.isDarwin) [ valgrind_varlat ];
68+
packages = [ pkgs.python3 pkgs.libllvm ] ++ pkgs.lib.optionals (!pkgs.stdenv.isDarwin) [ valgrind_varlat ];
6969
hardeningDisable = [ "fortify" ];
7070
};
7171

test/ctllvm/Makefile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
.PHONY: all clean
4+
5+
CC = clang
6+
CPPFLAGS += -Wno-c++17-extensions -fPIC -shared
7+
LDFLAGS += `llvm-config --cxxflags --ldflags --system-libs --libs core passes`
8+
9+
all: ctllvm.so
10+
11+
%.so: %.cpp
12+
$(CC) $(CPPFLAGS) $< -o $@ $(LDFLAGS)
13+
14+
clean:
15+
-$(RM) -rf *.so

0 commit comments

Comments
 (0)