ci: add static analysis, sanitizers, and formatting enforcement
CI / lint (push) Failing after 16s
CI / build-and-test (push) Has been skipped
CI / sanitizers (address) (push) Has been skipped
CI / sanitizers (thread) (push) Has been skipped
CI / lint (pull_request) Failing after 30s
CI / build-and-test (pull_request) Has been skipped
CI / sanitizers (address) (pull_request) Has been skipped
CI / sanitizers (thread) (pull_request) Has been skipped
CI / lint (push) Failing after 16s
CI / build-and-test (push) Has been skipped
CI / sanitizers (address) (push) Has been skipped
CI / sanitizers (thread) (push) Has been skipped
CI / lint (pull_request) Failing after 30s
CI / build-and-test (pull_request) Has been skipped
CI / sanitizers (address) (pull_request) Has been skipped
CI / sanitizers (thread) (pull_request) Has been skipped
Add Tier 1 review automation to catch issues before human review: - Add cppcheck and clang-format to CI lint job - Add sanitizer matrix (ASan + TSan) CI job - Enable -Wextra -Wpedantic -Werror in CI build - Add SANITIZER and STRICT_WARNINGS CMake options - Add .clang-format for consistent code style - Update Dockerfile with cppcheck and clang-format - Fix sign-compare and unused-parameter warnings for -Werror
This commit is contained in:
@@ -0,0 +1,10 @@
|
|||||||
|
BasedOnStyle: LLVM
|
||||||
|
IndentWidth: 2
|
||||||
|
ColumnLimit: 100
|
||||||
|
PointerAlignment: Left
|
||||||
|
AllowShortFunctionsOnASingleLine: None
|
||||||
|
SortIncludes: false
|
||||||
|
AllowShortIfStatementsOnASingleLine: false
|
||||||
|
AllowShortLoopsOnASingleLine: false
|
||||||
|
BinPackArguments: true
|
||||||
|
BinPackParameters: true
|
||||||
@@ -3,15 +3,32 @@ name: CI
|
|||||||
on: [push, pull_request]
|
on: [push, pull_request]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-and-test:
|
lint:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container: gitea.tap-tap.win/taptap/fastsync-ci:v6
|
container: gitea.tap-tap.win/taptap/fastsync-ci:v6
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Install lint tools
|
||||||
|
run: apt-get update && apt-get install -y cppcheck clang-format
|
||||||
|
|
||||||
|
- name: clang-format check
|
||||||
|
run: clang-format --dry-run --Werror src/ tests/
|
||||||
|
|
||||||
|
- name: cppcheck
|
||||||
|
run: cppcheck --enable=warning,style,performance,portability --suppress=missingIncludeSystem --error-exitcode=1 --inline-suppr src/ tests/
|
||||||
|
|
||||||
|
build-and-test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container: gitea.tap-tap.win/taptap/fastsync-ci:v6
|
||||||
|
needs: lint
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Configure
|
- name: Configure
|
||||||
run: cmake -B build -S .
|
run: cmake -B build -S . -DSTRICT_WARNINGS=ON
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: cmake --build build -j$(nproc)
|
run: cmake --build build -j$(nproc)
|
||||||
@@ -21,3 +38,23 @@ jobs:
|
|||||||
|
|
||||||
- name: Integration Tests
|
- name: Integration Tests
|
||||||
run: python3 -m pytest tests/ -v --tb=short
|
run: python3 -m pytest tests/ -v --tb=short
|
||||||
|
|
||||||
|
sanitizers:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container: gitea.tap-tap.win/taptap/fastsync-ci:v6
|
||||||
|
needs: lint
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
sanitizer: [address, thread]
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Configure
|
||||||
|
run: cmake -B build-${{ matrix.sanitizer }} -S . -DSANITIZER=${{ matrix.sanitizer }}
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: cmake --build build-${{ matrix.sanitizer }} -j$(nproc)
|
||||||
|
|
||||||
|
- name: Unit Tests
|
||||||
|
run: ./build-${{ matrix.sanitizer }}/tests
|
||||||
|
|||||||
+19
-2
@@ -7,9 +7,26 @@ set(CMAKE_C_STANDARD 11)
|
|||||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
add_compile_options(-Wall -g -O3)
|
add_compile_options(-Wall -g -O3)
|
||||||
# add_compile_options(-Wall -g -O1 -fsanitize=address)
|
|
||||||
|
|
||||||
# add_link_options(-fsanitize=address)
|
# --- Sanitizer option ---
|
||||||
|
set(SANITIZER "none" CACHE STRING "Sanitizer to enable (address, thread, none)")
|
||||||
|
set_property(CACHE SANITIZER PROPERTY STRINGS address thread none)
|
||||||
|
|
||||||
|
if(SANITIZER STREQUAL "address")
|
||||||
|
add_compile_options(-fsanitize=address -fno-omit-frame-pointer -g)
|
||||||
|
add_link_options(-fsanitize=address)
|
||||||
|
elseif(SANITIZER STREQUAL "thread")
|
||||||
|
add_compile_options(-fsanitize=thread -fno-omit-frame-pointer -g)
|
||||||
|
add_link_options(-fsanitize=thread)
|
||||||
|
elseif(NOT SANITIZER STREQUAL "none")
|
||||||
|
message(FATAL_ERROR "Unknown sanitizer: ${SANITIZER}. Supported values: address, thread, none")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# --- Strict warnings option ---
|
||||||
|
option(STRICT_WARNINGS "Enable strict warnings (Wextra, Wpedantic, Werror)" OFF)
|
||||||
|
if(STRICT_WARNINGS)
|
||||||
|
add_compile_options(-Wextra -Wpedantic -Werror)
|
||||||
|
endif()
|
||||||
|
|
||||||
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
||||||
find_package(Threads REQUIRED)
|
find_package(Threads REQUIRED)
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
FROM ubuntu:24.04
|
FROM ubuntu:24.04
|
||||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
gcc g++ make libc6-dev cmake libzstd-dev libssl-dev git ca-certificates curl \
|
gcc g++ make libc6-dev cmake libzstd-dev libssl-dev git ca-certificates curl cppcheck clang-format \
|
||||||
python3 python3-pip python3-venv openssl openssh-client && \
|
python3 python3-pip python3-venv openssl openssh-client && \
|
||||||
pip3 install --break-system-packages pytest && \
|
pip3 install --break-system-packages pytest && \
|
||||||
curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
|
curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#define INITIAL_DECOMPRESS_BUF_SIZE (1024 * 1024)
|
#define INITIAL_DECOMPRESS_BUF_SIZE (1024 * 1024)
|
||||||
|
|
||||||
Data *data_compress(Data *data_to_compress, int compression_level) {
|
Data *data_compress(Data *data_to_compress, int compression_level) {
|
||||||
|
(void)compression_level;
|
||||||
log_message(LOG_LEVEL_DEBUG, "Starting to compress data");
|
log_message(LOG_LEVEL_DEBUG, "Starting to compress data");
|
||||||
size_t dst_size = ZSTD_compressBound(data_to_compress->size);
|
size_t dst_size = ZSTD_compressBound(data_to_compress->size);
|
||||||
Data *compressed_data = data_create_empty(dst_size);
|
Data *compressed_data = data_create_empty(dst_size);
|
||||||
|
|||||||
+1
-1
@@ -235,7 +235,7 @@ bool file_send_sendfile(File *file, int file_descriptor, bool use_metadata, bool
|
|||||||
}
|
}
|
||||||
|
|
||||||
off_t offset = 0;
|
off_t offset = 0;
|
||||||
while (offset < file_size) {
|
while ((unsigned long long)offset < file_size) {
|
||||||
ssize_t sent = sendfile(file_descriptor, fd, &offset, file_size - offset);
|
ssize_t sent = sendfile(file_descriptor, fd, &offset, file_size - offset);
|
||||||
if (sent == -1) {
|
if (sent == -1) {
|
||||||
perror("sendfile failed");
|
perror("sendfile failed");
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ bool send_n_data(int file_descriptor, void *data, size_t data_size) {
|
|||||||
log_message(LOG_LEVEL_DEBUG, " Sending n Data: %zu", data_size);
|
log_message(LOG_LEVEL_DEBUG, " Sending n Data: %zu", data_size);
|
||||||
int fd = io_fd(io_write_fd, file_descriptor);
|
int fd = io_fd(io_write_fd, file_descriptor);
|
||||||
ssize_t total_bytes_send = 0;
|
ssize_t total_bytes_send = 0;
|
||||||
while (total_bytes_send < data_size) {
|
while ((size_t)total_bytes_send < data_size) {
|
||||||
size_t chunk = data_size - total_bytes_send;
|
size_t chunk = data_size - total_bytes_send;
|
||||||
if (io_bwlimit > 0 && chunk > 65536)
|
if (io_bwlimit > 0 && chunk > 65536)
|
||||||
chunk = 65536;
|
chunk = 65536;
|
||||||
|
|||||||
Reference in New Issue
Block a user