libtimeinstate: add more tests
Check reported values to confirm that getUidCpuFreqTimes() and
getUidsCpuFreqTimes() are behaving reasonably.
Also revise RemoveUid test to create and then delete map entries for
an unused UID rather than UID 0. getUidCpuFreqTimes() is only meant to
be called when an app is uninstalled, and calling it with a UID that
has running tasks creates data inconsistencies that can cause the new
tests to fail. Since the revised test needs to directly manipulate the
BPF map in order to add a fake entry, move some definitions from
cputimeinstate.cpp into a header file to make them available for the
test.
Test: libtimeinstate_test passes
Bug: 78498733
Change-Id: I1587b1c7db870343ff863f2156b2a810d8ace915
Signed-off-by: Connor O'Brien <connoro@google.com>
diff --git a/libs/cputimeinstate/cputimeinstate.cpp b/libs/cputimeinstate/cputimeinstate.cpp
index 41cbde1..0e68e62 100644
--- a/libs/cputimeinstate/cputimeinstate.cpp
+++ b/libs/cputimeinstate/cputimeinstate.cpp
@@ -17,6 +17,7 @@
#define LOG_TAG "libtimeinstate"
#include "cputimeinstate.h"
+#include "timeinstate.h"
#include <dirent.h>
#include <errno.h>
@@ -38,23 +39,12 @@
#include <libbpf.h>
#include <log/log.h>
-#define BPF_FS_PATH "/sys/fs/bpf/"
-
using android::base::StringPrintf;
using android::base::unique_fd;
namespace android {
namespace bpf {
-struct time_key_t {
- uint32_t uid;
- uint32_t freq;
-};
-
-struct val_t {
- uint64_t ar[100];
-};
-
static std::mutex gInitializedMutex;
static bool gInitialized = false;
static uint32_t gNPolicies = 0;