Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
61 changes: 61 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,5 @@ dkms.conf
build/
obj/
bin/
_codeql_detected_source_root
.github/
.vscode/
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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..."
Expand Down
79 changes: 46 additions & 33 deletions tests/cunit.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,55 @@
#include <string.h>

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 */
10 changes: 10 additions & 0 deletions tests/test_runners.h
Original file line number Diff line number Diff line change
@@ -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 */
2 changes: 1 addition & 1 deletion scripts/coverage_html.sh → tools/coverage_html.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ gcovr -r "${ROOT_DIR}" \
--html-details \
--output "${OUT_FILE}"

echo "Coverage HTML report written to: ${OUT_FILE}"
echo "Coverage HTML report written to: ${OUT_FILE}"