tools/testing/selftests/liveupdate/liveupdate.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/liveupdate/liveupdate.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/liveupdate/liveupdate.c- Extension
.c- Size
- 16400 bytes
- Lines
- 578
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
errno.hfcntl.hstring.hsys/ioctl.hunistd.hlinux/liveupdate.hluo_test_utils.h../kselftest.h../kselftest_harness.h
Detected Declarations
function Copyrightfunction create_sessionfunction get_session_namefunction preserve_fdfunction file
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2025, Google LLC.
* Pasha Tatashin <pasha.tatashin@soleen.com>
*/
/*
* Selftests for the Live Update Orchestrator.
* This test suite verifies the functionality and behavior of the
* /dev/liveupdate character device and its session management capabilities.
*
* Tests include:
* - Device access: basic open/close, and enforcement of exclusive access.
* - Session management: creation of unique sessions, and duplicate name detection.
* - Resource preservation: successfully preserving individual and multiple memfds,
* verifying contents remain accessible.
* - Complex multi-session scenarios involving mixed empty and populated files.
*/
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <linux/liveupdate.h>
#include "luo_test_utils.h"
#include "../kselftest.h"
#include "../kselftest_harness.h"
#define LIVEUPDATE_DEV "/dev/liveupdate"
FIXTURE(liveupdate_device) {
int fd1;
int fd2;
};
FIXTURE_SETUP(liveupdate_device)
{
self->fd1 = -1;
self->fd2 = -1;
}
FIXTURE_TEARDOWN(liveupdate_device)
{
if (self->fd1 >= 0)
close(self->fd1);
if (self->fd2 >= 0)
close(self->fd2);
}
/*
* Test Case: Basic Open and Close
*
* Verifies that the /dev/liveupdate device can be opened and subsequently
* closed without errors. Skips if the device does not exist.
*/
TEST_F(liveupdate_device, basic_open_close)
{
self->fd1 = open(LIVEUPDATE_DEV, O_RDWR);
if (self->fd1 < 0 && errno == ENOENT)
SKIP(return, "%s does not exist.", LIVEUPDATE_DEV);
ASSERT_GE(self->fd1, 0);
ASSERT_EQ(close(self->fd1), 0);
self->fd1 = -1;
}
/*
* Test Case: Exclusive Open Enforcement
*
* Verifies that the /dev/liveupdate device can only be opened by one process
* at a time. It checks that a second attempt to open the device fails with
* the EBUSY error code.
*/
TEST_F(liveupdate_device, exclusive_open)
{
self->fd1 = open(LIVEUPDATE_DEV, O_RDWR);
if (self->fd1 < 0 && errno == ENOENT)
SKIP(return, "%s does not exist.", LIVEUPDATE_DEV);
ASSERT_GE(self->fd1, 0);
self->fd2 = open(LIVEUPDATE_DEV, O_RDWR);
EXPECT_LT(self->fd2, 0);
EXPECT_EQ(errno, EBUSY);
}
Annotation
- Immediate include surface: `errno.h`, `fcntl.h`, `string.h`, `sys/ioctl.h`, `unistd.h`, `linux/liveupdate.h`, `luo_test_utils.h`, `../kselftest.h`.
- Detected declarations: `function Copyright`, `function create_session`, `function get_session_name`, `function preserve_fd`, `function file`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.