blob: caf492bd8eaa874fd7164f50cd791cb9b4c2ed8d [file] [log] [blame]
alexander3c798932021-03-26 21:42:19 +00001/*
2 * Copyright (c) 2021 Arm Limited. All rights reserved.
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17#include "Profiler.hpp"
18
19#include "AppContext.hpp"
20#include "TensorFlowLiteMicro.hpp"
21
22#include <catch.hpp>
23#include <iostream>
24
25
26TEST_CASE("Common: Test Profiler")
27{
28 hal_platform platform;
29 data_acq_module data_acq {};
30 data_psn_module data_psn {};
31 platform_timer timer {};
32
33 /* Initialise the HAL and platform. */
34 hal_init(&platform, &data_acq, &data_psn, &timer);
35 hal_platform_init(&platform);
36
37 /* An invalid profiler shouldn't be of much use. */
38 arm::app::Profiler profilerInvalid {nullptr, "test_invalid"};
39 REQUIRE(false == profilerInvalid.StartProfiling());
40 REQUIRE(false == profilerInvalid.StopProfiling());
41
42 arm::app::Profiler profilerValid{&platform, "test_valid"};
43 REQUIRE(true == profilerValid.StartProfiling());
44 REQUIRE(true == profilerValid.StopProfiling());
45
46 std::string strProfile = profilerValid.GetResultsAndReset();
47 REQUIRE(std::string::npos != strProfile.find("test_valid"));
48
49#if defined(CPU_PROFILE_ENABLED)
50 /* We should have milliseconds elapsed. */
51 REQUIRE(std::string::npos != strProfile.find("ms"));
52#endif /* defined(CPU_PROFILE_ENABLED) */
53
54 /* Abuse should fail: */
55 REQUIRE(false == profilerValid.StopProfiling()); /* We need to start it first. */
56 REQUIRE(true == profilerValid.StartProfiling()); /* Should be able to start it fine. */
57 REQUIRE(false == profilerValid.StartProfiling()); /* Can't restart it without resetting. */
58 profilerValid.Reset(); /* Reset. */
59 REQUIRE(true == profilerValid.StartProfiling()); /* Can start it again now. */
60 REQUIRE(true == profilerValid.StopProfiling()); /* Can start it again now. */
61}