diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 82045983..5a53dd6e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -14,7 +14,7 @@ # License for the specific language governing permissions and limitations under # the License. # -set(FALCO_TESTS_SOURCES test_base.cpp engine/test_token_bucket.cpp engine/test_rulesets.cpp falco/test_webserver.cpp) +set(FALCO_TESTS_SOURCES test_base.cpp engine/test_token_bucket.cpp falco/test_webserver.cpp engine/test_rulesets.cpp falco/test_profiler.cpp) set(FALCO_TESTED_LIBRARIES falco_engine) diff --git a/tests/falco/test_profiler.cpp b/tests/falco/test_profiler.cpp new file mode 100644 index 00000000..a216a9c3 --- /dev/null +++ b/tests/falco/test_profiler.cpp @@ -0,0 +1,39 @@ +/* +Copyright (C) 2020 The Falco 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 "profiler.h" +#include +#include +#include + +void profiler_test_do_work() +{ + PROFILEME(); + std::this_thread::sleep_for (std::chrono::seconds(1)); +} + +void profiler_test_do_work2() +{ + PROFILEME(); + std::this_thread::sleep_for (std::chrono::seconds(1)); +} + +TEST_CASE("profiler works", "[profiler]") +{ + alloc_chunk(); + profiler_test_do_work(); + profiler_test_do_work2(); + REQUIRE(labels.size() == 2); +} diff --git a/userspace/falco/profiler.h b/userspace/falco/profiler.h index 1c3fdacf..204424da 100644 --- a/userspace/falco/profiler.h +++ b/userspace/falco/profiler.h @@ -64,7 +64,7 @@ struct profiler { uint32_t* pd; - profiler(uint32_t label) + explicit profiler(uint32_t label) { pd = c.current; auto next = pd + 5;