Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
cbc96fb
add gitignore
lenow55 Oct 26, 2024
4ae012e
add more values at stack
lenow55 Oct 26, 2024
f22b92f
fix value search iteration
lenow55 Oct 26, 2024
94cea3a
Revert "add more values at stack"
lenow55 Oct 26, 2024
141d210
add and config formatter
lenow55 Oct 26, 2024
887fc1a
restructuise project
lenow55 Oct 26, 2024
34654a4
configure editor
lenow55 Oct 27, 2024
a9d4a19
add tests
lenow55 Oct 27, 2024
e5f4282
fix test init error
lenow55 Oct 27, 2024
68c4c90
fix others testing errors
lenow55 Oct 27, 2024
044e69b
fix isEmpty function
lenow55 Oct 27, 2024
3b4a137
add check for sigfault in pop function
lenow55 Oct 27, 2024
beb01cd
fix pop function
lenow55 Oct 27, 2024
308a4c1
add code coverage
lenow55 Oct 28, 2024
82dd2d6
add static checker target
lenow55 Oct 28, 2024
40cb600
add Asan profile with sanitize
lenow55 Oct 28, 2024
5916b78
add benchmarks for push and pop functions
lenow55 Oct 28, 2024
fb8548b
add fix for build coverage target normally
lenow55 Oct 29, 2024
8d50b3a
Create ci.yml
lenow55 Nov 30, 2024
59ac91b
try add gtest fetch
lenow55 Nov 30, 2024
9d19f2f
Merge branch 'fetch_req'
lenow55 Nov 30, 2024
5ee3a34
fix ci and add build kit
lenow55 Nov 30, 2024
164e463
fix ci again
lenow55 Nov 30, 2024
db78d8a
set workdir
lenow55 Nov 30, 2024
a294191
try simple test
lenow55 Nov 30, 2024
6a09fbd
fix simple test build
lenow55 Nov 30, 2024
05f0224
add common steps
lenow55 Nov 30, 2024
72e65c3
reorganize ci workflow
lenow55 Nov 30, 2024
f73aa12
fix targets
lenow55 Nov 30, 2024
933d04c
try add artifacts and fix analyze
lenow55 Nov 30, 2024
fc81b01
add ls
lenow55 Nov 30, 2024
3bded60
try add clang tools
lenow55 Nov 30, 2024
2ac60ba
add more logging
lenow55 Nov 30, 2024
027ece2
fix path
lenow55 Nov 30, 2024
026ecd5
try fix coverage
lenow55 Nov 30, 2024
b106571
try mv report
lenow55 Nov 30, 2024
687442d
fix version uppload report
lenow55 Nov 30, 2024
d62c2cd
fix path
lenow55 Nov 30, 2024
f2dbaca
now last fix
lenow55 Nov 30, 2024
d1838ec
try install cmake default
lenow55 Nov 30, 2024
b0ac287
check analyzer
lenow55 Nov 30, 2024
5850f1f
add mor info
lenow55 Nov 30, 2024
08cf6d3
clang extra not found
lenow55 Nov 30, 2024
f385172
try scan build
lenow55 Nov 30, 2024
e021ab0
try add memory leak
lenow55 Nov 30, 2024
30e4866
try add make command
lenow55 Nov 30, 2024
7e02107
fix commands
lenow55 Nov 30, 2024
808c871
fix again
lenow55 Nov 30, 2024
ecffa78
fix first command
lenow55 Nov 30, 2024
6522c83
add variable error
lenow55 Nov 30, 2024
ddca54f
add leak again
lenow55 Nov 30, 2024
55fc406
add leak flag for build
lenow55 Nov 30, 2024
e1cde8d
try add llvm
lenow55 Nov 30, 2024
831167a
fix repo path
lenow55 Nov 30, 2024
3f8c640
try llvm install via script
lenow55 Nov 30, 2024
1ac9a44
fix job
lenow55 Nov 30, 2024
7c7a586
fix again
lenow55 Nov 30, 2024
93204e6
fix build and add env
lenow55 Nov 30, 2024
f29366d
fix adding env
lenow55 Nov 30, 2024
a8c35e6
rm unused code
lenow55 Nov 30, 2024
f980e3e
fix help msg
lenow55 Nov 30, 2024
ed9c22a
rewrite view
lenow55 Nov 30, 2024
64c54d6
fix artifact path
lenow55 Nov 30, 2024
5270adf
revert leak bug
lenow55 Nov 30, 2024
ec217f1
rm logging from ci
lenow55 Nov 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: C/C++ CI coverage and sanitize

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
coverage:
runs-on: ubuntu-latest

