Skip to content

Commit 185cb25

Browse files
committed
more
Signed-off-by: joejiong <1004691415qq@gmail.com> more Signed-off-by: joejiong <1004691415qq@gmail.com> modify lit config Signed-off-by: joejiong <1004691415qq@gmail.com> fine tests Signed-off-by: joejiong <1004691415qq@gmail.com> recover cache Signed-off-by: joejiong <1004691415qq@gmail.com> git action cache changed script path, so I change the base address to workspace address Signed-off-by: joejiong <1004691415qq@gmail.com> clean Signed-off-by: joejiong <1004691415qq@gmail.com> new test Signed-off-by: joejiong <1004691415qq@gmail.com> clean Signed-off-by: joejiong <1004691415qq@gmail.com> disable gc, cause in future it is still need to merge to translate, somehow preserve the flow Signed-off-by: joejiong <1004691415qq@gmail.com>
1 parent e2d5f3c commit 185cb25

File tree

6 files changed

+78
-31
lines changed

6 files changed

+78
-31
lines changed

.github/workflows/build-and-test.yml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,22 @@ jobs:
3333
# Build and test MLIR. Use cache when available.
3434
# --------
3535

36-
# - name: Get LLVM hash
37-
# id: get-llvm-hash
38-
# run: echo "hash=$(git rev-parse @:./third_party/llvm-project)" >> $GITHUB_OUTPUT
36+
- name: Get LLVM hash
37+
id: get-llvm-hash
38+
run: echo "hash=$(git rev-parse @:./third_party/llvm-project)" >> $GITHUB_OUTPUT
3939

40-
# - name: Get workflow hash
41-
# id: get-workflow-hash
42-
# run: echo "hash=$(md5sum $GITHUB_WORKSPACE/.github/workflows/build-and-test.yml | awk '{print $1}')" >> $GITHUB_OUTPUT
40+
- name: Get workflow hash
41+
id: get-workflow-hash
42+
run: echo "hash=$(md5sum $GITHUB_WORKSPACE/.github/workflows/build-and-test.yml | awk '{print $1}')" >> $GITHUB_OUTPUT
4343

44-
# - name: Cache LLVM
45-
# id: cache-llvm
46-
# uses: actions/cache@v3
47-
# with:
48-
# path: |
49-
# third_party/llvm-project/build/bin/llvm-lit
50-
# install
51-
# key: ${{ runner.os }}-llvm-${{ steps.get-llvm-hash.outputs.hash }}-${{ steps.get-workflow-hash.outputs.hash }}
44+
- name: Cache LLVM
45+
id: cache-llvm
46+
uses: actions/cache@v3
47+
with:
48+
path: |
49+
third_party/llvm-project/build/bin/llvm-lit
50+
install
51+
key: ${{ runner.os }}-llvm-${{ steps.get-llvm-hash.outputs.hash }}-${{ steps.get-workflow-hash.outputs.hash }}
5252

5353
- name: Install requirements
5454
run: |

build_tools/unittest.sh

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,58 @@
1+
#!/usr/bin/env bash
12
set -ex
23

3-
# https://stackoverflow.com/a/246128
4-
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) # p4mlir/build_tools
4+
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
5+
echo "SCRIPT_DIR: $SCRIPT_DIR"
6+
7+
SCRIPT_DIR="${GITHUB_WORKSPACE}/build_tools"
8+
9+
echo "SCRIPT_DIR: $SCRIPT_DIR"
10+
511
P4MLIR_REPO_DIR=$( cd "$SCRIPT_DIR"/.. &> /dev/null && pwd )
612

713
P4C_REPO_DIR=$P4MLIR_REPO_DIR/third_party/p4c
814
P4C_BUILD_DIR=$P4C_REPO_DIR/build
915
P4C_EXT_DIR=$P4C_REPO_DIR/extensions
10-
1116
P4C_P4MLIR_EXT_DIR=$P4C_EXT_DIR/p4mlir
17+
LLVM_LIT="$P4MLIR_REPO_DIR/third_party/llvm-project/build/bin/llvm-lit"
18+
TEST_DIR="$P4MLIR_REPO_DIR/third_party/p4c/build/extensions/p4mlir/test"
1219

