summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike McTernan <mikemcternan@google.com>2024-02-15 11:59:30 +0000
committerMike McTernan <mikemcternan@google.com>2024-02-15 12:02:56 +0000
commit5f0034fa5d633846222b88f84009bc2d2e867a4f (patch)
tree35945b890dd3e90da2c8b6b80022e53fada59153
parent3a2e86e6df1f1575e3e641f1e0f54a08926519f0 (diff)
downloadsample-main-16k.tar.gz
trusty: timertest: add stress test modemain-16k
Add a long-running stress test that repeatedly sleeps for a short period. This allows other system aspects to be tested while the Trusty timers are firing. Bug: 325424592 Test: build.py qemu-generic-arm64-test-debug --test com.android.timer-unittest Change-Id: I1443db70a671fee9df5dbdf1c9c6d292b83e8817
-rw-r--r--timer/timer_app.c55
1 files changed, 50 insertions, 5 deletions
diff --git a/timer/timer_app.c b/timer/timer_app.c
index 2df4a05..307feb4 100644
--- a/timer/timer_app.c
+++ b/timer/timer_app.c
@@ -37,10 +37,13 @@ struct timer_unittest {
bool loop;
};
+/* Timer constants (nanoseconds) */
+#define ONE_US (1000ULL)
+#define ONE_MS (1000ULL * ONE_US)
+#define ONE_S (1000ULL * ONE_MS)
+
#define TIMER_TEST_NOP_LOOP_COUNT (100000000)
-#define ONE_MS (1000 * 1000ULL)
#define TIMER_TEST_MS_SLEEP_LOOP_COUNT (1000)
-#define ONE_S (1000 * ONE_MS)
static void check_timestamps(int64_t t1,
int64_t delta_min,
@@ -94,7 +97,42 @@ static bool timer_test(struct unittest* test) {
bool passed;
do {
- passed = RUN_ALL_TESTS();
+ passed = RUN_ALL_SUITE_TESTS("TimerTest");
+ } while (timer_test->loop);
+
+ return passed;
+}
+
+/* Repeatedly expire a 1 micro-second timer for about 60 seconds */
+TEST(TimerStressTest, NanoSleepStressTestSixtySeconds) {
+ int64_t end = 0, now = 0;
+ int i, remaining, last_remaining = 0;
+
+ trusty_gettime(0, &now);
+ end = now + (ONE_S * 60);
+
+ while (now < end) {
+ remaining = (end - now) / ONE_S;
+ if (remaining != last_remaining) {
+ trusty_unittest_printf("[ INFO ] remaining %ds\n", remaining);
+ last_remaining = remaining;
+ }
+
+ for (i = 0; i < 8192; i++) {
+ trusty_nanosleep(0, 0, ONE_US);
+ }
+
+ trusty_gettime(0, &now);
+ }
+}
+
+static bool timer_stress_test(struct unittest* test) {
+ struct timer_unittest* timer_test =
+ containerof(test, struct timer_unittest, unittest);
+ bool passed;
+
+ do {
+ passed = RUN_ALL_SUITE_TESTS("TimerStressTest");
} while (timer_test->loop);
return passed;
@@ -103,7 +141,7 @@ static bool timer_test(struct unittest* test) {
#define PORT_BASE "com.android.timer-unittest"
int main(void) {
- static struct timer_unittest timer_unittests[2] = {
+ static struct timer_unittest timer_unittests[] = {
{
.unittest =
{
@@ -120,7 +158,14 @@ int main(void) {
},
.loop = true,
},
- };
+ {
+ .unittest =
+ {
+ .port_name = PORT_BASE ".stress",
+ .run_test = timer_stress_test,
+ },
+ .loop = false,
+ }};
static struct unittest* unittests[countof(timer_unittests)];
for (size_t i = 0; i < countof(timer_unittests); i++) {