GCC Code Coverage Report


Directory: common/src/
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 10 / 0 / 10
Functions: 100.0% 1 / 0 / 1
Branches: 100.0% 2 / 0 / 2

fx_fault_tolerant_calculate_checksum.c
Line Branch Exec Source
1 /***************************************************************************
2 * Copyright (c) 2024 Microsoft Corporation
3 * Copyright (c) 2026-present Eclipse ThreadX contributors
4 *
5 * This program and the accompanying materials are made available under the
6 * terms of the MIT License which is available at
7 * https://opensource.org/licenses/MIT.
8 *
9 * SPDX-License-Identifier: MIT
10 **************************************************************************/
11
12
13 /**************************************************************************/
14 /**************************************************************************/
15 /** */
16 /** FileX Component */
17 /** */
18 /** Fault Tolerant */
19 /** */
20 /**************************************************************************/
21 /**************************************************************************/
22
23 #define FX_SOURCE_CODE
24
25 #include "fx_api.h"
26 #include "fx_fault_tolerant.h"
27 #include "fx_utility.h"
28
29
30 #ifdef FX_ENABLE_FAULT_TOLERANT
31 /**************************************************************************/
32 /* */
33 /* FUNCTION RELEASE */
34 /* */
35 /* _fx_fault_tolerant_calculate_checksum PORTABLE C */
36 /* 6.1 */
37 /* AUTHOR */
38 /* */
39 /* William E. Lamie, Microsoft Corporation */
40 /* */
41 /* DESCRIPTION */
42 /* */
43 /* This function calculates checksum for consecutive data. The size */
44 /* of the log file is required to be 4-byte aligned. Therefore this */
45 /* checksum routine is able to perform 4-byte access. */
46 /* */
47 /* INPUT */
48 /* */
49 /* data Pointer to data */
50 /* len Data length */
51 /* */
52 /* OUTPUT */
53 /* */
54 /* Computed checksum value */
55 /* */
56 /* CALLS */
57 /* */
58 /* _fx_utility_32_unsigned_read Read a UINT from memory */
59 /* */
60 /* CALLED BY */
61 /* */
62 /* _fx_fault_tolerant_enable */
63 /* _fx_fault_tolerant_cleanup_FAT_chain */
64 /* _fx_fault_tolerant_reset_log_file */
65 /* _fx_fault_tolerant_set_FAT_chain */
66 /* _fx_fault_tolerant_transaction_end */
67 /* */
68 /**************************************************************************/
69 493759346 USHORT _fx_fault_tolerant_calculate_checksum(UCHAR *data, UINT len)
70 {
71 493759346 ULONG checksum = 0;
72 ULONG long_value;
73
74
2/2
✓ Branch 5 → 3 taken 3163272621 times.
✓ Branch 5 → 6 taken 493759346 times.
3657031967 while (len >= 4)
75 {
76
77 /* Read first long value. */
78 3163272621 long_value = _fx_utility_32_unsigned_read(data);
79
80 /* Calculate checksum. */
81 3163272621 checksum += (long_value >> 16) + (long_value & 0xFFFF);
82
83 /* Decrease length. */
84 3163272621 len -= sizeof(ULONG);
85 3163272621 data += sizeof(ULONG);
86 }
87
88 /* Trim high 16 bits of checksum. */
89 493759346 checksum = (checksum & 0xFFFF) + (checksum >> 16);
90 493759346 checksum = (checksum & 0xFFFF) + (checksum >> 16);
91
92 493759346 return((USHORT)((~checksum) & 0xFFFF));
93 }
94 #endif /* FX_ENABLE_FAULT_TOLERANT */
95
96