Skip to content

[protocol] Add unittest for libhoth_payload_update_read_chunk#241

Open
esnguyen wants to merge 1 commit intogoogle:mainfrom
esnguyen:esnguyen/add_unittest_payload_chunk_read
Open

[protocol] Add unittest for libhoth_payload_update_read_chunk#241
esnguyen wants to merge 1 commit intogoogle:mainfrom
esnguyen:esnguyen/add_unittest_payload_chunk_read

Conversation

@esnguyen
Copy link
Collaborator

This function is being used within libhoth host command and needs a check.

This function is being used within libhoth host command and needs a
check.

Signed-off-by: Ellis Nguyen <sarzanguyen@google.com>
@esnguyen esnguyen force-pushed the esnguyen/add_unittest_payload_chunk_read branch from ebffcbe to 7978751 Compare March 17, 2026 20:31
}

MATCHER_P2(IsReadRequest, offset, len, "") {
const uint8_t* data = static_cast<const uint8_t*>(arg);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be a good idea to check that (struct hoth_host_request *)arg has appropriate data as well? like struct version and command? Without those checks, this matcher might also match other host commands which have appropriate values in the data.

EXPECT_CALL(mock_, receive)
.WillOnce(DoAll(CopyResp(expected_data, len), Return(LIBHOTH_OK)));

char temp_path[] = "/tmp/libhoth_payload_read_XXXXXX";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor nit: Would it be a good idea to use testing::TempDir? Although it might just return /tmp as well.

EXPECT_EQ(libhoth_payload_update_read_chunk(&hoth_dev_, fd, len, offset),
PAYLOAD_UPDATE_OK);

lseek(fd, 0, SEEK_SET);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit. Would it be a good idea to check the return value here as well?

ASSERT_EQ(read(fd, actual_data, len), static_cast<ssize_t>(len));
EXPECT_THAT(actual_data, ::testing::ElementsAreArray(expected_data));

close(fd);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: These might not execute if any of the asserts above fail after opening the file successfully.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at man 2 open, you might able to use O_TMPFILE (with other appropriate flags) to create an unnamed temporary file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants