diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..0e49e25 --- /dev/null +++ b/.clang-format @@ -0,0 +1,61 @@ +--- +Language: C +BasedOnStyle: LLVM + +# Indentation +IndentWidth: 4 +TabWidth: 4 +UseTab: Never +ContinuationIndentWidth: 4 + +# Line length — keep short for embedded readability +ColumnLimit: 100 + +# Braces +BreakBeforeBraces: Allman +InsertBraces: false + +# Spaces +SpaceAfterCStyleCast: false +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +SpaceBeforeSquareBrackets: false + +# Alignment +AlignTrailingComments: + Kind: Always + OverEmptyLines: 0 + +# Pointers — ptr goes with the type +PointerAlignment: Right +ReferenceAlignment: Right + +# Short constructs — keep them on separate lines for readability +AllowShortBlocksOnASingleLine: Never +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortIfStatementsOnASingleLine: Never +AllowShortLoopsOnASingleLine: false + +# Function parameters +BinPackArguments: false +BinPackParameters: false +AllowAllArgumentsOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: false +PenaltyReturnTypeOnItsOwnLine: 10000 + +# Includes +SortIncludes: CaseInsensitive +IncludeBlocks: Regroup + +# Preprocessor +IndentPPDirectives: AfterHash + +# Misc +MaxEmptyLinesToKeep: 1 +KeepEmptyLinesAtTheStartOfBlocks: false + +# Do not indent extern "C" blocks +IndentExternBlock: NoIndent diff --git a/.gitignore b/.gitignore index a0a9120..4748466 100644 --- a/.gitignore +++ b/.gitignore @@ -58,4 +58,5 @@ dkms.conf build/ obj/ bin/ -_codeql_detected_source_root +.github/ +.vscode/ diff --git a/Makefile b/Makefile index 77b866a..16d8762 100644 --- a/Makefile +++ b/Makefile @@ -59,7 +59,7 @@ clean: rm -rf $(BUILD_DIR) obj bin libsdlp.a coverage-html: - bash scripts/coverage_html.sh + bash tools/coverage_html.sh test: unit-tests @echo "Running unit tests..." diff --git a/tests/cunit.h b/tests/cunit.h index 89a89c4..76fcac3 100644 --- a/tests/cunit.h +++ b/tests/cunit.h @@ -9,42 +9,55 @@ #include static int cunit_overall_failures = 0; +static int cunit_total_tests = 0; -#define ASSERT_EQ_INT(expected, actual) \ - do { \ - if ((int)(expected) != (int)(actual)) { \ - printf("ASSERT_EQ_INT failed: %s:%d: expected %d got %d\n", __FILE__, \ - __LINE__, (int)(expected), (int)(actual)); \ - return 1; \ - } \ - } while (0) +#define ASSERT_EQ_INT(expected, actual) \ + do \ + { \ + if ((int)(expected) != (int)(actual)) \ + { \ + printf("ASSERT_EQ_INT failed: %s:%d: expected %d got %d\n", \ + __FILE__, \ + __LINE__, \ + (int)(expected), \ + (int)(actual)); \ + return 1; \ + } \ + } while (0) -#define ASSERT_EQ_MEM(a, b, len) \ - do { \ - if (memcmp((a), (b), (len)) != 0) { \ - printf("ASSERT_EQ_MEM failed: %s:%d\n", __FILE__, __LINE__); \ - return 1; \ - } \ - } while (0) +#define ASSERT_EQ_MEM(a, b, len) \ + do \ + { \ + if (memcmp((a), (b), (len)) != 0) \ + { \ + printf("ASSERT_EQ_MEM failed: %s:%d\n", __FILE__, __LINE__); \ + return 1; \ + } \ + } while (0) -#define ASSERT_TRUE(cond) \ - do { \ - if (!(cond)) { \ - printf("ASSERT_TRUE failed: %s:%d\n", __FILE__, __LINE__); \ - return 1; \ - } \ - } while (0) +#define ASSERT_TRUE(cond) \ + do \ + { \ + if (!(cond)) \ + { \ + printf("ASSERT_TRUE failed: %s:%d\n", __FILE__, __LINE__); \ + return 1; \ + } \ + } while (0) -#define RUN_TEST(fn) \ - do { \ - printf("RUN %s\n", #fn); \ - int r = fn(); \ - if (r == 0) \ - printf("PASS %s\n", #fn); \ - else { \ - printf("FAIL %s\n", #fn); \ - cunit_overall_failures++; \ - } \ - } while (0) +#define RUN_TEST(fn) \ + do \ + { \ + printf("RUN %s\n", #fn); \ + cunit_total_tests++; \ + int r = fn(); \ + if (r == 0) \ + printf("PASS %s\n", #fn); \ + else \ + { \ + printf("FAIL %s\n", #fn); \ + cunit_overall_failures++; \ + } \ + } while (0) #endif /* CUNIT_H */ diff --git a/tests/test_runners.h b/tests/test_runners.h new file mode 100644 index 0000000..c2b648a --- /dev/null +++ b/tests/test_runners.h @@ -0,0 +1,10 @@ +#ifndef TEST_RUNNERS_H +#define TEST_RUNNERS_H + +typedef struct +{ + int passed; + int total; +} pus_test_result_t; + +#endif /* TEST_RUNNERS_H */ diff --git a/scripts/coverage_html.sh b/tools/coverage_html.sh similarity index 94% rename from scripts/coverage_html.sh rename to tools/coverage_html.sh index af3d4ad..9fbbe06 100644 --- a/scripts/coverage_html.sh +++ b/tools/coverage_html.sh @@ -29,4 +29,4 @@ gcovr -r "${ROOT_DIR}" \ --html-details \ --output "${OUT_FILE}" -echo "Coverage HTML report written to: ${OUT_FILE}" \ No newline at end of file +echo "Coverage HTML report written to: ${OUT_FILE}"