Skip to content

Commit a1f8ed3

Browse files
blucarppt
authored andcommitted
selftests/liveupdate: add test cases for LIVEUPDATE_SESSION_GET_NAME
Verify that the new LIVEUPDATE_SESSION_GET_NAME ioctl works as expected via new test cases in the existing liveupdate selftest. Signed-off-by: Luca Boccassi <luca.boccassi@gmail.com> Reviewed-by: Pasha Tatashin <pasha.tatashin@soleen.com> Reviewed-by: Pratyush Yadav <pratyush@kernel.org> Link: https://lore.kernel.org/r/20260429212221.814107-5-luca.boccassi@gmail.com Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
1 parent 4c08a9f commit a1f8ed3

1 file changed

Lines changed: 71 additions & 0 deletions

File tree

tools/testing/selftests/liveupdate/liveupdate.c

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,22 @@ static int create_session(int lu_fd, const char *name)
102102
return args.fd;
103103
}
104104

105+
/* Helper function to get a session name via ioctl. */
106+
static int get_session_name(int session_fd, char *name, size_t name_len)
107+
{
108+
struct liveupdate_session_get_name args = {};
109+
110+
args.size = sizeof(args);
111+
112+
if (ioctl(session_fd, LIVEUPDATE_SESSION_GET_NAME, &args))
113+
return -errno;
114+
115+
strncpy(name, (char *)args.name, name_len - 1);
116+
name[name_len - 1] = '\0';
117+
118+
return 0;
119+
}
120+
105121
/*
106122
* Test Case: Create Duplicate Session
107123
*
@@ -428,4 +444,59 @@ TEST_F(liveupdate_device, create_session_empty_name)
428444
EXPECT_EQ(session_fd, -EINVAL);
429445
}
430446

447+
/*
448+
* Test Case: Get Session Name
449+
*
450+
* Verifies that the full session name can be retrieved from a session file
451+
* descriptor via ioctl.
452+
*/
453+
TEST_F(liveupdate_device, get_session_name)
454+
{
455+
char name_buf[LIVEUPDATE_SESSION_NAME_LENGTH] = {};
456+
const char *session_name = "get-name-test-session";
457+
int session_fd;
458+
459+
self->fd1 = open(LIVEUPDATE_DEV, O_RDWR);
460+
if (self->fd1 < 0 && errno == ENOENT)
461+
SKIP(return, "%s does not exist", LIVEUPDATE_DEV);
462+
ASSERT_GE(self->fd1, 0);
463+
464+
session_fd = create_session(self->fd1, session_name);
465+
ASSERT_GE(session_fd, 0);
466+
467+
ASSERT_EQ(get_session_name(session_fd, name_buf, sizeof(name_buf)), 0);
468+
ASSERT_STREQ(name_buf, session_name);
469+
470+
ASSERT_EQ(close(session_fd), 0);
471+
}
472+
473+
/*
474+
* Test Case: Get Session Name at Maximum Length
475+
*
476+
* Verifies that a session name using the full LIVEUPDATE_SESSION_NAME_LENGTH
477+
* (minus the null terminator) can be correctly retrieved.
478+
*/
479+
TEST_F(liveupdate_device, get_session_name_max_length)
480+
{
481+
char name_buf[LIVEUPDATE_SESSION_NAME_LENGTH] = {};
482+
char long_name[LIVEUPDATE_SESSION_NAME_LENGTH];
483+
int session_fd;
484+
485+
memset(long_name, 'A', sizeof(long_name) - 1);
486+
long_name[sizeof(long_name) - 1] = '\0';
487+
488+
self->fd1 = open(LIVEUPDATE_DEV, O_RDWR);
489+
if (self->fd1 < 0 && errno == ENOENT)
490+
SKIP(return, "%s does not exist", LIVEUPDATE_DEV);
491+
ASSERT_GE(self->fd1, 0);
492+
493+
session_fd = create_session(self->fd1, long_name);
494+
ASSERT_GE(session_fd, 0);
495+
496+
ASSERT_EQ(get_session_name(session_fd, name_buf, sizeof(name_buf)), 0);
497+
ASSERT_STREQ(name_buf, long_name);
498+
499+
ASSERT_EQ(close(session_fd), 0);
500+
}
501+
431502
TEST_HARNESS_MAIN

0 commit comments

Comments
 (0)