defaults:
run:
working-directory: ./05_hw

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up CMake
uses: jwlawson/actions-setup-cmake@v2

- name: Install dependencies
run: sudo apt-get install -y gcovr lcov

- name: Configure CMake
run: cmake -B build -S . -DCMAKE_EXPORT_COMPILE_COMMANDS=True -DSTACKLIB_COVERAGE=ON

- name: Build project and run ctest
run: cmake --build build --target stack_test

- name: Run ctest
run: cmake --build build --target coverage

- name: ls
run: ls -lah ./coverage/

- name: uppload cov report
uses: actions/upload-artifact@v4
with:
name: cov-report
path: 05_hw/coverage/

analyze:
runs-on: ubuntu-latest

defaults:
run:
working-directory: ./05_hw

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up CMake
uses: jwlawson/actions-setup-cmake@v2

- name: Install dependencies
run: |
sudo wget https://apt.llvm.org/llvm.sh
sudo chmod +x llvm.sh
sudo ./llvm.sh 17

- name: Add directory to PATH
run: |
echo "/usr/lib/llvm-15/bin" >> $GITHUB_PATH
echo "Added to PATH"

- name: Configure CMake
run: cmake -B build -S . -DCMAKE_EXPORT_COMPILE_COMMANDS=True -DCMAKE_BUILD_TYPE=Asan

- name: Build project and run scan
run: cmake --build build --target main

- name: Run analyze
run: cmake --build build --target analyze

- name: uppload clang-tidy report
uses: actions/upload-artifact@v4
with:
name: clang-tidy-report
path: 05_hw/build/analyzer/
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
**/.cache
**/out
compile_commands.json
coverage
05_hw/build
05_hw/venv
12 changes: 12 additions & 0 deletions 05_hw/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
# We'll use defaults from the LLVM style, but with 4 columns indentation.
BasedOnStyle: LLVM
IndentWidth: 4
---
Language: Cpp
# Force pointers to the type for C++.
DerivePointerAlignment: false
PointerAlignment: Left

AllowShortBlocksOnASingleLine: Empty
AllowShortFunctionsOnASingleLine: Empty
5 changes: 5 additions & 0 deletions 05_hw/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
root = true

[*]
indent_style = space
indent_size = 4
48 changes: 45 additions & 3 deletions 05_hw/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,49 @@
cmake_minimum_required(VERSION 3.10)
project(stack)

add_library(stack stack.c)
enable_testing()

add_executable(main main.c)
target_link_libraries(main stack)
add_subdirectory(src)
add_subdirectory(tests)
add_subdirectory(benchmarks)

if(CMAKE_EXPORT_COMPILE_COMMANDS)
find_program(CLANG_EXECUTABLE clang)
add_custom_target(analyze
COMMAND
analyze-build --cdb ${PROJECT_BINARY_DIR}/compile_commands.json
--use-analyzer ${CLANG_EXECUTABLE}
--output ${PROJECT_BINARY_DIR}/analyzer
)
endif()

get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)

if(isMultiConfig)
if(NOT "Asan" IN_LIST CMAKE_CONFIGURATION_TYPES)
list(APPEND CMAKE_CONFIGURATION_TYPES Asan)
endif()
else()
set(allowedBuildTypes Asan Debug Release RelWithDebInfo MinSizeRel)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "${allowedBuildTypes}")

if(CMAKE_BUILD_TYPE AND NOT CMAKE_BUILD_TYPE IN_LIST allowedBuildTypes)
message(FATAL_ERROR "Invalid build type: ${CMAKE_BUILD_TYPE}")
endif()
endif()

set(CMAKE_C_FLAGS_ASAN
"${CMAKE_C_FLAGS_DEBUG} -fsanitize=address,undefined,leak -fno-omit-frame-pointer" CACHE STRING
"Flags used by the C compiler for Asan build type or configuration." FORCE)

set(CMAKE_CXX_FLAGS_ASAN
"${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address,undefined,leak -fno-omit-frame-pointer" CACHE STRING
"Flags used by the C++ compiler for Asan build type or configuration." FORCE)

set(CMAKE_EXE_LINKER_FLAGS_ASAN
"${CMAKE_EXE_LINKER_FLAGS_DEBUG} -fsanitize=address,undefined,leak" CACHE STRING
"Linker flags to be used to create executables for Asan build type." FORCE)

set(CMAKE_SHARED_LINKER_FLAGS_ASAN
"${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fsanitize=address,undefined,leak" CACHE STRING
"Linker lags to be used to create shared libraries for Asan build type." FORCE)
28 changes: 28 additions & 0 deletions 05_hw/benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
include(FetchContent)

