GCC Code Coverage Report


Directory: Svc/FileUplink/
File: File.cpp
Date: 2026-09-03 21:17:46
Exec Total Coverage
Lines: 23 26 88.5%
Functions: 2 2 100.0%
Branches: 15 20 75.0%

Line Branch Exec Source
1 // ======================================================================
2 // \title File.cpp
3 // \author bocchino
4 // \brief cpp file for FileUplink::File
5 //
6 // \copyright
7 // Copyright 2009-2016, by the California Institute of Technology.
8 // ALL RIGHTS RESERVED. United States Government Sponsorship
9 // acknowledged.
10 //
11 // ======================================================================
12
13 #include <Fw/Types/Assert.hpp>
14 #include <Fw/Types/StringUtils.hpp>
15 #include <Svc/FileUplink/FileUplink.hpp>
16
17 #include <cstring>
18 namespace Svc {
19
20 11 Os::File::Status FileUplink::File::open(const Fw::FilePacket::StartPacket& startPacket) {
21 11 const U32 length = startPacket.getDestinationPath().getLength();
22 11 char path[Fw::FilePacket::PathName::MAX_LENGTH + 1];
23 // Ensure that length is not greater that the size of the variable we will copy into
24
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (length >= sizeof(path)) {
25 return Os::File::Status::BAD_SIZE;
26 }
27
2/4
✗ Branch 4 not taken.
✓ Branch 5 taken 11 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 11 times.
11 (void)memcpy(path, startPacket.getDestinationPath().getValue(), length);
28 11 path[length] = 0;
29
1/1
✓ Branch 2 taken 11 times.
11 Fw::LogStringArg logStringArg(path);
30
1/1
✓ Branch 6 taken 11 times.
11 this->name = logStringArg;
31 11 this->size = startPacket.getFileSize();
32
1/1
✓ Branch 2 taken 11 times.
11 CFDP::Checksum checksum;
33
1/1
✓ Branch 4 taken 11 times.
11 this->m_checksum = checksum;
34
1/1
✓ Branch 4 taken 11 times.
11 return this->osFile.open(path, Os::File::OPEN_WRITE);
35 11 }
36
37 8 Os::File::Status FileUplink::File::write(const U8* const data, const U32 byteOffset, const U32 length) {
38 Os::File::Status status;
39
1/1
✓ Branch 4 taken 8 times.
8 status = this->osFile.seek(byteOffset, Os::File::SeekType::ABSOLUTE);
40
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 7 times.
8 if (status != Os::File::OP_OK) {
41 1 return status;
42 }
43
44 7 FwSizeType intLength = length;
45 // Note: not waiting for the file write to finish
46
1/1
✓ Branch 4 taken 7 times.
7 status = this->osFile.write(data, intLength, Os::File::WaitType::NO_WAIT);
47
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if (status != Os::File::OP_OK) {
48 return status;
49 }
50
51 // A short write (e.g. disk full) is an error, not an assertion failure
52
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if (static_cast<U32>(intLength) != length) {
53 return Os::File::NO_SPACE;
54 }
55
1/1
✓ Branch 4 taken 7 times.
7 this->m_checksum.update(data, byteOffset, length);
56 7 return Os::File::OP_OK;
57 }
58
59 } // namespace Svc
60