1320
cd "$P4C_BUILD_DIR"
14-
# Run some tests
15-
ninja check-p4mlir -j1
21+
echo "*********** Listing all available tests ***************"
22+
TEST_LIST=$($LLVM_LIT --show-tests "$TEST_DIR")
23+
24+
TOTAL_TESTS=0
25+
PASSED_TESTS=0
26+
FAILED_TESTS=0
27+
28+
TESTS=()
29+
while IFS= read -r line; do
30+
TESTS+=("$line")
31+
done < <($LLVM_LIT --show-tests "$TEST_DIR" | grep "P4MLIR ::" | sed 's/^ P4MLIR :: //')
32+
33+
for TEST_ITEM in "${TESTS[@]}"; do
34+
35+
FULL_TEST_PATH="$TEST_DIR/$TEST_ITEM"
36+
37+
echo "Test Item: $TEST_ITEM"
38+
echo "Full Test Path: $FULL_TEST_PATH"
39+
40+
TOTAL_TESTS=$((TOTAL_TESTS + 1))
41+
42+
if $LLVM_LIT -v "$FULL_TEST_PATH"; then
43+
PASSED_TESTS=$((PASSED_TESTS + 1))
44+
echo "PASSED"
45+
else
46+
FAILED_TESTS=$((FAILED_TESTS + 1))
47+
echo "FAILED"
48+
fi
49+
done
50+
51+
52+
echo "==== Test Summary ===="
53+
echo "Total tests: $TOTAL_TESTS"
54+
echo "Passed tests: $PASSED_TESTS"
55+
echo "Failed tests: $FAILED_TESTS"
1656

17-
# Install
57+
echo "==== Installing ===="
1858
ninja install

test/Export/BMV2/bool_test.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ module {
44
%1 = p4hir.const #p4hir.bool<false> : !p4hir.bool
55
}
66

7-
// CHECK: p4hir.const
7+
// CHECK: p4hir.const

test/lit.cfg.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
1-
# -*- Python -*-
2-
31
import os
42
import platform
5-
import re
6-
import subprocess
7-
import tempfile
8-
93
import lit.formats
104
import lit.util
11-
125
from lit.llvm import llvm_config
136
from lit.llvm.subst import ToolSubst
147
from lit.llvm.subst import FindTool
@@ -18,7 +11,9 @@
1811
# name: The name of this test suite.
1912
config.name = "P4MLIR"
2013

21-
config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell)
14+
# Check if use_lit_shell exists, fallback to True if not
15+
use_lit_shell = getattr(llvm_config, "use_lit_shell", True)
16+
config.test_format = lit.formats.ShTest(not use_lit_shell)
2217

2318
# suffixes: A list of file extensions to treat as test files.
2419
config.suffixes = [".mlir", ".p4"]
@@ -56,7 +51,7 @@
5651
"mlir-opt",
5752
"p4mlir-opt",
5853
"p4mlir-translate",
59-
"p4mlir-export-bmv2",
54+
"p4mlir-export-bmv2"
6055
]
6156

6257
llvm_config.add_tool_substitutions(tools, tool_dirs)

tools/p4mlir-export-bmv2/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ mlir_check_all_link_libraries(p4mlir-export-bmv2)
2929

3030
add_custom_target(linkp4mlir_export_out
3131
COMMAND ${CMAKE_COMMAND} -E create_symlink
32-
${P4MLIR_BINARY_DIR}/bin/p4mlir-export-bmv2
32+
${P4MLIR_BINARY_DIR}/bin/p4mlir-export-bmv2
3333
${P4C_BINARY_DIR}/p4mlir-export-bmv2
3434
COMMAND ${CMAKE_COMMAND} -E create_symlink
3535
${P4C_BINARY_DIR}/p4include

tools/p4mlir-export-bmv2/p4mlir-export-bmv2.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ limitations under the License.
1616
#include <iostream>
1717
#include "options.h"
1818

19+
#if HAVE_LIBGC
20+
extern "C" {
21+
#include "gc.h"
22+
}
23+
#endif
24+
1925
#pragma GCC diagnostic push
2026
#pragma GCC diagnostic ignored "-Wunused-parameter"
2127
#include "mlir/IR/OperationSupport.h"
@@ -27,8 +33,14 @@ limitations under the License.
2733
#include "json_emitter.h"
2834

2935

36+
37+
3038
int main(int argc, char *const argv[]) {
3139

40+
#if HAVE_LIBGC
41+
GC_disable();
42+
#endif
43+
3244
P4::AutoCompileContext autoP4MLIRExportContext(new P4::MLIR::ExportContext);
3345
auto &options = P4::MLIR::ExportContext::get().options();
3446
options.langVersion = P4::CompilerOptions::FrontendVersion::P4_16;

0 commit comments

Comments
 (0)