Skip to content

Commit

Permalink
Add some tests and run them in CI.
Browse files Browse the repository at this point in the history
Also fix a bug with demangling libcalls and fix another issue with
trieste's use of snmalloc.
  • Loading branch information
davidchisnall committed Mar 5, 2024
1 parent 12d58fd commit 7e7f178
Show file tree
Hide file tree
Showing 14 changed files with 46 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
jobs:
build:
strategy:
fail-fast: false
matrix:
config:
- {
Expand Down Expand Up @@ -60,3 +61,7 @@ jobs:
working-directory: ${{github.workspace}}/build
# Build your program with the given configuration
run: NINJA_STATUS="%p [%f:%s/%t] %o/s, %es" && ninja
- name: Test
working-directory: ${{github.workspace}}/build
# Build your program with the given configuration
run: ctest -j4 --output-on-failure
2 changes: 1 addition & 1 deletion Tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
message(STATUS "Adding tests")
file(GLOB TESTS "*.query" CONFIGURE_DEPENDS "*.query")
file(GLOB TESTS CONFIGURE_DEPENDS "*.query")

message(STATUS "Tests: ${TESTS}")

Expand Down
3 changes: 3 additions & 0 deletions Tests/compartment_check.query
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Check that we can demangle a library export correctly.
--board inputs/sail.json -j inputs/test-suite.json -q 'data.compartment.compartment_call_allow_list("allocator_test", `test_allocator\(\)`, {"test_runner"})'

1 change: 1 addition & 0 deletions Tests/compartment_check.query.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
true
4 changes: 4 additions & 0 deletions Tests/demangle_compartment_call.query
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Check that we can demangle a compartment export correctly.
--board inputs/sail.json -j inputs/test-suite.json -q 'export_entry_demangle("alloc", input.compartments.allocator.exports[6].export_symbol)'


1 change: 1 addition & 0 deletions Tests/demangle_compartment_call.query.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"heap_free(SObjStruct*, void*)"
3 changes: 3 additions & 0 deletions Tests/demangle_libcall.query
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Check that we can demangle a library export correctly.
--board inputs/sail.json -j inputs/test-suite.json -q 'export_entry_demangle("token_library", input.compartments.token_library.exports[0].export_symbol)'

1 change: 1 addition & 0 deletions Tests/demangle_libcall.query.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"token_obj_unseal(SKeyStruct*, SObjStruct*)"
3 changes: 3 additions & 0 deletions Tests/mmio_check.query
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Check that we can demangle a library export correctly.
--board inputs/sail.json -j inputs/test-suite.json -q 'data.compartment.mmio_allow_list("clint", {"scheduler"})'

1 change: 1 addition & 0 deletions Tests/mmio_check.query.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
true
3 changes: 3 additions & 0 deletions Tests/sum_quotas.query
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Check that we can demangle a library export correctly.
--board inputs/sail.json -j inputs/test-suite.json -q 'sum([ data.rtos.decode_allocator_capability(c).quota | c = input.compartments[_].imports[_] ; data.rtos.is_allocator_capability(c) ])'

1 change: 1 addition & 0 deletions Tests/sum_quotas.query.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1070080
2 changes: 1 addition & 1 deletion Tests/testexpected.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
set -e
cd $(dirname $(realpath $0))
cd "$(dirname $(readlink -f -- "$0"))"
/bin/sh -c "$1 $(grep -v '^#' $2)" | diff - $2.expected
25 changes: 18 additions & 7 deletions audit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,23 +101,34 @@ namespace
}
auto string = get_string(exportName);
auto compartmentNameString = get_string(compartmentName);
const std::string_view LibraryExportPrefix = "__library_export_libcalls";
const std::string_view ExportPrefix = "__export_";
if (!string.starts_with(ExportPrefix))
if (string.starts_with(LibraryExportPrefix))
{
return scalar(false);
string = string.substr(LibraryExportPrefix.size());
}
string = string.substr(ExportPrefix.size());
if (!string.starts_with(compartmentNameString))
else
{
return scalar(false);
if (!string.starts_with(ExportPrefix))
{
return scalar(false);
}
string = string.substr(ExportPrefix.size());
if (!string.starts_with(compartmentNameString))
{
return scalar(false);
}
string = string.substr(compartmentNameString.size());
}
string = string.substr(compartmentNameString.size());
if (!string.starts_with("_"))
{
return scalar(false);
}
string = string.substr(1);
size_t bufferSize = 128;
// The way that rego-cpp exposes snmalloc can cause the realloc here to
// crash. Try to allocate a buffer that's large enough that we don't
// care.
size_t bufferSize = strlen(string.c_str()) * 8;
char *buffer = static_cast<char *>(malloc(bufferSize));
int error;
buffer =
Expand Down

0 comments on commit 7e7f178

Please sign in to comment.