Skip to content

Commit

Permalink
Attempt to create a trivial native key-value lookup test
Browse files Browse the repository at this point in the history
  • Loading branch information
andrisaar committed Feb 13, 2024
1 parent 58a843a commit 50cfd97
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions cc/native_sdk/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,13 @@ cc_library(
"@com_google_absl//absl/strings",
],
)

cc_binary(
name = "key_value_lookup",
srcs = ["key_value_lookup.cc"],
linkshared = True,
deps = [
":native_sdk",
"@com_google_absl//absl/log:check",
],
)
25 changes: 25 additions & 0 deletions cc/native_sdk/key_value_lookup.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2024 The Project Oak Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "absl/log/check.h"
#include "cc/native_sdk/native_sdk.h"

OAK_MAIN {
auto request = ::oak::functions::sdk::read_request().value();
CHECK_OK(::oak::functions::sdk::log("received request"));
auto response = ::oak::functions::sdk::storage_get_item(request).value();
CHECK_OK(::oak::functions::sdk::write_response(response));
}
1 change: 1 addition & 0 deletions oak_functions_containers_app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ tracing = "*"

[dev-dependencies]
oak_functions_test_utils = { workspace = true }
xtask = { workspace = true }
61 changes: 61 additions & 0 deletions oak_functions_containers_app/tests/native_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//
// Copyright 2024 The Project Oak Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

use std::sync::Arc;

use oak_functions_service::{logger::StandaloneLogger, lookup::LookupDataManager};
use tokio::{fs, process::Command};
use xtask::workspace_path;

#[tokio::test]
async fn test_native_handler() {
let status = Command::new("bazel")
.arg("build")
.arg("//cc/native_sdk:key_value_lookup")
.current_dir(workspace_path(&[]))
.spawn()
.expect("failed to spawn bazel")
.wait()
.await
.expect("failed to wait for bazel");
eprintln!("bazel status: {:?}", status);
assert!(status.success());

let _library =
fs::read(workspace_path(&[]).join("bazel-bin/cc/native_sdk/libkey_value_lookup.so"))
.await
.expect("failed to read test library");

let logger = Arc::new(StandaloneLogger);
let lookup_data_manager = Arc::new(LookupDataManager::new_empty(logger));
lookup_data_manager.extend_next_lookup_data(
[("key_0".as_bytes().into(), "value_0".as_bytes().into())].into_iter(),
);
lookup_data_manager.finish_next_lookup_data();

// This test fails right now because the library links in too many other libraries.
/*
let handler = NativeHandler::new_handler(&library, lookup_data_manager, None)
.expect("failed to load test library");
let response = handler
.handle_invoke(Request {
body: "key_0".as_bytes().to_vec(),
})
.expect("failed to issue invoke");
assert_eq!(StatusCode::Success, response.status);
assert_eq!("value_0".as_bytes(), response.body().unwrap());
*/
}

0 comments on commit 50cfd97

Please sign in to comment.