diff --git a/oss-internship-2020/sapi_lodepng/README.md b/oss-internship-2020/sapi_lodepng/README.md index 8e74c10..6f30a26 100644 --- a/oss-internship-2020/sapi_lodepng/README.md +++ b/oss-internship-2020/sapi_lodepng/README.md @@ -5,7 +5,7 @@ TODO - add more functions - this readme - remove path from CMakeLists.txt -- include abseil flags for unit testing +- include abseil flags for unit testing (done, should be changed in main.cc also) - improve tests (images, generating images etc.) - clear redundant includes - check if security policy can be stricter \ No newline at end of file diff --git a/oss-internship-2020/sapi_lodepng/main_sandboxed.cc b/oss-internship-2020/sapi_lodepng/main_sandboxed.cc index 035fbe7..c489a0e 100644 --- a/oss-internship-2020/sapi_lodepng/main_sandboxed.cc +++ b/oss-internship-2020/sapi_lodepng/main_sandboxed.cc @@ -15,6 +15,7 @@ #include #include +#include #include #include "lodepng_sapi.sapi.h" @@ -23,6 +24,8 @@ ABSL_DECLARE_FLAG(string, sandbox2_danger_danger_permit_all); ABSL_DECLARE_FLAG(string, sandbox2_danger_danger_permit_all_and_log); +ABSL_FLAG(string, images_path, std::filesystem::current_path().string(), + "path to the folder containing test images"); // takes a png image (f1), decodes it and ecodes it into f2. // can be viewed as copying f1 into f2. This function has a basic usage @@ -132,6 +135,7 @@ bool cmp_images32(SapiLodepngSandbox &sandbox, LodepngApi &api, return false; } } + return true; } @@ -167,13 +171,9 @@ int main(int argc, char *argv[]) { gflags::ParseCommandLineFlags(&argc, &argv, true); absl::Status ret; - if (argc != 2) { - std::cout << "usage: " << basename(argv[0]) << " images_folder_path" - << std::endl; - return 1; - } + std::string images_path(absl::GetFlag(FLAGS_images_path)); - std::string images_path(argv[1]); + std::cout << "flag = " << images_path << std::endl; SapiLodepngSandbox sandbox(images_path); ret = sandbox.Init(); diff --git a/oss-internship-2020/sapi_lodepng/main_unit_test.cc b/oss-internship-2020/sapi_lodepng/main_unit_test.cc index a3d02dd..c9b84ec 100644 --- a/oss-internship-2020/sapi_lodepng/main_unit_test.cc +++ b/oss-internship-2020/sapi_lodepng/main_unit_test.cc @@ -1,14 +1,38 @@ +// Copyright 2020 Google LLC +// +// 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 + +#include + +#include "gmock/gmock.h" #include "gtest/gtest.h" #include "lodepng_sapi.sapi.h" #include "sandbox.h" -#include -#include "gmock/gmock.h" -// #include "gtest/gtest.h" +#include "sandboxed_api/util/flag.h" + +// defining the flag does not work as intended (always has the default value) +// ignore for now +ABSL_FLAG(string, images_path, std::filesystem::current_path().string(), + "path to the folder containing test images"); namespace { TEST(addition, basic) { - EXPECT_EQ(2, 1 + 1); + EXPECT_EQ(2, 1 + 1); +// std::cout << "flag=" << std::string(absl::GetFlag(FLAGS_images_path)) +// << std::endl; } -} // namespace \ No newline at end of file +} // namespace \ No newline at end of file diff --git a/oss-internship-2020/sapi_lodepng/sandbox.h b/oss-internship-2020/sapi_lodepng/sandbox.h index e85ffaa..4c4e571 100644 --- a/oss-internship-2020/sapi_lodepng/sandbox.h +++ b/oss-internship-2020/sapi_lodepng/sandbox.h @@ -15,19 +15,23 @@ #ifndef SAPI_LODEPNG_SANDBOX_H_ #define SAPI_LODEPNG_SANDBOX_H_ -#include "lodepng_sapi.sapi.h" -#include #include +#include + +#include "lodepng_sapi.sapi.h" // TODO change this with the location on your own machine -#define base_path "/usr/local/google/home/amedar/internship/sandboxed-api/oss-internship-2020/sapi_lodepng/" +#define base_path \ + "/usr/local/google/home/amedar/internship/sandboxed-api/" \ + "oss-internship-2020/sapi_lodepng/" class SapiLodepngSandbox : public LodepngSandbox { public: - SapiLodepngSandbox(const std::string &images_path): images_path_(images_path) {} + SapiLodepngSandbox(const std::string &images_path) + : images_path_(images_path) {} - std::unique_ptr ModifyPolicy( - sandbox2::PolicyBuilder*) override { + std::unique_ptr ModifyPolicy( + sandbox2::PolicyBuilder *) override { return sandbox2::PolicyBuilder() .AllowStaticStartup() .AllowRead() @@ -38,17 +42,18 @@ class SapiLodepngSandbox : public LodepngSandbox { .AllowStat() // .AddFile("/usr/local/google/home/amedar/sapi_lodepng/test_images/test1.png") .AddDirectory(images_path_, /*is_ro=*/false) - // .AddDirectory("/usr/local/google/home/amedar/sapi_lodepng/test_images/out", /*is_ro=*/false) + // .AddDirectory("/usr/local/google/home/amedar/sapi_lodepng/test_images/out", + // /*is_ro=*/false) .AllowSyscalls({ - __NR_futex, - __NR_lseek, - __NR_close, + __NR_futex, + __NR_lseek, + __NR_close, }) .BuildOrDie(); - } - + } + private: std::string images_path_; }; -#endif // SAPI_LODEPNG_SANDBOX_H_ \ No newline at end of file +#endif // SAPI_LODEPNG_SANDBOX_H_ \ No newline at end of file