WIP FPC-III support
[linux/fpc-iii.git] / drivers / base / power / qos-test.c
blob79fc6c4418da4514571a4a2c0d31d2694130399e
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright 2019 NXP
4 */
5 #include <kunit/test.h>
6 #include <linux/pm_qos.h>
8 /* Basic test for aggregating two "min" requests */
9 static void freq_qos_test_min(struct kunit *test)
11 struct freq_constraints qos;
12 struct freq_qos_request req1, req2;
13 int ret;
15 freq_constraints_init(&qos);
16 memset(&req1, 0, sizeof(req1));
17 memset(&req2, 0, sizeof(req2));
19 ret = freq_qos_add_request(&qos, &req1, FREQ_QOS_MIN, 1000);
20 KUNIT_EXPECT_EQ(test, ret, 1);
21 ret = freq_qos_add_request(&qos, &req2, FREQ_QOS_MIN, 2000);
22 KUNIT_EXPECT_EQ(test, ret, 1);
24 KUNIT_EXPECT_EQ(test, freq_qos_read_value(&qos, FREQ_QOS_MIN), 2000);
26 ret = freq_qos_remove_request(&req2);
27 KUNIT_EXPECT_EQ(test, ret, 1);
28 KUNIT_EXPECT_EQ(test, freq_qos_read_value(&qos, FREQ_QOS_MIN), 1000);
30 ret = freq_qos_remove_request(&req1);
31 KUNIT_EXPECT_EQ(test, ret, 1);
32 KUNIT_EXPECT_EQ(test, freq_qos_read_value(&qos, FREQ_QOS_MIN),
33 FREQ_QOS_MIN_DEFAULT_VALUE);
36 /* Test that requests for MAX_DEFAULT_VALUE have no effect */
37 static void freq_qos_test_maxdef(struct kunit *test)
39 struct freq_constraints qos;
40 struct freq_qos_request req1, req2;
41 int ret;
43 freq_constraints_init(&qos);
44 memset(&req1, 0, sizeof(req1));
45 memset(&req2, 0, sizeof(req2));
46 KUNIT_EXPECT_EQ(test, freq_qos_read_value(&qos, FREQ_QOS_MAX),
47 FREQ_QOS_MAX_DEFAULT_VALUE);
49 ret = freq_qos_add_request(&qos, &req1, FREQ_QOS_MAX,
50 FREQ_QOS_MAX_DEFAULT_VALUE);
51 KUNIT_EXPECT_EQ(test, ret, 0);
52 ret = freq_qos_add_request(&qos, &req2, FREQ_QOS_MAX,
53 FREQ_QOS_MAX_DEFAULT_VALUE);
54 KUNIT_EXPECT_EQ(test, ret, 0);
56 /* Add max 1000 */
57 ret = freq_qos_update_request(&req1, 1000);
58 KUNIT_EXPECT_EQ(test, ret, 1);
59 KUNIT_EXPECT_EQ(test, freq_qos_read_value(&qos, FREQ_QOS_MAX), 1000);
61 /* Add max 2000, no impact */
62 ret = freq_qos_update_request(&req2, 2000);
63 KUNIT_EXPECT_EQ(test, ret, 0);
64 KUNIT_EXPECT_EQ(test, freq_qos_read_value(&qos, FREQ_QOS_MAX), 1000);
66 /* Remove max 1000, new max 2000 */
67 ret = freq_qos_remove_request(&req1);
68 KUNIT_EXPECT_EQ(test, ret, 1);
69 KUNIT_EXPECT_EQ(test, freq_qos_read_value(&qos, FREQ_QOS_MAX), 2000);
73 * Test that a freq_qos_request can be added again after removal
75 * This issue was solved by commit 05ff1ba412fd ("PM: QoS: Invalidate frequency
76 * QoS requests after removal")
78 static void freq_qos_test_readd(struct kunit *test)
80 struct freq_constraints qos;
81 struct freq_qos_request req;
82 int ret;
84 freq_constraints_init(&qos);
85 memset(&req, 0, sizeof(req));
86 KUNIT_EXPECT_EQ(test, freq_qos_read_value(&qos, FREQ_QOS_MIN),
87 FREQ_QOS_MIN_DEFAULT_VALUE);
89 /* Add */
90 ret = freq_qos_add_request(&qos, &req, FREQ_QOS_MIN, 1000);
91 KUNIT_EXPECT_EQ(test, ret, 1);
92 KUNIT_EXPECT_EQ(test, freq_qos_read_value(&qos, FREQ_QOS_MIN), 1000);
94 /* Remove */
95 ret = freq_qos_remove_request(&req);
96 KUNIT_EXPECT_EQ(test, ret, 1);
97 KUNIT_EXPECT_EQ(test, freq_qos_read_value(&qos, FREQ_QOS_MIN),
98 FREQ_QOS_MIN_DEFAULT_VALUE);
100 /* Add again */
101 ret = freq_qos_add_request(&qos, &req, FREQ_QOS_MIN, 2000);
102 KUNIT_EXPECT_EQ(test, ret, 1);
103 KUNIT_EXPECT_EQ(test, freq_qos_read_value(&qos, FREQ_QOS_MIN), 2000);
106 static struct kunit_case pm_qos_test_cases[] = {
107 KUNIT_CASE(freq_qos_test_min),
108 KUNIT_CASE(freq_qos_test_maxdef),
109 KUNIT_CASE(freq_qos_test_readd),
113 static struct kunit_suite pm_qos_test_module = {
114 .name = "qos-kunit-test",
115 .test_cases = pm_qos_test_cases,
117 kunit_test_suites(&pm_qos_test_module);