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 <[email protected]>
  • Loading branch information
g2flyer committed Jun 11, 2024
1 parent 7100d5d commit 4201693
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
51 changes: 48 additions & 3 deletions libos/test/regression/pf_rollback.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
#include <assert.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>

#include "common.h"
#include "rw_file.h"
Expand All @@ -28,6 +31,7 @@ static_assert(sizeof(message1) != sizeof(message2), "the messages should have di

/* TODO: eventually remove below copy/paste/extract heap
static int create_file(const char* path, const char* str, size_t len) {
int fd = open(path, O_RDWR | O_CREAT | O_TRUNC, 0600);
if (fd < 0)
err(1, "open %s", path);
Expand Down Expand Up @@ -58,24 +62,65 @@ static void adversary_reset_file(const char* path) {}
static void adversary_delete_file(const char* path) {}
#pragma GCC pop_options

#define test_report(result) printf("%s: %s\n", result, __func__)

static void test_open_pre_existing(const char* path1, const char* path2) {
int fd = open(path1, O_RDWR);
if (fd < 0) {
test_report("OK");
} else {
test_report("FAIL");
}
}

// DEBUG
static void test_test(const char* path1, const char* path2) {
adversary_save_file(path1);
adversary_reset_file(path1);
adversary_delete_file(path1);
adversary_delete_file(path2);
test_report("OK");
}

static void run_tests(const char* path1, const char* path2) {
test_open_pre_existing(path1, path2); /* this must be first test!! */
test_test(path1, path2); // DEBUG:
}

int main(int argc, char* argv[]) {
setbuf(stdout, NULL);
setbuf(stderr, NULL);

if (argc != 3)
errx(1, "Usage: %s <file1> <file2>", argv[0]);
errx(1, "Usage: %s <file1> <file2> (with file1 assumed to be pre-created)", argv[0]);

const char* path1 = argv[1];
const char* path2 = argv[2];

test_test(path1, path2);
/* all tests started in process leader */
run_tests(path1, path2);

// TODO: also add variants of test with fork: all tests in child and split leader/child
// test. However, this will require adaption of the gdb file that the right process is follosed.
// In particular the second seot of tests might be problematic?
// /* all tests started in child */
// int child_pid = fork();

// if (child_pid == 0) { /* child, runs tests*/
// run_tests(path1, path2);
// return 0; /* we ignore all errors ... */
// } else if (child_pid > 0) { /* parent just waits for child ter return */
// int status;
// pid_t pid = wait(&status);
// if (pid < 0) {
// perror("wait failed");
// return 1;
// }
// } else { /* error */
// perror("fork failed");
// return 1;
// }

printf("TEST OK\n");
return 0;
exit(0);
}
6 changes: 6 additions & 0 deletions libos/test/regression/test_libos.py
Original file line number Diff line number Diff line change
Expand Up @@ -1385,6 +1385,7 @@ def test_020_gdb_fork_and_access_file_bug(self):
with open('fork_and_access_file_testfile', 'w') as f:
f.write('fork_and_access_file_testfile')

# TODO: move me to fs so i can benefit from plumbug from TC_50_EncryptedFiles
def test_030_gdb_pf_rollback(self):
# To run this test manually, use:
# GDB=1 GDB_SCRIPT=pf_rollback.gdb gramine-[sgx|direct] pf_rollback <file1> <file2>
Expand All @@ -1393,10 +1394,15 @@ def test_030_gdb_pf_rollback(self):
try:
file1='/tmp_enc/pm_strict/file1'
file2='/tmp_enc/pm_strict/file2'
# TODO (MST): pre-create a version of file1
stdout, _ = self.run_gdb(['pf_rollback', file1, file2], 'pf_rollback.gdb')
# TODO (MST): This test is not yet implemented.
# - loop for /tmp_enc/pm_strict, /tmp_enc/pm_non_strict, /tmp_enc/pm_none
# - define expected sequence for each test

# - test_open_pre_existing
self.assertIn('FAIL: test_open_pre_existing', stdout)
# - test_test
self.assertIn('OK: test_test in adversary_save_file', stdout)
self.assertIn('OK: test_test in adversary_reset_file', stdout)
self.assertIn(f'OK: test_test in adversary_delete_file({file1})', stdout)
Expand Down

0 comments on commit 4201693

Please sign in to comment.