Skip to content

Commit

Permalink
fixup! [LibOS] Test-cases for SPLRB (2)
Browse files Browse the repository at this point in the history
Signed-off-by: g2flyer <michael.steiner@intel.com>
  • Loading branch information
g2flyer committed Jul 9, 2024
1 parent 3d5f8c6 commit 1e77fa2
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 7 deletions.
15 changes: 11 additions & 4 deletions libos/test/fs/gdb_helper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import gdb
import re
import shutil

def adversary_do(cmd):
# extract interesting info from context
Expand All @@ -9,10 +8,18 @@ def adversary_do(cmd):
internal_path=gdb.selected_frame().read_var('path').string()
external_path=re.sub(r'/tmp/enc_input/', './tmp/enc_input/', internal_path)
external_path_saved=external_path+"._saved_"
try:
internal_path2=gdb.selected_frame().read_var('path2').string()
external_path2=re.sub(r'/tmp/enc_input/', './tmp/enc_input/', internal_path2)
opt_arg=f",{internal_path2}"
except ValueError:
internal_path2=""
external_path2=""
opt_arg=""

# execute and report result for pytest digestion
try:
cmd(external_path, external_path_saved)
print(f"OK: {test_function} in {operation}({internal_path})")
cmd(external_path, external_path_saved, external_path2)
print(f"OK: {test_function} in {operation}({internal_path}{opt_arg}])")
except:
print(f"FAIL: {test_function} in {operation}({internal_path})")
print(f"FAIL: {test_function} in {operation}({internal_path}{opt_arg})")
78 changes: 78 additions & 0 deletions libos/test/fs/pf_rollback.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ static void adversary_save_file(const char* path) {
static void adversary_reset_file(const char* path) {
__UNUSED(path); /* neeed in gdb though! */
}
static void adversary_reset_file_as(const char* path, const char* path2) {
__UNUSED(path); /* neeed in gdb though! */
__UNUSED(path2); /* neeed in gdb though! */
}
static void adversary_delete_file(const char* path) {
__UNUSED(path); /* neeed in gdb though! */
/* NOTE: as of 2024-06-14 this attack will never work as the dcache never
Expand Down Expand Up @@ -453,6 +457,77 @@ static void test_rollback_after_rename_non_exclusive(const char* work_dir) {
}
}

static void test_rename_rollback_after_rename_base(const char* path1, const char* path2) {
int fd = open(path1, O_RDWR | O_EXCL | O_CREAT, 0600);
if (fd < 0) {
err(1, "open %s", path1);
}

ssize_t n = write(fd, message, message_len);
if (n < 0)
err(1, "write %s", path1);
if ((size_t)n != message_len)
errx(1, "written less bytes than expected into %s", path1);

if (close(fd) != 0)
err(1, "close %s", path1);

adversary_save_file(path1);

if (rename(path1, path2) != 0)
err(1, "rename");

adversary_reset_file_as(path1, path2);
}

static void test_rename_rollback_after_rename_rw(const char* work_dir) {
char path1[MAX_FILE_NAME_SIZE];
snprintf(path1, MAX_FILE_NAME_SIZE, "%s/%s", work_dir, __func__);
char path2[MAX_FILE_NAME_SIZE];
snprintf(path2, MAX_FILE_NAME_SIZE, "%s/%s.renamed", work_dir, __func__);

test_rename_rollback_after_rename_base(path1, path2);

int fd = open(path2, O_RDWR);
if (fd < 0) {
test_report("OK");
} else {
test_report("FAIL");
}
}

static void test_rename_rollback_after_rename_exclusive(const char* work_dir) {
char path1[MAX_FILE_NAME_SIZE];
snprintf(path1, MAX_FILE_NAME_SIZE, "%s/%s", work_dir, __func__);
char path2[MAX_FILE_NAME_SIZE];
snprintf(path2, MAX_FILE_NAME_SIZE, "%s/%s.renamed", work_dir, __func__);

test_rename_rollback_after_rename_base(path1, path2);

int fd = open(path2, O_RDWR | O_CREAT | O_EXCL, 0600);
if (fd < 0) {
test_report("OK");
} else {
test_report("FAIL");
}
}

static void test_rename_rollback_after_rename_non_exclusive(const char* work_dir) {
char path1[MAX_FILE_NAME_SIZE];
snprintf(path1, MAX_FILE_NAME_SIZE, "%s/%s", work_dir, __func__);
char path2[MAX_FILE_NAME_SIZE];
snprintf(path2, MAX_FILE_NAME_SIZE, "%s/%s.renamed", work_dir, __func__);

test_rename_rollback_after_rename_base(path1, path2);

int fd = open(path2, O_RDWR | O_CREAT, 0600);
if (fd < 0) {
test_report("OK");
} else {
test_report("FAIL");
}
}

static void test_delete_rollback_after_rename_base(const char* path1, const char* path2) {
int fd = open(path1, O_RDWR | O_EXCL | O_CREAT, 0600);
if (fd < 0) {
Expand Down Expand Up @@ -612,6 +687,9 @@ static void run_tests(const char* work_dir, const char* input_file) {
test_rollback_after_rename_rw(work_dir);
test_rollback_after_rename_exclusive(work_dir);
test_rollback_after_rename_non_exclusive(work_dir);
test_rename_rollback_after_rename_rw(work_dir);
test_rename_rollback_after_rename_exclusive(work_dir);
test_rename_rollback_after_rename_non_exclusive(work_dir);
test_delete_rollback_after_rename_rw(work_dir);
test_delete_rollback_after_rename_exclusive(work_dir);
test_delete_rollback_after_rename_non_exclusive(work_dir);
Expand Down
18 changes: 15 additions & 3 deletions libos/test/fs/pf_rollback.gdb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ commands
python
from shutil import copyfile
from gdb_helper import adversary_do
adversary_do(lambda external_path, external_path_saved: copyfile(external_path, external_path_saved))
adversary_do(lambda external_path, external_path_saved, external_path2: copyfile(external_path, external_path_saved))
end

continue
Expand All @@ -27,7 +27,19 @@ commands
python
from shutil import move
from gdb_helper import adversary_do
adversary_do(lambda external_path, external_path_saved: move(external_path_saved, external_path))
adversary_do(lambda external_path, external_path_saved, external_path2: move(external_path_saved, external_path))
end

continue
end


break adversary_reset_file_as
commands
python
from shutil import move
from gdb_helper import adversary_do
adversary_do(lambda external_path, external_path_saved, external_path2: move(external_path_saved, external_path2))
end

continue
Expand All @@ -39,7 +51,7 @@ commands
python
from pathlib import Path
from gdb_helper import adversary_do
adversary_do(lambda external_path, external_path_saved: Path.unlink(external_path))
adversary_do(lambda external_path, external_path_saved, external_path2: Path.unlink(external_path))
end

continue
Expand Down
3 changes: 3 additions & 0 deletions libos/test/fs/test_enc.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@ def test_600_gdb_pf_rollback(self):
'test_rollback_after_rename_rw': [ 'OK', 'OK', 'FAIL' ],
'test_rollback_after_rename_exclusive': [ 'OK', 'OK', 'OK' ],
'test_rollback_after_rename_non_exclusive': [ 'OK', 'OK', 'FAIL' ],
'test_rename_rollback_after_rename_rw': [ 'OK', 'OK', 'OK' ],
'test_rename_rollback_after_rename_exclusive': [ 'OK', 'OK', 'OK' ],
'test_rename_rollback_after_rename_non_exclusive': [ 'OK', 'OK', 'OK' ],
'test_delete_rollback_after_rename_rw': [ 'OK', 'OK', 'OK' ],
'test_delete_rollback_after_rename_exclusive': [ 'OK', 'OK', 'OK' ],
'test_delete_rollback_after_rename_non_exclusive': [ 'OK', 'OK', 'OK' ],
Expand Down

0 comments on commit 1e77fa2

Please sign in to comment.