Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 12 additions & 0 deletions protocol/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,18 @@ cc_library(
],
)

cc_test(
name = "console_test",
srcs = ["console_test.cc"],
deps = [
":console",
"//protocol/test:libhoth_device_mock",
"//transports:libhoth_device",
"@googletest//:gtest",
"@googletest//:gtest_main",
],
)


cc_library(
name = "dfu_hostcmd",
Expand Down
2 changes: 1 addition & 1 deletion protocol/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ libhoth_error libhoth_read_console(struct libhoth_device* dev, int fd,
struct hoth_channel_read_request req = {
.channel_id = channel_id,
.offset = *offset,
.size = HOTH_FIFO_MAX_REQUEST_SIZE -
.size = HOTH_FIFO_MAX_REQUEST_SIZE - sizeof(struct hoth_host_response) -
sizeof(struct hoth_channel_read_response),
.timeout_us = 10000,
};
Expand Down
56 changes: 56 additions & 0 deletions protocol/console_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "console.h"

#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <unistd.h>

#include <cstdint>

#include "test/libhoth_device_mock.h"

using ::testing::_;
using ::testing::DoAll;
using ::testing::Return;

constexpr uint32_t kCmdChannelRead =
HOTH_CMD_BOARD_SPECIFIC_BASE + HOTH_PRV_CMD_HOTH_CHANNEL_READ;

bool CheckReadSize(const void* data) {
const auto* req = static_cast<const struct hoth_channel_read_request*>(data);
return req->size == 1012;
}

TEST_F(LibHothTest, read_console_test) {
EXPECT_CALL(mock_,
send(_, UsesCommandWithData(kCmdChannelRead, CheckReadSize), _))
.WillOnce(Return(LIBHOTH_OK));

struct {
struct hoth_channel_read_response hdr;
uint8_t data[1012];
} fake_response = {};
fake_response.hdr.offset = 100;

EXPECT_CALL(mock_, receive)
.WillOnce(DoAll(CopyResp(&fake_response, sizeof(fake_response)),
Return(LIBHOTH_OK)));

uint32_t offset = 100;
EXPECT_EQ(libhoth_read_console(&hoth_dev_, STDOUT_FILENO, false, 0, &offset),
HOTH_SUCCESS);
EXPECT_EQ(offset, 100 + 1012);
}
Loading