Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clang-format tests/unit/s2n_s.*\.c and enforce in CI #3678

Merged
merged 20 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
f70d5ff
Clang-format s and hand review + add to CI
uwaces Dec 2, 2022
3dc176d
Merge branch 'main' into clang-format-tests-unit-s2n_s
harrisonkaiser Dec 2, 2022
21fad06
Remove empty statment work-around
uwaces Dec 5, 2022
1d99e6c
Merge branch 'main' into clang-format-tests-unit-s2n_s
harrisonkaiser Dec 5, 2022
63b8fb2
Add semicolons at the end of code scopes for clang-format
uwaces Dec 6, 2022
907b9e7
Merge branch 'main' into clang-format-tests-unit-s2n_s
harrisonkaiser Dec 6, 2022
1e218e5
Merge branch 'main' into clang-format-tests-unit-s2n_s
harrisonkaiser Dec 7, 2022
bf346ca
Appease cpp check
uwaces Dec 8, 2022
75f48ce
Merge branch 'main' into clang-format-tests-unit-s2n_s
uwaces Dec 8, 2022
3194569
Merge branch 'main' into clang-format-tests-unit-s2n_s
uwaces Dec 8, 2022
d47357a
Merge branch 'main' into clang-format-tests-unit-s2n_s
harrisonkaiser Dec 9, 2022
198ed6b
Merge branch 'main' into clang-format-tests-unit-s2n_s
uwaces Dec 9, 2022
7da0459
Merge branch 'main' into clang-format-tests-unit-s2n_s
harrisonkaiser Dec 9, 2022
99540b3
Merge branch 'main' into clang-format-tests-unit-s2n_s
harrisonkaiser Dec 9, 2022
1c79d0d
Merge branch 'main' into clang-format-tests-unit-s2n_s
harrisonkaiser Dec 12, 2022
ad6a944
Merge branch 'main' into clang-format-tests-unit-s2n_s
harrisonkaiser Dec 12, 2022
765bf59
Add clang-format off for s2n_safety_macros_test.c
uwaces Dec 13, 2022
a778a00
respond to comments
uwaces Dec 13, 2022
349fa08
Merge branch 'main' into clang-format-tests-unit-s2n_s
harrisonkaiser Dec 13, 2022
f215665
Merge branch 'main' into clang-format-tests-unit-s2n_s
harrisonkaiser Dec 14, 2022
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
2 changes: 1 addition & 1 deletion .github/workflows/ci_clang_format_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- check: 'tests/testlib'
exclude: ''
- check: 'tests/unit'
exclude: "s2n_[^3a-cd-kt-z].*\\.c"
exclude: "s2n_[^3a-csd-kt-z].*\\.c"
- check: 'tls'
exclude: ''
- check: 'tls/extensions'
Expand Down
2 changes: 2 additions & 0 deletions scripts/s2n_safety_macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,8 @@ def write(f, contents):
write("utils/s2n_safety_macros.h", header)

test = copyright + '''
/* clang-format off */
#include "s2n_test.h"
#include "utils/s2n_safety.h"
Expand Down
29 changes: 14 additions & 15 deletions tests/unit/s2n_safety_blinding_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,22 @@
*/

#include "s2n_test.h"

#include "tls/s2n_connection.h"
#include "utils/s2n_safety.h"

#define TEST_ERRNO S2N_ERR_T_INTERNAL_END

#define SETUP_TEST(conn) \
#define SETUP_TEST(conn) \
EXPECT_SUCCESS(s2n_connection_wipe(conn)); \
EXPECT_SUCCESS(s2n_connection_set_blinding(conn, S2N_SELF_SERVICE_BLINDING)); \
EXPECT_SUCCESS(s2n_connection_set_blinding(conn, S2N_SELF_SERVICE_BLINDING));

#define EXPECT_BLINDING(conn) \
#define EXPECT_BLINDING(conn) \
EXPECT_NOT_EQUAL(s2n_connection_get_delay(conn), 0); \
EXPECT_TRUE(conn->closed); \
EXPECT_TRUE(conn->closed);

#define EXPECT_NO_BLINDING(conn) \
#define EXPECT_NO_BLINDING(conn) \
EXPECT_EQUAL(s2n_connection_get_delay(conn), 0); \
EXPECT_FALSE(conn->closed); \
EXPECT_FALSE(conn->closed);

S2N_RESULT s2n_result_func(bool success)
{
Expand All @@ -45,7 +44,7 @@ int s2n_posix_func(bool success)
}

int ptr_value = 0;
int* s2n_ptr_func(bool success)
int *s2n_ptr_func(bool success)
{
PTR_ENSURE(success, TEST_ERRNO);
return &ptr_value;
Expand Down Expand Up @@ -87,7 +86,7 @@ int s2n_posix_test(struct s2n_connection *conn)
return S2N_SUCCESS;
}

int* s2n_ptr_test(struct s2n_connection *conn)
int *s2n_ptr_test(struct s2n_connection *conn)
{
WITH_ERROR_BLINDING(conn, PTR_GUARD_RESULT(s2n_result_func(true)));
EXPECT_NO_BLINDING(conn);
Expand Down Expand Up @@ -125,15 +124,15 @@ int main(int argc, char **argv)
s2n_errno = S2N_ERR_OK;
EXPECT_OK(s2n_connection_apply_error_blinding(&conn));
EXPECT_NO_BLINDING(conn);
}
};

/* No-op for retriable errors */
{
SETUP_TEST(conn);
s2n_errno = S2N_ERR_IO_BLOCKED;
EXPECT_OK(s2n_connection_apply_error_blinding(&conn));
EXPECT_NO_BLINDING(conn);
}
};

/* Closes connection but does not blind for non-blinding errors */
{
Expand All @@ -142,18 +141,18 @@ int main(int argc, char **argv)
EXPECT_OK(s2n_connection_apply_error_blinding(&conn));
EXPECT_EQUAL(s2n_connection_get_delay(conn), 0);
EXPECT_TRUE(conn->closed);
}
};

/* Blinds for an average error */
{
SETUP_TEST(conn);
s2n_errno = S2N_ERR_UNIMPLEMENTED;
EXPECT_OK(s2n_connection_apply_error_blinding(&conn));
EXPECT_BLINDING(conn);
}
};

EXPECT_SUCCESS(s2n_connection_free(conn));
}
};

/* Test: WITH_ERROR_BLINDING macro
* The WITH_ERROR_BLINDING macro relies on the current method exiting early.
Expand All @@ -178,7 +177,7 @@ int main(int argc, char **argv)
EXPECT_BLINDING(conn);

EXPECT_SUCCESS(s2n_connection_free(conn));
}
};

END_TEST();
}
2 changes: 2 additions & 0 deletions tests/unit/s2n_safety_macros_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* permissions and limitations under the License.
*/

/* clang-format off */

#include "s2n_test.h"

#include "utils/s2n_safety.h"
Expand Down
67 changes: 32 additions & 35 deletions tests/unit/s2n_safety_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,34 @@
* permissions and limitations under the License.
*/

#include "s2n_test.h"

#include "utils/s2n_safety.h"

#define CHECK_OVF_0(fn, type, a, b) \
do { \
type result_val; \
EXPECT_FAILURE(fn((a), (b), &result_val)); \
} while (0)


#define CHECK_OVF(fn, type, a, b) \
do { \
CHECK_OVF_0(fn, type, a, b); \
CHECK_OVF_0(fn, type, b, a); \
} while (0)

#define CHECK_NO_OVF_0(fn, type, a, b, r) \
do { \
type result_val; \
EXPECT_SUCCESS(fn((a), (b), &result_val)); \
EXPECT_EQUAL(result_val,(r)); \
} while (0)

#define CHECK_NO_OVF(fn, type, a, b, r) \
do { \
CHECK_NO_OVF_0(fn, type, a, b, r); \
CHECK_NO_OVF_0(fn, type, b, a, r); \
} while (0)
#include "s2n_test.h"

#define CHECK_OVF_0(fn, type, a, b) \
do { \
type result_val; \
EXPECT_FAILURE(fn((a), (b), &result_val)); \
} while (0)

#define CHECK_OVF(fn, type, a, b) \
do { \
CHECK_OVF_0(fn, type, a, b); \
CHECK_OVF_0(fn, type, b, a); \
} while (0)

#define CHECK_NO_OVF_0(fn, type, a, b, r) \
do { \
type result_val; \
EXPECT_SUCCESS(fn((a), (b), &result_val)); \
EXPECT_EQUAL(result_val, (r)); \
} while (0)

#define CHECK_NO_OVF(fn, type, a, b, r) \
do { \
CHECK_NO_OVF_0(fn, type, a, b, r); \
CHECK_NO_OVF_0(fn, type, b, a, r); \
} while (0)

static int failure_gte()
{
Expand Down Expand Up @@ -121,7 +119,7 @@ static int failure_notnull()
static int success_memcpy()
{
char dst[1024];
char src[1024] = {0};
char src[1024] = { 0 };

POSIX_CHECKED_MEMCPY(dst, src, 1024);

Expand Down Expand Up @@ -252,7 +250,6 @@ static int success_ct_pkcs1_negative()
return 0;
}


int main(int argc, char **argv)
{
BEGIN_TEST();
Expand Down Expand Up @@ -314,16 +311,16 @@ int main(int argc, char **argv)

for (int i = 0; i < 256; i++) {
for (int j = 0; j < 256; j++) {
x[0] = i;
y[0] = j;
x[0] = i;
y[0] = j;

int expected = 0;
int expected = 0;

if (i == j) {
if (i == j) {
expected = 1;
}
}

EXPECT_EQUAL(s2n_constant_time_equals(x, y, sizeof(x)), expected);
EXPECT_EQUAL(s2n_constant_time_equals(x, y, sizeof(x)), expected);
}
}

Expand Down
Loading