set(BENCHMARK_ENABLE_TESTING OFF)
set(ENABLE_GPROF OFF)

FetchContent_Declare(googlebenchmark
GIT_REPOSITORY https://github.com/google/benchmark
GIT_TAG main)

FetchContent_MakeAvailable(googlebenchmark)

add_executable(stack_benchmark stack_benchmark.cpp)


if(STACKLIB_COVERAGE)
target_link_libraries(stack_benchmark
PRIVATE
benchmark::benchmark
stack_lib
gcov
)
else()
target_link_libraries(stack_benchmark
PRIVATE
benchmark::benchmark
stack_lib
)
endif()
66 changes: 66 additions & 0 deletions 05_hw/benchmarks/stack_benchmark.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#include <benchmark/benchmark.h>
#include <stack.h>

static void PushBenchmark(benchmark::State& state, Stack* stack) {
for (auto _ : state) {
push(stack, 1111111);
}
}

class PushFixture : public benchmark::Fixture {
protected:
Stack* stack;

public:
void SetUp(const benchmark::State& state) override {
stack = new Stack();
initStack(stack);
}

void TearDown(const benchmark::State& state) override {
destroyStack(stack);
}
};

BENCHMARK_DEFINE_F(PushFixture, PushBenchmark)(benchmark::State& state) {
PushBenchmark(state, stack);
}

BENCHMARK_REGISTER_F(PushFixture, PushBenchmark)
->RangeMultiplier(2)
->Range(1, 512);

static void PopBenchmark(benchmark::State& state, Stack* stack) {
for (auto _ : state) {
pop(stack);
}
}

class PopFixture : public benchmark::Fixture {
protected:
Stack* stack;

public:
void SetUp(const benchmark::State& state) override {
stack = new Stack();
initStack(stack);
long count = state.range(0);
for (long i = 0; i <= count; i++) {
push(stack, 1111111);
}
}

void TearDown(const benchmark::State& state) override {
destroyStack(stack);
}
};

BENCHMARK_DEFINE_F(PopFixture, PopBenchmark)(benchmark::State& state) {
PopBenchmark(state, stack);
}

BENCHMARK_REGISTER_F(PopFixture, PopBenchmark)
->RangeMultiplier(2)
->Range(1, 1024);

BENCHMARK_MAIN();
10 changes: 10 additions & 0 deletions 05_hw/cmake-kits.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"name": "Windows Kit",
"generator": "MinGW Makefiles",
"compilers": {
"C": "C:\\MinGW\\bin\\gcc.exe",
"CXX": "C:\\MinGW\\bin\\g++.exe"
}
}
]
11 changes: 11 additions & 0 deletions 05_hw/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
add_library(stack_lib stack.c)

target_include_directories(stack_lib PUBLIC .)

add_executable(main main.c)
target_compile_options(stack_lib PRIVATE)
if(STACKLIB_COVERAGE)
target_link_libraries(main stack_lib gcov)
else()
target_link_libraries(main stack_lib)
endif()
2 changes: 0 additions & 2 deletions 05_hw/main.c → 05_hw/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,3 @@ int main() {

return 0;
}


12 changes: 8 additions & 4 deletions 05_hw/stack.c → 05_hw/src/stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ void initStack(Stack* stack) {
void destroyStack(Stack* stack) {
Node* current = stack->top;
while (current != NULL) {
Node *tmp = current;
Node* tmp = current;
current = current->next;
free(tmp);
free(tmp);
}
}

Expand All @@ -30,8 +30,13 @@ void push(Stack* stack, int data) {
}

void pop(Stack* stack) {
if (stack->top == NULL) {
return;
}
Node* temp = stack->top;
stack->top = stack->top->next;
free(temp);
temp = NULL;
}

Node* searchByValue(Stack* stack, int value) {
Expand All @@ -40,6 +45,7 @@ Node* searchByValue(Stack* stack, int value) {
if (current->data == value) {
return current;
}
current = current->next;
}
return NULL;
}
Expand Down Expand Up @@ -72,7 +78,5 @@ void traverseStack(Stack* stack) {
}

bool isEmpty(Stack* stack) {
free(stack->top);
return stack->top == NULL;
}

2 changes: 1 addition & 1 deletion 05_hw/stack.h → 05_hw/src/stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Node* createNode(int data);

void initStack(Stack* stack);

void destroyStack(Stack *stack);
void destroyStack(Stack* stack);

void push(Stack* stack, int data);

Expand Down
Loading