@@ -100,16 +100,16 @@ ZTEST(usage_api, test_all_stats_usage)
100100
101101 /*
102102 * Verify that before the system idles for 2 ticks that
103- * [execution_cycles] is increasing, [total_cycles] matches
103+ * [execution_cycles] is increasing, [total_cycles + idle_cycles ] matches
104104 * [execution_cycles] and [idle_cycles] is not changing (as the
105- * system has been idle yet .
105+ * system is not going to idle during that test) .
106106 */
107107
108108 zassert_true (stats2 .execution_cycles > stats1 .execution_cycles );
109109 zassert_true (stats3 .execution_cycles > stats2 .execution_cycles );
110- zassert_true (stats1 .execution_cycles == stats1 .total_cycles );
111- zassert_true (stats2 .execution_cycles == stats2 .total_cycles );
112- zassert_true (stats3 .execution_cycles == stats3 .total_cycles );
110+ zassert_true (stats1 .execution_cycles == ( stats1 .total_cycles + stats1 . idle_cycles ) );
111+ zassert_true (stats2 .execution_cycles == ( stats2 .total_cycles + stats2 . idle_cycles ) );
112+ zassert_true (stats3 .execution_cycles == ( stats3 .total_cycles + stats3 . idle_cycles ) );
113113#ifdef CONFIG_SCHED_THREAD_USAGE_ALL
114114 zassert_true (stats1 .idle_cycles == stats2 .idle_cycles );
115115 zassert_true (stats1 .idle_cycles == stats3 .idle_cycles );
@@ -122,8 +122,8 @@ ZTEST(usage_api, test_all_stats_usage)
122122 * going idle.
123123 * 1. [current_cycles] increases.
124124 * 2. [peak_cycles] matches [current_cycles].
125- * 3. [average_cycles] is 0 (because system has not gone idle yet)
126- * 4. [current_cycles] matches [execution_cycles].
125+ * 3. [average_cycles] is 0 if system has not gone idle yet
126+ * 4. [current_cycles] matches [execution_cycles] if system has not gone idle yet
127127 */
128128
129129 zassert_true (stats2 .current_cycles > stats1 .current_cycles );
@@ -133,13 +133,19 @@ ZTEST(usage_api, test_all_stats_usage)
133133 zassert_true (stats2 .peak_cycles == stats2 .current_cycles );
134134 zassert_true (stats3 .peak_cycles == stats3 .current_cycles );
135135
136- zassert_true (stats1 .average_cycles == 0 );
137- zassert_true (stats2 .average_cycles == 0 );
138- zassert_true (stats3 .average_cycles == 0 );
139-
140- zassert_true (stats1 .current_cycles == stats1 .execution_cycles );
141- zassert_true (stats2 .current_cycles == stats2 .execution_cycles );
142- zassert_true (stats3 .current_cycles == stats3 .execution_cycles );
136+ if (stats1 .idle_cycles == 0 ) {
137+ zassert_true (stats1 .average_cycles == 0 );
138+ zassert_true (stats2 .average_cycles == 0 );
139+ zassert_true (stats3 .average_cycles == 0 );
140+
141+ zassert_true (stats1 .current_cycles == stats1 .execution_cycles );
142+ zassert_true (stats2 .current_cycles == stats2 .execution_cycles );
143+ zassert_true (stats3 .current_cycles == stats3 .execution_cycles );
144+ } else {
145+ zassert_true (stats1 .current_cycles < stats1 .execution_cycles );
146+ zassert_true (stats2 .current_cycles < stats2 .execution_cycles );
147+ zassert_true (stats3 .current_cycles < stats3 .execution_cycles );
148+ }
143149#endif
144150
145151 /*
@@ -172,7 +178,7 @@ ZTEST(usage_api, test_all_stats_usage)
172178 stats3 .peak_cycles , IDLE_EVENT_STATS_PRECISION ), NULL );
173179 zassert_true (stats4 .peak_cycles == stats5 .peak_cycles );
174180
175- zassert_true (stats4 .average_cycles > stats3 . average_cycles );
181+ zassert_true (stats4 .average_cycles > 0 );
176182 zassert_true (stats5 .average_cycles > stats4 .average_cycles );
177183#endif
178184
0 commit comments