Skip to content

Commit

Permalink
Add basic linting CI (#6)
Browse files Browse the repository at this point in the history
* Add basic linting CI
  • Loading branch information
Scheremo authored Aug 7, 2024
1 parent 4f20bc4 commit 5269bce
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 26 deletions.
7 changes: 7 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
IndentWidth: 4
ColumnLimit: 100
AlignEscapedNewlines: DontAlign
SortIncludes: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
52 changes: 52 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Copyright 2024 ETH Zurich and University of Bologna.
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0

# Author: Sergio Mazzola <[email protected]>
# Author: Moritz Scherer <[email protected]>

name: lint

on: [ push ]

jobs:

lint-license:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Check license
uses: pulp-platform/pulp-actions/lint-license@v2
with:
license: |
Copyright (\d{4}(-\d{4})?\s)?.*
(Solderpad Hardware License, Version 0.51|Licensed under the Apache License, Version 2.0), see LICENSE for details.
SPDX-License-Identifier: (SHL-0.51|Apache-2.0)
exclude_paths: |
scripts/run_clang_format.py
lint-cxx:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Run Clang-format
uses: DoozyX/[email protected]
with:
extensions: 'c,h,cpp'
clangFormatVersion: 12
style: >
{
IndentWidth: 4,
ColumnLimit: 100,
AlignEscapedNewlines: DontAlign,
SortIncludes: false,
AllowShortFunctionsOnASingleLine: None,
AllowShortIfStatementsOnASingleLine: true,
AllowShortLoopsOnASingleLine: true
}
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,17 @@ cmake -DTARGET_PLATFORM=[YOURTARGETPLATFORM] ../
cmake --build .
```

where you should replace `[YOURTARGETPLATFORM]` by one of the platforms defined in `targets/CMakeLists.txt` under `AVAILABLE_TARGETS`.

The resulting binaries will be stored in `build/bin`, and can be used within the `chimera` repo as tests.

## CXX Formatting

To format all source files, run
```
python scripts/run_clang_format.py -ir sw/
python scripts/run_clang_format.py -ir hal/
python scripts/run_clang_format.py -ir targets/
python scripts/run_clang_format.py -ir tests/
```

Our CI uses llvm-12 for clang-format, so on IIS machines you may run
Expand Down
18 changes: 9 additions & 9 deletions hal/inc/device_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
typedef bool (*chi_device_callback)(struct chi_device *device);

typedef struct chi_device_api {
int (*open)(struct chi_device *device);
int (*close)(struct chi_device *device);
ssize_t (*read_async)(struct chi_device *device, void *buffer, uint32_t size,
chi_device_callback cb);
ssize_t (*write_async)(struct chi_device *device, const void *buffer,
uint32_t size, chi_device_callback cb);
int (*open)(struct chi_device *device);
int (*close)(struct chi_device *device);
ssize_t (*read_async)(struct chi_device *device, void *buffer, uint32_t size,
chi_device_callback cb);
ssize_t (*write_async)(struct chi_device *device, const void *buffer, uint32_t size,
chi_device_callback cb);
} chi_device_api_t;

typedef struct chi_device {
struct chi_device_api *api; // function pointers
uint32_t *device_addr;
void *cfg;
struct chi_device_api *api; // function pointers
uint32_t *device_addr;
void *cfg;
} chi_device_t;
6 changes: 6 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
#
# Moritz Scherer <[email protected]>

set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

add_subdirectory(generic)

# TODO: Add target-specific test directories
18 changes: 3 additions & 15 deletions tests/generic/testReturnZero/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,15 @@
#
# Moritz Scherer <[email protected]>

cmake_minimum_required(VERSION 3.13)

set(CMAKE_C_COMPILER_WORKS 1)

set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_LIST_DIR}/toolchain_gcc.cmake)

project(chimera-sdk-test-build LANGUAGES C ASM)
project(chimera-sdk-testReturnZero LANGUAGES C ASM)

file(GLOB_RECURSE TEST_SRCS
"src/testReturn0.c"
)

add_chimera_test(
return0
testReturnZero
${TEST_SRCS}
)

target_link_libraries(return0 PUBLIC chimera-sdk)
target_link_libraries(testReturnZero PUBLIC chimera-sdk)
4 changes: 3 additions & 1 deletion tests/generic/testReturnZero/src/testReturn0.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
//
// Moritz Scherer <[email protected]>

int main() { return 0; }
int main() {
return 0;
}

0 comments on commit 5269bce

Please sign in to comment.