diff options
author | Yaroslav de la Peña Smirnov <yps@yaroslavps.com> | 2025-09-12 12:31:51 +0300 |
---|---|---|
committer | Yaroslav de la Peña Smirnov <yps@yaroslavps.com> | 2025-09-12 12:31:51 +0300 |
commit | 3620253a9463a9a256a2a031312d175fd23c73c1 (patch) | |
tree | 6481bcaacc3ace65bf61686eaf2686153237834f | |
parent | ac22f535bcd14f8e201d410265aab268899d7753 (diff) | |
download | c-wares-master.tar.gz c-wares-master.zip |
Also updated clang-format a bit.
-rw-r--r-- | .clang-format | 200 | ||||
-rw-r--r-- | utest/utest.h | 41 |
2 files changed, 75 insertions, 166 deletions
diff --git a/.clang-format b/.clang-format index 008800f..d78aa7a 100644 --- a/.clang-format +++ b/.clang-format @@ -1,187 +1,71 @@ -# SPDX-License-Identifier: GPL-2.0 -# -# clang-format configuration file. Intended for clang-format >= 11. -# -# For more information, see: -# -# Documentation/process/clang-format.rst -# https://clang.llvm.org/docs/ClangFormat.html -# https://clang.llvm.org/docs/ClangFormatStyleOptions.html -# -# Taken from Linux v6.0 with some adjustments --- -AccessModifierOffset: -4 AlignAfterOpenBracket: Align -AlignArrayOfStructures: Left -AlignConsecutiveAssignments: Consecutive -AlignConsecutiveDeclarations: Consecutive +AlignArrayOfStructures: None AlignConsecutiveMacros: Consecutive +AlignConsecutiveAssignments: Consecutive AlignConsecutiveBitFields: Consecutive +AlignConsecutiveDeclarations: Consecutive AlignEscapedNewlines: Left -AlignOperands: AlignAfterOperator +AlignOperands: AlignAfterOperator AlignTrailingComments: true +AllowAllArgumentsOnNextLine: true AllowAllParametersOfDeclarationOnNextLine: false -AllowShortBlocksOnASingleLine: false +AllowShortEnumsOnASingleLine: false +AllowShortBlocksOnASingleLine: Empty AllowShortCaseLabelsOnASingleLine: false AllowShortFunctionsOnASingleLine: None -AllowShortIfStatementsOnASingleLine: false +AllowShortIfStatementsOnASingleLine: Never AllowShortLoopsOnASingleLine: false -AlwaysBreakAfterDefinitionReturnType: None -AlwaysBreakAfterReturnType: None AlwaysBreakBeforeMultilineStrings: false -AlwaysBreakTemplateDeclarations: false -# Taken from RAIDIX Generic -AttributeMacros: - - '__init' - - '__exit' - - '__packed' - - '__aligned' - - '__rcu' - - '__must_hold' - - '__read_mostly' - +AlwaysBreakAfterReturnType: None BinPackArguments: true BinPackParameters: true -BraceWrapping: - AfterClass: false - AfterControlStatement: false - AfterEnum: false - AfterFunction: true - AfterNamespace: true - AfterObjCDeclaration: false - AfterStruct: false - AfterUnion: false - AfterExternBlock: false - BeforeCatch: false - BeforeElse: false - IndentBraces: false - SplitEmptyFunction: true - SplitEmptyRecord: true - SplitEmptyNamespace: true -BreakBeforeBinaryOperators: NonAssignment -BreakBeforeBraces: Custom -BreakBeforeInheritanceComma: false +BitFieldColonSpacing: Both +BreakBeforeBraces: Linux +BreakBeforeBinaryOperators: None BreakBeforeTernaryOperators: true -BreakConstructorInitializersBeforeComma: false -BreakConstructorInitializers: BeforeComma -BreakAfterJavaFieldAnnotations: false -BreakStringLiterals: false -ColumnLimit: 80 -CommentPragmas: '^ IWYU pragma:' -CompactNamespaces: false -ConstructorInitializerAllOnOneLineOrOnePerLine: false -ConstructorInitializerIndentWidth: 8 -ContinuationIndentWidth: 8 -Cpp11BracedListStyle: false -DerivePointerAlignment: false -DisableFormat: false +BreakStringLiterals: true +ColumnLimit: 80 +DeriveLineEnding: false +DisableFormat: false ExperimentalAutoDetectBinPacking: false -FixNamespaceComments: false - -# Taken from: -# git grep -h '^#define [^[:space:]]*for_each[^[:space:]]*(' include/ tools/ \ -# | sed "s,^#define \([^[:space:]]*for_each[^[:space:]]*\)(.*$, - '\1'," \ -# | LC_ALL=C sort -u -ForEachMacros: - - 'hlist_bl_for_each_entry' - - 'hlist_bl_for_each_entry_rcu' - - 'hlist_bl_for_each_entry_safe' - - 'hlist_for_each' - - 'hlist_for_each_entry' - - 'hlist_for_each_entry_continue' - - 'hlist_for_each_entry_continue_rcu' - - 'hlist_for_each_entry_continue_rcu_bh' - - 'hlist_for_each_entry_from' - - 'hlist_for_each_entry_from_rcu' - - 'hlist_for_each_entry_rcu' - - 'hlist_for_each_entry_rcu_bh' - - 'hlist_for_each_entry_rcu_notrace' - - 'hlist_for_each_entry_safe' - - 'hlist_for_each_entry_srcu' - - 'hlist_for_each_safe' - - 'hlist_nulls_for_each_entry' - - 'hlist_nulls_for_each_entry_from' - - 'hlist_nulls_for_each_entry_rcu' - - 'hlist_nulls_for_each_entry_safe' - - 'hmap_iter_foreach' - - 'list_for_each' - - 'list_for_each_codec' - - 'list_for_each_codec_safe' - - 'list_for_each_continue' - - 'list_for_each_entry' - - 'list_for_each_entry_continue' - - 'list_for_each_entry_continue_rcu' - - 'list_for_each_entry_continue_reverse' - - 'list_for_each_entry_from' - - 'list_for_each_entry_from_rcu' - - 'list_for_each_entry_from_reverse' - - 'list_for_each_entry_lockless' - - 'list_for_each_entry_rcu' - - 'list_for_each_entry_reverse' - - 'list_for_each_entry_safe' - - 'list_for_each_entry_safe_continue' - - 'list_for_each_entry_safe_from' - - 'list_for_each_entry_safe_reverse' - - 'list_for_each_entry_srcu' - - 'list_for_each_from' - - 'list_for_each_prev' - - 'list_for_each_prev_safe' - - 'list_for_each_safe' - - 'llist_for_each' - - 'llist_for_each_entry' - - 'llist_for_each_entry_safe' - - 'llist_for_each_safe' - -IncludeBlocks: Preserve -IncludeCategories: - - Regex: '.*' - Priority: 1 -IncludeIsMainRegex: '(Test)?$' +IncludeBlocks: Preserve IndentCaseLabels: false +IndentCaseBlocks: false IndentGotoLabels: false IndentPPDirectives: None -IndentWidth: 4 +IndentExternBlock: NoIndent +IndentWidth: 4 IndentWrappedFunctionNames: false +InsertTrailingCommas: None JavaScriptQuotes: Leave JavaScriptWrapImports: true -KeepEmptyLinesAtTheStartOfBlocks: true -MacroBlockBegin: '' -MacroBlockEnd: '' +KeepEmptyLinesAtTheStartOfBlocks: false MaxEmptyLinesToKeep: 1 -NamespaceIndentation: None -ObjCBinPackProtocolList: Auto -ObjCBlockIndentWidth: 4 -ObjCSpaceAfterProperty: true -ObjCSpaceBeforeProtocolList: true - -# Taken from git's rules -PenaltyBreakAssignment: 30 -PenaltyBreakBeforeFirstCallParameter: 10 -PenaltyBreakComment: 10 -PenaltyBreakFirstLessLess: 0 -PenaltyBreakString: 10 -PenaltyExcessCharacter: 100 -PenaltyReturnTypeOnItsOwnLine: 60 - PointerAlignment: Right -ReflowComments: false -SortIncludes: false -SortUsingDeclarations: false +PPIndentWidth: 0 +ReflowComments: true +SortIncludes: Never SpaceAfterCStyleCast: false -SpaceAfterTemplateKeyword: true +SpaceAfterLogicalNot: false SpaceBeforeAssignmentOperators: true -SpaceBeforeCtorInitializerColon: true -SpaceBeforeInheritanceColon: true -SpaceBeforeParens: ControlStatementsExceptForEachMacros -SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: false +SpaceBeforeParens: ControlStatements +SpaceAroundPointerQualifiers: Default +SpaceInEmptyBlock: false SpaceInEmptyParentheses: false -SpacesBeforeTrailingComments: 1 -SpacesInAngles: false -SpacesInContainerLiterals: false +SpacesBeforeTrailingComments: 2 +SpacesInConditionalStatement: false +SpacesInContainerLiterals: true SpacesInCStyleCastParentheses: false +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: -1 SpacesInParentheses: false SpacesInSquareBrackets: false -Standard: Auto -TabWidth: 4 -UseTab: Always -... +SpaceBeforeSquareBrackets: false +Standard: Auto +TabWidth: 4 +UseCRLF: false +UseTab: Always diff --git a/utest/utest.h b/utest/utest.h index 218b2b7..4222183 100644 --- a/utest/utest.h +++ b/utest/utest.h @@ -10,6 +10,7 @@ #include <stdio.h> #include <stdlib.h> #include <stdbool.h> +#include <time.h> /* * TODO?: test runners that run in different processes in order to not crash the @@ -89,7 +90,7 @@ static setup_fn tests_destroy = NULL; */ #define asserteq(a, b) \ ({ \ - if ((a) != (b)) { \ + if ((a) != (b)) { \ FAIL_TEST("assertion " TBLD TBLU #a " == " #b TRST " failed"); \ } \ }) @@ -101,7 +102,7 @@ static setup_fn tests_destroy = NULL; */ #define assertneq(a, b) \ ({ \ - if ((a) == (b)) { \ + if ((a) == (b)) { \ FAIL_TEST("assertion " TBLD TBLU #a " != " #b TRST " failed"); \ } \ }) @@ -114,7 +115,7 @@ static setup_fn tests_destroy = NULL; */ #define expect(cond, reason...) \ ({ \ - if (!(cond)) { \ + if (!(cond)) { \ FAIL_TEST(reason); \ } \ }) @@ -125,11 +126,11 @@ static setup_fn tests_destroy = NULL; * * Should be followed by TEST_OUT and TEST_END. */ -#define TEST_BEGIN(name) \ - int name(void) \ - { \ - const char *__this_name = #name; \ - bool __ret = true; \ +#define TEST_BEGIN(name) \ + int name(void) \ + { \ + const char *__this_name = #name; \ + bool __ret = true; \ printf(" [⏳]\t%s: " TBLU "running..." TRST, __this_name); \ fflush(stdout); @@ -154,6 +155,30 @@ test_out:; return __ret; \ } +#define BENCH_BEGIN(name) \ + int name(void) \ + { \ + const char *__this_name = #name; \ + struct timespec __t1, __t2; \ + clock_gettime(CLOCK_MONOTONIC, &__t1); \ + printf(" [⏳]\t%s: " TBLU "running..." TRST, __this_name); \ + fflush(stdout); + +#define BENCH_END \ + clock_gettime(CLOCK_MONOTONIC, &__t2); \ + __t2.tv_sec -= __t1.tv_sec; \ + if (__t2.tv_nsec < __t1.tv_nsec) { \ + __t2.tv_nsec = __t1.tv_nsec - __t2.tv_nsec; \ + __t2.tv_sec -= 1; \ + } else { \ + __t2.tv_nsec = __t2.tv_nsec - __t1.tv_nsec; \ + } \ + printf(TDEL " [" TBLD TGRN "✓" TRST "]\t%s: ran in\t" TBLD TBLU \ + "%lu.%09lus\n" TRST, \ + __this_name, __t2.tv_sec, __t2.tv_nsec); \ + return true; \ + } + /** * __run_tests() - runs tests; for internal use. */ |