From ad73615bf6e7e9b420e7a8cc38956903d08665fa Mon Sep 17 00:00:00 2001 From: Nirjhar Roy Date: Wed, 15 Mar 2023 12:13:36 +0000 Subject: [PATCH 1/7] [LibOS] Add support for two new pseudo files in /proc dir The files which are added are: - /proc/sys/fs/pipe-max-size - /proc/sys/fs/lease-break-time The values are hard-coded and taken from Linux v6.2, see: - https://elixir.bootlin.com/linux/v6.2/source/fs/pipe.c#L54 - https://elixir.bootlin.com/linux/v6.2/source/fs/locks.c#L93 Signed-off-by: Nirjhar Roy --- libos/include/libos_types.h | 3 ++ libos/src/fs/proc/fs.c | 48 ++++++++++++++++++++++- libos/test/fs/common.h | 8 +++- libos/test/fs/meson.build | 1 + libos/test/fs/proc_pseudo_files.c | 64 +++++++++++++++++++++++++++++++ libos/test/fs/test_fs.py | 14 +++++++ libos/test/fs/tests.toml | 1 + 7 files changed, 137 insertions(+), 2 deletions(-) create mode 100644 libos/test/fs/proc_pseudo_files.c diff --git a/libos/include/libos_types.h b/libos/include/libos_types.h index abadaeb01d..95609e3640 100644 --- a/libos/include/libos_types.h +++ b/libos/include/libos_types.h @@ -162,6 +162,9 @@ typedef uint32_t IDTYPE; #define PID_MAX_LIMIT 4194304 /* Linux limit 2^22, this value is *one greater* than max PID */ #define PID_MAX (PID_MAX_LIMIT - 1) +/* The following values are taken from Linux v6.2 */ +#define PIPE_MAX_SIZE 1048576 +#define LEASE_BREAK_TIME_MAX 45 typedef uint64_t HASHTYPE; diff --git a/libos/src/fs/proc/fs.c b/libos/src/fs/proc/fs.c index 6ebbcebef2..94ef452bff 100644 --- a/libos/src/fs/proc/fs.c +++ b/libos/src/fs/proc/fs.c @@ -32,6 +32,49 @@ static int proc_pid_max_load(struct libos_dentry* dent, char** out_data, size_t* return 0; } +static int proc_lease_break_time_load(struct libos_dentry* dent, char** out_data, + size_t* out_size) { + __UNUSED(dent); + + size_t buffer_size = 8; /* enough to hold LEASE_BREAK_TIME_MAX */ + char* buffer = malloc(buffer_size); + if (!buffer) + return -ENOMEM; + + static_assert(LEASE_BREAK_TIME_MAX <= UINT_MAX, "wrong types"); + int ret = snprintf(buffer, buffer_size, "%u", LEASE_BREAK_TIME_MAX); + if (ret < 0) { + free(buffer); + return ret; + } + assert((size_t)ret < buffer_size); + + *out_data = buffer; + *out_size = buffer_size; + return 0; +} + +static int proc_pipe_max_load(struct libos_dentry* dent, char** out_data, size_t* out_size) { + __UNUSED(dent); + + size_t buffer_size = 16; /* enough to hold PIPE_MAX_SIZE */ + char* buffer = malloc(buffer_size); + if (!buffer) + return -ENOMEM; + + static_assert(PIPE_MAX_SIZE <= UINT_MAX, "wrong types"); + int ret = snprintf(buffer, buffer_size, "%u", PIPE_MAX_SIZE); + if (ret < 0) { + free(buffer); + return ret; + } + assert((size_t)ret < buffer_size); + + *out_data = buffer; + *out_size = buffer_size; + return 0; +} + int proc_self_follow_link(struct libos_dentry* dent, char** out_target) { __UNUSED(dent); IDTYPE pid = g_process.pid; @@ -71,8 +114,11 @@ int init_procfs(void) { struct pseudo_node* sys = pseudo_add_dir(root, "sys"); struct pseudo_node* kernel = pseudo_add_dir(sys, "kernel"); - pseudo_add_str(kernel, "pid_max", &proc_pid_max_load); + struct pseudo_node* fs = pseudo_add_dir(sys, "fs"); + pseudo_add_str(fs, "pipe-max-size", &proc_pipe_max_load); + pseudo_add_str(fs, "lease-break-time", &proc_lease_break_time_load); + pseudo_add_str(kernel, "pid_max", &proc_pid_max_load); pseudo_add_str(root, "meminfo", &proc_meminfo_load); pseudo_add_str(root, "cpuinfo", &proc_cpuinfo_load); pseudo_add_str(root, "stat", &proc_stat_load); diff --git a/libos/test/fs/common.h b/libos/test/fs/common.h index 860f6ee502..ea217a7abe 100644 --- a/libos/test/fs/common.h +++ b/libos/test/fs/common.h @@ -26,7 +26,13 @@ type __dummy; \ __builtin_add_overflow((val), 0, &__dummy); \ }) - +#define CHECK(x) ({ \ + __typeof__(x) _x = (x); \ + if (_x == -1) { \ + err(1, "error at %s (line %d): %m", #x, __LINE__); \ + } \ + _x; \ +}) noreturn void fatal_error(const char* fmt, ...); void setup(void); int open_input_fd(const char* path); diff --git a/libos/test/fs/meson.build b/libos/test/fs/meson.build index cbce1090f8..45c9bed02e 100644 --- a/libos/test/fs/meson.build +++ b/libos/test/fs/meson.build @@ -42,6 +42,7 @@ tests = { }, 'open_close': {}, 'open_flags': {}, + 'proc_pseudo_files': {}, 'read_write': {}, 'seek_tell': {}, 'seek_tell_truncate': {}, diff --git a/libos/test/fs/proc_pseudo_files.c b/libos/test/fs/proc_pseudo_files.c new file mode 100644 index 0000000000..604e53f8c7 --- /dev/null +++ b/libos/test/fs/proc_pseudo_files.c @@ -0,0 +1,64 @@ +/* SPDX-License-Identifier: LGPL-3.0-or-later */ +/* Copyright (C) 2023 Fortanix Inc + * Nirjhar Roy */ + +/* Test description: this test reads the contents of the pseudo file /proc/sys/fs/pipe-max-size and + * /proc/sys/fs/lease-break-time and then tries to match the read contents with the expected + * contents. */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "common.h" + +#define BUF_SZ 1024 +/* The following values are defined in gramine/libos/include/libos_types.h */ +#define PIPE_MAX_SIZE "1048576" +#define LEASE_BREAK_TIME "45" + +int main(void) { + struct test_cases { + const char* path; + const char* expected_value; + size_t expected_length; + } tc [] = { + { + "/proc/sys/fs/pipe-max-size", + PIPE_MAX_SIZE, + strlen(PIPE_MAX_SIZE) + }, + { + "/proc/sys/fs/lease-break-time", + LEASE_BREAK_TIME, + strlen(LEASE_BREAK_TIME) + }, + }; + + char buf[BUF_SZ]; + for (size_t i = 0; i < sizeof(tc)/sizeof(*tc); i++) { + memset(buf, 0, sizeof(buf)); + int fd = open_input_fd(tc[i].path); + if (fd < 0) + errx(1,"opening file %s failed", tc[i].path); + read_fd(tc[i].path, fd, buf, tc[i].expected_length); + if (strcmp(tc[i].expected_value, buf)) { + errx(1,"Content mismatch for file = %s. Expected %s got %s", tc[i].path, + tc[i].expected_value, buf); + } + + struct stat sb; + CHECK(stat(tc[i].path, &sb)); + if (!S_ISREG(sb.st_mode)) + errx(1,"Unexpected type for file = %s. Expected S_ISREG", tc[i].path); + CHECK(close(fd)); + } + puts("TEST OK"); + return 0; +} diff --git a/libos/test/fs/test_fs.py b/libos/test/fs/test_fs.py index 2324ab4608..d8c25a0091 100644 --- a/libos/test/fs/test_fs.py +++ b/libos/test/fs/test_fs.py @@ -343,3 +343,17 @@ def test_002_multiple_writers_many_processes(self): @unittest.skip('file handle sync is not supported yet') def test_003_multiple_writers_many_processes_and_threads(self): self._test_multiple_writers(20, 5, 5) + +class TC_02_Proc_Pseudo_Files(RegressionTestCase): + TEST_DIR = 'tmp' + + def setUp(self): + shutil.rmtree(self.TEST_DIR, ignore_errors=True) + os.mkdir(self.TEST_DIR) + + def tearDown(self): + shutil.rmtree(self.TEST_DIR) + + def test_000_proc_pseudo_files(self): + stdout, stderr = self.run_binary(['proc_pseudo_files']) + self.assertIn('TEST OK', stdout) diff --git a/libos/test/fs/tests.toml b/libos/test/fs/tests.toml index e7e462e314..e89848956c 100644 --- a/libos/test/fs/tests.toml +++ b/libos/test/fs/tests.toml @@ -13,6 +13,7 @@ manifests = [ "multiple_writers", "open_close", "open_flags", + "proc_pseudo_files", "read_write", "seek_tell", "seek_tell_truncate", From a6a57d51248e7225811b33225439e9dfe28232d7 Mon Sep 17 00:00:00 2001 From: Nirjhar Roy Date: Wed, 22 Mar 2023 13:14:51 +0000 Subject: [PATCH 2/7] fixes Signed-off-by: Nirjhar Roy --- libos/include/libos_types.h | 3 --- libos/src/fs/proc/fs.c | 22 ++++++++++++------- libos/test/fs/common.h | 8 +------ libos/test/fs/meson.build | 1 - libos/test/fs/test_fs.py | 14 ------------ libos/test/fs/tests.toml | 1 - libos/test/regression/meson.build | 1 + .../{fs => regression}/proc_pseudo_files.c | 15 ++++++++----- libos/test/regression/test_libos.py | 4 ++++ libos/test/regression/tests.toml | 1 + libos/test/regression/tests_musl.toml | 1 + 11 files changed, 32 insertions(+), 39 deletions(-) rename libos/test/{fs => regression}/proc_pseudo_files.c (78%) diff --git a/libos/include/libos_types.h b/libos/include/libos_types.h index 95609e3640..abadaeb01d 100644 --- a/libos/include/libos_types.h +++ b/libos/include/libos_types.h @@ -162,9 +162,6 @@ typedef uint32_t IDTYPE; #define PID_MAX_LIMIT 4194304 /* Linux limit 2^22, this value is *one greater* than max PID */ #define PID_MAX (PID_MAX_LIMIT - 1) -/* The following values are taken from Linux v6.2 */ -#define PIPE_MAX_SIZE 1048576 -#define LEASE_BREAK_TIME_MAX 45 typedef uint64_t HASHTYPE; diff --git a/libos/src/fs/proc/fs.c b/libos/src/fs/proc/fs.c index 94ef452bff..8c61c5e38f 100644 --- a/libos/src/fs/proc/fs.c +++ b/libos/src/fs/proc/fs.c @@ -11,6 +11,10 @@ #include "libos_fs_pseudo.h" #include "libos_process.h" +/* The following values are taken from Linux v6.2 */ +#define PIPE_MAX_SIZE 1048576 +#define LEASE_BREAK_TIME 45 + static int proc_pid_max_load(struct libos_dentry* dent, char** out_data, size_t* out_size) { __UNUSED(dent); @@ -33,16 +37,16 @@ static int proc_pid_max_load(struct libos_dentry* dent, char** out_data, size_t* } static int proc_lease_break_time_load(struct libos_dentry* dent, char** out_data, - size_t* out_size) { + size_t* out_size) { __UNUSED(dent); - size_t buffer_size = 8; /* enough to hold LEASE_BREAK_TIME_MAX */ + size_t buffer_size = 16; /* enough to hold LEASE_BREAK_TIME */ char* buffer = malloc(buffer_size); if (!buffer) return -ENOMEM; - static_assert(LEASE_BREAK_TIME_MAX <= UINT_MAX, "wrong types"); - int ret = snprintf(buffer, buffer_size, "%u", LEASE_BREAK_TIME_MAX); + static_assert(LEASE_BREAK_TIME <= UINT_MAX, "wrong types"); + int ret = snprintf(buffer, buffer_size, "%u", LEASE_BREAK_TIME); if (ret < 0) { free(buffer); return ret; @@ -50,11 +54,11 @@ static int proc_lease_break_time_load(struct libos_dentry* dent, char** out_data assert((size_t)ret < buffer_size); *out_data = buffer; - *out_size = buffer_size; + *out_size = ret; return 0; } -static int proc_pipe_max_load(struct libos_dentry* dent, char** out_data, size_t* out_size) { +static int proc_pipe_max_size_load(struct libos_dentry* dent, char** out_data, size_t* out_size) { __UNUSED(dent); size_t buffer_size = 16; /* enough to hold PIPE_MAX_SIZE */ @@ -71,7 +75,7 @@ static int proc_pipe_max_load(struct libos_dentry* dent, char** out_data, size_t assert((size_t)ret < buffer_size); *out_data = buffer; - *out_size = buffer_size; + *out_size = ret; return 0; } @@ -116,9 +120,11 @@ int init_procfs(void) { struct pseudo_node* kernel = pseudo_add_dir(sys, "kernel"); struct pseudo_node* fs = pseudo_add_dir(sys, "fs"); - pseudo_add_str(fs, "pipe-max-size", &proc_pipe_max_load); + pseudo_add_str(fs, "pipe-max-size", &proc_pipe_max_size_load); pseudo_add_str(fs, "lease-break-time", &proc_lease_break_time_load); + pseudo_add_str(kernel, "pid_max", &proc_pid_max_load); + pseudo_add_str(root, "meminfo", &proc_meminfo_load); pseudo_add_str(root, "cpuinfo", &proc_cpuinfo_load); pseudo_add_str(root, "stat", &proc_stat_load); diff --git a/libos/test/fs/common.h b/libos/test/fs/common.h index ea217a7abe..860f6ee502 100644 --- a/libos/test/fs/common.h +++ b/libos/test/fs/common.h @@ -26,13 +26,7 @@ type __dummy; \ __builtin_add_overflow((val), 0, &__dummy); \ }) -#define CHECK(x) ({ \ - __typeof__(x) _x = (x); \ - if (_x == -1) { \ - err(1, "error at %s (line %d): %m", #x, __LINE__); \ - } \ - _x; \ -}) + noreturn void fatal_error(const char* fmt, ...); void setup(void); int open_input_fd(const char* path); diff --git a/libos/test/fs/meson.build b/libos/test/fs/meson.build index 45c9bed02e..cbce1090f8 100644 --- a/libos/test/fs/meson.build +++ b/libos/test/fs/meson.build @@ -42,7 +42,6 @@ tests = { }, 'open_close': {}, 'open_flags': {}, - 'proc_pseudo_files': {}, 'read_write': {}, 'seek_tell': {}, 'seek_tell_truncate': {}, diff --git a/libos/test/fs/test_fs.py b/libos/test/fs/test_fs.py index d8c25a0091..2324ab4608 100644 --- a/libos/test/fs/test_fs.py +++ b/libos/test/fs/test_fs.py @@ -343,17 +343,3 @@ def test_002_multiple_writers_many_processes(self): @unittest.skip('file handle sync is not supported yet') def test_003_multiple_writers_many_processes_and_threads(self): self._test_multiple_writers(20, 5, 5) - -class TC_02_Proc_Pseudo_Files(RegressionTestCase): - TEST_DIR = 'tmp' - - def setUp(self): - shutil.rmtree(self.TEST_DIR, ignore_errors=True) - os.mkdir(self.TEST_DIR) - - def tearDown(self): - shutil.rmtree(self.TEST_DIR) - - def test_000_proc_pseudo_files(self): - stdout, stderr = self.run_binary(['proc_pseudo_files']) - self.assertIn('TEST OK', stdout) diff --git a/libos/test/fs/tests.toml b/libos/test/fs/tests.toml index e89848956c..e7e462e314 100644 --- a/libos/test/fs/tests.toml +++ b/libos/test/fs/tests.toml @@ -13,7 +13,6 @@ manifests = [ "multiple_writers", "open_close", "open_flags", - "proc_pseudo_files", "read_write", "seek_tell", "seek_tell_truncate", diff --git a/libos/test/regression/meson.build b/libos/test/regression/meson.build index 18107ccbc8..d47a03c4a1 100644 --- a/libos/test/regression/meson.build +++ b/libos/test/regression/meson.build @@ -82,6 +82,7 @@ tests = { 'proc_common': {}, 'proc_cpuinfo': {}, 'proc_path': {}, + 'proc_pseudo_files': {}, 'proc_stat': {}, 'pselect': {}, 'pthread_set_get_affinity': {}, diff --git a/libos/test/fs/proc_pseudo_files.c b/libos/test/regression/proc_pseudo_files.c similarity index 78% rename from libos/test/fs/proc_pseudo_files.c rename to libos/test/regression/proc_pseudo_files.c index 604e53f8c7..5afe1e8f27 100644 --- a/libos/test/fs/proc_pseudo_files.c +++ b/libos/test/regression/proc_pseudo_files.c @@ -9,17 +9,18 @@ #include #include #include +#include #include #include #include #include #include -#include +#include #include "common.h" #define BUF_SZ 1024 -/* The following values are defined in gramine/libos/include/libos_types.h */ +/* The following values are defined in gramine/libos/src/fs/proc/fs.c */ #define PIPE_MAX_SIZE "1048576" #define LEASE_BREAK_TIME "45" @@ -27,7 +28,7 @@ int main(void) { struct test_cases { const char* path; const char* expected_value; - size_t expected_length; + ssize_t expected_length; } tc [] = { { "/proc/sys/fs/pipe-max-size", @@ -44,10 +45,14 @@ int main(void) { char buf[BUF_SZ]; for (size_t i = 0; i < sizeof(tc)/sizeof(*tc); i++) { memset(buf, 0, sizeof(buf)); - int fd = open_input_fd(tc[i].path); + int fd = open(tc[i].path, O_RDONLY); if (fd < 0) errx(1,"opening file %s failed", tc[i].path); - read_fd(tc[i].path, fd, buf, tc[i].expected_length); + ssize_t read_bytes = read(fd, buf, sizeof(buf)); + if (read_bytes != tc[i].expected_length) { + errx(1,"Content length mismatch for file = %s. Expected %ld got %ld", tc[i].path, + tc[i].expected_length, read_bytes); + } if (strcmp(tc[i].expected_value, buf)) { errx(1,"Content mismatch for file = %s. Expected %s got %s", tc[i].path, tc[i].expected_value, buf); diff --git a/libos/test/regression/test_libos.py b/libos/test/regression/test_libos.py index 0d2fa2a97d..9e694c2f0f 100644 --- a/libos/test/regression/test_libos.py +++ b/libos/test/regression/test_libos.py @@ -1018,6 +1018,10 @@ def test_000_proc(self): self.assertIn('/proc/1/exe: link: /proc_common', lines) self.assertIn('/proc/1/root: link: /', lines) + def test_001_proc(self): + stdout, stderr = self.run_binary(['proc_pseudo_files']) + self.assertIn('TEST OK', stdout) + def test_001_devfs(self): stdout, _ = self.run_binary(['devfs']) self.assertIn('/dev/.', stdout) diff --git a/libos/test/regression/tests.toml b/libos/test/regression/tests.toml index f36a1c4a2f..0f8f3706ae 100644 --- a/libos/test/regression/tests.toml +++ b/libos/test/regression/tests.toml @@ -83,6 +83,7 @@ manifests = [ "proc_common", "proc_cpuinfo", "proc_path", + "proc_pseudo_files", "proc_stat", "pselect", "pthread_set_get_affinity", diff --git a/libos/test/regression/tests_musl.toml b/libos/test/regression/tests_musl.toml index f872d14950..208634cc91 100644 --- a/libos/test/regression/tests_musl.toml +++ b/libos/test/regression/tests_musl.toml @@ -85,6 +85,7 @@ manifests = [ "proc_common", "proc_cpuinfo", "proc_path", + "proc_pseudo_files", "proc_stat", "pselect", "pthread_set_get_affinity", From 0d55f2f892668b05fd35564f2d076bc1b06ffdc8 Mon Sep 17 00:00:00 2001 From: Nirjhar Roy Date: Thu, 23 Mar 2023 05:54:43 +0000 Subject: [PATCH 3/7] fixes --- libos/test/regression/meson.build | 2 +- .../{proc_pseudo_files.c => proc_hardcoded_files.c} | 0 libos/test/regression/test_libos.py | 8 ++++---- libos/test/regression/tests.toml | 2 +- libos/test/regression/tests_musl.toml | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) rename libos/test/regression/{proc_pseudo_files.c => proc_hardcoded_files.c} (100%) diff --git a/libos/test/regression/meson.build b/libos/test/regression/meson.build index d47a03c4a1..fa030f1ffe 100644 --- a/libos/test/regression/meson.build +++ b/libos/test/regression/meson.build @@ -82,7 +82,7 @@ tests = { 'proc_common': {}, 'proc_cpuinfo': {}, 'proc_path': {}, - 'proc_pseudo_files': {}, + 'proc_hardcoded_files': {}, 'proc_stat': {}, 'pselect': {}, 'pthread_set_get_affinity': {}, diff --git a/libos/test/regression/proc_pseudo_files.c b/libos/test/regression/proc_hardcoded_files.c similarity index 100% rename from libos/test/regression/proc_pseudo_files.c rename to libos/test/regression/proc_hardcoded_files.c diff --git a/libos/test/regression/test_libos.py b/libos/test/regression/test_libos.py index 9e694c2f0f..0120bf49d2 100644 --- a/libos/test/regression/test_libos.py +++ b/libos/test/regression/test_libos.py @@ -1018,10 +1018,6 @@ def test_000_proc(self): self.assertIn('/proc/1/exe: link: /proc_common', lines) self.assertIn('/proc/1/root: link: /', lines) - def test_001_proc(self): - stdout, stderr = self.run_binary(['proc_pseudo_files']) - self.assertIn('TEST OK', stdout) - def test_001_devfs(self): stdout, _ = self.run_binary(['devfs']) self.assertIn('/dev/.', stdout) @@ -1039,6 +1035,10 @@ def test_002_device_passthrough(self): stdout, _ = self.run_binary(['device_passthrough']) self.assertIn('TEST OK', stdout) + def test_003_proc_hardcoded_files(self): + stdout, stderr = self.run_binary(['proc_hardcoded_files']) + self.assertIn('TEST OK', stdout) + def test_010_path(self): stdout, _ = self.run_binary(['proc_path']) self.assertIn('proc path test success', stdout) diff --git a/libos/test/regression/tests.toml b/libos/test/regression/tests.toml index 0f8f3706ae..c24224d36c 100644 --- a/libos/test/regression/tests.toml +++ b/libos/test/regression/tests.toml @@ -83,7 +83,7 @@ manifests = [ "proc_common", "proc_cpuinfo", "proc_path", - "proc_pseudo_files", + "proc_hardcoded_files", "proc_stat", "pselect", "pthread_set_get_affinity", diff --git a/libos/test/regression/tests_musl.toml b/libos/test/regression/tests_musl.toml index 208634cc91..ddb0fded72 100644 --- a/libos/test/regression/tests_musl.toml +++ b/libos/test/regression/tests_musl.toml @@ -85,7 +85,7 @@ manifests = [ "proc_common", "proc_cpuinfo", "proc_path", - "proc_pseudo_files", + "proc_hardcoded_files", "proc_stat", "pselect", "pthread_set_get_affinity", From a1bd9c086b176ab7708e7e1c7867617eb2fcd086 Mon Sep 17 00:00:00 2001 From: Nirjhar Roy Date: Thu, 23 Mar 2023 06:04:45 +0000 Subject: [PATCH 4/7] fxes Signed-off-by: Nirjhar Roy --- libos/test/regression/proc_hardcoded_files.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/libos/test/regression/proc_hardcoded_files.c b/libos/test/regression/proc_hardcoded_files.c index 5afe1e8f27..8d6fea9cdf 100644 --- a/libos/test/regression/proc_hardcoded_files.c +++ b/libos/test/regression/proc_hardcoded_files.c @@ -59,10 +59,15 @@ int main(void) { } struct stat sb; - CHECK(stat(tc[i].path, &sb)); + int ret = stat(tc[i].path, &sb); + if (ret < 0) + errx(1, "stat failed for file %s with error code = %d", tc[i].path, errno); if (!S_ISREG(sb.st_mode)) errx(1,"Unexpected type for file = %s. Expected S_ISREG", tc[i].path); - CHECK(close(fd)); + ret = close(fd); + if (ret < 0) + errx(1, "close() failed for file %s fd = %d with error code = %d", tc[i].path, fd, + errno); } puts("TEST OK"); return 0; From 5d0a35c4a56890c9c01d7a5e5d6af2ae8df8bd20 Mon Sep 17 00:00:00 2001 From: Nirjhar Roy Date: Thu, 23 Mar 2023 08:10:54 +0000 Subject: [PATCH 5/7] fixes Signed-off-by: Nirjhar Roy --- libos/test/regression/proc_hardcoded_files.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/libos/test/regression/proc_hardcoded_files.c b/libos/test/regression/proc_hardcoded_files.c index 8d6fea9cdf..719e1ebc8b 100644 --- a/libos/test/regression/proc_hardcoded_files.c +++ b/libos/test/regression/proc_hardcoded_files.c @@ -47,11 +47,13 @@ int main(void) { memset(buf, 0, sizeof(buf)); int fd = open(tc[i].path, O_RDONLY); if (fd < 0) - errx(1,"opening file %s failed", tc[i].path); + err(1, "opening file %s failed", tc[i].path); ssize_t read_bytes = read(fd, buf, sizeof(buf)); + if (read_bytes < 0) + err(1, "reading file %s failed", tc[i].path); if (read_bytes != tc[i].expected_length) { - errx(1,"Content length mismatch for file = %s. Expected %ld got %ld", tc[i].path, - tc[i].expected_length, read_bytes); + errx(1, "Content length mismatch for file = %s. Expected %ld got %ld", tc[i].path, + tc[i].expected_length, read_bytes); } if (strcmp(tc[i].expected_value, buf)) { errx(1,"Content mismatch for file = %s. Expected %s got %s", tc[i].path, @@ -61,13 +63,12 @@ int main(void) { struct stat sb; int ret = stat(tc[i].path, &sb); if (ret < 0) - errx(1, "stat failed for file %s with error code = %d", tc[i].path, errno); + err(1, "stat failed for file %s", tc[i].path); if (!S_ISREG(sb.st_mode)) errx(1,"Unexpected type for file = %s. Expected S_ISREG", tc[i].path); ret = close(fd); if (ret < 0) - errx(1, "close() failed for file %s fd = %d with error code = %d", tc[i].path, fd, - errno); + err(1, "close() failed for file %s", tc[i].path); } puts("TEST OK"); return 0; From ce039afda4712a11a786ac96ba50eca5e0606a7a Mon Sep 17 00:00:00 2001 From: Nirjhar Roy Date: Thu, 23 Mar 2023 08:15:54 +0000 Subject: [PATCH 6/7] fixes Signed-off-by: Nirjhar Roy --- libos/test/regression/test_libos.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libos/test/regression/test_libos.py b/libos/test/regression/test_libos.py index 0120bf49d2..5a250c83c0 100644 --- a/libos/test/regression/test_libos.py +++ b/libos/test/regression/test_libos.py @@ -1036,7 +1036,7 @@ def test_002_device_passthrough(self): self.assertIn('TEST OK', stdout) def test_003_proc_hardcoded_files(self): - stdout, stderr = self.run_binary(['proc_hardcoded_files']) + stdout, _ = self.run_binary(['proc_hardcoded_files']) self.assertIn('TEST OK', stdout) def test_010_path(self): From 91751a16e364f1c522c73469573c3628718afa0b Mon Sep 17 00:00:00 2001 From: Nirjhar Roy Date: Thu, 23 Mar 2023 12:03:39 +0000 Subject: [PATCH 7/7] fixes Signed-off-by: Nirjhar Roy --- libos/test/regression/proc_hardcoded_files.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libos/test/regression/proc_hardcoded_files.c b/libos/test/regression/proc_hardcoded_files.c index 719e1ebc8b..a131a9aa53 100644 --- a/libos/test/regression/proc_hardcoded_files.c +++ b/libos/test/regression/proc_hardcoded_files.c @@ -53,10 +53,10 @@ int main(void) { err(1, "reading file %s failed", tc[i].path); if (read_bytes != tc[i].expected_length) { errx(1, "Content length mismatch for file = %s. Expected %ld got %ld", tc[i].path, - tc[i].expected_length, read_bytes); + tc[i].expected_length, read_bytes); } if (strcmp(tc[i].expected_value, buf)) { - errx(1,"Content mismatch for file = %s. Expected %s got %s", tc[i].path, + errx(1, "Content mismatch for file = %s. Expected %s got %s", tc[i].path, tc[i].expected_value, buf); } @@ -65,7 +65,7 @@ int main(void) { if (ret < 0) err(1, "stat failed for file %s", tc[i].path); if (!S_ISREG(sb.st_mode)) - errx(1,"Unexpected type for file = %s. Expected S_ISREG", tc[i].path); + errx(1, "Unexpected type for file = %s. Expected S_ISREG", tc[i].path); ret = close(fd); if (ret < 0) err(1, "close() failed for file %s", tc[i].path);